@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.
- package/dist/cli.js +190 -36
- package/dist/cli.mjs +188 -34
- package/dist/index.browser.global.js +79130 -49354
- package/dist/index.browser.mjs +18039 -11431
- package/dist/index.d.ts +2869 -898
- package/dist/index.js +19036 -12207
- package/dist/index.mjs +18942 -12158
- package/package.json +1 -1
- package/src/data/avnu.abi.json +840 -0
- package/src/data/ekubo-price-fethcer.abi.json +265 -0
- package/src/dataTypes/_bignumber.ts +13 -4
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +76 -41
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +167 -2
- package/src/modules/ExtendedWrapperSDk/types.ts +26 -4
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +110 -67
- package/src/modules/apollo-client-config.ts +28 -0
- package/src/modules/avnu.ts +4 -4
- package/src/modules/ekubo-pricer.ts +79 -0
- package/src/modules/ekubo-quoter.ts +46 -30
- package/src/modules/erc20.ts +17 -0
- package/src/modules/harvests.ts +43 -29
- package/src/modules/pragma.ts +23 -8
- package/src/modules/pricer-from-api.ts +156 -15
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +40 -4
- package/src/modules/pricerBase.ts +2 -1
- package/src/node/deployer.ts +36 -1
- package/src/node/pricer-redis.ts +2 -1
- package/src/strategies/base-strategy.ts +78 -10
- package/src/strategies/ekubo-cl-vault.tsx +906 -347
- package/src/strategies/factory.ts +159 -0
- package/src/strategies/index.ts +6 -1
- package/src/strategies/registry.ts +239 -0
- package/src/strategies/sensei.ts +335 -7
- package/src/strategies/svk-strategy.ts +97 -27
- package/src/strategies/types.ts +4 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +177 -268
- package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
- package/src/strategies/universal-adapters/common-adapter.ts +206 -203
- package/src/strategies/universal-adapters/extended-adapter.ts +155 -336
- package/src/strategies/universal-adapters/index.ts +9 -8
- package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
- package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +110 -75
- package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +762 -844
- package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +396 -204
- package/src/strategies/universal-strategy.tsx +1426 -1178
- package/src/strategies/vesu-extended-strategy/services/executionService.ts +2251 -0
- package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +2941 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +12 -1
- package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +52 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +3 -1
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1781
- package/src/strategies/vesu-rebalance.tsx +255 -152
- package/src/utils/health-factor-math.ts +4 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/logger.browser.ts +22 -4
- package/src/utils/logger.node.ts +259 -24
- package/src/utils/starknet-call-parser.ts +1036 -0
- package/src/utils/strategy-utils.ts +61 -0
- 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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.config.
|
|
80
|
-
|
|
81
|
-
toBigInt(uint256Amount.
|
|
82
|
-
toBigInt(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
toBigInt(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
//
|
|
165
|
-
//
|
|
166
|
-
//
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
// toBigInt(params.props.
|
|
182
|
-
// toBigInt(params.props.
|
|
183
|
-
// toBigInt(
|
|
184
|
-
// toBigInt(params.props.
|
|
185
|
-
//
|
|
186
|
-
// toBigInt(
|
|
187
|
-
//
|
|
188
|
-
|
|
189
|
-
// //
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
//
|
|
195
|
-
// BigInt(r.
|
|
196
|
-
// BigInt(r.
|
|
197
|
-
//
|
|
198
|
-
//
|
|
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
|
}
|