@strkfarm/sdk 2.0.0-dev.27 → 2.0.0-dev.28

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.
Files changed (70) hide show
  1. package/dist/cli.js +190 -36
  2. package/dist/cli.mjs +188 -34
  3. package/dist/index.browser.global.js +79130 -49357
  4. package/dist/index.browser.mjs +18039 -11434
  5. package/dist/index.d.ts +2869 -898
  6. package/dist/index.js +19036 -12210
  7. package/dist/index.mjs +18942 -12161
  8. package/package.json +1 -1
  9. package/src/data/avnu.abi.json +840 -0
  10. package/src/data/ekubo-price-fethcer.abi.json +265 -0
  11. package/src/dataTypes/_bignumber.ts +13 -4
  12. package/src/dataTypes/index.ts +3 -2
  13. package/src/dataTypes/mynumber.ts +141 -0
  14. package/src/global.ts +76 -41
  15. package/src/index.browser.ts +2 -1
  16. package/src/interfaces/common.tsx +167 -2
  17. package/src/modules/ExtendedWrapperSDk/types.ts +26 -4
  18. package/src/modules/ExtendedWrapperSDk/wrapper.ts +110 -67
  19. package/src/modules/apollo-client-config.ts +28 -0
  20. package/src/modules/avnu.ts +4 -4
  21. package/src/modules/ekubo-pricer.ts +79 -0
  22. package/src/modules/ekubo-quoter.ts +46 -30
  23. package/src/modules/erc20.ts +17 -0
  24. package/src/modules/harvests.ts +43 -29
  25. package/src/modules/pragma.ts +23 -8
  26. package/src/modules/pricer-from-api.ts +156 -15
  27. package/src/modules/pricer-lst.ts +1 -1
  28. package/src/modules/pricer.ts +40 -4
  29. package/src/modules/pricerBase.ts +2 -1
  30. package/src/node/deployer.ts +36 -1
  31. package/src/node/pricer-redis.ts +2 -1
  32. package/src/strategies/base-strategy.ts +78 -10
  33. package/src/strategies/ekubo-cl-vault.tsx +906 -347
  34. package/src/strategies/factory.ts +159 -0
  35. package/src/strategies/index.ts +6 -1
  36. package/src/strategies/registry.ts +239 -0
  37. package/src/strategies/sensei.ts +335 -7
  38. package/src/strategies/svk-strategy.ts +97 -27
  39. package/src/strategies/types.ts +4 -0
  40. package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
  41. package/src/strategies/universal-adapters/avnu-adapter.ts +177 -268
  42. package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
  43. package/src/strategies/universal-adapters/common-adapter.ts +206 -203
  44. package/src/strategies/universal-adapters/extended-adapter.ts +155 -336
  45. package/src/strategies/universal-adapters/index.ts +9 -8
  46. package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
  47. package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
  48. package/src/strategies/universal-adapters/vesu-adapter.ts +110 -75
  49. package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
  50. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +762 -844
  51. package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
  52. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
  53. package/src/strategies/universal-lst-muliplier-strategy.tsx +396 -204
  54. package/src/strategies/universal-strategy.tsx +1426 -1178
  55. package/src/strategies/vesu-extended-strategy/services/executionService.ts +2251 -0
  56. package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +2941 -0
  57. package/src/strategies/vesu-extended-strategy/services/operationService.ts +12 -1
  58. package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +52 -0
  59. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
  60. package/src/strategies/vesu-extended-strategy/utils/constants.ts +2 -0
  61. package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
  62. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1788
  63. package/src/strategies/vesu-rebalance.tsx +255 -152
  64. package/src/utils/health-factor-math.ts +4 -1
  65. package/src/utils/index.ts +2 -1
  66. package/src/utils/logger.browser.ts +22 -4
  67. package/src/utils/logger.node.ts +259 -24
  68. package/src/utils/starknet-call-parser.ts +1036 -0
  69. package/src/utils/strategy-utils.ts +61 -0
  70. package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
