@zyfai/sdk 0.1.30 → 0.2.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 +12 -12
- package/dist/index.d.mts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +38 -19
- package/dist/index.mjs +38 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,11 +112,11 @@ const walletInfo = await sdk.getSmartWalletAddress(userAddress, 8453);
|
|
|
112
112
|
console.log("Safe Address:", walletInfo.address);
|
|
113
113
|
console.log("Is Deployed:", walletInfo.isDeployed);
|
|
114
114
|
|
|
115
|
-
// Deploy the Safe with default
|
|
115
|
+
// Deploy the Safe with default conservative strategy (automatically checks if already deployed)
|
|
116
116
|
const result = await sdk.deploySafe(userAddress, 8453);
|
|
117
117
|
|
|
118
|
-
// Or deploy with
|
|
119
|
-
const
|
|
118
|
+
// Or deploy with aggressive strategy
|
|
119
|
+
const aggressiveResult = await sdk.deploySafe(userAddress, 8453, "aggressive");
|
|
120
120
|
|
|
121
121
|
if (result.success) {
|
|
122
122
|
console.log("Safe Address:", result.safeAddress);
|
|
@@ -129,8 +129,8 @@ if (result.success) {
|
|
|
129
129
|
|
|
130
130
|
**Strategy Options:**
|
|
131
131
|
|
|
132
|
-
- `"
|
|
133
|
-
- `"
|
|
132
|
+
- `"conservative"` (default): Low-risk, stable yield strategy
|
|
133
|
+
- `"aggressive"`: High-risk, high-reward strategy
|
|
134
134
|
|
|
135
135
|
### 2. Multi-Chain Support
|
|
136
136
|
|
|
@@ -280,9 +280,9 @@ Deploy a Safe smart wallet for a user. **Deployment is handled by the backend AP
|
|
|
280
280
|
|
|
281
281
|
- `userAddress`: User's EOA address
|
|
282
282
|
- `chainId`: Target chain ID
|
|
283
|
-
- `strategy`: Optional strategy selection (default: `"
|
|
284
|
-
- `"
|
|
285
|
-
- `"
|
|
283
|
+
- `strategy`: Optional strategy selection (default: `"conservative"`)
|
|
284
|
+
- `"conservative"`: Low-risk, stable yield strategy (default)
|
|
285
|
+
- `"aggressive"`: High-risk, high-reward strategy
|
|
286
286
|
|
|
287
287
|
**Returns:**
|
|
288
288
|
|
|
@@ -602,7 +602,7 @@ degenStrats.data.forEach((s) => {
|
|
|
602
602
|
|
|
603
603
|
```typescript
|
|
604
604
|
// Get same-chain rebalances
|
|
605
|
-
const apyPerStrategy = await sdk.getAPYPerStrategy(false,
|
|
605
|
+
const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
606
606
|
console.log("APY per strategy:", apyPerStrategy.data);
|
|
607
607
|
```
|
|
608
608
|
|
|
@@ -712,11 +712,11 @@ async function main() {
|
|
|
712
712
|
return;
|
|
713
713
|
}
|
|
714
714
|
|
|
715
|
-
// Deploy Safe with default
|
|
715
|
+
// Deploy Safe with default conservative strategy
|
|
716
716
|
const result = await sdk.deploySafe(userAddress, 8453);
|
|
717
717
|
|
|
718
|
-
// Or deploy with
|
|
719
|
-
// const result = await sdk.deploySafe(userAddress, 8453, "
|
|
718
|
+
// Or deploy with aggressive strategy
|
|
719
|
+
// const result = await sdk.deploySafe(userAddress, 8453, "aggressive");
|
|
720
720
|
|
|
721
721
|
if (result.success) {
|
|
722
722
|
console.log("✅ Successfully deployed Safe");
|
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ import { Chain, PublicClient } from 'viem';
|
|
|
5
5
|
*/
|
|
6
6
|
type Address = `0x${string}`;
|
|
7
7
|
type Hex = `0x${string}`;
|
|
8
|
-
type Strategy = "
|
|
8
|
+
type Strategy = "conservative" | "aggressive";
|
|
9
9
|
interface RpcUrlsConfig {
|
|
10
10
|
8453?: string;
|
|
11
11
|
42161?: string;
|
|
@@ -305,13 +305,13 @@ interface Opportunity {
|
|
|
305
305
|
tvl?: number;
|
|
306
306
|
asset?: string;
|
|
307
307
|
risk?: string;
|
|
308
|
-
strategyType: "
|
|
308
|
+
strategyType: "conservative" | "aggressive";
|
|
309
309
|
status?: string;
|
|
310
310
|
}
|
|
311
311
|
interface OpportunitiesResponse {
|
|
312
312
|
success: boolean;
|
|
313
313
|
chainId?: number;
|
|
314
|
-
strategyType: "
|
|
314
|
+
strategyType: "conservative" | "aggressive";
|
|
315
315
|
data: Opportunity[];
|
|
316
316
|
}
|
|
317
317
|
interface DailyApyEntry {
|
|
@@ -513,16 +513,16 @@ declare class ZyfaiSDK {
|
|
|
513
513
|
*
|
|
514
514
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
515
515
|
* @param chainId - Target chain ID
|
|
516
|
-
* @param strategy - Optional strategy selection: "
|
|
516
|
+
* @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
|
|
517
517
|
* @returns Deployment response with Safe address and transaction hash
|
|
518
518
|
*
|
|
519
519
|
* @example
|
|
520
520
|
* ```typescript
|
|
521
|
-
* // Deploy with default
|
|
521
|
+
* // Deploy with default conservative strategy
|
|
522
522
|
* await sdk.deploySafe(userAddress, 8453);
|
|
523
523
|
*
|
|
524
|
-
* // Deploy with
|
|
525
|
-
* await sdk.deploySafe(userAddress, 8453, "
|
|
524
|
+
* // Deploy with aggressive strategy
|
|
525
|
+
* await sdk.deploySafe(userAddress, 8453, "aggressive");
|
|
526
526
|
* ```
|
|
527
527
|
*/
|
|
528
528
|
deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>;
|
|
@@ -676,17 +676,17 @@ declare class ZyfaiSDK {
|
|
|
676
676
|
* Get APY per strategy for a specific chain
|
|
677
677
|
*
|
|
678
678
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
679
|
-
* @param days - Time period:
|
|
680
|
-
* @param
|
|
679
|
+
* @param days - Time period: 7, 14, or 30
|
|
680
|
+
* @param strategy - Strategy type: "conservative" (default) or "aggressive"
|
|
681
681
|
* @returns APY per strategy for a specific chain
|
|
682
682
|
*
|
|
683
683
|
* @example
|
|
684
684
|
* ```typescript
|
|
685
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false,
|
|
685
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
686
686
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
687
687
|
* ```
|
|
688
688
|
*/
|
|
689
|
-
getAPYPerStrategy(crossChain?: boolean, days?:
|
|
689
|
+
getAPYPerStrategy(crossChain?: boolean, days?: number, strategy?: Strategy): Promise<APYPerStrategyResponse>;
|
|
690
690
|
/**
|
|
691
691
|
* Get total volume across all Zyfai accounts
|
|
692
692
|
*
|
|
@@ -816,10 +816,10 @@ declare class ZyfaiSDK {
|
|
|
816
816
|
*/
|
|
817
817
|
getDebankPortfolio(walletAddress: string): Promise<DebankPortfolioResponse>;
|
|
818
818
|
/**
|
|
819
|
-
* Get
|
|
819
|
+
* Get conservative (low-risk) yield opportunities
|
|
820
820
|
*
|
|
821
821
|
* @param chainId - Optional chain ID filter
|
|
822
|
-
* @returns List of
|
|
822
|
+
* @returns List of conservative yield opportunities
|
|
823
823
|
*
|
|
824
824
|
* @example
|
|
825
825
|
* ```typescript
|
|
@@ -829,10 +829,10 @@ declare class ZyfaiSDK {
|
|
|
829
829
|
*/
|
|
830
830
|
getSafeOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
|
|
831
831
|
/**
|
|
832
|
-
* Get
|
|
832
|
+
* Get aggressive (high-risk, high-reward) yield strategies
|
|
833
833
|
*
|
|
834
834
|
* @param chainId - Optional chain ID filter
|
|
835
|
-
* @returns List of
|
|
835
|
+
* @returns List of aggressive strategies
|
|
836
836
|
*
|
|
837
837
|
* @example
|
|
838
838
|
* ```typescript
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { Chain, PublicClient } from 'viem';
|
|
|
5
5
|
*/
|
|
6
6
|
type Address = `0x${string}`;
|
|
7
7
|
type Hex = `0x${string}`;
|
|
8
|
-
type Strategy = "
|
|
8
|
+
type Strategy = "conservative" | "aggressive";
|
|
9
9
|
interface RpcUrlsConfig {
|
|
10
10
|
8453?: string;
|
|
11
11
|
42161?: string;
|
|
@@ -305,13 +305,13 @@ interface Opportunity {
|
|
|
305
305
|
tvl?: number;
|
|
306
306
|
asset?: string;
|
|
307
307
|
risk?: string;
|
|
308
|
-
strategyType: "
|
|
308
|
+
strategyType: "conservative" | "aggressive";
|
|
309
309
|
status?: string;
|
|
310
310
|
}
|
|
311
311
|
interface OpportunitiesResponse {
|
|
312
312
|
success: boolean;
|
|
313
313
|
chainId?: number;
|
|
314
|
-
strategyType: "
|
|
314
|
+
strategyType: "conservative" | "aggressive";
|
|
315
315
|
data: Opportunity[];
|
|
316
316
|
}
|
|
317
317
|
interface DailyApyEntry {
|
|
@@ -513,16 +513,16 @@ declare class ZyfaiSDK {
|
|
|
513
513
|
*
|
|
514
514
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
515
515
|
* @param chainId - Target chain ID
|
|
516
|
-
* @param strategy - Optional strategy selection: "
|
|
516
|
+
* @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
|
|
517
517
|
* @returns Deployment response with Safe address and transaction hash
|
|
518
518
|
*
|
|
519
519
|
* @example
|
|
520
520
|
* ```typescript
|
|
521
|
-
* // Deploy with default
|
|
521
|
+
* // Deploy with default conservative strategy
|
|
522
522
|
* await sdk.deploySafe(userAddress, 8453);
|
|
523
523
|
*
|
|
524
|
-
* // Deploy with
|
|
525
|
-
* await sdk.deploySafe(userAddress, 8453, "
|
|
524
|
+
* // Deploy with aggressive strategy
|
|
525
|
+
* await sdk.deploySafe(userAddress, 8453, "aggressive");
|
|
526
526
|
* ```
|
|
527
527
|
*/
|
|
528
528
|
deploySafe(userAddress: string, chainId: SupportedChainId, strategy?: Strategy): Promise<DeploySafeResponse>;
|
|
@@ -676,17 +676,17 @@ declare class ZyfaiSDK {
|
|
|
676
676
|
* Get APY per strategy for a specific chain
|
|
677
677
|
*
|
|
678
678
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
679
|
-
* @param days - Time period:
|
|
680
|
-
* @param
|
|
679
|
+
* @param days - Time period: 7, 14, or 30
|
|
680
|
+
* @param strategy - Strategy type: "conservative" (default) or "aggressive"
|
|
681
681
|
* @returns APY per strategy for a specific chain
|
|
682
682
|
*
|
|
683
683
|
* @example
|
|
684
684
|
* ```typescript
|
|
685
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false,
|
|
685
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
686
686
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
687
687
|
* ```
|
|
688
688
|
*/
|
|
689
|
-
getAPYPerStrategy(crossChain?: boolean, days?:
|
|
689
|
+
getAPYPerStrategy(crossChain?: boolean, days?: number, strategy?: Strategy): Promise<APYPerStrategyResponse>;
|
|
690
690
|
/**
|
|
691
691
|
* Get total volume across all Zyfai accounts
|
|
692
692
|
*
|
|
@@ -816,10 +816,10 @@ declare class ZyfaiSDK {
|
|
|
816
816
|
*/
|
|
817
817
|
getDebankPortfolio(walletAddress: string): Promise<DebankPortfolioResponse>;
|
|
818
818
|
/**
|
|
819
|
-
* Get
|
|
819
|
+
* Get conservative (low-risk) yield opportunities
|
|
820
820
|
*
|
|
821
821
|
* @param chainId - Optional chain ID filter
|
|
822
|
-
* @returns List of
|
|
822
|
+
* @returns List of conservative yield opportunities
|
|
823
823
|
*
|
|
824
824
|
* @example
|
|
825
825
|
* ```typescript
|
|
@@ -829,10 +829,10 @@ declare class ZyfaiSDK {
|
|
|
829
829
|
*/
|
|
830
830
|
getSafeOpportunities(chainId?: number): Promise<OpportunitiesResponse>;
|
|
831
831
|
/**
|
|
832
|
-
* Get
|
|
832
|
+
* Get aggressive (high-risk, high-reward) yield strategies
|
|
833
833
|
*
|
|
834
834
|
* @param chainId - Optional chain ID filter
|
|
835
|
-
* @returns List of
|
|
835
|
+
* @returns List of aggressive strategies
|
|
836
836
|
*
|
|
837
837
|
* @example
|
|
838
838
|
* ```typescript
|
package/dist/index.js
CHANGED
|
@@ -94,7 +94,7 @@ var DATA_ENDPOINTS = {
|
|
|
94
94
|
// Rebalance
|
|
95
95
|
REBALANCE_INFO: (isCrossChain) => isCrossChain !== void 0 ? `/rebalance/rebalance-info?isCrossChain=${isCrossChain}` : "/rebalance/rebalance-info",
|
|
96
96
|
// APY Per Strategy
|
|
97
|
-
APY_PER_STRATEGY: (isCrossChain = false, days =
|
|
97
|
+
APY_PER_STRATEGY: (isCrossChain = false, days = 7, strategy = "safe") => `/rebalance/rebalance-info?isCrossChain=${isCrossChain}&days=${days}&strategy=${strategy}`
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
// src/utils/http-client.ts
|
|
@@ -624,6 +624,20 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
624
624
|
};
|
|
625
625
|
};
|
|
626
626
|
|
|
627
|
+
// src/utils/strategy.ts
|
|
628
|
+
function toInternalStrategy(publicStrategy) {
|
|
629
|
+
switch (publicStrategy) {
|
|
630
|
+
case "conservative":
|
|
631
|
+
return "safe_strategy";
|
|
632
|
+
case "aggressive":
|
|
633
|
+
return "degen_strategy";
|
|
634
|
+
default:
|
|
635
|
+
throw new Error(
|
|
636
|
+
`Invalid public strategy: ${publicStrategy}. Must be "conservative" or "aggressive".`
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
627
641
|
// src/core/ZyfaiSDK.ts
|
|
628
642
|
var import_siwe = require("siwe");
|
|
629
643
|
var ZyfaiSDK = class {
|
|
@@ -1005,16 +1019,16 @@ var ZyfaiSDK = class {
|
|
|
1005
1019
|
*
|
|
1006
1020
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
1007
1021
|
* @param chainId - Target chain ID
|
|
1008
|
-
* @param strategy - Optional strategy selection: "
|
|
1022
|
+
* @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
|
|
1009
1023
|
* @returns Deployment response with Safe address and transaction hash
|
|
1010
1024
|
*
|
|
1011
1025
|
* @example
|
|
1012
1026
|
* ```typescript
|
|
1013
|
-
* // Deploy with default
|
|
1027
|
+
* // Deploy with default conservative strategy
|
|
1014
1028
|
* await sdk.deploySafe(userAddress, 8453);
|
|
1015
1029
|
*
|
|
1016
|
-
* // Deploy with
|
|
1017
|
-
* await sdk.deploySafe(userAddress, 8453, "
|
|
1030
|
+
* // Deploy with aggressive strategy
|
|
1031
|
+
* await sdk.deploySafe(userAddress, 8453, "aggressive");
|
|
1018
1032
|
* ```
|
|
1019
1033
|
*/
|
|
1020
1034
|
async deploySafe(userAddress, chainId, strategy) {
|
|
@@ -1057,6 +1071,7 @@ var ZyfaiSDK = class {
|
|
|
1057
1071
|
status: "deployed"
|
|
1058
1072
|
};
|
|
1059
1073
|
}
|
|
1074
|
+
const internalStrategy = strategy ? toInternalStrategy(strategy) : "safe_strategy";
|
|
1060
1075
|
const deploymentResult = await deploySafeAccount({
|
|
1061
1076
|
owner: walletClient,
|
|
1062
1077
|
safeOwnerAddress: userAddress,
|
|
@@ -1064,7 +1079,7 @@ var ZyfaiSDK = class {
|
|
|
1064
1079
|
publicClient: chainConfig.publicClient,
|
|
1065
1080
|
chainId,
|
|
1066
1081
|
httpClient: this.httpClient,
|
|
1067
|
-
strategy:
|
|
1082
|
+
strategy: internalStrategy
|
|
1068
1083
|
});
|
|
1069
1084
|
try {
|
|
1070
1085
|
await this.initializeUser(deploymentResult.safeAddress, chainId);
|
|
@@ -1621,19 +1636,23 @@ var ZyfaiSDK = class {
|
|
|
1621
1636
|
* Get APY per strategy for a specific chain
|
|
1622
1637
|
*
|
|
1623
1638
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1624
|
-
* @param days - Time period:
|
|
1625
|
-
* @param
|
|
1639
|
+
* @param days - Time period: 7, 14, or 30
|
|
1640
|
+
* @param strategy - Strategy type: "conservative" (default) or "aggressive"
|
|
1626
1641
|
* @returns APY per strategy for a specific chain
|
|
1627
1642
|
*
|
|
1628
1643
|
* @example
|
|
1629
1644
|
* ```typescript
|
|
1630
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false,
|
|
1645
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
1631
1646
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1632
1647
|
* ```
|
|
1633
1648
|
*/
|
|
1634
|
-
async getAPYPerStrategy(crossChain = false, days =
|
|
1649
|
+
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative") {
|
|
1635
1650
|
try {
|
|
1636
|
-
const
|
|
1651
|
+
const internalStrategy = toInternalStrategy(strategy);
|
|
1652
|
+
const internalStrategyShort = internalStrategy === "safe_strategy" ? "safe" : "degen";
|
|
1653
|
+
const response = await this.httpClient.dataGet(
|
|
1654
|
+
DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, internalStrategyShort)
|
|
1655
|
+
);
|
|
1637
1656
|
return {
|
|
1638
1657
|
success: true,
|
|
1639
1658
|
count: response.count || 0,
|
|
@@ -1978,10 +1997,10 @@ var ZyfaiSDK = class {
|
|
|
1978
1997
|
// Opportunities Methods (Data API v2)
|
|
1979
1998
|
// ============================================================================
|
|
1980
1999
|
/**
|
|
1981
|
-
* Get
|
|
2000
|
+
* Get conservative (low-risk) yield opportunities
|
|
1982
2001
|
*
|
|
1983
2002
|
* @param chainId - Optional chain ID filter
|
|
1984
|
-
* @returns List of
|
|
2003
|
+
* @returns List of conservative yield opportunities
|
|
1985
2004
|
*
|
|
1986
2005
|
* @example
|
|
1987
2006
|
* ```typescript
|
|
@@ -1998,7 +2017,7 @@ var ZyfaiSDK = class {
|
|
|
1998
2017
|
return {
|
|
1999
2018
|
success: true,
|
|
2000
2019
|
chainId,
|
|
2001
|
-
strategyType: "
|
|
2020
|
+
strategyType: "conservative",
|
|
2002
2021
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
2003
2022
|
id: o.id,
|
|
2004
2023
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -2009,7 +2028,7 @@ var ZyfaiSDK = class {
|
|
|
2009
2028
|
tvl: o.tvl || o.zyfiTvl,
|
|
2010
2029
|
asset: o.asset || o.underlying_token,
|
|
2011
2030
|
risk: o.risk,
|
|
2012
|
-
strategyType: "
|
|
2031
|
+
strategyType: "conservative",
|
|
2013
2032
|
status: o.status
|
|
2014
2033
|
})) : []
|
|
2015
2034
|
};
|
|
@@ -2020,10 +2039,10 @@ var ZyfaiSDK = class {
|
|
|
2020
2039
|
}
|
|
2021
2040
|
}
|
|
2022
2041
|
/**
|
|
2023
|
-
* Get
|
|
2042
|
+
* Get aggressive (high-risk, high-reward) yield strategies
|
|
2024
2043
|
*
|
|
2025
2044
|
* @param chainId - Optional chain ID filter
|
|
2026
|
-
* @returns List of
|
|
2045
|
+
* @returns List of aggressive strategies
|
|
2027
2046
|
*
|
|
2028
2047
|
* @example
|
|
2029
2048
|
* ```typescript
|
|
@@ -2040,7 +2059,7 @@ var ZyfaiSDK = class {
|
|
|
2040
2059
|
return {
|
|
2041
2060
|
success: true,
|
|
2042
2061
|
chainId,
|
|
2043
|
-
strategyType: "
|
|
2062
|
+
strategyType: "aggressive",
|
|
2044
2063
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
2045
2064
|
id: o.id,
|
|
2046
2065
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -2051,7 +2070,7 @@ var ZyfaiSDK = class {
|
|
|
2051
2070
|
tvl: o.tvl || o.zyfiTvl,
|
|
2052
2071
|
asset: o.asset || o.underlying_token,
|
|
2053
2072
|
risk: o.risk,
|
|
2054
|
-
strategyType: "
|
|
2073
|
+
strategyType: "aggressive",
|
|
2055
2074
|
status: o.status
|
|
2056
2075
|
})) : []
|
|
2057
2076
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -53,7 +53,7 @@ var DATA_ENDPOINTS = {
|
|
|
53
53
|
// Rebalance
|
|
54
54
|
REBALANCE_INFO: (isCrossChain) => isCrossChain !== void 0 ? `/rebalance/rebalance-info?isCrossChain=${isCrossChain}` : "/rebalance/rebalance-info",
|
|
55
55
|
// APY Per Strategy
|
|
56
|
-
APY_PER_STRATEGY: (isCrossChain = false, days =
|
|
56
|
+
APY_PER_STRATEGY: (isCrossChain = false, days = 7, strategy = "safe") => `/rebalance/rebalance-info?isCrossChain=${isCrossChain}&days=${days}&strategy=${strategy}`
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// src/utils/http-client.ts
|
|
@@ -601,6 +601,20 @@ var signSessionKey = async (config, sessions, allPublicClients, signingParams) =
|
|
|
601
601
|
};
|
|
602
602
|
};
|
|
603
603
|
|
|
604
|
+
// src/utils/strategy.ts
|
|
605
|
+
function toInternalStrategy(publicStrategy) {
|
|
606
|
+
switch (publicStrategy) {
|
|
607
|
+
case "conservative":
|
|
608
|
+
return "safe_strategy";
|
|
609
|
+
case "aggressive":
|
|
610
|
+
return "degen_strategy";
|
|
611
|
+
default:
|
|
612
|
+
throw new Error(
|
|
613
|
+
`Invalid public strategy: ${publicStrategy}. Must be "conservative" or "aggressive".`
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
604
618
|
// src/core/ZyfaiSDK.ts
|
|
605
619
|
import { SiweMessage } from "siwe";
|
|
606
620
|
var ZyfaiSDK = class {
|
|
@@ -982,16 +996,16 @@ var ZyfaiSDK = class {
|
|
|
982
996
|
*
|
|
983
997
|
* @param userAddress - User's EOA address (the connected EOA, not the smart wallet address)
|
|
984
998
|
* @param chainId - Target chain ID
|
|
985
|
-
* @param strategy - Optional strategy selection: "
|
|
999
|
+
* @param strategy - Optional strategy selection: "conservative" (default) or "aggressive"
|
|
986
1000
|
* @returns Deployment response with Safe address and transaction hash
|
|
987
1001
|
*
|
|
988
1002
|
* @example
|
|
989
1003
|
* ```typescript
|
|
990
|
-
* // Deploy with default
|
|
1004
|
+
* // Deploy with default conservative strategy
|
|
991
1005
|
* await sdk.deploySafe(userAddress, 8453);
|
|
992
1006
|
*
|
|
993
|
-
* // Deploy with
|
|
994
|
-
* await sdk.deploySafe(userAddress, 8453, "
|
|
1007
|
+
* // Deploy with aggressive strategy
|
|
1008
|
+
* await sdk.deploySafe(userAddress, 8453, "aggressive");
|
|
995
1009
|
* ```
|
|
996
1010
|
*/
|
|
997
1011
|
async deploySafe(userAddress, chainId, strategy) {
|
|
@@ -1034,6 +1048,7 @@ var ZyfaiSDK = class {
|
|
|
1034
1048
|
status: "deployed"
|
|
1035
1049
|
};
|
|
1036
1050
|
}
|
|
1051
|
+
const internalStrategy = strategy ? toInternalStrategy(strategy) : "safe_strategy";
|
|
1037
1052
|
const deploymentResult = await deploySafeAccount({
|
|
1038
1053
|
owner: walletClient,
|
|
1039
1054
|
safeOwnerAddress: userAddress,
|
|
@@ -1041,7 +1056,7 @@ var ZyfaiSDK = class {
|
|
|
1041
1056
|
publicClient: chainConfig.publicClient,
|
|
1042
1057
|
chainId,
|
|
1043
1058
|
httpClient: this.httpClient,
|
|
1044
|
-
strategy:
|
|
1059
|
+
strategy: internalStrategy
|
|
1045
1060
|
});
|
|
1046
1061
|
try {
|
|
1047
1062
|
await this.initializeUser(deploymentResult.safeAddress, chainId);
|
|
@@ -1598,19 +1613,23 @@ var ZyfaiSDK = class {
|
|
|
1598
1613
|
* Get APY per strategy for a specific chain
|
|
1599
1614
|
*
|
|
1600
1615
|
* @param crossChain - Whether to get cross-chain APY (true = omni account, false = simple account)
|
|
1601
|
-
* @param days - Time period:
|
|
1602
|
-
* @param
|
|
1616
|
+
* @param days - Time period: 7, 14, or 30
|
|
1617
|
+
* @param strategy - Strategy type: "conservative" (default) or "aggressive"
|
|
1603
1618
|
* @returns APY per strategy for a specific chain
|
|
1604
1619
|
*
|
|
1605
1620
|
* @example
|
|
1606
1621
|
* ```typescript
|
|
1607
|
-
* const apyPerStrategy = await sdk.getAPYPerStrategy(false,
|
|
1622
|
+
* const apyPerStrategy = await sdk.getAPYPerStrategy(false, 7, "conservative");
|
|
1608
1623
|
* console.log("APY per strategy per chain:", apyPerStrategy.data);
|
|
1609
1624
|
* ```
|
|
1610
1625
|
*/
|
|
1611
|
-
async getAPYPerStrategy(crossChain = false, days =
|
|
1626
|
+
async getAPYPerStrategy(crossChain = false, days = 7, strategy = "conservative") {
|
|
1612
1627
|
try {
|
|
1613
|
-
const
|
|
1628
|
+
const internalStrategy = toInternalStrategy(strategy);
|
|
1629
|
+
const internalStrategyShort = internalStrategy === "safe_strategy" ? "safe" : "degen";
|
|
1630
|
+
const response = await this.httpClient.dataGet(
|
|
1631
|
+
DATA_ENDPOINTS.APY_PER_STRATEGY(crossChain, days, internalStrategyShort)
|
|
1632
|
+
);
|
|
1614
1633
|
return {
|
|
1615
1634
|
success: true,
|
|
1616
1635
|
count: response.count || 0,
|
|
@@ -1955,10 +1974,10 @@ var ZyfaiSDK = class {
|
|
|
1955
1974
|
// Opportunities Methods (Data API v2)
|
|
1956
1975
|
// ============================================================================
|
|
1957
1976
|
/**
|
|
1958
|
-
* Get
|
|
1977
|
+
* Get conservative (low-risk) yield opportunities
|
|
1959
1978
|
*
|
|
1960
1979
|
* @param chainId - Optional chain ID filter
|
|
1961
|
-
* @returns List of
|
|
1980
|
+
* @returns List of conservative yield opportunities
|
|
1962
1981
|
*
|
|
1963
1982
|
* @example
|
|
1964
1983
|
* ```typescript
|
|
@@ -1975,7 +1994,7 @@ var ZyfaiSDK = class {
|
|
|
1975
1994
|
return {
|
|
1976
1995
|
success: true,
|
|
1977
1996
|
chainId,
|
|
1978
|
-
strategyType: "
|
|
1997
|
+
strategyType: "conservative",
|
|
1979
1998
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
1980
1999
|
id: o.id,
|
|
1981
2000
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -1986,7 +2005,7 @@ var ZyfaiSDK = class {
|
|
|
1986
2005
|
tvl: o.tvl || o.zyfiTvl,
|
|
1987
2006
|
asset: o.asset || o.underlying_token,
|
|
1988
2007
|
risk: o.risk,
|
|
1989
|
-
strategyType: "
|
|
2008
|
+
strategyType: "conservative",
|
|
1990
2009
|
status: o.status
|
|
1991
2010
|
})) : []
|
|
1992
2011
|
};
|
|
@@ -1997,10 +2016,10 @@ var ZyfaiSDK = class {
|
|
|
1997
2016
|
}
|
|
1998
2017
|
}
|
|
1999
2018
|
/**
|
|
2000
|
-
* Get
|
|
2019
|
+
* Get aggressive (high-risk, high-reward) yield strategies
|
|
2001
2020
|
*
|
|
2002
2021
|
* @param chainId - Optional chain ID filter
|
|
2003
|
-
* @returns List of
|
|
2022
|
+
* @returns List of aggressive strategies
|
|
2004
2023
|
*
|
|
2005
2024
|
* @example
|
|
2006
2025
|
* ```typescript
|
|
@@ -2017,7 +2036,7 @@ var ZyfaiSDK = class {
|
|
|
2017
2036
|
return {
|
|
2018
2037
|
success: true,
|
|
2019
2038
|
chainId,
|
|
2020
|
-
strategyType: "
|
|
2039
|
+
strategyType: "aggressive",
|
|
2021
2040
|
data: Array.isArray(data) ? data.map((o) => ({
|
|
2022
2041
|
id: o.id,
|
|
2023
2042
|
protocolId: o.protocol_id || o.protocolId,
|
|
@@ -2028,7 +2047,7 @@ var ZyfaiSDK = class {
|
|
|
2028
2047
|
tvl: o.tvl || o.zyfiTvl,
|
|
2029
2048
|
asset: o.asset || o.underlying_token,
|
|
2030
2049
|
risk: o.risk,
|
|
2031
|
-
strategyType: "
|
|
2050
|
+
strategyType: "aggressive",
|
|
2032
2051
|
status: o.status
|
|
2033
2052
|
})) : []
|
|
2034
2053
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zyfai/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for Zyfai Yield Optimization Engine - Deploy Safe smart wallets, manage session keys, and interact with DeFi protocols",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|