Cookbook
USD to EUR, priced on the pools
Fund a USD holding, price the conversion on the pools, route EUR to an IBAN on sepa-inst or to a PATH address, and read the execution and the signed receipt.
Needs one test key with the scopes accounts, router, liquidity and settlement.
USD held in an Omni Account is paid out as EUR to an IBAN on sepa-inst. The pools give a price
first; the router then quotes the route, with its guarantee level, and executes it once.
1. Open an Omni Account and fund it
const account = await pg.accounts.openOmni(
{ holder: { name: 'Acme Treasury' }, holdings: [{ kind: 'virtual_account', currency: 'USD' }] },
{ idempotencyKey: 'open-acme-treasury' },
);
const usd = account.holdings[0];
// Test mode only: credits the holding without a deposit.
await pg.accounts.fund(usd.id, { value: '5000.00', asset: 'USD' }, 'sandbox funding 1');A route from an Omni Account draws on its holding in the asset sent. A holding that does not hold
the amount gives a route that answers failed (see below).
2. Price the conversion on the pools
const price = await pg.liquidity.poolQuote({
from: 'USD',
to: 'EUR',
amount: { value: '1000.00', asset: 'USD' },
deliver_on: 'sepa-inst',
});
// price.rate, price.fee_bps, price.buy: { value, asset: 'EUR' }A pool quote reserves nothing. It states the rate, the fee in basis points and what the pools would deliver.
3. Quote the route
const intent = {
amount: { value: '1000.00', asset: 'USD' },
source: { omni_account: account.id },
destination: { network: 'sepa-inst', identifier: 'DE89370400440532013000', holder: 'Example Treasury Ltd' },
deliver: { asset: 'EUR' },
reference: 'invoice-2041',
};
const quote = await pg.router.quote(intent);{
"id": "qt_…",
"kind": "router.quote",
"route": {
"legs": [
{ "kind": "convert", "provider": "…", "in": { "value": "…", "asset": "USD" }, "out": { "value": "…", "asset": "EUR" } },
{ "kind": "payout", "network": "sepa-inst", "in": { "value": "…", "asset": "EUR" } }
],
"send": { "value": "1000.00", "asset": "USD" },
"deliver": { "value": "…", "asset": "EUR" },
"fees": { "value": "…", "asset": "USD" }
},
"alternatives": [{ "id": "cand_…", "deliver": { "value": "…", "asset": "EUR" } }],
"guarantee": "conditional",
"expires_at": "…",
"mode": "test"
}| Field | Read it for |
|---|---|
route.legs | How the value moves. The convert leg names who converts in provider: the pools (liquid-pools) or a liquidity provider |
route.deliver | What the beneficiary receives |
alternatives | The other routes that were considered |
guarantee | What the route promises; see guarantee levels |
expires_at | The quote executes once, before this instant |
intent.router defaults to path-flash-1.0: the router of Path Global, powered by the decision
model of the same name, chooses the route. The pool quote of step 2 is a price, not a reservation; the quote of step 3 is the
firm one.
4. Execute it once
const route = await pg.router.execute(quote.id, { idempotencyKey: 'pay-invoice-2041' });The same Idempotency-Key with the same body answers the same route, with
PathGlobal-Idempotent-Replay: true. A second execution of the quote under another key answers
409 pathglobal.router.quote_already_used.
5. Follow it to a final status
const final = await until(() => pg.router.get(route.id), (r) => r.status !== 'executing');
if (final.status !== 'settled') {
// failed, refund_required or review: read final.failure and the SETTL
}A route answers executing and then settled or failed. A route can also be settled at once.
6. Read the SETTL, the execution and the receipt
const settl = await pg.settlement.get(final.settlement!); // state: 'closed'
const execution = await pg.settlement.execution(settl.execution);
const receipt = await pg.settlement.receipt(final.receipt!);| Object | What it says |
|---|---|
| SETTL | The settlement of the route, its history of states and its legs with their rail references |
| Execution | type: "payment", its mode, its legs (pay_in, exchange, pay_out) with their states, and holding: where value still sits. Empty once settled |
| Receipt | What was sent and received, the legs, the destination and guarantee, signed by Path Global |
pg.settlement.find('invoice-2041') finds the SETTL by the reference of the intent. Verify the
signature of the receipt with verifySigned(receipt) of @pathglobal/sdk, against the keys of
GET /.well-known/path-keys.
7. Pay a PATH address instead
The same USD pays a PATH address. path:4a91c2f7e8d3 is a
fixture payee of test mode that accepts EUR on
sepa-inst, up to 10 000 EUR a payment:
const toAddress = await pg.router.route(
{ ...intent, destination: { path: 'path:4a91c2f7e8d3' }, reference: 'invoice-2042' },
{ idempotencyKey: 'pay-invoice-2042' },
);
// toAddress.quoted.route.destination.capability: { rail: 'sepa-inst', asset_type: 'fiat', asset_code: 'EUR' }
// toAddress.path_instruction: the payment instruction of the payee's member
// toAddress.payer_receipt: { reference: '…', status: 'pending' } once the SETTL existsPath Global resolves the address at its holding member and pays the instruction that member issues;
the quote and the route name the address and the capability, never the IBAN credited. The route has
the settlement receipt of step 6 and a payer path.receipt
(The receipts of a route). An amount above
10 000 EUR answers 422 pathglobal.router.no_route.
When it does not go through
| Case | Answer |
|---|---|
The quote is executed past expires_at | 409 pathglobal.router.quote_expired. Quote again |
| The quote was executed already | 409 pathglobal.router.quote_already_used |
| No route delivers the amount | 422 pathglobal.router.no_route on the quote |
| A PATH address that does not resolve | 404 pathglobal.router.payee_unknown on the quote |
| The pools do not fill the amount | pathglobal.liquidity.no_liquidity on the pool quote |
| The holding does not hold the amount | The route answers status: "failed" with failure.code pathglobal.accounts.insufficient_funds. Nothing moves |
const short = await pg.router.route({ ...intent, amount: { value: '9000.00', asset: 'USD' }, reference: 'invoice-2045' });
// short.status === 'failed'
// short.failure?.code === 'pathglobal.accounts.insufficient_funds'Sandbox outcomes
A word of the payment reference gives the order an outcome at the sandbox bank (see the
sandbox). The word applies to an order the
sandbox bank carries; a pay-out that the converting provider makes itself takes no keyword. A USD
pay-out to a USD account on fednow goes through the sandbox bank:
const fednow = { network: 'fednow', identifier: '<routing number>-<account number>', holder: 'Example Treasury Ltd' };
const payout = (reference: string) =>
pg.router.route({ amount: { value: '100.00', asset: 'USD' }, source: { omni_account: account.id }, destination: fednow, deliver: { asset: 'USD' }, reference });
const refused = await payout('payout-77 fail');
const doubtful = await payout('payout-78 unknown');
const later = await payout('payout-79 slow');| Reference | Route | SETTL and execution |
|---|---|---|
… fail | refund_required | SETTL refund_required. The value stays on the holding: execution.holding names it |
… unknown | executing | SETTL and execution in_doubt. The hold stays and no second order is sent. Path Global decides the execution under an approval |
… slow | executing, then settled | Final once the order is final |
refund_required is not a terminal state of the SETTL; closed and expired are.