Receive

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

CallReturns
positions(filter?)TreasuryPosition[]Filter { network?, asset?, purpose?, tier?, partner? }. purpose is safeguarding, liquidity, settlement or gas; tier is hot, warm or cold
position(account)TreasuryPositionOne position: balance, reserved, pending_in, pending_out, in_transit_to, available, its band and status
view()TreasuryViewThe 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

CallReturns
policy(networkAccount)TreasuryPolicyThe policy of a physical account, by its id
setPolicy(networkAccount, policy)TreasuryPolicy | ApprovalWaitingWrites a policy (TreasuryPolicyRequest) under an approval policy_change
safeguard(asset)SafeguardPolicyThe safeguard policy of an asset
setSafeguard(asset, { gap_trigger, gap_max, margin_bps })SafeguardPolicy | ApprovalWaitingWrites 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

CallReturns
proposeTransfer(input)TreasuryTransferProposes a transfer. It answers 202 in pending_approval, naming its approval, and executes once approved
transfers(filter?)TreasuryTransfer[]Filter { state?, type?, asset? }
transfer(id)TreasuryTransferOne transfer
cancelTransfer(id)TreasuryTransferCancels a transfer that has not left
resolveTransfer(id, resolution, approval)TreasuryTransferNeeds 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.

Typesrebalance, refuel, sweep, funding, defunding, conversion, fees, gas
Statesproposed, 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, settled

Expected fundings and the allowlist

CallReturns
expectFunding(input)ExpectedFunding | ApprovalWaitingDeclares 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

CallReturns
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)ReconciliationNeeds treasury_approve. Resolves a break under an approval break_resolve
inbound()InboundItem[]The inbound items that wait for a decision
returnInbound(id)InboundItemReturns an item to its sender
escalateInbound(id, approval, owner?)InboundItemNeeds treasury_approve. Decides an item under an approval

A notification alone books nothing.

Refuel cycles

CallReturns
refuelCycles()RefuelCycle[]The refuel cycles, the latest first
currentRefuelCycle()RefuelCycleThe open cycle that started last
refuelCycle(id)RefuelCycleOne cycle, rf_YYYYMMDD or rf_YYYYMMDD_nn
refuelReport(id)RefuelReportThe 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.

CallReturns
ledgerAccount(id)LedgerAccountOne 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?)LedgerResultTest mode only. Funds a position from the sandbox bank; the same reference funds once
defund(account, amount, reference?)LedgerResultTest 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

CodeStatusWhen
pathglobal.treasury.destination_not_allowed403The destination is not one the transfer may pay
pathglobal.treasury.out_of_policy422The transfer is outside the policy of its accounts
pathglobal.treasury.reconciliation_break409The source takes no debit until its break is resolved
pathglobal.ledger.account_frozen409The account is frozen or closed
pathglobal.ledger.insufficient_position422The account does not hold what the change takes
pathglobal.ledger.limit_exceeded422The change passes a limit of an account
pathglobal.refuel.cycle_state409No cycle has started, or the cycle has no report yet
pathglobal.risk.self_approval403The checker is the maker
pathglobal.risk.approval_pending409The change waits for a decision
pathglobal.risk.approval_invalid409The 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.

On this page