Skip to content

Commit aecd780

Browse files
committed
feat: export computeTargetBalances and prod-network for yds consumption
1 parent 6678205 commit aecd780

17 files changed

Lines changed: 1025 additions & 864 deletions

File tree

packages/portfolio-api/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
# Portfolio management API
22

33
API shared between on-chain contract and external clients
4+
5+
## YDS Target Balances
6+
7+
YDS should import the shared target-balance helper and production network data
8+
from this public package:
9+
10+
```js
11+
import { computeTargetBalances } from '@agoric/portfolio-api/src/target-balances.js';
12+
import { PROD_NETWORK } from '@agoric/portfolio-api/src/network/prod-network.js';
13+
14+
const changedTargets = computeTargetBalances({
15+
brand: usdcBrand,
16+
currentBalances,
17+
balanceDelta,
18+
targetAllocation,
19+
network: PROD_NETWORK,
20+
depositFromChain,
21+
});
22+
```
23+
24+
`changedTargets` contains only balances that need to change. Use signed
25+
minor-unit deltas: positive for deposits, negative for withdrawals, and `0n` for
26+
rebalances.

packages/portfolio-api/src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export * from './constants.js';
22
export * from './instruments.js';
3+
export * from './network/prod-network.ts';
34
export * from './resolver.js';
5+
export * from './target-balances.ts';
46
export * from './type-guards.ts';
57

68
// eslint-disable-next-line import/export -- just types
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import type { NatValue } from '@agoric/ertp';
2+
import type { SupportedChain, YieldProtocol } from '../constants.js';
3+
import type { InstrumentId } from '../instruments.js';
4+
import type { AssetPlaceRef } from '../types.js';
5+
6+
// Control and transfer planes
7+
export type ControlProtocol = 'ibc' | 'axelar' | 'local';
8+
export type TransferProtocol =
9+
| 'ibc'
10+
| 'fastusdc'
11+
| 'cctpFromNoble'
12+
| 'cctpToNoble' // (often to a forwarding address)
13+
| 'cctpV2'
14+
| 'local';
15+
/**
16+
* Link to Factory and Wallet contracts:
17+
* https://github.com/agoric-labs/agoric-to-axelar-local/blob/cd6087fa44de3b019b2cdac6962bb49b6a2bc1ca/packages/axelar-local-dev-cosmos/src/__tests__/contracts/Factory.sol
18+
*
19+
* Steps submitted to the contract are expected to include fee/gas payment
20+
* details which vary by the traversed link.
21+
* - toUSDN: transferring into USDN transfer reduces the *payload* (e.g., $10k
22+
* might get reduced to $9995)
23+
* - makeEvmAccount: the fee for executing the Factory contract to create a new
24+
* remote wallet
25+
* - evmToNoble: the fee for running the tx to send tokens from the remote
26+
* wallet to Noble
27+
* - evmToPool: the fee for sending and executing a tx on the Wallet contract
28+
* to supply tokens to a specified pool
29+
* - poolToEvm: the fee for sending and executing a tx on the Wallet contract
30+
* to withdraw tokens from a specified pool
31+
*/
32+
export type FeeMode =
33+
| 'toUSDN'
34+
| 'makeEvmAccount'
35+
| 'evmToNoble'
36+
| 'evmToPool'
37+
| 'poolToEvm'
38+
| 'evmToEvm';
39+
40+
// Chains (hubs)
41+
export interface ChainSpec {
42+
readonly name: SupportedChain;
43+
/** how agoric reaches this chain: 'ibc' (noble) or 'axelar' (EVM) or 'local' */
44+
readonly control: ControlProtocol;
45+
/** minimum delta amount for planned moves involving this chain */
46+
readonly deltaSoftMin?: NatValue;
47+
}
48+
49+
// Any reason to block withdrawal is by extension also a reason to block
50+
// deposit.
51+
type BlockWithdrawReason = 'LOW_LIQUIDITY';
52+
type BlockDepositReason = BlockWithdrawReason | 'AT_CAPACITY';
53+
54+
export type PoolKey = InstrumentId;
55+
56+
// Pools (leaves)
57+
export interface PoolSpec {
58+
readonly pool: PoolKey;
59+
/** host chain of the corresponding instrument */
60+
readonly chain: SupportedChain;
61+
/** protocol of the corresponding instrument */
62+
readonly protocol: YieldProtocol;
63+
/** when increases are unavailable, the (primary) reason why */
64+
readonly blockDepositReason?: BlockDepositReason;
65+
/** when decreases are unavailable, the (primary) reason why */
66+
readonly blockWithdrawReason?: BlockWithdrawReason;
67+
}
68+
69+
/**
70+
* A +agoric local account or <Deposit>/<Cash> Agoric blockchain contract seat.
71+
*/
72+
export interface LocalPlaceSpec {
73+
readonly id: '<Deposit>' | '<Cash>' | '+agoric';
74+
readonly chain: 'agoric';
75+
}
76+
77+
/**
78+
* A directed edge from one place to another, usually having at least one hub
79+
* endpoint.
80+
*/
81+
export interface LinkSpec {
82+
readonly src: AssetPlaceRef;
83+
readonly dest: AssetPlaceRef;
84+
85+
/**
86+
* variable transfer fee in basis points to be applied against the transferred
87+
* amount of major units (e.g., USDC)
88+
*/
89+
readonly variableFeeBps: number;
90+
/** flat-rate transfer fee in minor units (e.g., uusdc) */
91+
readonly flatFee?: NatValue;
92+
93+
/** expected transfer settlement time in seconds */
94+
readonly timeSec: number;
95+
/** inclusive maximum transfer amount in minor units (e.g., uusdc) */
96+
readonly capacity?: NatValue;
97+
/** inclusive minimum transfer amount in minor units (e.g., uusdc) */
98+
readonly min?: NatValue;
99+
100+
/** mechanism by which the transfer occurs */
101+
readonly transfer: TransferProtocol;
102+
/** designator for how fees apply to transactions over this link */
103+
readonly feeMode?: FeeMode;
104+
}
105+
106+
/** Details of how chains/pools/etc. and how they connect. */
107+
export interface NetworkSpec {
108+
readonly debug?: boolean;
109+
readonly environment?: 'dev' | 'test' | 'prod';
110+
111+
readonly chains: ChainSpec[];
112+
readonly pools: PoolSpec[];
113+
readonly localPlaces?: LocalPlaceSpec[];
114+
readonly links: LinkSpec[];
115+
}

0 commit comments

Comments
 (0)