@owney/sdk 0.6.0-beta.2 → 0.6.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -46
- package/dist/index.cjs +11 -109
- package/dist/index.d.cts +7 -13
- package/dist/index.d.ts +7 -13
- package/dist/index.js +11 -109
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -211,9 +211,9 @@ console.log(results.agentResult.zyfai.type); // "full"
|
|
|
211
211
|
|
|
212
212
|
Get the user's balances for a specific agent, or aggregated across all agents.
|
|
213
213
|
|
|
214
|
-
| Param | Type
|
|
215
|
-
| --------- |
|
|
216
|
-
| `agentId` | `"zyfai"` (optional)
|
|
214
|
+
| Param | Type | Description |
|
|
215
|
+
| --------- | -------------------- | ------------------------------------ |
|
|
216
|
+
| `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
|
|
217
217
|
|
|
218
218
|
Returns: `AgentBalance` (single agent) or `OwneyBalances` (all agents)
|
|
219
219
|
|
|
@@ -221,22 +221,25 @@ Returns: `AgentBalance` (single agent) or `OwneyBalances` (all agents)
|
|
|
221
221
|
// Single agent
|
|
222
222
|
const balance = await sdk.getBalances("zyfai");
|
|
223
223
|
console.log(balance.totalBalance); // "150.25"
|
|
224
|
+
console.log(balance.totalBalanceAsset); // "usdc" — unit of totalBalance
|
|
224
225
|
console.log(balance.smartWallet); // "0x..."
|
|
225
226
|
console.log(balance.tokens); // [{ chain: "BASE", chainId: 8453, asset: "USDC", amount: "150.25" }]
|
|
226
227
|
|
|
227
228
|
// All agents
|
|
228
229
|
const allBalances = await sdk.getBalances();
|
|
229
230
|
console.log(allBalances.totalBalance); // "150.25"
|
|
231
|
+
console.log(allBalances.totalBalanceAsset); // "usdc" — unit of totalBalance
|
|
230
232
|
console.log(allBalances.agentBalances.zyfai.totalBalance); // "150.25"
|
|
233
|
+
console.log(allBalances.agentBalances.zyfai.totalBalanceAsset); // "usdc"
|
|
231
234
|
```
|
|
232
235
|
|
|
233
236
|
### `getEarnings(agentId?)`
|
|
234
237
|
|
|
235
238
|
Get the user's on-chain earnings for a specific agent, or aggregated across all agents.
|
|
236
239
|
|
|
237
|
-
| Param | Type
|
|
238
|
-
| --------- |
|
|
239
|
-
| `agentId` | `"zyfai"` (optional)
|
|
240
|
+
| Param | Type | Description |
|
|
241
|
+
| --------- | -------------------- | ------------------------------------ |
|
|
242
|
+
| `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
|
|
240
243
|
|
|
241
244
|
Returns: `AgentEarnings` (single agent) or `OwneyEarnings` (all agents)
|
|
242
245
|
|
|
@@ -262,10 +265,10 @@ console.log(allEarnings.agentEarnings.zyfai.tokens); // per-chain, per-asset bre
|
|
|
262
265
|
|
|
263
266
|
Get the weighted APY for the user's account. When querying all agents, the total APY is a balance-weighted average.
|
|
264
267
|
|
|
265
|
-
| Param | Type
|
|
266
|
-
| --------- |
|
|
267
|
-
| `agentId` | `"zyfai"` (optional)
|
|
268
|
-
| `days` | `"7D" \| "14D" \| "30D"`
|
|
268
|
+
| Param | Type | Description |
|
|
269
|
+
| --------- | ------------------------ | ------------------------------------------------ |
|
|
270
|
+
| `agentId` | `"zyfai"` (optional) | Agent to query. Omit for balance-weighted total. |
|
|
271
|
+
| `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
|
|
269
272
|
|
|
270
273
|
Returns: `AccountAgentApy` (single agent) or `OwneyAccountApy` (all agents)
|
|
271
274
|
|
|
@@ -297,13 +300,13 @@ Results are **cursor-paginated**. The first call (no `cursor`) anchors a stable
|
|
|
297
300
|
|
|
298
301
|
> **Per-chain filtering:** The Zyfai backend no longer accepts a `chainId` filter directly. The SDK performs a bounded internal drain (up to 5 backend round-trips per logical page) to fill the requested `limit` with entries matching the active chain. This is transparent to callers — the `getHistory` API is unchanged.
|
|
299
302
|
|
|
300
|
-
| Param | Type
|
|
301
|
-
| ------------------ |
|
|
302
|
-
| `agentId` | `"zyfai"` (optional)
|
|
303
|
-
| `filters.fromDate` | `string` (optional)
|
|
304
|
-
| `filters.toDate` | `string` (optional)
|
|
305
|
-
| `filters.limit` | `number` (optional)
|
|
306
|
-
| `filters.cursor` | `string` (optional)
|
|
303
|
+
| Param | Type | Description |
|
|
304
|
+
| ------------------ | -------------------- | ------------------------------------------------------- |
|
|
305
|
+
| `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
|
|
306
|
+
| `filters.fromDate` | `string` (optional) | Start date (`YYYY-MM-DD`) |
|
|
307
|
+
| `filters.toDate` | `string` (optional) | End date (`YYYY-MM-DD`) |
|
|
308
|
+
| `filters.limit` | `number` (optional) | Max entries returned per call. Defaults to `10`. |
|
|
309
|
+
| `filters.cursor` | `string` (optional) | Opaque cursor returned by a previous `getHistory` call. |
|
|
307
310
|
|
|
308
311
|
Returns: `OwneyAgentHistory`
|
|
309
312
|
|
|
@@ -350,9 +353,9 @@ do {
|
|
|
350
353
|
|
|
351
354
|
Get the user's profile for a specific agent, or all agents.
|
|
352
355
|
|
|
353
|
-
| Param | Type
|
|
354
|
-
| --------- |
|
|
355
|
-
| `agentId` | `"zyfai"` (optional)
|
|
356
|
+
| Param | Type | Description |
|
|
357
|
+
| --------- | -------------------- | ------------------------------------ |
|
|
358
|
+
| `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
|
|
356
359
|
|
|
357
360
|
Returns: `AgentUserProfile` (single agent) or `OwneyUserProfile` (all agents)
|
|
358
361
|
|
|
@@ -374,16 +377,16 @@ console.log(allProfiles.agentUserProfile.zyfai.smartWallet); // "0x..."
|
|
|
374
377
|
|
|
375
378
|
Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
376
379
|
|
|
377
|
-
| Param | Type
|
|
378
|
-
| ------------- |
|
|
379
|
-
| `agentId` | `"zyfai"` (optional)
|
|
380
|
-
| `days` | `"7D" \| "14D" \| "30D"`
|
|
381
|
-
| `tokenSymbol` | `string` (optional)
|
|
382
|
-
| `chainId` | `number` (optional)
|
|
380
|
+
| Param | Type | Description |
|
|
381
|
+
| ------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
382
|
+
| `agentId` | `"zyfai"` (optional) | Agent to query. Omit for all agents. |
|
|
383
|
+
| `days` | `"7D" \| "14D" \| "30D"` | Lookback period |
|
|
384
|
+
| `tokenSymbol` | `string` (optional) | Asset symbol (e.g. `"USDC"`). Scopes the upstream request to a specific asset when the agent's backend supports it. |
|
|
385
|
+
| `chainId` | `number` (optional) | Chain id. Typically paired with `tokenSymbol` for per-asset+chain APY. |
|
|
383
386
|
|
|
384
387
|
Returns: `AgentApy` (single agent) or `OwneyAgentApy` (all agents)
|
|
385
388
|
|
|
386
|
-
|
|
389
|
+
The agent populates `detailedApys.apyPerAsset` with a per-chain, per-token
|
|
387
390
|
breakdown when available. `tokenSymbol` / `chainId` only affect whether the
|
|
388
391
|
upstream query is scoped — the breakdown is built from whatever the agent
|
|
389
392
|
returns.
|
|
@@ -407,17 +410,6 @@ const usdcBaseApy = await sdk.getAgentApy({
|
|
|
407
410
|
console.log(usdcBaseApy.agentApy.zyfai.averageApy); // APY scoped to USDC on Base
|
|
408
411
|
```
|
|
409
412
|
|
|
410
|
-
### `getAgentAllocation()`
|
|
411
|
-
|
|
412
|
-
Get the current fund allocation percentages across agents.
|
|
413
|
-
|
|
414
|
-
Returns: `OwneyAgentAllocation`
|
|
415
|
-
|
|
416
|
-
```typescript
|
|
417
|
-
const allocation = await sdk.getAgentAllocation();
|
|
418
|
-
console.log(allocation.agentAllocation); // { zyfai: 100 }
|
|
419
|
-
```
|
|
420
|
-
|
|
421
413
|
## Types
|
|
422
414
|
|
|
423
415
|
### Configuration
|
|
@@ -529,11 +521,13 @@ interface OwneyToken {
|
|
|
529
521
|
interface AgentBalance {
|
|
530
522
|
smartWallet?: `0x${string}`;
|
|
531
523
|
totalBalance: string;
|
|
524
|
+
totalBalanceAsset: string; // unit of totalBalance, currently always "usdc"
|
|
532
525
|
tokens: OwneyToken[];
|
|
533
526
|
}
|
|
534
527
|
|
|
535
528
|
interface OwneyBalances {
|
|
536
529
|
totalBalance: string;
|
|
530
|
+
totalBalanceAsset: string; // unit of totalBalance, currently always "usdc"
|
|
537
531
|
agentBalances: Record<AgentId, AgentBalance>;
|
|
538
532
|
}
|
|
539
533
|
|
|
@@ -630,10 +624,6 @@ interface AgentApyDetails {
|
|
|
630
624
|
interface OwneyAgentApy {
|
|
631
625
|
agentApy: Record<AgentId, AgentApy>;
|
|
632
626
|
}
|
|
633
|
-
|
|
634
|
-
interface OwneyAgentAllocation {
|
|
635
|
-
agentAllocation: Record<AgentId, number>;
|
|
636
|
-
}
|
|
637
627
|
```
|
|
638
628
|
|
|
639
629
|
### Callback Types
|
|
@@ -642,7 +632,7 @@ interface OwneyAgentAllocation {
|
|
|
642
632
|
type DepositCallback = (
|
|
643
633
|
smartWalletAddress: string,
|
|
644
634
|
chainId: number,
|
|
645
|
-
amount: string
|
|
635
|
+
amount: string,
|
|
646
636
|
) => Promise<`0x${string}`> | `0x${string}`;
|
|
647
637
|
```
|
|
648
638
|
|
|
@@ -755,9 +745,9 @@ try {
|
|
|
755
745
|
|
|
756
746
|
**Recovery:** catch `InvalidHistoryCursorError`, clear your stored cursor, and refetch from page 1.
|
|
757
747
|
|
|
758
|
-
| Class
|
|
759
|
-
|
|
|
760
|
-
| `InvalidHistoryCursorError`
|
|
748
|
+
| Class | `code` | Extends |
|
|
749
|
+
| --------------------------- | ------------------ | ------- |
|
|
750
|
+
| `InvalidHistoryCursorError` | `"invalid_cursor"` | `Error` |
|
|
761
751
|
|
|
762
752
|
## License
|
|
763
753
|
|
package/dist/index.cjs
CHANGED
|
@@ -40,7 +40,7 @@ var P_SUPPORTED_CHAINS = {
|
|
|
40
40
|
chainIds: [8453, 42161],
|
|
41
41
|
chains: ["BASE", "ARBITRUM"]
|
|
42
42
|
};
|
|
43
|
-
var SUPPORTED_TOKENS = ["USDC", "USDT"
|
|
43
|
+
var SUPPORTED_TOKENS = ["USDC", "USDT"];
|
|
44
44
|
var SUPPORTED_CHAIN_IDS = P_SUPPORTED_CHAINS.chainIds;
|
|
45
45
|
var SUPPORTED_CHAINS = P_SUPPORTED_CHAINS.chains;
|
|
46
46
|
var SupportedAssets = [
|
|
@@ -61,18 +61,6 @@ var SupportedAssets = [
|
|
|
61
61
|
symbol: "USDT",
|
|
62
62
|
chainId: 42161,
|
|
63
63
|
decimals: 6
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
address: `0x4200000000000000000000000000000000000006`,
|
|
67
|
-
symbol: "WETH",
|
|
68
|
-
chainId: 8453,
|
|
69
|
-
decimals: 18
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
address: `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1`,
|
|
73
|
-
symbol: "WETH",
|
|
74
|
-
chainId: 42161,
|
|
75
|
-
decimals: 18
|
|
76
64
|
}
|
|
77
65
|
];
|
|
78
66
|
|
|
@@ -222,6 +210,7 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
222
210
|
return {
|
|
223
211
|
smartWallet,
|
|
224
212
|
totalBalance: String(totalBalance),
|
|
213
|
+
totalBalanceAsset: "usdc",
|
|
225
214
|
tokens,
|
|
226
215
|
positions
|
|
227
216
|
};
|
|
@@ -545,10 +534,6 @@ var DEFAULT_ZYFAI_RPC_URLS = {
|
|
|
545
534
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
546
535
|
42161: "https://arb-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V"
|
|
547
536
|
};
|
|
548
|
-
var WETH_ADDRESS_BY_CHAIN = {
|
|
549
|
-
8453: "0x4200000000000000000000000000000000000006",
|
|
550
|
-
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
|
|
551
|
-
};
|
|
552
537
|
var VIEM_CHAIN = { 8453: import_chains.base, 42161: import_chains.arbitrum };
|
|
553
538
|
var ZyfaiAgent = class {
|
|
554
539
|
id = "zyfai";
|
|
@@ -557,18 +542,12 @@ var ZyfaiAgent = class {
|
|
|
557
542
|
{
|
|
558
543
|
chainId: 8453,
|
|
559
544
|
chain: "BASE",
|
|
560
|
-
assets: [
|
|
561
|
-
{ symbol: "USDC", minDepositAmount: "1500000" },
|
|
562
|
-
{ symbol: "WETH", minDepositAmount: "500000000000000" }
|
|
563
|
-
]
|
|
545
|
+
assets: [{ symbol: "USDC", minDepositAmount: "1500000" }]
|
|
564
546
|
},
|
|
565
547
|
{
|
|
566
548
|
chainId: 42161,
|
|
567
549
|
chain: "ARBITRUM",
|
|
568
|
-
assets: [
|
|
569
|
-
{ symbol: "USDC", minDepositAmount: "1500000" },
|
|
570
|
-
{ symbol: "WETH", minDepositAmount: "500000000000000" }
|
|
571
|
-
]
|
|
550
|
+
assets: [{ symbol: "USDC", minDepositAmount: "1500000" }]
|
|
572
551
|
}
|
|
573
552
|
];
|
|
574
553
|
sdk;
|
|
@@ -804,7 +783,7 @@ var ZyfaiAgent = class {
|
|
|
804
783
|
throw error;
|
|
805
784
|
}
|
|
806
785
|
}
|
|
807
|
-
async deposit(state, chainId, amount,
|
|
786
|
+
async deposit(state, chainId, amount, depositCallback) {
|
|
808
787
|
try {
|
|
809
788
|
await this.connectFull(state, chainId);
|
|
810
789
|
const validChainId = isValidChainId(chainId);
|
|
@@ -818,15 +797,13 @@ var ZyfaiAgent = class {
|
|
|
818
797
|
validChainId,
|
|
819
798
|
amount
|
|
820
799
|
);
|
|
821
|
-
|
|
822
|
-
await (tokenAddress ? this.sdk.logDeposit(validChainId, txHash, amount, tokenAddress) : this.sdk.logDeposit(validChainId, txHash, amount));
|
|
800
|
+
await this.sdk.logDeposit(validChainId, txHash, amount);
|
|
823
801
|
return { txHash, smartWallet: wallet.address, amount };
|
|
824
802
|
}
|
|
825
803
|
const raw = await this.sdk.depositFunds(
|
|
826
804
|
this.getAddress(),
|
|
827
805
|
validChainId,
|
|
828
|
-
amount
|
|
829
|
-
asset
|
|
806
|
+
amount
|
|
830
807
|
);
|
|
831
808
|
return mapDeposit(raw);
|
|
832
809
|
} catch (error) {
|
|
@@ -1553,7 +1530,7 @@ var OwneySDK = class {
|
|
|
1553
1530
|
}
|
|
1554
1531
|
const state = this.requireState();
|
|
1555
1532
|
const chainId = this.requireChainId();
|
|
1556
|
-
const effectiveCallback = depositCallback ??
|
|
1533
|
+
const effectiveCallback = depositCallback ?? this.getDefaultSponsoredCallback();
|
|
1557
1534
|
if (agentId) {
|
|
1558
1535
|
if (this.isAgentDisabled(agentId)) {
|
|
1559
1536
|
throw new OwneyError(
|
|
@@ -1568,13 +1545,7 @@ var OwneySDK = class {
|
|
|
1568
1545
|
return withFailureReporting(
|
|
1569
1546
|
this.apiKey,
|
|
1570
1547
|
agent.id,
|
|
1571
|
-
() => agent.deposit(
|
|
1572
|
-
state,
|
|
1573
|
-
chainId,
|
|
1574
|
-
amount,
|
|
1575
|
-
asset,
|
|
1576
|
-
effectiveCallback
|
|
1577
|
-
)
|
|
1548
|
+
() => agent.deposit(state, chainId, amount, effectiveCallback)
|
|
1578
1549
|
);
|
|
1579
1550
|
}
|
|
1580
1551
|
const totalAmount = BigInt(amount);
|
|
@@ -1608,13 +1579,7 @@ var OwneySDK = class {
|
|
|
1608
1579
|
agentResults[agent.id] = await withFailureReporting(
|
|
1609
1580
|
this.apiKey,
|
|
1610
1581
|
agent.id,
|
|
1611
|
-
() => agent.deposit(
|
|
1612
|
-
state,
|
|
1613
|
-
chainId,
|
|
1614
|
-
agentAmount,
|
|
1615
|
-
asset,
|
|
1616
|
-
effectiveCallback
|
|
1617
|
-
)
|
|
1582
|
+
() => agent.deposit(state, chainId, agentAmount, effectiveCallback)
|
|
1618
1583
|
);
|
|
1619
1584
|
}
|
|
1620
1585
|
return { agentResults };
|
|
@@ -1911,6 +1876,7 @@ var OwneySDK = class {
|
|
|
1911
1876
|
}
|
|
1912
1877
|
return {
|
|
1913
1878
|
totalBalance: String(totalBalance),
|
|
1879
|
+
totalBalanceAsset: "usdc",
|
|
1914
1880
|
agentBalances: results
|
|
1915
1881
|
};
|
|
1916
1882
|
}
|
|
@@ -2144,70 +2110,6 @@ var OwneySDK = class {
|
|
|
2144
2110
|
agentApy: results
|
|
2145
2111
|
};
|
|
2146
2112
|
}
|
|
2147
|
-
/**
|
|
2148
|
-
* Get the current fund allocation percentages across agents.
|
|
2149
|
-
* @returns Object with agent names as keys and allocation percentages as values
|
|
2150
|
-
*/
|
|
2151
|
-
async getAgentAllocation() {
|
|
2152
|
-
const state = this.requireState();
|
|
2153
|
-
const chainId = this.requireChainId();
|
|
2154
|
-
const activeAgents = this.getActiveAgents();
|
|
2155
|
-
const balances = {};
|
|
2156
|
-
const positionsByAgent = {};
|
|
2157
|
-
let totalBalance = 0;
|
|
2158
|
-
const entries = [...activeAgents.entries()];
|
|
2159
|
-
const balanceResults = await Promise.allSettled(
|
|
2160
|
-
entries.map(async ([id, agent]) => {
|
|
2161
|
-
const b = await agent.getBalances(state, chainId);
|
|
2162
|
-
return [id, Number(b.totalBalance), b.positions ?? []];
|
|
2163
|
-
})
|
|
2164
|
-
);
|
|
2165
|
-
let successCount = 0;
|
|
2166
|
-
const agentErrors = {};
|
|
2167
|
-
for (let i = 0; i < balanceResults.length; i++) {
|
|
2168
|
-
const settledResult = balanceResults[i];
|
|
2169
|
-
const [agentId] = entries[i];
|
|
2170
|
-
if (settledResult.status === "fulfilled") {
|
|
2171
|
-
const [id, bal, agentPositions] = settledResult.value;
|
|
2172
|
-
balances[id] = bal;
|
|
2173
|
-
positionsByAgent[id] = agentPositions;
|
|
2174
|
-
totalBalance += bal;
|
|
2175
|
-
successCount += 1;
|
|
2176
|
-
} else {
|
|
2177
|
-
const reason = settledResult.reason;
|
|
2178
|
-
agentErrors[agentId] = reason instanceof Error ? reason.message : String(reason);
|
|
2179
|
-
console.error(`getAgentAllocation agent "${agentId}" failed:`, reason);
|
|
2180
|
-
}
|
|
2181
|
-
}
|
|
2182
|
-
if (successCount === 0) {
|
|
2183
|
-
throw new OwneyError(
|
|
2184
|
-
"ALLOCATION_ALL_FAILED",
|
|
2185
|
-
"Failed to fetch allocation: all agents failed.",
|
|
2186
|
-
{ agentErrors }
|
|
2187
|
-
);
|
|
2188
|
-
}
|
|
2189
|
-
const allocation = {};
|
|
2190
|
-
if (totalBalance === 0) {
|
|
2191
|
-
for (const id of activeAgents.keys()) {
|
|
2192
|
-
allocation[id] = 0;
|
|
2193
|
-
}
|
|
2194
|
-
} else {
|
|
2195
|
-
for (const id of activeAgents.keys()) {
|
|
2196
|
-
allocation[id] = balances[id] > 0 ? Math.max(1, Math.floor(balances[id] / totalBalance * 100)) : 0;
|
|
2197
|
-
}
|
|
2198
|
-
const remainder = 100 - Object.values(allocation).reduce((a, b) => a + b, 0);
|
|
2199
|
-
if (remainder > 0) {
|
|
2200
|
-
const largestId = [...activeAgents.keys()].reduce(
|
|
2201
|
-
(a, b) => balances[a] >= balances[b] ? a : b
|
|
2202
|
-
);
|
|
2203
|
-
allocation[largestId] += remainder;
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
2206
|
-
return {
|
|
2207
|
-
agentAllocation: allocation,
|
|
2208
|
-
agentPositions: positionsByAgent
|
|
2209
|
-
};
|
|
2210
|
-
}
|
|
2211
2113
|
/**
|
|
2212
2114
|
* Allocation-weighted APY from the current portfolio: each pool's APY
|
|
2213
2115
|
* weighted by the user's position value in it. More accurate per-user than
|
package/dist/index.d.cts
CHANGED
|
@@ -14,7 +14,7 @@ interface ConnectionState {
|
|
|
14
14
|
walletAddress: `0x${string}`;
|
|
15
15
|
chainId: number | null;
|
|
16
16
|
}
|
|
17
|
-
declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT"
|
|
17
|
+
declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT"];
|
|
18
18
|
declare const SUPPORTED_CHAIN_IDS: readonly [8453, 42161];
|
|
19
19
|
declare const SUPPORTED_CHAINS: readonly ["BASE", "ARBITRUM"];
|
|
20
20
|
type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
@@ -61,6 +61,8 @@ interface OwneyPosition {
|
|
|
61
61
|
interface AgentBalance {
|
|
62
62
|
smartWallet?: `0x${string}`;
|
|
63
63
|
totalBalance: string;
|
|
64
|
+
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
65
|
+
totalBalanceAsset: string;
|
|
64
66
|
tokens: OwneyToken[];
|
|
65
67
|
/**
|
|
66
68
|
* Per-protocol/pool positions when the agent's portfolio payload includes
|
|
@@ -70,6 +72,8 @@ interface AgentBalance {
|
|
|
70
72
|
}
|
|
71
73
|
interface OwneyBalances {
|
|
72
74
|
totalBalance: string;
|
|
75
|
+
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
76
|
+
totalBalanceAsset: string;
|
|
73
77
|
agentBalances: Record<AgentId, AgentBalance>;
|
|
74
78
|
}
|
|
75
79
|
interface AgentEarnings {
|
|
@@ -171,11 +175,6 @@ interface AgentApy {
|
|
|
171
175
|
interface OwneyAgentApy {
|
|
172
176
|
agentApy: Record<AgentId, AgentApy>;
|
|
173
177
|
}
|
|
174
|
-
interface OwneyAgentAllocation {
|
|
175
|
-
agentAllocation: Record<AgentId, number>;
|
|
176
|
-
/** Per-agent positions. Empty array for agents that don't expose positions. */
|
|
177
|
-
agentPositions: Record<AgentId, OwneyPosition[]>;
|
|
178
|
-
}
|
|
179
178
|
|
|
180
179
|
type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
|
|
181
180
|
interface IAgent {
|
|
@@ -184,7 +183,7 @@ interface IAgent {
|
|
|
184
183
|
readonly supportedAssets: readonly AgentSupportedAssets[];
|
|
185
184
|
disconnect(): Promise<void>;
|
|
186
185
|
activateAgent(state: ConnectionState, chainId: number): Promise<void>;
|
|
187
|
-
deposit(state: ConnectionState, chainId: number, amount: string,
|
|
186
|
+
deposit(state: ConnectionState, chainId: number, amount: string, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
|
|
188
187
|
withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
|
|
189
188
|
getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
|
|
190
189
|
getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
@@ -414,11 +413,6 @@ declare class OwneySDK {
|
|
|
414
413
|
* @returns {AgentApy} for a single agent, or {OwneyAgentApy} with per-agent APY
|
|
415
414
|
*/
|
|
416
415
|
getAgentApy({ agentId, days, tokenSymbol, chainId, }: AgentsApyOptions): Promise<OwneyAgentApy | AgentApy>;
|
|
417
|
-
/**
|
|
418
|
-
* Get the current fund allocation percentages across agents.
|
|
419
|
-
* @returns Object with agent names as keys and allocation percentages as values
|
|
420
|
-
*/
|
|
421
|
-
getAgentAllocation(): Promise<OwneyAgentAllocation>;
|
|
422
416
|
/**
|
|
423
417
|
* Allocation-weighted APY from the current portfolio: each pool's APY
|
|
424
418
|
* weighted by the user's position value in it. More accurate per-user than
|
|
@@ -474,4 +468,4 @@ type OwneySIWXConfig = {
|
|
|
474
468
|
*/
|
|
475
469
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
476
470
|
|
|
477
|
-
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy,
|
|
471
|
+
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface ConnectionState {
|
|
|
14
14
|
walletAddress: `0x${string}`;
|
|
15
15
|
chainId: number | null;
|
|
16
16
|
}
|
|
17
|
-
declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT"
|
|
17
|
+
declare const SUPPORTED_TOKENS: readonly ["USDC", "USDT"];
|
|
18
18
|
declare const SUPPORTED_CHAIN_IDS: readonly [8453, 42161];
|
|
19
19
|
declare const SUPPORTED_CHAINS: readonly ["BASE", "ARBITRUM"];
|
|
20
20
|
type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
@@ -61,6 +61,8 @@ interface OwneyPosition {
|
|
|
61
61
|
interface AgentBalance {
|
|
62
62
|
smartWallet?: `0x${string}`;
|
|
63
63
|
totalBalance: string;
|
|
64
|
+
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
65
|
+
totalBalanceAsset: string;
|
|
64
66
|
tokens: OwneyToken[];
|
|
65
67
|
/**
|
|
66
68
|
* Per-protocol/pool positions when the agent's portfolio payload includes
|
|
@@ -70,6 +72,8 @@ interface AgentBalance {
|
|
|
70
72
|
}
|
|
71
73
|
interface OwneyBalances {
|
|
72
74
|
totalBalance: string;
|
|
75
|
+
/** Asset that `totalBalance` is denominated in. Currently always `"usdc"`. */
|
|
76
|
+
totalBalanceAsset: string;
|
|
73
77
|
agentBalances: Record<AgentId, AgentBalance>;
|
|
74
78
|
}
|
|
75
79
|
interface AgentEarnings {
|
|
@@ -171,11 +175,6 @@ interface AgentApy {
|
|
|
171
175
|
interface OwneyAgentApy {
|
|
172
176
|
agentApy: Record<AgentId, AgentApy>;
|
|
173
177
|
}
|
|
174
|
-
interface OwneyAgentAllocation {
|
|
175
|
-
agentAllocation: Record<AgentId, number>;
|
|
176
|
-
/** Per-agent positions. Empty array for agents that don't expose positions. */
|
|
177
|
-
agentPositions: Record<AgentId, OwneyPosition[]>;
|
|
178
|
-
}
|
|
179
178
|
|
|
180
179
|
type DepositCallback = (smartWalletAddress: string, chainId: number, amount: string) => Promise<`0x${string}`> | `0x${string}`;
|
|
181
180
|
interface IAgent {
|
|
@@ -184,7 +183,7 @@ interface IAgent {
|
|
|
184
183
|
readonly supportedAssets: readonly AgentSupportedAssets[];
|
|
185
184
|
disconnect(): Promise<void>;
|
|
186
185
|
activateAgent(state: ConnectionState, chainId: number): Promise<void>;
|
|
187
|
-
deposit(state: ConnectionState, chainId: number, amount: string,
|
|
186
|
+
deposit(state: ConnectionState, chainId: number, amount: string, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
|
|
188
187
|
withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
|
|
189
188
|
getBalances(state: ConnectionState, chainId: number): Promise<AgentBalance>;
|
|
190
189
|
getEarnings(state: ConnectionState, chainId: number): Promise<AgentEarnings>;
|
|
@@ -414,11 +413,6 @@ declare class OwneySDK {
|
|
|
414
413
|
* @returns {AgentApy} for a single agent, or {OwneyAgentApy} with per-agent APY
|
|
415
414
|
*/
|
|
416
415
|
getAgentApy({ agentId, days, tokenSymbol, chainId, }: AgentsApyOptions): Promise<OwneyAgentApy | AgentApy>;
|
|
417
|
-
/**
|
|
418
|
-
* Get the current fund allocation percentages across agents.
|
|
419
|
-
* @returns Object with agent names as keys and allocation percentages as values
|
|
420
|
-
*/
|
|
421
|
-
getAgentAllocation(): Promise<OwneyAgentAllocation>;
|
|
422
416
|
/**
|
|
423
417
|
* Allocation-weighted APY from the current portfolio: each pool's APY
|
|
424
418
|
* weighted by the user's position value in it. More accurate per-user than
|
|
@@ -474,4 +468,4 @@ type OwneySIWXConfig = {
|
|
|
474
468
|
*/
|
|
475
469
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
476
470
|
|
|
477
|
-
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy,
|
|
471
|
+
export { AccountAgentApy, AccountApyOptions, AgentApy, AgentApyDetails, AgentBalance, AgentChainIncompatibleError, AgentEarnings, AgentHistoryEntry, AgentHistoryPosition, AgentId, AgentNotFoundError, AgentSupportedAsset, AgentSupportedAssets, AgentUserProfile, AgentWithdrawResult, AgentsApyOptions, AllocationAgentApy, ApyByChainAndAsset, Asset, ConnectionState, DailyApyDays, DepositCallback, DepositOptions, HistoryAction, HistoryFilters, HistoryOptions, HistoryTransaction, IAgent, InvalidHistoryCursorError, NotConnectedError, OwneyAccountApy, OwneyAgentApy, OwneyAgentHistory, OwneyAllocationApy, OwneyBalances, OwneyDepositResult, OwneyEarnings, OwneyError, OwneyErrorCode, OwneyMultiDepositResult, OwneyPosition, OwneySDK, OwneySDKConfig, OwneySIWXConfig, OwneySupportedChainId, OwneySupportedChains, OwneySupportedTokens, OwneyToken, OwneyUserProfile, OwneyWithdrawResult, RebalanceLog, WithdrawOptions, createOwneySIWX };
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var P_SUPPORTED_CHAINS = {
|
|
|
8
8
|
chainIds: [8453, 42161],
|
|
9
9
|
chains: ["BASE", "ARBITRUM"]
|
|
10
10
|
};
|
|
11
|
-
var SUPPORTED_TOKENS = ["USDC", "USDT"
|
|
11
|
+
var SUPPORTED_TOKENS = ["USDC", "USDT"];
|
|
12
12
|
var SUPPORTED_CHAIN_IDS = P_SUPPORTED_CHAINS.chainIds;
|
|
13
13
|
var SUPPORTED_CHAINS = P_SUPPORTED_CHAINS.chains;
|
|
14
14
|
var SupportedAssets = [
|
|
@@ -29,18 +29,6 @@ var SupportedAssets = [
|
|
|
29
29
|
symbol: "USDT",
|
|
30
30
|
chainId: 42161,
|
|
31
31
|
decimals: 6
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
address: `0x4200000000000000000000000000000000000006`,
|
|
35
|
-
symbol: "WETH",
|
|
36
|
-
chainId: 8453,
|
|
37
|
-
decimals: 18
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
address: `0x82aF49447D8a07e3bd95BD0d56f35241523fBab1`,
|
|
41
|
-
symbol: "WETH",
|
|
42
|
-
chainId: 42161,
|
|
43
|
-
decimals: 18
|
|
44
32
|
}
|
|
45
33
|
];
|
|
46
34
|
|
|
@@ -190,6 +178,7 @@ function mapBalances(raw, _chainId, smartWallet) {
|
|
|
190
178
|
return {
|
|
191
179
|
smartWallet,
|
|
192
180
|
totalBalance: String(totalBalance),
|
|
181
|
+
totalBalanceAsset: "usdc",
|
|
193
182
|
tokens,
|
|
194
183
|
positions
|
|
195
184
|
};
|
|
@@ -513,10 +502,6 @@ var DEFAULT_ZYFAI_RPC_URLS = {
|
|
|
513
502
|
8453: "https://base-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V",
|
|
514
503
|
42161: "https://arb-mainnet.g.alchemy.com/v2/ZWyVU-9XfS3z8Rn-xkq7V"
|
|
515
504
|
};
|
|
516
|
-
var WETH_ADDRESS_BY_CHAIN = {
|
|
517
|
-
8453: "0x4200000000000000000000000000000000000006",
|
|
518
|
-
42161: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
|
|
519
|
-
};
|
|
520
505
|
var VIEM_CHAIN = { 8453: base, 42161: arbitrum };
|
|
521
506
|
var ZyfaiAgent = class {
|
|
522
507
|
id = "zyfai";
|
|
@@ -525,18 +510,12 @@ var ZyfaiAgent = class {
|
|
|
525
510
|
{
|
|
526
511
|
chainId: 8453,
|
|
527
512
|
chain: "BASE",
|
|
528
|
-
assets: [
|
|
529
|
-
{ symbol: "USDC", minDepositAmount: "1500000" },
|
|
530
|
-
{ symbol: "WETH", minDepositAmount: "500000000000000" }
|
|
531
|
-
]
|
|
513
|
+
assets: [{ symbol: "USDC", minDepositAmount: "1500000" }]
|
|
532
514
|
},
|
|
533
515
|
{
|
|
534
516
|
chainId: 42161,
|
|
535
517
|
chain: "ARBITRUM",
|
|
536
|
-
assets: [
|
|
537
|
-
{ symbol: "USDC", minDepositAmount: "1500000" },
|
|
538
|
-
{ symbol: "WETH", minDepositAmount: "500000000000000" }
|
|
539
|
-
]
|
|
518
|
+
assets: [{ symbol: "USDC", minDepositAmount: "1500000" }]
|
|
540
519
|
}
|
|
541
520
|
];
|
|
542
521
|
sdk;
|
|
@@ -772,7 +751,7 @@ var ZyfaiAgent = class {
|
|
|
772
751
|
throw error;
|
|
773
752
|
}
|
|
774
753
|
}
|
|
775
|
-
async deposit(state, chainId, amount,
|
|
754
|
+
async deposit(state, chainId, amount, depositCallback) {
|
|
776
755
|
try {
|
|
777
756
|
await this.connectFull(state, chainId);
|
|
778
757
|
const validChainId = isValidChainId(chainId);
|
|
@@ -786,15 +765,13 @@ var ZyfaiAgent = class {
|
|
|
786
765
|
validChainId,
|
|
787
766
|
amount
|
|
788
767
|
);
|
|
789
|
-
|
|
790
|
-
await (tokenAddress ? this.sdk.logDeposit(validChainId, txHash, amount, tokenAddress) : this.sdk.logDeposit(validChainId, txHash, amount));
|
|
768
|
+
await this.sdk.logDeposit(validChainId, txHash, amount);
|
|
791
769
|
return { txHash, smartWallet: wallet.address, amount };
|
|
792
770
|
}
|
|
793
771
|
const raw = await this.sdk.depositFunds(
|
|
794
772
|
this.getAddress(),
|
|
795
773
|
validChainId,
|
|
796
|
-
amount
|
|
797
|
-
asset
|
|
774
|
+
amount
|
|
798
775
|
);
|
|
799
776
|
return mapDeposit(raw);
|
|
800
777
|
} catch (error) {
|
|
@@ -1525,7 +1502,7 @@ var OwneySDK = class {
|
|
|
1525
1502
|
}
|
|
1526
1503
|
const state = this.requireState();
|
|
1527
1504
|
const chainId = this.requireChainId();
|
|
1528
|
-
const effectiveCallback = depositCallback ??
|
|
1505
|
+
const effectiveCallback = depositCallback ?? this.getDefaultSponsoredCallback();
|
|
1529
1506
|
if (agentId) {
|
|
1530
1507
|
if (this.isAgentDisabled(agentId)) {
|
|
1531
1508
|
throw new OwneyError(
|
|
@@ -1540,13 +1517,7 @@ var OwneySDK = class {
|
|
|
1540
1517
|
return withFailureReporting(
|
|
1541
1518
|
this.apiKey,
|
|
1542
1519
|
agent.id,
|
|
1543
|
-
() => agent.deposit(
|
|
1544
|
-
state,
|
|
1545
|
-
chainId,
|
|
1546
|
-
amount,
|
|
1547
|
-
asset,
|
|
1548
|
-
effectiveCallback
|
|
1549
|
-
)
|
|
1520
|
+
() => agent.deposit(state, chainId, amount, effectiveCallback)
|
|
1550
1521
|
);
|
|
1551
1522
|
}
|
|
1552
1523
|
const totalAmount = BigInt(amount);
|
|
@@ -1580,13 +1551,7 @@ var OwneySDK = class {
|
|
|
1580
1551
|
agentResults[agent.id] = await withFailureReporting(
|
|
1581
1552
|
this.apiKey,
|
|
1582
1553
|
agent.id,
|
|
1583
|
-
() => agent.deposit(
|
|
1584
|
-
state,
|
|
1585
|
-
chainId,
|
|
1586
|
-
agentAmount,
|
|
1587
|
-
asset,
|
|
1588
|
-
effectiveCallback
|
|
1589
|
-
)
|
|
1554
|
+
() => agent.deposit(state, chainId, agentAmount, effectiveCallback)
|
|
1590
1555
|
);
|
|
1591
1556
|
}
|
|
1592
1557
|
return { agentResults };
|
|
@@ -1883,6 +1848,7 @@ var OwneySDK = class {
|
|
|
1883
1848
|
}
|
|
1884
1849
|
return {
|
|
1885
1850
|
totalBalance: String(totalBalance),
|
|
1851
|
+
totalBalanceAsset: "usdc",
|
|
1886
1852
|
agentBalances: results
|
|
1887
1853
|
};
|
|
1888
1854
|
}
|
|
@@ -2116,70 +2082,6 @@ var OwneySDK = class {
|
|
|
2116
2082
|
agentApy: results
|
|
2117
2083
|
};
|
|
2118
2084
|
}
|
|
2119
|
-
/**
|
|
2120
|
-
* Get the current fund allocation percentages across agents.
|
|
2121
|
-
* @returns Object with agent names as keys and allocation percentages as values
|
|
2122
|
-
*/
|
|
2123
|
-
async getAgentAllocation() {
|
|
2124
|
-
const state = this.requireState();
|
|
2125
|
-
const chainId = this.requireChainId();
|
|
2126
|
-
const activeAgents = this.getActiveAgents();
|
|
2127
|
-
const balances = {};
|
|
2128
|
-
const positionsByAgent = {};
|
|
2129
|
-
let totalBalance = 0;
|
|
2130
|
-
const entries = [...activeAgents.entries()];
|
|
2131
|
-
const balanceResults = await Promise.allSettled(
|
|
2132
|
-
entries.map(async ([id, agent]) => {
|
|
2133
|
-
const b = await agent.getBalances(state, chainId);
|
|
2134
|
-
return [id, Number(b.totalBalance), b.positions ?? []];
|
|
2135
|
-
})
|
|
2136
|
-
);
|
|
2137
|
-
let successCount = 0;
|
|
2138
|
-
const agentErrors = {};
|
|
2139
|
-
for (let i = 0; i < balanceResults.length; i++) {
|
|
2140
|
-
const settledResult = balanceResults[i];
|
|
2141
|
-
const [agentId] = entries[i];
|
|
2142
|
-
if (settledResult.status === "fulfilled") {
|
|
2143
|
-
const [id, bal, agentPositions] = settledResult.value;
|
|
2144
|
-
balances[id] = bal;
|
|
2145
|
-
positionsByAgent[id] = agentPositions;
|
|
2146
|
-
totalBalance += bal;
|
|
2147
|
-
successCount += 1;
|
|
2148
|
-
} else {
|
|
2149
|
-
const reason = settledResult.reason;
|
|
2150
|
-
agentErrors[agentId] = reason instanceof Error ? reason.message : String(reason);
|
|
2151
|
-
console.error(`getAgentAllocation agent "${agentId}" failed:`, reason);
|
|
2152
|
-
}
|
|
2153
|
-
}
|
|
2154
|
-
if (successCount === 0) {
|
|
2155
|
-
throw new OwneyError(
|
|
2156
|
-
"ALLOCATION_ALL_FAILED",
|
|
2157
|
-
"Failed to fetch allocation: all agents failed.",
|
|
2158
|
-
{ agentErrors }
|
|
2159
|
-
);
|
|
2160
|
-
}
|
|
2161
|
-
const allocation = {};
|
|
2162
|
-
if (totalBalance === 0) {
|
|
2163
|
-
for (const id of activeAgents.keys()) {
|
|
2164
|
-
allocation[id] = 0;
|
|
2165
|
-
}
|
|
2166
|
-
} else {
|
|
2167
|
-
for (const id of activeAgents.keys()) {
|
|
2168
|
-
allocation[id] = balances[id] > 0 ? Math.max(1, Math.floor(balances[id] / totalBalance * 100)) : 0;
|
|
2169
|
-
}
|
|
2170
|
-
const remainder = 100 - Object.values(allocation).reduce((a, b) => a + b, 0);
|
|
2171
|
-
if (remainder > 0) {
|
|
2172
|
-
const largestId = [...activeAgents.keys()].reduce(
|
|
2173
|
-
(a, b) => balances[a] >= balances[b] ? a : b
|
|
2174
|
-
);
|
|
2175
|
-
allocation[largestId] += remainder;
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
return {
|
|
2179
|
-
agentAllocation: allocation,
|
|
2180
|
-
agentPositions: positionsByAgent
|
|
2181
|
-
};
|
|
2182
|
-
}
|
|
2183
2085
|
/**
|
|
2184
2086
|
* Allocation-weighted APY from the current portfolio: each pool's APY
|
|
2185
2087
|
* weighted by the user's position value in it. More accurate per-user than
|