@strkfarm/sdk 2.0.0-dev.26 → 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 -49354
  4. package/dist/index.browser.mjs +18039 -11431
  5. package/dist/index.d.ts +2869 -898
  6. package/dist/index.js +19036 -12207
  7. package/dist/index.mjs +18942 -12158
  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 +3 -1
  61. package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
  62. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1781
  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
@@ -1,204 +1,207 @@
1
- import { ContractAddr, Web3Number } from "@/dataTypes";
2
- import { LeafData } from "@/utils";
3
- import { Call, hash, num, shortString, uint256 } from "starknet";
4
- import { AVNU_EXCHANGE, AVNU_MIDDLEWARE, SIMPLE_SANITIZER, toBigInt } from "./adapter-utils";
5
- import { AdapterLeafType, BaseAdapter, GenerateCallFn, LeafAdapterFn, ManageCall } from "./baseAdapter";
6
- import { SwapInfo } from "@/modules";
7
-
8
- export interface FlashloanCallParams {
9
- amount: Web3Number,
10
- data: bigint[]
11
- }
12
- export interface ApproveCallParams {
13
- amount: Web3Number,
14
- }
15
- export interface AvnuSwapCallParams {
16
- props: SwapInfo
17
- }
18
-
19
- export interface CommonAdapterConfig {
20
- id: string,
21
- vaultAddress: ContractAddr,
22
- vaultAllocator: ContractAddr,
23
- manager: ContractAddr,
24
- asset: ContractAddr
25
- }
26
-
27
- export class CommonAdapter {
28
- config: CommonAdapterConfig;
29
-
30
- constructor(config: CommonAdapterConfig) {
31
- this.config = config;
32
- }
33
-
34
- protected constructSimpleLeafData(params: {
35
- id: string,
36
- target: ContractAddr,
37
- method: string,
38
- packedArguments: bigint[],
39
- }, sanitizer: ContractAddr = SIMPLE_SANITIZER): LeafData {
40
- const { id, target, method, packedArguments } = params;
41
- return {
42
- id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
43
- readableId: id,
44
- data: [
45
- sanitizer.toBigInt(), // sanitizer address
46
- target.toBigInt(), // contract
47
- toBigInt(hash.getSelectorFromName(method)), // method name
48
- BigInt(packedArguments.length),
49
- ...packedArguments
50
- ]
51
- };
52
- }
53
-
54
- async getFlashloanAdapter(): Promise<AdapterLeafType<FlashloanCallParams>> {
55
- const manageCall = this.getFlashloanCall.bind(this)({amount: Web3Number.fromWei('0', 6), data: []});
56
- const packedArguments: bigint[] = [
57
- this.config.manager.toBigInt(), // receiver
58
- this.config.asset.toBigInt(), // asset
59
- toBigInt(0), // is legacy false
60
- ];
61
- const leaf = this.constructSimpleLeafData({
62
- id: this.config.id,
63
- target: (await manageCall)[0].call.contractAddress,
64
- method: 'flash_loan',
65
- packedArguments
66
- });
67
- return { leaves: [leaf], callConstructor: this.getFlashloanCall.bind(this) };
68
- }
69
-
70
- async getFlashloanCall(params: FlashloanCallParams): Promise<ManageCall[]> {
71
- const uint256Amount = uint256.bnToUint256(params.amount.toWei());
72
- return [{
73
- sanitizer: SIMPLE_SANITIZER,
74
- call: {
75
- contractAddress: this.config.manager,
76
- selector: hash.getSelectorFromName('flash_loan'),
77
- calldata: [
78
- this.config.manager.toBigInt(), // receiver
79
- this.config.asset.toBigInt(), // asset
80
- toBigInt(uint256Amount.low.toString()), // amount low
81
- toBigInt(uint256Amount.high.toString()), // amount high
82
- toBigInt(0), // is legacy false
83
- BigInt(params.data.length),
84
- ...params.data
85
- ]
86
- }
87
- }]
88
- }
89
-
90
- getBringLiquidityAdapter(id: string): () => AdapterLeafType<ApproveCallParams> {
91
- return () => ({
92
- leaves: [this.constructSimpleLeafData({
93
- id: id,
94
- target: this.config.vaultAddress,
95
- method: 'bring_liquidity',
96
- packedArguments: []
97
- })],
98
- callConstructor: this.getBringLiquidityCall().bind(this)
99
- });
100
- }
101
-
102
- getApproveAdapter(token: ContractAddr, spender: ContractAddr, id: string): () => AdapterLeafType<ApproveCallParams> {
103
- return () => ({
104
- leaves: [this.constructSimpleLeafData({
105
- id: id,
106
- target: token,
107
- method: 'approve',
108
- packedArguments: [
109
- spender.toBigInt(), // spender
110
- ]
111
- })],
112
- callConstructor: this.getApproveCall(token, spender).bind(this)
113
- });
114
- }
115
-
116
- getApproveCall(token: ContractAddr, spender: ContractAddr) {
117
- return async (params: ApproveCallParams) => {
118
- const uint256Amount = uint256.bnToUint256(params.amount.toWei());
119
- console.log(`${CommonAdapter.name}::getApproveCall token: ${token}, spender: ${spender}, amount: ${params.amount}`);
120
- return [{
121
- sanitizer: SIMPLE_SANITIZER,
122
- call: {
123
- contractAddress: token,
124
- selector: hash.getSelectorFromName('approve'),
125
- calldata: [
126
- spender.toBigInt(), // spender
127
- toBigInt(uint256Amount.low.toString()), // amount low
128
- toBigInt(uint256Amount.high.toString()), // amount high
129
- ]
130
- }
131
- }]
132
- }
133
- }
134
-
135
-
136
- getBringLiquidityCall(): GenerateCallFn<ApproveCallParams> {
137
- return async (params: ApproveCallParams) => {
138
- const uint256Amount = uint256.bnToUint256(params.amount.toWei());
139
- return [{
140
- sanitizer: SIMPLE_SANITIZER,
141
- call: {
142
- contractAddress: this.config.vaultAddress,
143
- selector: hash.getSelectorFromName('bring_liquidity'),
144
- calldata: [
145
- toBigInt(uint256Amount.low.toString()), // amount low
146
- toBigInt(uint256Amount.high.toString()), // amount high
147
- ]
148
- }
149
- }]
150
- }
151
- }
152
-
153
- // getAvnuAdapter(fromToken: ContractAddr, toToken: ContractAddr, id: string, isMiddleware: boolean): () => AdapterLeafType<AvnuSwapCallParams> {
154
- // return () => ({
155
- // leaf: this.constructSimpleLeafData({
156
- // id: id,
157
- // target: isMiddleware ? AVNU_MIDDLEWARE : AVNU_EXCHANGE,
158
- // method: 'multi_route_swap',
159
- // packedArguments: [
160
- // fromToken.toBigInt(),
161
- // toToken.toBigInt(),
162
- // this.config.vaultAllocator.toBigInt(),
163
- // ]
164
- // }),
165
- // callConstructor: this.getAvnuCall(fromToken, toToken, isMiddleware).bind(this)
166
- // });
167
- // }
168
-
169
- // getAvnuCall(fromToken: ContractAddr, toToken: ContractAddr, isMiddleware: boolean): GenerateCallFn<AvnuSwapCallParams> {
170
- // return (params: AvnuSwapCallParams): ManageCall => {
171
- // return {
172
- // sanitizer: SIMPLE_SANITIZER,
173
- // call: {
174
- // contractAddress: isMiddleware ? AVNU_MIDDLEWARE : AVNU_EXCHANGE,
175
- // selector: hash.getSelectorFromName('multi_route_swap'),
176
- // calldata: [
177
- // fromToken.toBigInt(), // sell_token_address
178
- // toBigInt(params.props.token_from_amount.low.toString()), // sell_token_amount low
179
- // toBigInt(params.props.token_from_amount.high.toString()), // sell_token_amount high
180
- // toToken.toBigInt(), // buy_token_address
181
- // toBigInt(params.props.token_to_amount.low.toString()), // buy_token_amount low
182
- // toBigInt(params.props.token_to_amount.high.toString()), // buy_token_amount high
183
- // toBigInt(params.props.token_to_min_amount.low.toString()), // buy_token_min_amount low
184
- // toBigInt(params.props.token_to_min_amount.high.toString()), // buy_token_min_amount high
185
- // this.config.vaultAllocator.toBigInt(), // beneficiary
186
- // toBigInt(0), // integrator_fee_amount_bps
187
- // this.config.vaultAllocator.toBigInt(), // integrator_fee_recipient
188
-
189
- // // unpack routes
190
- // BigInt(params.props.routes.length),
191
- // ...params.props.routes.map(r => ([
192
- // BigInt(num.hexToDecimalString(r.token_from)),
193
- // BigInt(num.hexToDecimalString(r.token_to)),
194
- // BigInt(num.hexToDecimalString(r.exchange_address)),
195
- // BigInt(r.percent),
196
- // BigInt(r.additional_swap_params.length),
197
- // ...r.additional_swap_params.map(p => BigInt(num.hexToDecimalString(p)))
198
- // ])).flat()
199
- // ]
200
- // }
201
- // }
202
- // }
203
- // }
1
+ import { ContractAddr, Web3Number } from "@/dataTypes";
2
+ import { LeafData } from "@/utils";
3
+ import { Call, hash, num, shortString, uint256 } from "starknet";
4
+ import { AVNU_EXCHANGE, AVNU_MIDDLEWARE, SIMPLE_SANITIZER, toBigInt } from "./adapter-utils";
5
+ import { AdapterLeafType, BaseAdapter, GenerateCallFn, LeafAdapterFn, ManageCall } from "./baseAdapter";
6
+ import { SwapInfo } from "@/modules";
7
+
8
+ export interface FlashloanCallParams {
9
+ amount: Web3Number,
10
+ data: bigint[]
11
+ }
12
+ export interface ApproveCallParams {
13
+ amount: Web3Number,
14
+ }
15
+ export interface AvnuSwapCallParams {
16
+ props: SwapInfo
17
+ }
18
+
19
+ export interface CommonAdapterConfig {
20
+ id: string,
21
+ vaultAddress: ContractAddr,
22
+ vaultAllocator: ContractAddr,
23
+ manager: ContractAddr,
24
+ asset: ContractAddr
25
+ }
26
+
27
+ export class CommonAdapter {
28
+ config: CommonAdapterConfig;
29
+
30
+ constructor(config: CommonAdapterConfig) {
31
+ this.config = config;
32
+ }
33
+
34
+ protected constructSimpleLeafData(params: {
35
+ id: string,
36
+ target: ContractAddr,
37
+ method: string,
38
+ packedArguments: bigint[],
39
+ }, sanitizer: ContractAddr = SIMPLE_SANITIZER): LeafData {
40
+ const { id, target, method, packedArguments } = params;
41
+ return {
42
+ id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
43
+ readableId: id,
44
+ data: [
45
+ sanitizer.toBigInt(), // sanitizer address
46
+ target.toBigInt(), // contract
47
+ toBigInt(hash.getSelectorFromName(method)), // method name
48
+ BigInt(packedArguments.length),
49
+ ...packedArguments
50
+ ]
51
+ };
52
+ }
53
+
54
+ async getFlashloanAdapter(): Promise<AdapterLeafType<FlashloanCallParams>> {
55
+ const manageCall = this.getFlashloanCall.bind(this)({amount: Web3Number.fromWei('0', 6), data: []});
56
+ const packedArguments: bigint[] = [
57
+ this.config.manager.toBigInt(), // receiver
58
+ this.config.asset.toBigInt(), // asset
59
+ toBigInt(0), // is legacy false
60
+ ];
61
+ const leaf = this.constructSimpleLeafData({
62
+ id: this.config.id,
63
+ target: (await manageCall)[0].call.contractAddress,
64
+ method: 'flash_loan',
65
+ packedArguments
66
+ });
67
+ return { leaves: [leaf], callConstructor: this.getFlashloanCall.bind(this) };
68
+ }
69
+
70
+ async getFlashloanCall(params: FlashloanCallParams): Promise<ManageCall[]> {
71
+ const uint256Amount = uint256.bnToUint256(params.amount.toWei());
72
+ return [{
73
+ proofReadableId: this.config.id,
74
+ sanitizer: SIMPLE_SANITIZER,
75
+ call: {
76
+ contractAddress: this.config.manager,
77
+ selector: hash.getSelectorFromName('flash_loan'),
78
+ calldata: [
79
+ this.config.manager.toBigInt(), // receiver
80
+ this.config.asset.toBigInt(), // asset
81
+ toBigInt(uint256Amount.low.toString()), // amount low
82
+ toBigInt(uint256Amount.high.toString()), // amount high
83
+ toBigInt(0), // is legacy false
84
+ BigInt(params.data.length),
85
+ ...params.data
86
+ ]
87
+ }
88
+ }]
89
+ }
90
+
91
+ getBringLiquidityAdapter(id: string): () => AdapterLeafType<ApproveCallParams> {
92
+ return () => ({
93
+ leaves: [this.constructSimpleLeafData({
94
+ id: id,
95
+ target: this.config.vaultAddress,
96
+ method: 'bring_liquidity',
97
+ packedArguments: []
98
+ })],
99
+ callConstructor: this.getBringLiquidityCall(id).bind(this)
100
+ });
101
+ }
102
+
103
+ getApproveAdapter(token: ContractAddr, spender: ContractAddr, id: string): () => AdapterLeafType<ApproveCallParams> {
104
+ return () => ({
105
+ leaves: [this.constructSimpleLeafData({
106
+ id: id,
107
+ target: token,
108
+ method: 'approve',
109
+ packedArguments: [
110
+ spender.toBigInt(), // spender
111
+ ]
112
+ })],
113
+ callConstructor: this.getApproveCall(token, spender, id).bind(this)
114
+ });
115
+ }
116
+
117
+ getApproveCall(token: ContractAddr, spender: ContractAddr, proofReadableId: string) {
118
+ return async (params: ApproveCallParams) => {
119
+ const uint256Amount = uint256.bnToUint256(params.amount.toWei());
120
+ console.log(`${CommonAdapter.name}::getApproveCall token: ${token}, spender: ${spender}, amount: ${params.amount}`);
121
+ return [{
122
+ proofReadableId,
123
+ sanitizer: SIMPLE_SANITIZER,
124
+ call: {
125
+ contractAddress: token,
126
+ selector: hash.getSelectorFromName('approve'),
127
+ calldata: [
128
+ spender.toBigInt(), // spender
129
+ toBigInt(uint256Amount.low.toString()), // amount low
130
+ toBigInt(uint256Amount.high.toString()), // amount high
131
+ ]
132
+ }
133
+ }]
134
+ }
135
+ }
136
+
137
+
138
+ getBringLiquidityCall(proofReadableId: string): GenerateCallFn<ApproveCallParams> {
139
+ return async (params: ApproveCallParams) => {
140
+ const uint256Amount = uint256.bnToUint256(params.amount.toWei());
141
+ return [{
142
+ proofReadableId,
143
+ sanitizer: SIMPLE_SANITIZER,
144
+ call: {
145
+ contractAddress: this.config.vaultAddress,
146
+ selector: hash.getSelectorFromName('bring_liquidity'),
147
+ calldata: [
148
+ toBigInt(uint256Amount.low.toString()), // amount low
149
+ toBigInt(uint256Amount.high.toString()), // amount high
150
+ ]
151
+ }
152
+ }]
153
+ }
154
+ }
155
+
156
+ // getAvnuAdapter(fromToken: ContractAddr, toToken: ContractAddr, id: string, isMiddleware: boolean): () => AdapterLeafType<AvnuSwapCallParams> {
157
+ // return () => ({
158
+ // leaf: this.constructSimpleLeafData({
159
+ // id: id,
160
+ // target: isMiddleware ? AVNU_MIDDLEWARE : AVNU_EXCHANGE,
161
+ // method: 'multi_route_swap',
162
+ // packedArguments: [
163
+ // fromToken.toBigInt(),
164
+ // toToken.toBigInt(),
165
+ // this.config.vaultAllocator.toBigInt(),
166
+ // ]
167
+ // }),
168
+ // callConstructor: this.getAvnuCall(fromToken, toToken, isMiddleware).bind(this)
169
+ // });
170
+ // }
171
+
172
+ // getAvnuCall(fromToken: ContractAddr, toToken: ContractAddr, isMiddleware: boolean): GenerateCallFn<AvnuSwapCallParams> {
173
+ // return (params: AvnuSwapCallParams): ManageCall => {
174
+ // return {
175
+ // sanitizer: SIMPLE_SANITIZER,
176
+ // call: {
177
+ // contractAddress: isMiddleware ? AVNU_MIDDLEWARE : AVNU_EXCHANGE,
178
+ // selector: hash.getSelectorFromName('multi_route_swap'),
179
+ // calldata: [
180
+ // fromToken.toBigInt(), // sell_token_address
181
+ // toBigInt(params.props.token_from_amount.low.toString()), // sell_token_amount low
182
+ // toBigInt(params.props.token_from_amount.high.toString()), // sell_token_amount high
183
+ // toToken.toBigInt(), // buy_token_address
184
+ // toBigInt(params.props.token_to_amount.low.toString()), // buy_token_amount low
185
+ // toBigInt(params.props.token_to_amount.high.toString()), // buy_token_amount high
186
+ // toBigInt(params.props.token_to_min_amount.low.toString()), // buy_token_min_amount low
187
+ // toBigInt(params.props.token_to_min_amount.high.toString()), // buy_token_min_amount high
188
+ // this.config.vaultAllocator.toBigInt(), // beneficiary
189
+ // toBigInt(0), // integrator_fee_amount_bps
190
+ // this.config.vaultAllocator.toBigInt(), // integrator_fee_recipient
191
+
192
+ // // unpack routes
193
+ // BigInt(params.props.routes.length),
194
+ // ...params.props.routes.map(r => ([
195
+ // BigInt(num.hexToDecimalString(r.token_from)),
196
+ // BigInt(num.hexToDecimalString(r.token_to)),
197
+ // BigInt(num.hexToDecimalString(r.exchange_address)),
198
+ // BigInt(r.percent),
199
+ // BigInt(r.additional_swap_params.length),
200
+ // ...r.additional_swap_params.map(p => BigInt(num.hexToDecimalString(p)))
201
+ // ])).flat()
202
+ // ]
203
+ // }
204
+ // }
205
+ // }
206
+ // }
204
207
  }