Operations

Cookbook

A treasury transfer under dual control

One person proposes a rebalance between two own accounts, a second person approves it, and the transfer executes — with the refusals each side can meet.

Needs two test keys, held by two different people: the maker with the scope treasury, the checker with the scopes risk and treasury_approve. Each key names its own operator.

Treasury is an operator product. A transfer moves value out of an account, so it waits for a second person: another credential and another operator than the one that proposed it. This recipe runs in the sandbox, on the sandbox positions.

import { PathGlobal } from '@pathglobal/sdk';

const maker = new PathGlobal({ apiKey: process.env.PATHGLOBAL_MAKER_KEY! });
const checker = new PathGlobal({ apiKey: process.env.PATHGLOBAL_CHECKER_KEY! });

1. Pick two own accounts

const positions = await maker.treasury.positions({ purpose: 'liquidity', asset: 'USD' });
const [from, to] = positions.filter((p) => p.tier === 'hot' && p.status === 'open');
[
  {
    "account": "nostro:-:na_sandbox_USD_liquidity:USD",
    "network_account": "na_sandbox_USD_liquidity",
    "networks": ["fednow"],
    "asset": "USD",
    "purpose": "liquidity",
    "tier": "hot",
    "balance": { "value": "5000000", "asset": "USD" },
    "available": { "value": "5000000", "asset": "USD" },
    "status": "open"
  }
]

A position is named by the ledger account of its physical account, nostro:-:<physical account>:<asset>. The second hot USD account of the sandbox is nostro:-:na_sandbox_USD_liquidity_2:USD, on ach-us. The values above are sandbox balances.

2. The maker proposes

const transfer = await maker.treasury.proposeTransfer({
  type: 'rebalance',
  from: from.account,
  to: to.account,
  amount: { value: '1000.00', asset: 'USD' },
  reason: 'move USD between two hot accounts',
});

The API answers 202 with the transfer, pending_approval, and the approval it waits for:

{
  "id": "tt_…",
  "kind": "treasury.transfer",
  "type": "rebalance",
  "from": "nostro:-:na_sandbox_USD_liquidity:USD",
  "to": "nostro:-:na_sandbox_USD_liquidity_2:USD",
  "amount": { "value": "1000.00", "asset": "USD" },
  "state": "pending_approval",
  "origin": { "maker": "…" },
  "reason": "move USD between two hot accounts",
  "approval": "apr_…"
}

3. The checker reads the approval and decides

const approval = await checker.risk.approval(transfer.approval!);
// approval.action === 'treasury_transfer', approval.subject === transfer.id, approval.state === 'requested'

await checker.risk.approve(approval.id); // state: 'approved'
// or: await checker.risk.reject(approval.id);

checker.risk.approvals({ state: 'requested' }) lists what waits for a decision. An approval applies once, to the change it names, at the version it names.

Approval state
requestedWaiting for a decision
approvedDecided; the change it names can be applied
rejectedDecided against
consumedApplied
expiredNot decided before expires_at

4. The transfer executes

A treasury transfer executes once its approval is approved, with no second call. Read it until it is final:

const done = await until(() => maker.treasury.transfer(transfer.id), (t) => ['settled', 'failed', 'in_doubt', 'blocked'].includes(t.state));
// done.state === 'settled'
Transfer state
proposed, pending_approvalWaiting for its approval
approved, scheduledApproved; waiting to leave
executing, in_transitSent; waiting to arrive
settledArrived
in_doubt, blockedWaiting for a decision of Path Global
failed, rejected, cancelledEnded without moving value

Variants

Rejected. checker.risk.reject(approval.id): the transfer becomes rejected.

Cancelled before it leaves. maker.treasury.cancelTransfer(transfer.id) answers the transfer, cancelled. A transfer that has left, or has ended, answers 409 pathglobal.core.conflict.

The maker decides its own request. A maker whose key also carries risk and treasury_approve and decides its own request gets 403 pathglobal.risk.self_approval, as does a decision by another credential of the same operator. A key without risk and the approver scope gets 403 pathglobal.auth.scope_missing.

The approval is decided already. A second decision answers 409 pathglobal.risk.approval_invalid, with the state of the approval in details.

CodeStatusWhen
pathglobal.risk.self_approval403The checker is the maker's credential or operator
pathglobal.risk.approval_pending409A change is called again while its approval waits
pathglobal.risk.approval_invalid409The approval is absent, not approved, expired, used or for another change
pathglobal.treasury.destination_not_allowed403The destination is not on the allowlist
pathglobal.treasury.out_of_policy422The transfer is outside the policy of the account

In live mode

Treasury routes are available to a key whose agreement includes operator access, and every request carries the signature of a registered operator: Path-Operator, Path-Operator-Timestamp and Path-Operator-Signature, which the SDK adds with its operator option. The checker's decision also carries signature, 128 hexadecimal characters: the Ed25519 signature of the checker's operator over sha256(canonical({ approval, payload_digest, decision })), with payload_digest read from the approval and decision approve or reject.

await checker.risk.approve(approval.id, signature);

See approvals and treasury.

On this page