SDK reference
Treasury
pg.treasury — positions and the treasury view, policies, transfers under dual control, expected fundings, the allowlist, reconciliation, inbound items, refuel cycles and the ledger.
pg.treasury is an operator product: it acts on the positions of the deployment, not on the
caller's objects. Every call needs the treasury scope; a decision needs treasury_approve as well.
Exercise it in the sandbox with test keys. In live mode it is available to a key whose agreement
includes operator access, and every request carries the signature of a registered operator
(operator).
A position is read by the ledger account of its physical account,
nostro:-:<physical account>:<asset>. Pass it as it is; the client encodes it.
Positions and reads
| Call | Returns | |
|---|---|---|
positions(filter?) | TreasuryPosition[] | Filter { network?, asset?, purpose?, tier?, partner? }. purpose is safeguarding, liquidity, settlement or gas; tier is hot, warm or cold |
position(account) | TreasuryPosition | One position: balance, reserved, pending_in, pending_out, in_transit_to, available, its band and status |
view() | TreasuryView | The treasury by asset, by network and by partner, with the journal head { seq, hash } |
fx() | OpenPosition[] | The open position per asset |
safeguarding() | SafeguardingState[] | The safeguarding gap per asset, with its policy |
accounts() | NetworkAccount[] | The physical accounts, each shown by its mask |
Client funds are held on segregated safeguarding accounts.
Policies
| Call | Returns | |
|---|---|---|
policy(networkAccount) | TreasuryPolicy | The policy of a physical account, by its id |
setPolicy(networkAccount, policy) | TreasuryPolicy | ApprovalWaiting | Writes a policy (TreasuryPolicyRequest) under an approval policy_change |
safeguard(asset) | SafeguardPolicy | The safeguard policy of an asset |
setSafeguard(asset, { gap_trigger, gap_max, margin_bps }) | SafeguardPolicy | ApprovalWaiting | Writes it under an approval policy_change |
A policy carries a band (min, target, max) and its bounds; the values are set per deployment.
The first call requests the approval; the same call, made again once the approval is approved,
writes the policy.
Transfers
| Call | Returns | |
|---|---|---|
proposeTransfer(input) | TreasuryTransfer | Proposes a transfer. It answers 202 in pending_approval, naming its approval, and executes once approved |
transfers(filter?) | TreasuryTransfer[] | Filter { state?, type?, asset? } |
transfer(id) | TreasuryTransfer | One transfer |
cancelTransfer(id) | TreasuryTransfer | Cancels a transfer that has not left |
resolveTransfer(id, resolution, approval) | TreasuryTransfer | Needs treasury_approve. Ends a blocked transfer under an approval instruction_resolve: { decision: 'arrived' | 'returned', rail_reference } or { decision: 'written_off' } |
proposeTransfer takes a TransferRequest: type, from, to, amount, reason, and advice
when it follows an advice. from and to are ledger accounts,
or allowlist entries for a funding and a defunding.
| Types | rebalance, refuel, sweep, funding, defunding, conversion, fees, gas |
| States | proposed, pending_approval, approved, scheduled, executing, in_transit, in_doubt, blocked, settled, failed, rejected, cancelled |
// Two test keys of two people: the maker carries `treasury`,
// the checker `risk` and `treasury_approve`.
const [from, to] = (await maker.treasury.positions({ purpose: 'liquidity', asset: 'USD' }))
.filter((p) => p.tier === 'hot' && p.status === 'open');
const transfer = await maker.treasury.proposeTransfer({
type: 'rebalance',
from: from!.account,
to: to!.account,
amount: { value: '5000.00', asset: 'USD' },
reason: 'rebalance before the cut-off',
});
transfer.state; // 'pending_approval'
transfer.approval; // the approval it waits for
await checker.risk.approve(transfer.approval!);
// then: approved, executing, in_transit, settledExpected fundings and the allowlist
| Call | Returns | |
|---|---|---|
expectFunding(input) | ExpectedFunding | ApprovalWaiting | Declares a funding that will arrive from outside, under an approval funding_expect, as setPolicy |
fundings(filter?) | ExpectedFunding[] | Filter { state?, account? }; a funding is expected, matched, expired or cancelled |
allowlist() | AllowlistEntry[] | The destinations value may leave to, each counted from its not_before |
allow(destination) | { approval: Approval; entry?: AllowlistEntry } | Adds a destination under an approval allowlist_add; entry is present once it is added |
expectFunding takes { account, amount, reference, credit_to }, where credit_to is
{ house: true }, { pool, owner } or { collateral }. A reference awaited or booked on the
account is 409 pathglobal.core.reference_taken.
allow takes { account } for an own ledger account, or { network, identifier, holder? } for an
external account. An external entry is shown by its mask: the identifier is not kept in clear.
Reconciliation and inbound items
| Call | Returns | |
|---|---|---|
reconciliations(filter?) | Reconciliation[] | Filter { account?, state? }; a reconciliation is matched, break or resolved |
reconcile(account?) | Reconciliation[] | Reconciles one physical account, or all of them |
resolveBreak(id, approval) | Reconciliation | Needs treasury_approve. Resolves a break under an approval break_resolve |
inbound() | InboundItem[] | The inbound items that wait for a decision |
returnInbound(id) | InboundItem | Returns an item to its sender |
escalateInbound(id, approval, owner?) | InboundItem | Needs treasury_approve. Decides an item under an approval |
A notification alone books nothing.
Refuel cycles
| Call | Returns | |
|---|---|---|
refuelCycles() | RefuelCycle[] | The refuel cycles, the latest first |
currentRefuelCycle() | RefuelCycle | The open cycle that started last |
refuelCycle(id) | RefuelCycle | One cycle, rf_YYYYMMDD or rf_YYYYMMDD_nn |
refuelReport(id) | RefuelReport | The signed report of a cycle that has ended, with the journal head |
The ledger
One double-entry ledger carries every balance. A batch is applied whole or not at all; a line never changes, and a correction is a new line.
| Call | Returns | |
|---|---|---|
ledgerAccount(id) | LedgerAccount | One account of the ledger, by the reference a position or an entry carries |
ledgerEntries(filter) | JournalEntry[] | By account, reference, rail_reference or instruction (one is required), after after_seq; 200 entries at a time |
ledgerHead() | { seq: number; hash: string } | The sealed head of the journal |
fund(account, amount, reference?) | LedgerResult | Test mode only. Funds a position from the sandbox bank; the same reference funds once |
defund(account, amount, reference?) | LedgerResult | Test mode only. Takes value out of a position |
let after: number | undefined;
for (;;) {
const page = await pg.treasury.ledgerEntries({ account: position.account, after_seq: after });
if (!page.length) break;
after = page[page.length - 1]!.seq;
}Errors
| Code | Status | When |
|---|---|---|
pathglobal.treasury.destination_not_allowed | 403 | The destination is not one the transfer may pay |
pathglobal.treasury.out_of_policy | 422 | The transfer is outside the policy of its accounts |
pathglobal.treasury.reconciliation_break | 409 | The source takes no debit until its break is resolved |
pathglobal.ledger.account_frozen | 409 | The account is frozen or closed |
pathglobal.ledger.insufficient_position | 422 | The account does not hold what the change takes |
pathglobal.ledger.limit_exceeded | 422 | The change passes a limit of an account |
pathglobal.refuel.cycle_state | 409 | No cycle has started, or the cycle has no report yet |
pathglobal.risk.self_approval | 403 | The checker is the maker |
pathglobal.risk.approval_pending | 409 | The change waits for a decision |
pathglobal.risk.approval_invalid | 409 | The approval is absent, not approved, expired, used, or for another change |
The guide is Treasury, positions and refuel, the recipe A treasury transfer under dual control. The routes are on Treasury.
Accounts, addresses and endpoints
pg.accounts, pg.addresses and pg.endpoints — Omni Accounts and their holdings, subjects and PATH addresses, and the endpoints a deposit arrives on.
Liquidity
pg.liquidity — provider corridors and quotes, the pools, pool quotes and positions, and where an amount can be delivered now.