@owney/sdk 0.7.37 → 0.8.0-beta.1
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 +25 -4
- package/dist/index.cjs +448 -287
- package/dist/index.d.cts +58 -75
- package/dist/index.d.ts +58 -75
- package/dist/index.js +448 -287
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -247,32 +247,8 @@ type SwapQuoteParams = {
|
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
|
|
250
|
-
/**
|
|
251
|
-
* Where an agent keeps its login session (for Zyfai: the JWT plus the flags
|
|
252
|
-
* it caches). The value is opaque JSON owned by the agent; the agent validates
|
|
253
|
-
* it on read. Default is the browser's localStorage; a server passes its own
|
|
254
|
-
* store (database, cache) so one login survives across requests and replicas.
|
|
255
|
-
*/
|
|
256
|
-
interface AgentSessionStore {
|
|
257
|
-
read(agentId: string, address: string): Promise<unknown | null> | unknown | null;
|
|
258
|
-
write(agentId: string, address: string, session: unknown): Promise<void> | void;
|
|
259
|
-
clear(agentId: string, address: string): Promise<void> | void;
|
|
260
|
-
}
|
|
261
250
|
interface OwneySDKConfig {
|
|
262
251
|
apiKey: string;
|
|
263
|
-
/**
|
|
264
|
-
* Optional persistence for agent authentication sessions.
|
|
265
|
-
*
|
|
266
|
-
* When omitted, browser integrations use the default localStorage store.
|
|
267
|
-
* On the server the default store is a no-op, so every `connect` signs in
|
|
268
|
-
* again unless a store is provided.
|
|
269
|
-
*
|
|
270
|
-
* Stored values may contain bearer tokens and must be treated as secrets.
|
|
271
|
-
* Server implementations should bind each store instance to a trusted
|
|
272
|
-
* application user/session, encrypt values, apply a TTL, and never use a
|
|
273
|
-
* caller-provided wallet address as the sole authorization boundary.
|
|
274
|
-
*/
|
|
275
|
-
sessionStore?: AgentSessionStore;
|
|
276
252
|
/**
|
|
277
253
|
* Optional per-chain RPC overrides for Zyfai SDK network calls.
|
|
278
254
|
* Example: { 8453: "https://...", 42161: "https://..." }
|
|
@@ -326,7 +302,7 @@ interface ConnectionState {
|
|
|
326
302
|
walletAddress: `0x${string}`;
|
|
327
303
|
chainId: number | null;
|
|
328
304
|
}
|
|
329
|
-
declare const SUPPORTED_TOKENS: readonly ["USDC", "WETH"];
|
|
305
|
+
declare const SUPPORTED_TOKENS: readonly ["USDC", "WETH", "EURC", "USDT"];
|
|
330
306
|
declare const SUPPORTED_CHAIN_IDS: readonly [8453, 42161, 1];
|
|
331
307
|
declare const SUPPORTED_CHAINS: readonly ["BASE", "ARBITRUM", "ETHEREUM"];
|
|
332
308
|
type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
@@ -580,7 +556,7 @@ type AvailablePool = {
|
|
|
580
556
|
type PoolSelectionStrategy = "aggressive" | "yieldmaxxing";
|
|
581
557
|
/** One asset's explicit choice for a protocol on one chain. */
|
|
582
558
|
type UserPoolSelection = {
|
|
583
|
-
asset:
|
|
559
|
+
asset: OwneySupportedTokens;
|
|
584
560
|
protocolId: string;
|
|
585
561
|
chainId: number;
|
|
586
562
|
/** Names enabled by the user for this asset/protocol/chain. */
|
|
@@ -591,7 +567,7 @@ type UserPoolSelection = {
|
|
|
591
567
|
/** The complete saved draft for the asset/chain legs selected in the deposit. */
|
|
592
568
|
type UserPoolSelectionRequest = {
|
|
593
569
|
strategies: Array<{
|
|
594
|
-
asset:
|
|
570
|
+
asset: OwneySupportedTokens;
|
|
595
571
|
strategy: PoolSelectionStrategy;
|
|
596
572
|
}>;
|
|
597
573
|
selections: UserPoolSelection[];
|
|
@@ -603,7 +579,7 @@ type UserPoolSelectionRequest = {
|
|
|
603
579
|
*/
|
|
604
580
|
type SavedPoolSelection = {
|
|
605
581
|
strategies: Array<{
|
|
606
|
-
asset:
|
|
582
|
+
asset: OwneySupportedTokens;
|
|
607
583
|
strategy: string;
|
|
608
584
|
}>;
|
|
609
585
|
pairs: Array<{
|
|
@@ -1001,7 +977,7 @@ interface IAgent {
|
|
|
1001
977
|
protocolId: string;
|
|
1002
978
|
chainId: number;
|
|
1003
979
|
}>;
|
|
1004
|
-
assets: Array<
|
|
980
|
+
assets: Array<OwneySupportedTokens>;
|
|
1005
981
|
}): Promise<SavedPoolSelection>;
|
|
1006
982
|
deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
|
|
1007
983
|
withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
|
|
@@ -1039,7 +1015,7 @@ interface IAgent {
|
|
|
1039
1015
|
* backend models per-asset protocol selection implement it. Returns whether
|
|
1040
1016
|
* a write occurred (`false` = already enabled / not supported).
|
|
1041
1017
|
*/
|
|
1042
|
-
ensureAutoSelectProtocols?(state: ConnectionState, chainId: number, asset:
|
|
1018
|
+
ensureAutoSelectProtocols?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): Promise<boolean>;
|
|
1043
1019
|
getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
|
|
1044
1020
|
}
|
|
1045
1021
|
/**
|
|
@@ -1220,9 +1196,8 @@ declare class OwneySDK {
|
|
|
1220
1196
|
private userPoolCustomization;
|
|
1221
1197
|
private routingApiBaseUrl?;
|
|
1222
1198
|
private referralSource?;
|
|
1223
|
-
private
|
|
1224
|
-
private
|
|
1225
|
-
private cachedWethSponsoredCallback;
|
|
1199
|
+
private cachedSponsoredCallbacks;
|
|
1200
|
+
private cachedPermit2SponsoredCallbacks;
|
|
1226
1201
|
private paymasterServiceUrl?;
|
|
1227
1202
|
private cachedSponsoredCallsCallbacks;
|
|
1228
1203
|
private readonly agentReads;
|
|
@@ -1263,19 +1238,18 @@ declare class OwneySDK {
|
|
|
1263
1238
|
*/
|
|
1264
1239
|
private getDefaultSponsoredCallback;
|
|
1265
1240
|
/**
|
|
1266
|
-
* Lazily builds (and caches) the default
|
|
1267
|
-
* callback used when the caller omits `depositCallback`
|
|
1268
|
-
*
|
|
1269
|
-
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1241
|
+
* Lazily builds (and caches, per asset) the default paymaster-sponsored
|
|
1242
|
+
* deposit callback used when the caller omits `depositCallback` and a
|
|
1243
|
+
* `paymasterServiceUrl` is configured. One rail serves every asset.
|
|
1270
1244
|
*/
|
|
1271
1245
|
private getDefaultSponsoredCallsCallback;
|
|
1272
1246
|
/**
|
|
1273
|
-
* Lazily builds (and caches) the default Permit2 sponsored
|
|
1274
|
-
* callback used when the caller omits `depositCallback` for a
|
|
1275
|
-
* Mirrors `getDefaultSponsoredCallback()` but
|
|
1276
|
-
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1247
|
+
* Lazily builds (and caches, per asset) the default Permit2 sponsored
|
|
1248
|
+
* deposit callback used when the caller omits `depositCallback` for a
|
|
1249
|
+
* Permit2 asset (WETH, USDT). Mirrors `getDefaultSponsoredCallback()` but
|
|
1250
|
+
* signs a Permit2 `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1277
1251
|
*/
|
|
1278
|
-
private
|
|
1252
|
+
private getDefaultPermit2SponsoredCallback;
|
|
1279
1253
|
private getAgent;
|
|
1280
1254
|
private getActiveAgents;
|
|
1281
1255
|
/**
|
|
@@ -1350,15 +1324,16 @@ declare class OwneySDK {
|
|
|
1350
1324
|
*
|
|
1351
1325
|
* 1. Missing Permit2 allowance: when the app did not supply its own
|
|
1352
1326
|
* callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
|
|
1353
|
-
* WETH
|
|
1354
|
-
* the one-time (user-paid) Permit2
|
|
1355
|
-
* retry the SAME sponsored
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1327
|
+
* Permit2 asset (WETH, USDT), this is the wallet's first gasless deposit
|
|
1328
|
+
* of that asset on this chain. We send the one-time (user-paid) Permit2
|
|
1329
|
+
* approval via `approvePermit2(asset)` and retry the SAME sponsored
|
|
1330
|
+
* attempt once. Bounded to one approval attempt per call so a
|
|
1331
|
+
* wallet/agent that keeps reporting the allowance as missing can't loop
|
|
1332
|
+
* forever. If `approvePermit2()` itself throws (e.g.
|
|
1358
1333
|
* the user rejects the wallet prompt), that error propagates as-is —
|
|
1359
1334
|
* the user said no to a transaction, so we must not turn around and ask
|
|
1360
1335
|
* them to pay for a different one via the fallback below.
|
|
1361
|
-
* 2. `shouldFallbackToUserPaid`: the SDK's own
|
|
1336
|
+
* 2. `shouldFallbackToUserPaid`: the SDK's own sponsor path failed at
|
|
1362
1337
|
* the infrastructure layer in a provably safe-to-retry way, so we warn
|
|
1363
1338
|
* and retry once with `undefined`, falling through to a user-paid
|
|
1364
1339
|
* native deposit. This still applies after a successful Permit2
|
|
@@ -1465,23 +1440,26 @@ declare class OwneySDK {
|
|
|
1465
1440
|
* figure directly. It is the entire arrival, so there is no slack: anything
|
|
1466
1441
|
* that spends the target asset between the two fails the deposit outright.
|
|
1467
1442
|
*
|
|
1468
|
-
* Something does. A first
|
|
1469
|
-
* and that approval is a transaction.
|
|
1470
|
-
*
|
|
1471
|
-
* for it out of the WETH. The
|
|
1472
|
-
*
|
|
1473
|
-
* the funds were safe
|
|
1443
|
+
* Something does. A first deposit of a Permit2 asset (WETH, USDT) needs a
|
|
1444
|
+
* one-time Permit2 approval, and that approval is a transaction. For WETH,
|
|
1445
|
+
* a wallet holding no native gas token - the normal state of someone who
|
|
1446
|
+
* just swapped everything INTO WETH - pays for it out of the WETH. The
|
|
1447
|
+
* deposit then asked for ~2e12 wei more than was left and refused with
|
|
1448
|
+
* DEPOSIT_INSUFFICIENT_BALANCE, under a wrapper saying the funds were safe
|
|
1449
|
+
* but unadded (ROUT-242). For USDT the gas cannot come out of the token, so
|
|
1450
|
+
* this step only adds the one-time approval and the read changes nothing.
|
|
1474
1451
|
*
|
|
1475
1452
|
* So the approval happens here, before the amount is settled, and the amount
|
|
1476
1453
|
* comes from a read taken after it. Two things this deliberately is not:
|
|
1477
1454
|
*
|
|
1478
1455
|
* - It is not a balance sweep. `received` is a DELTA over the pre-swap
|
|
1479
|
-
* balance, so a wallet already holding
|
|
1480
|
-
* the balance would move funds the user never offered. The
|
|
1481
|
-
* ceiling and the balance is only ever allowed to lower it.
|
|
1482
|
-
* - It does not touch USDC, which
|
|
1483
|
-
* nothing of the user's in between, nor a
|
|
1484
|
-
* where the sponsor covers the transfer and
|
|
1456
|
+
* balance, so a wallet already holding the asset reads far above it;
|
|
1457
|
+
* depositing the balance would move funds the user never offered. The
|
|
1458
|
+
* arrival is the ceiling and the balance is only ever allowed to lower it.
|
|
1459
|
+
* - It does not touch USDC or EURC, which move on signed typed data
|
|
1460
|
+
* (EIP-3009) and so spend nothing of the user's in between, nor a
|
|
1461
|
+
* paymaster-configured client, where the sponsor covers the transfer and
|
|
1462
|
+
* Permit2 never applies.
|
|
1485
1463
|
*/
|
|
1486
1464
|
private settleSwapDepositAmount;
|
|
1487
1465
|
/**
|
|
@@ -1883,7 +1861,7 @@ declare class OwneySDK {
|
|
|
1883
1861
|
protocolId: string;
|
|
1884
1862
|
chainId: number;
|
|
1885
1863
|
}>;
|
|
1886
|
-
assets: Array<
|
|
1864
|
+
assets: Array<OwneySupportedTokens>;
|
|
1887
1865
|
agentId?: AgentId;
|
|
1888
1866
|
}): Promise<SavedPoolSelection>;
|
|
1889
1867
|
getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
|
|
@@ -1915,20 +1893,26 @@ declare class OwneySDK {
|
|
|
1915
1893
|
/**
|
|
1916
1894
|
* Ensure the given asset uses backend protocol auto-selection for the active
|
|
1917
1895
|
* chain's account. No-op (returns false) for agents that don't support it.
|
|
1918
|
-
* @param asset -
|
|
1896
|
+
* @param asset - Asset symbol (e.g. "USDC").
|
|
1919
1897
|
* @param agentId - Agent to target. Defaults to "zyfai".
|
|
1920
1898
|
* @returns whether a profile write occurred.
|
|
1921
1899
|
*/
|
|
1922
|
-
ensureAutoSelectProtocols(asset:
|
|
1900
|
+
ensureAutoSelectProtocols(asset: OwneySupportedTokens, agentId?: AgentId): Promise<boolean>;
|
|
1923
1901
|
/**
|
|
1924
|
-
* One-time, user-paid approval of Permit2 on the sponsored WETH
|
|
1925
|
-
* the active chain. Required once per wallet per chain before
|
|
1926
|
-
* deposits; afterwards deposit() is signature-only.
|
|
1927
|
-
* approval transaction is mined (1 confirmation), so
|
|
1928
|
-
* will see the new allowance; throws if the
|
|
1902
|
+
* One-time, user-paid approval of Permit2 on the sponsored WETH (default) or
|
|
1903
|
+
* USDT token for the active chain. Required once per wallet per chain before
|
|
1904
|
+
* gasless deposits of that asset; afterwards deposit() is signature-only.
|
|
1905
|
+
* Resolves only after the approval transaction is mined (1 confirmation), so
|
|
1906
|
+
* a subsequent deposit() will see the new allowance; throws if the
|
|
1907
|
+
* transaction reverted.
|
|
1908
|
+
*
|
|
1909
|
+
* On mainnet USDT only (`needsAllowanceReset`), a non-zero existing allowance
|
|
1910
|
+
* is first zeroed in its own transaction. If the user rejects the second
|
|
1911
|
+
* prompt, the previous Permit2 allowance stays zeroed; calling this again
|
|
1912
|
+
* approves from zero in a single transaction.
|
|
1929
1913
|
* @returns the approval transaction hash.
|
|
1930
1914
|
*/
|
|
1931
|
-
approvePermit2(asset?: "WETH"): Promise<`0x${string}`>;
|
|
1915
|
+
approvePermit2(asset?: "WETH" | "USDT"): Promise<`0x${string}`>;
|
|
1932
1916
|
/**
|
|
1933
1917
|
* Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
1934
1918
|
* @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
|
|
@@ -1994,17 +1978,16 @@ type OwneySIWXConfig = {
|
|
|
1994
1978
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
1995
1979
|
|
|
1996
1980
|
/**
|
|
1997
|
-
*
|
|
1981
|
+
* Ask the wallet ITSELF to switch networks, over WalletConnect.
|
|
1998
1982
|
*
|
|
1999
1983
|
* WalletConnect's provider answers `wallet_switchEthereumChain` locally when
|
|
2000
1984
|
* the chain was approved at connect time: it moves its own default chain and
|
|
2001
1985
|
* reports success without telling the wallet. MetaMask mobile then stays on
|
|
2002
1986
|
* its network, keeps reporting it, and every guard downstream fails with
|
|
2003
1987
|
* CHAIN_MISMATCH — after a swap, with the user's funds already moved (ROUT-727).
|
|
2004
|
-
* Sending the request through the session client reaches
|
|
2005
|
-
* a real "switch network" prompt
|
|
2006
|
-
*
|
|
2007
|
-
* explicitly scoped to that chain and needs no separate network prompt.
|
|
1988
|
+
* Sending the request through the session client reaches the wallet, which
|
|
1989
|
+
* shows a real "switch network" prompt; the client also deep-links the wallet
|
|
1990
|
+
* app open on mobile.
|
|
2008
1991
|
*
|
|
2009
1992
|
* Returns false when `provider` is not a WalletConnect session, so the caller
|
|
2010
1993
|
* can fall back to an ordinary switch.
|
|
@@ -2047,4 +2030,4 @@ type StoredOrder = {
|
|
|
2047
2030
|
*/
|
|
2048
2031
|
declare function listOrders(now?: number): StoredOrder[];
|
|
2049
2032
|
|
|
2050
|
-
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type
|
|
2033
|
+
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type ApyIncentive, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SavedPoolSelection, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, switchWalletConnectChain, updateWithdrawSwap };
|
package/dist/index.d.ts
CHANGED
|
@@ -247,32 +247,8 @@ type SwapQuoteParams = {
|
|
|
247
247
|
};
|
|
248
248
|
|
|
249
249
|
type ZyfaiRpcUrlsConfig = Partial<Record<(typeof SUPPORTED_CHAIN_IDS)[number], string>>;
|
|
250
|
-
/**
|
|
251
|
-
* Where an agent keeps its login session (for Zyfai: the JWT plus the flags
|
|
252
|
-
* it caches). The value is opaque JSON owned by the agent; the agent validates
|
|
253
|
-
* it on read. Default is the browser's localStorage; a server passes its own
|
|
254
|
-
* store (database, cache) so one login survives across requests and replicas.
|
|
255
|
-
*/
|
|
256
|
-
interface AgentSessionStore {
|
|
257
|
-
read(agentId: string, address: string): Promise<unknown | null> | unknown | null;
|
|
258
|
-
write(agentId: string, address: string, session: unknown): Promise<void> | void;
|
|
259
|
-
clear(agentId: string, address: string): Promise<void> | void;
|
|
260
|
-
}
|
|
261
250
|
interface OwneySDKConfig {
|
|
262
251
|
apiKey: string;
|
|
263
|
-
/**
|
|
264
|
-
* Optional persistence for agent authentication sessions.
|
|
265
|
-
*
|
|
266
|
-
* When omitted, browser integrations use the default localStorage store.
|
|
267
|
-
* On the server the default store is a no-op, so every `connect` signs in
|
|
268
|
-
* again unless a store is provided.
|
|
269
|
-
*
|
|
270
|
-
* Stored values may contain bearer tokens and must be treated as secrets.
|
|
271
|
-
* Server implementations should bind each store instance to a trusted
|
|
272
|
-
* application user/session, encrypt values, apply a TTL, and never use a
|
|
273
|
-
* caller-provided wallet address as the sole authorization boundary.
|
|
274
|
-
*/
|
|
275
|
-
sessionStore?: AgentSessionStore;
|
|
276
252
|
/**
|
|
277
253
|
* Optional per-chain RPC overrides for Zyfai SDK network calls.
|
|
278
254
|
* Example: { 8453: "https://...", 42161: "https://..." }
|
|
@@ -326,7 +302,7 @@ interface ConnectionState {
|
|
|
326
302
|
walletAddress: `0x${string}`;
|
|
327
303
|
chainId: number | null;
|
|
328
304
|
}
|
|
329
|
-
declare const SUPPORTED_TOKENS: readonly ["USDC", "WETH"];
|
|
305
|
+
declare const SUPPORTED_TOKENS: readonly ["USDC", "WETH", "EURC", "USDT"];
|
|
330
306
|
declare const SUPPORTED_CHAIN_IDS: readonly [8453, 42161, 1];
|
|
331
307
|
declare const SUPPORTED_CHAINS: readonly ["BASE", "ARBITRUM", "ETHEREUM"];
|
|
332
308
|
type OwneySupportedChainId = (typeof SUPPORTED_CHAIN_IDS)[number];
|
|
@@ -580,7 +556,7 @@ type AvailablePool = {
|
|
|
580
556
|
type PoolSelectionStrategy = "aggressive" | "yieldmaxxing";
|
|
581
557
|
/** One asset's explicit choice for a protocol on one chain. */
|
|
582
558
|
type UserPoolSelection = {
|
|
583
|
-
asset:
|
|
559
|
+
asset: OwneySupportedTokens;
|
|
584
560
|
protocolId: string;
|
|
585
561
|
chainId: number;
|
|
586
562
|
/** Names enabled by the user for this asset/protocol/chain. */
|
|
@@ -591,7 +567,7 @@ type UserPoolSelection = {
|
|
|
591
567
|
/** The complete saved draft for the asset/chain legs selected in the deposit. */
|
|
592
568
|
type UserPoolSelectionRequest = {
|
|
593
569
|
strategies: Array<{
|
|
594
|
-
asset:
|
|
570
|
+
asset: OwneySupportedTokens;
|
|
595
571
|
strategy: PoolSelectionStrategy;
|
|
596
572
|
}>;
|
|
597
573
|
selections: UserPoolSelection[];
|
|
@@ -603,7 +579,7 @@ type UserPoolSelectionRequest = {
|
|
|
603
579
|
*/
|
|
604
580
|
type SavedPoolSelection = {
|
|
605
581
|
strategies: Array<{
|
|
606
|
-
asset:
|
|
582
|
+
asset: OwneySupportedTokens;
|
|
607
583
|
strategy: string;
|
|
608
584
|
}>;
|
|
609
585
|
pairs: Array<{
|
|
@@ -1001,7 +977,7 @@ interface IAgent {
|
|
|
1001
977
|
protocolId: string;
|
|
1002
978
|
chainId: number;
|
|
1003
979
|
}>;
|
|
1004
|
-
assets: Array<
|
|
980
|
+
assets: Array<OwneySupportedTokens>;
|
|
1005
981
|
}): Promise<SavedPoolSelection>;
|
|
1006
982
|
deposit(state: ConnectionState, chainId: number, amount: string, asset: OwneySupportedTokens, depositCallback?: DepositCallback): Promise<OwneyDepositResult>;
|
|
1007
983
|
withdraw(state: ConnectionState, chainId: number, token: OwneySupportedTokens, amount?: string): Promise<AgentWithdrawResult>;
|
|
@@ -1039,7 +1015,7 @@ interface IAgent {
|
|
|
1039
1015
|
* backend models per-asset protocol selection implement it. Returns whether
|
|
1040
1016
|
* a write occurred (`false` = already enabled / not supported).
|
|
1041
1017
|
*/
|
|
1042
|
-
ensureAutoSelectProtocols?(state: ConnectionState, chainId: number, asset:
|
|
1018
|
+
ensureAutoSelectProtocols?(state: ConnectionState, chainId: number, asset: OwneySupportedTokens): Promise<boolean>;
|
|
1043
1019
|
getAgentApy(days: DailyApyDays, options?: AgentApyOptions): Promise<AgentApy>;
|
|
1044
1020
|
}
|
|
1045
1021
|
/**
|
|
@@ -1220,9 +1196,8 @@ declare class OwneySDK {
|
|
|
1220
1196
|
private userPoolCustomization;
|
|
1221
1197
|
private routingApiBaseUrl?;
|
|
1222
1198
|
private referralSource?;
|
|
1223
|
-
private
|
|
1224
|
-
private
|
|
1225
|
-
private cachedWethSponsoredCallback;
|
|
1199
|
+
private cachedSponsoredCallbacks;
|
|
1200
|
+
private cachedPermit2SponsoredCallbacks;
|
|
1226
1201
|
private paymasterServiceUrl?;
|
|
1227
1202
|
private cachedSponsoredCallsCallbacks;
|
|
1228
1203
|
private readonly agentReads;
|
|
@@ -1263,19 +1238,18 @@ declare class OwneySDK {
|
|
|
1263
1238
|
*/
|
|
1264
1239
|
private getDefaultSponsoredCallback;
|
|
1265
1240
|
/**
|
|
1266
|
-
* Lazily builds (and caches) the default
|
|
1267
|
-
* callback used when the caller omits `depositCallback`
|
|
1268
|
-
*
|
|
1269
|
-
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1241
|
+
* Lazily builds (and caches, per asset) the default paymaster-sponsored
|
|
1242
|
+
* deposit callback used when the caller omits `depositCallback` and a
|
|
1243
|
+
* `paymasterServiceUrl` is configured. One rail serves every asset.
|
|
1270
1244
|
*/
|
|
1271
1245
|
private getDefaultSponsoredCallsCallback;
|
|
1272
1246
|
/**
|
|
1273
|
-
* Lazily builds (and caches) the default Permit2 sponsored
|
|
1274
|
-
* callback used when the caller omits `depositCallback` for a
|
|
1275
|
-
* Mirrors `getDefaultSponsoredCallback()` but
|
|
1276
|
-
* `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1247
|
+
* Lazily builds (and caches, per asset) the default Permit2 sponsored
|
|
1248
|
+
* deposit callback used when the caller omits `depositCallback` for a
|
|
1249
|
+
* Permit2 asset (WETH, USDT). Mirrors `getDefaultSponsoredCallback()` but
|
|
1250
|
+
* signs a Permit2 `PermitTransferFrom` instead of an EIP-3009 authorization.
|
|
1277
1251
|
*/
|
|
1278
|
-
private
|
|
1252
|
+
private getDefaultPermit2SponsoredCallback;
|
|
1279
1253
|
private getAgent;
|
|
1280
1254
|
private getActiveAgents;
|
|
1281
1255
|
/**
|
|
@@ -1350,15 +1324,16 @@ declare class OwneySDK {
|
|
|
1350
1324
|
*
|
|
1351
1325
|
* 1. Missing Permit2 allowance: when the app did not supply its own
|
|
1352
1326
|
* callback and the attempt fails with `PERMIT2_APPROVAL_REQUIRED` on a
|
|
1353
|
-
* WETH
|
|
1354
|
-
* the one-time (user-paid) Permit2
|
|
1355
|
-
* retry the SAME sponsored
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1327
|
+
* Permit2 asset (WETH, USDT), this is the wallet's first gasless deposit
|
|
1328
|
+
* of that asset on this chain. We send the one-time (user-paid) Permit2
|
|
1329
|
+
* approval via `approvePermit2(asset)` and retry the SAME sponsored
|
|
1330
|
+
* attempt once. Bounded to one approval attempt per call so a
|
|
1331
|
+
* wallet/agent that keeps reporting the allowance as missing can't loop
|
|
1332
|
+
* forever. If `approvePermit2()` itself throws (e.g.
|
|
1358
1333
|
* the user rejects the wallet prompt), that error propagates as-is —
|
|
1359
1334
|
* the user said no to a transaction, so we must not turn around and ask
|
|
1360
1335
|
* them to pay for a different one via the fallback below.
|
|
1361
|
-
* 2. `shouldFallbackToUserPaid`: the SDK's own
|
|
1336
|
+
* 2. `shouldFallbackToUserPaid`: the SDK's own sponsor path failed at
|
|
1362
1337
|
* the infrastructure layer in a provably safe-to-retry way, so we warn
|
|
1363
1338
|
* and retry once with `undefined`, falling through to a user-paid
|
|
1364
1339
|
* native deposit. This still applies after a successful Permit2
|
|
@@ -1465,23 +1440,26 @@ declare class OwneySDK {
|
|
|
1465
1440
|
* figure directly. It is the entire arrival, so there is no slack: anything
|
|
1466
1441
|
* that spends the target asset between the two fails the deposit outright.
|
|
1467
1442
|
*
|
|
1468
|
-
* Something does. A first
|
|
1469
|
-
* and that approval is a transaction.
|
|
1470
|
-
*
|
|
1471
|
-
* for it out of the WETH. The
|
|
1472
|
-
*
|
|
1473
|
-
* the funds were safe
|
|
1443
|
+
* Something does. A first deposit of a Permit2 asset (WETH, USDT) needs a
|
|
1444
|
+
* one-time Permit2 approval, and that approval is a transaction. For WETH,
|
|
1445
|
+
* a wallet holding no native gas token - the normal state of someone who
|
|
1446
|
+
* just swapped everything INTO WETH - pays for it out of the WETH. The
|
|
1447
|
+
* deposit then asked for ~2e12 wei more than was left and refused with
|
|
1448
|
+
* DEPOSIT_INSUFFICIENT_BALANCE, under a wrapper saying the funds were safe
|
|
1449
|
+
* but unadded (ROUT-242). For USDT the gas cannot come out of the token, so
|
|
1450
|
+
* this step only adds the one-time approval and the read changes nothing.
|
|
1474
1451
|
*
|
|
1475
1452
|
* So the approval happens here, before the amount is settled, and the amount
|
|
1476
1453
|
* comes from a read taken after it. Two things this deliberately is not:
|
|
1477
1454
|
*
|
|
1478
1455
|
* - It is not a balance sweep. `received` is a DELTA over the pre-swap
|
|
1479
|
-
* balance, so a wallet already holding
|
|
1480
|
-
* the balance would move funds the user never offered. The
|
|
1481
|
-
* ceiling and the balance is only ever allowed to lower it.
|
|
1482
|
-
* - It does not touch USDC, which
|
|
1483
|
-
* nothing of the user's in between, nor a
|
|
1484
|
-
* where the sponsor covers the transfer and
|
|
1456
|
+
* balance, so a wallet already holding the asset reads far above it;
|
|
1457
|
+
* depositing the balance would move funds the user never offered. The
|
|
1458
|
+
* arrival is the ceiling and the balance is only ever allowed to lower it.
|
|
1459
|
+
* - It does not touch USDC or EURC, which move on signed typed data
|
|
1460
|
+
* (EIP-3009) and so spend nothing of the user's in between, nor a
|
|
1461
|
+
* paymaster-configured client, where the sponsor covers the transfer and
|
|
1462
|
+
* Permit2 never applies.
|
|
1485
1463
|
*/
|
|
1486
1464
|
private settleSwapDepositAmount;
|
|
1487
1465
|
/**
|
|
@@ -1883,7 +1861,7 @@ declare class OwneySDK {
|
|
|
1883
1861
|
protocolId: string;
|
|
1884
1862
|
chainId: number;
|
|
1885
1863
|
}>;
|
|
1886
|
-
assets: Array<
|
|
1864
|
+
assets: Array<OwneySupportedTokens>;
|
|
1887
1865
|
agentId?: AgentId;
|
|
1888
1866
|
}): Promise<SavedPoolSelection>;
|
|
1889
1867
|
getAccountApy({ agentId, days, tokenSymbol, chainId: scope, }: AccountApyOptions): Promise<OwneyAccountApy | AccountAgentApy>;
|
|
@@ -1915,20 +1893,26 @@ declare class OwneySDK {
|
|
|
1915
1893
|
/**
|
|
1916
1894
|
* Ensure the given asset uses backend protocol auto-selection for the active
|
|
1917
1895
|
* chain's account. No-op (returns false) for agents that don't support it.
|
|
1918
|
-
* @param asset -
|
|
1896
|
+
* @param asset - Asset symbol (e.g. "USDC").
|
|
1919
1897
|
* @param agentId - Agent to target. Defaults to "zyfai".
|
|
1920
1898
|
* @returns whether a profile write occurred.
|
|
1921
1899
|
*/
|
|
1922
|
-
ensureAutoSelectProtocols(asset:
|
|
1900
|
+
ensureAutoSelectProtocols(asset: OwneySupportedTokens, agentId?: AgentId): Promise<boolean>;
|
|
1923
1901
|
/**
|
|
1924
|
-
* One-time, user-paid approval of Permit2 on the sponsored WETH
|
|
1925
|
-
* the active chain. Required once per wallet per chain before
|
|
1926
|
-
* deposits; afterwards deposit() is signature-only.
|
|
1927
|
-
* approval transaction is mined (1 confirmation), so
|
|
1928
|
-
* will see the new allowance; throws if the
|
|
1902
|
+
* One-time, user-paid approval of Permit2 on the sponsored WETH (default) or
|
|
1903
|
+
* USDT token for the active chain. Required once per wallet per chain before
|
|
1904
|
+
* gasless deposits of that asset; afterwards deposit() is signature-only.
|
|
1905
|
+
* Resolves only after the approval transaction is mined (1 confirmation), so
|
|
1906
|
+
* a subsequent deposit() will see the new allowance; throws if the
|
|
1907
|
+
* transaction reverted.
|
|
1908
|
+
*
|
|
1909
|
+
* On mainnet USDT only (`needsAllowanceReset`), a non-zero existing allowance
|
|
1910
|
+
* is first zeroed in its own transaction. If the user rejects the second
|
|
1911
|
+
* prompt, the previous Permit2 allowance stays zeroed; calling this again
|
|
1912
|
+
* approves from zero in a single transaction.
|
|
1929
1913
|
* @returns the approval transaction hash.
|
|
1930
1914
|
*/
|
|
1931
|
-
approvePermit2(asset?: "WETH"): Promise<`0x${string}`>;
|
|
1915
|
+
approvePermit2(asset?: "WETH" | "USDT"): Promise<`0x${string}`>;
|
|
1932
1916
|
/**
|
|
1933
1917
|
* Get the agent's average APY performance over a time period. Does not require a wallet connection.
|
|
1934
1918
|
* @param options - Contains agentId (optional) and days ("7D", "14D", or "30D")
|
|
@@ -1994,17 +1978,16 @@ type OwneySIWXConfig = {
|
|
|
1994
1978
|
declare function createOwneySIWX(config: OwneySIWXConfig): SIWXConfig;
|
|
1995
1979
|
|
|
1996
1980
|
/**
|
|
1997
|
-
*
|
|
1981
|
+
* Ask the wallet ITSELF to switch networks, over WalletConnect.
|
|
1998
1982
|
*
|
|
1999
1983
|
* WalletConnect's provider answers `wallet_switchEthereumChain` locally when
|
|
2000
1984
|
* the chain was approved at connect time: it moves its own default chain and
|
|
2001
1985
|
* reports success without telling the wallet. MetaMask mobile then stays on
|
|
2002
1986
|
* its network, keeps reporting it, and every guard downstream fails with
|
|
2003
1987
|
* CHAIN_MISMATCH — after a swap, with the user's funds already moved (ROUT-727).
|
|
2004
|
-
* Sending the request through the session client reaches
|
|
2005
|
-
* a real "switch network" prompt
|
|
2006
|
-
*
|
|
2007
|
-
* explicitly scoped to that chain and needs no separate network prompt.
|
|
1988
|
+
* Sending the request through the session client reaches the wallet, which
|
|
1989
|
+
* shows a real "switch network" prompt; the client also deep-links the wallet
|
|
1990
|
+
* app open on mobile.
|
|
2008
1991
|
*
|
|
2009
1992
|
* Returns false when `provider` is not a WalletConnect session, so the caller
|
|
2010
1993
|
* can fall back to an ordinary switch.
|
|
@@ -2047,4 +2030,4 @@ type StoredOrder = {
|
|
|
2047
2030
|
*/
|
|
2048
2031
|
declare function listOrders(now?: number): StoredOrder[];
|
|
2049
2032
|
|
|
2050
|
-
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type
|
|
2033
|
+
export { type AccountAgentApy, type AccountApyOptions, type AccountDailyEarnings, type ActivateAgentOptions, type AgentApy, type AgentApyDetails, type AgentBalance, AgentChainIncompatibleError, type AgentEarnings, type AgentHistoryEntry, type AgentHistoryPosition, type AgentId, AgentNotFoundError, type AgentSupportedAsset, type AgentSupportedAssets, type AgentUserProfile, type AgentWithdrawResult, type AgentsApyOptions, type AllocationAgentApy, type AllocationApyOptions, type ApyByChainAndAsset, type ApyCoverage, type ApyHistoryPoint, type ApyIncentive, type Asset, type AssetDailyEarnings, type AvailableAgent, type AvailableAgentsOptions, type AvailablePool, type ConnectionState, type DailyApyDays, type DailyEarningsOptions, type DailyEarningsPoint, type DepositCallback, type DepositOptions, type HistoryAction, type HistoryFilters, type HistoryOptions, type HistoryTransaction, type IAgent, InvalidHistoryCursorError, type LookbackDays, NotConnectedError, type OrgPoolPolicy, type OrgPoolSelection, type OwneyAccountApy, type OwneyAgentApy, type OwneyAgentHistory, type OwneyAllocationApy, type OwneyBalances, type OwneyDepositResult, type OwneyEarnings, OwneyError, type OwneyErrorCode, type OwneyMultiDepositResult, type OwneyPosition, OwneySDK, type OwneySDKConfig, type OwneySIWXConfig, type OwneySupportedChainId, type OwneySupportedChains, type OwneySupportedTokens, type OwneyToken, type OwneyUserProfile, type OwneyWithdrawAllLeg, type OwneyWithdrawAllResult, type OwneyWithdrawResult, type PendingDeposit, type PoolCatalogProtocol, type PoolSelectionStrategy, type RebalanceLog, type SavedPoolSelection, type SwapChainTokens, type SwapDirection, type SwapOrderStatus, type SwapQuote, type SwapQuoteParams, type SwapRail, type SwapStage, type SwapTokenInfo, type SwapTokenSearchResult, type UserPoolSelection, type UserPoolSelectionRequest, type WithdrawOptions, type WithdrawSwapRecord, type WithdrawSwapStatus, clearWithdrawSwap, createOwneySIWX, listPendingDeposits, listOrders as listPendingSwaps, listWithdrawSwaps, saveWithdrawSwap, setOwneyDebug, subscribeWithdrawSwaps, switchWalletConnectChain, updateWithdrawSwap };
|