@@ -0,0 +1,61 @@
1
+ import { SingleTokenInfo, DualTokenInfo } from "../strategies/base-strategy";
2
+ import { BaseStrategy } from "../strategies/base-strategy";
3
+ import { AmountsInfo, StrategyCapabilities, TokenInfo } from "@/interfaces";
4
+ import { ContractAddr, Web3Number } from "@/dataTypes";
5
+ import { gql } from "@apollo/client";
6
+ import apolloClient from "@/modules/apollo-client";
7
+ import { num } from "starknet";
8
+ import { logger } from "./logger";
9
+
10
+ /**
11
+ * Convert SDK TVL info (SingleTokenInfo or DualTokenInfo) to client AmountsInfo format
12
+ */
13
+ export function toAmountsInfo(tvlInfo: SingleTokenInfo | DualTokenInfo): Omit<
14
+ AmountsInfo,
15
+ "amounts"
16
+ > & {
17
+ amounts: Array<{
18
+ amount: Web3Number;
19
+ tokenInfo: TokenInfo;
20
+ }>;
21
+ } {
22
+ if ("token0" in tvlInfo) {
23
+ // Dual token
24
+ return {
25
+ usdValue: tvlInfo.usdValue,
26
+ amounts: [tvlInfo.token0, tvlInfo.token1]
27
+ };
28
+ } else {
29
+ // Single token
30
+ return {
31
+ usdValue: tvlInfo.usdValue,
32
+ amounts: [tvlInfo]
33
+ };
34
+ }
35
+ }
36
+
37
+ /**
38
+ * Detect what capabilities a strategy instance has
39
+ */
40
+ export function detectCapabilities(
41
+ strategy: BaseStrategy<any, any>
42
+ ): StrategyCapabilities {
43
+ return {
44
+ hasMatchInputAmounts:
45
+ typeof (strategy as any).matchInputAmounts === "function",
46
+ hasNetAPY: typeof (strategy as any).netAPY === "function",
47
+ hasGetInvestmentFlows:
48
+ typeof (strategy as any).getInvestmentFlows === "function",
49
+ hasGetPendingRewards: typeof strategy.getPendingRewards === "function",
50
+ hasHarvest: typeof (strategy as any).harvest === "function",
51
+ hasRebalance: typeof (strategy as any).getRebalanceCall === "function"
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Check if a strategy is a dual-token strategy
57
+ */
58
+ export function isDualTokenStrategy(strategy: BaseStrategy<any, any>): boolean {
59
+ // Check if strategy has matchInputAmounts (dual token strategies have this)
60
+ return typeof (strategy as any).matchInputAmounts === "function";
61
+ }
@@ -1,109 +0,0 @@
1
- import { ContractAddr, Web3Number } from "@/dataTypes";
2
- import { APYType, BaseAdapter, BaseAdapterConfig, DepositParams, ManageCall, PositionAmount, PositionAPY, PositionInfo, SupportedPosition, WithdrawParams } from "./baseAdapter";
3
- import { Contract, uint256 } from "starknet";
4
- import erc20Abi from "@/data/erc20.abi.json";
5
- import { ERC20, TokenMarketData } from "@/modules";
6
- import { Protocols } from "@/interfaces";
7
-
8
- export interface UnusedBalanceAdapterConfig extends BaseAdapterConfig {}
9
-
10
- export class UnusedBalanceAdapter extends BaseAdapter<DepositParams, WithdrawParams> {
11
- readonly config: UnusedBalanceAdapterConfig;
12
- readonly tokenMarketData: TokenMarketData;
13
-
14
- constructor(config: UnusedBalanceAdapterConfig) {
15
- super(config, UnusedBalanceAdapter.name, Protocols.NONE);
16
- this.config = config;
17
- this.tokenMarketData = new TokenMarketData(this.config.pricer, this.config.networkConfig);
18
- }
19
-
20
- protected async getAPY(_supportedPosition: SupportedPosition): Promise<PositionAPY> {
21
- const isSupported = this.tokenMarketData.isAPYSupported(this.config.baseToken);
22
- const apy = isSupported ? await this.tokenMarketData.getAPY(this.config.baseToken) : 0;
23
- return { apy: apy, type: isSupported ? APYType.LST : APYType.BASE };
24
- }
25
-
26
- protected async getPosition(supportedPosition: SupportedPosition): Promise<PositionAmount> {
27
- try {
28
- const balance = await (new ERC20(this.config.networkConfig)).balanceOf(supportedPosition.asset.address, this.config.vaultAllocator.address, supportedPosition.asset.decimals);
29
- return {
30
- amount: balance,
31
- remarks: "Unused balance"
32
- }
33
- } catch (_e) {
34
- throw new Error(`${UnusedBalanceAdapter.name}: Failed to get position for ${supportedPosition.asset.symbol}`);
35
- }
36
- }
37
-
38
- async maxDeposit(amount?: Web3Number): Promise<PositionInfo> {
39
- const baseToken = this.config.baseToken;
40
- if (!amount) {
41
- const infinite = new Web3Number('999999999999999999999999999', baseToken.decimals);
42
- return {
43
- tokenInfo: baseToken,
44
- amount: infinite,
45
- usdValue: Number.POSITIVE_INFINITY,
46
- remarks: "Max deposit (infinity)",
47
- apy: await this.getAPY({ asset: baseToken, isDebt: false }),
48
- protocol: this.protocol
49
- };
50
- }
51
- const usdValue = await this.getUSDValue(baseToken, amount);
52
- return {
53
- tokenInfo: baseToken,
54
- amount,
55
- usdValue,
56
- remarks: "Deposit amount",
57
- apy: await this.getAPY({ asset: baseToken, isDebt: false }),
58
- protocol: this.protocol
59
- };
60
- }
61
-
62
- async maxWithdraw(): Promise<PositionInfo> {
63
- const baseToken = this.config.baseToken;
64
- const current = await this.getPosition({ asset: baseToken, isDebt: false });
65
- const usdValue = await this.getUSDValue(baseToken, current.amount);
66
- return {
67
- tokenInfo: baseToken,
68
- amount: current.amount,
69
- usdValue,
70
- remarks: "Max withdraw",
71
- apy: await this.getAPY({ asset: baseToken, isDebt: false }),
72
- protocol: this.protocol
73
- };
74
- }
75
-
76
- protected _getDepositLeaf(): {
77
- target: ContractAddr,
78
- method: string,
79
- packedArguments: bigint[];
80
- sanitizer: ContractAddr,
81
- id: string
82
- }[] {
83
- return [];
84
- }
85
-
86
- protected _getWithdrawLeaf(): {
87
- target: ContractAddr,
88
- method: string,
89
- packedArguments: bigint[];
90
- sanitizer: ContractAddr,
91
- id: string
92
- }[] {
93
- return [];
94
- }
95
-
96
- async getHealthFactor(): Promise<number> {
97
- return Promise.resolve(10);
98
- }
99
-
100
- getDepositCall(params: DepositParams): Promise<ManageCall[]> {
101
- return Promise.resolve([]);
102
- }
103
-
104
- getWithdrawCall(params: WithdrawParams): Promise<ManageCall[]> {
105
- return Promise.resolve([]);
106
- }
107
- }
108
-
109
-