@strkfarm/sdk 1.1.69 → 2.0.0-dev.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/dist/cli.js +2 -2
- package/dist/cli.mjs +2 -2
- package/dist/index.browser.global.js +66861 -59746
- package/dist/index.browser.mjs +24970 -18579
- package/dist/index.d.ts +1969 -776
- package/dist/index.js +25259 -18845
- package/dist/index.mjs +25464 -19090
- package/package.json +80 -76
- package/src/data/extended-deposit.abi.json +3613 -0
- package/src/data/universal-vault.abi.json +135 -20
- package/src/dataTypes/address.ts +8 -1
- package/src/global.ts +240 -193
- package/src/interfaces/common.tsx +26 -2
- package/src/modules/ExtendedWrapperSDk/index.ts +62 -0
- package/src/modules/ExtendedWrapperSDk/types.ts +311 -0
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +395 -0
- package/src/modules/avnu.ts +17 -4
- package/src/modules/ekubo-quoter.ts +99 -11
- package/src/modules/erc20.ts +67 -21
- package/src/modules/harvests.ts +16 -29
- package/src/modules/index.ts +5 -1
- package/src/modules/lst-apr.ts +36 -0
- package/src/modules/midas.ts +159 -0
- package/src/modules/pricer-from-api.ts +2 -2
- package/src/modules/pricer.ts +3 -38
- package/src/modules/token-market-data.ts +202 -0
- package/src/node/deployer.ts +1 -36
- package/src/strategies/autoCompounderStrk.ts +1 -1
- package/src/strategies/base-strategy.ts +20 -3
- package/src/strategies/ekubo-cl-vault.tsx +123 -306
- package/src/strategies/index.ts +4 -1
- package/src/strategies/svk-strategy.ts +247 -0
- package/src/strategies/universal-adapters/adapter-optimizer.ts +65 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +5 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +418 -0
- package/src/strategies/universal-adapters/baseAdapter.ts +181 -153
- package/src/strategies/universal-adapters/common-adapter.ts +98 -77
- package/src/strategies/universal-adapters/extended-adapter.ts +544 -0
- package/src/strategies/universal-adapters/index.ts +5 -1
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +109 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +220 -218
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +924 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +58 -51
- package/src/strategies/universal-lst-muliplier-strategy.tsx +707 -774
- package/src/strategies/universal-strategy.tsx +1098 -1180
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +28 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +77 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +48 -0
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +374 -0
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +992 -0
- package/src/strategies/vesu-rebalance.tsx +16 -19
- package/src/utils/health-factor-math.ts +11 -5
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Call, hash, num, shortString } from "starknet";
|
|
2
2
|
import { SIMPLE_SANITIZER, toBigInt } from "./adapter-utils";
|
|
3
3
|
import { ContractAddr, Web3Number } from "@/dataTypes";
|
|
4
|
-
import { IConfig, TokenInfo } from "@/interfaces";
|
|
4
|
+
import { IConfig, IProtocol, TokenInfo } from "@/interfaces";
|
|
5
5
|
import { PricerBase } from "@/modules/pricerBase";
|
|
6
|
-
import { LeafData } from "@/utils";
|
|
6
|
+
import { LeafData, logger, StandardMerkleTree } from "@/utils";
|
|
7
7
|
import { CacheClass } from "@/utils/cacheClass";
|
|
8
8
|
|
|
9
9
|
export interface ManageCall {
|
|
@@ -15,10 +15,19 @@ export interface ManageCall {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
|
|
19
|
+
export interface DepositParams {
|
|
20
|
+
amount: Web3Number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface WithdrawParams {
|
|
24
|
+
amount: Web3Number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// export type GenerateCallFn<T> = (params: T) => ManageCall;
|
|
28
|
+
// export type AdapterLeafType<T> = {leaf: LeafData, callConstructor: GenerateCallFn<T>}
|
|
29
|
+
export type GenerateCallFn<T> = (params: T) => Promise<ManageCall[]>;
|
|
30
|
+
export type AdapterLeafType<T> = {leaves: LeafData[], callConstructor: GenerateCallFn<T>}
|
|
22
31
|
export type LeafAdapterFn<T> = () => AdapterLeafType<T>;
|
|
23
32
|
|
|
24
33
|
export enum APYType {
|
|
@@ -43,68 +52,73 @@ export interface BaseAdapterConfig {
|
|
|
43
52
|
|
|
44
53
|
export type PositionAPY = { apy: number, type: APYType };
|
|
45
54
|
export type PositionInfo = {
|
|
55
|
+
tokenInfo: TokenInfo,
|
|
46
56
|
amount: Web3Number,
|
|
47
57
|
usdValue: number,
|
|
48
|
-
remarks
|
|
49
|
-
apy: PositionAPY
|
|
58
|
+
remarks: string,
|
|
59
|
+
apy: PositionAPY,
|
|
60
|
+
protocol: IProtocol
|
|
50
61
|
};
|
|
51
62
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
export type PositionAmount = {
|
|
64
|
+
amount: Web3Number,
|
|
65
|
+
remarks: string,
|
|
66
|
+
}
|
|
56
67
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
68
|
+
export abstract class BaseAdapter<DepositParams, WithdrawParams> extends CacheClass {
|
|
69
|
+
readonly name: string;
|
|
70
|
+
readonly config: BaseAdapterConfig;
|
|
71
|
+
readonly protocol: IProtocol;
|
|
61
72
|
|
|
62
|
-
constructor() {
|
|
73
|
+
constructor(config: BaseAdapterConfig, name: string, protocol: IProtocol) {
|
|
63
74
|
super();
|
|
75
|
+
this.config = config;
|
|
76
|
+
this.name = name;
|
|
77
|
+
this.protocol = protocol;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Loop through all supported positions and return amount, usd value, remarks and apy for each
|
|
82
|
+
*/
|
|
83
|
+
async getPositions(): Promise<PositionInfo[]> {
|
|
84
|
+
const results: PositionInfo[] = [];
|
|
85
|
+
for (const supported of this.config.supportedPositions) {
|
|
86
|
+
const amount = await this.getPosition(supported);
|
|
87
|
+
const usdValue = await this.getUSDValue(supported.asset, amount.amount);
|
|
88
|
+
const apy = await this.getAPY(supported);
|
|
89
|
+
results.push({ tokenInfo: supported.asset, amount: amount.amount, usdValue, apy, protocol: this.protocol, remarks: amount.remarks });
|
|
90
|
+
}
|
|
91
|
+
return results;
|
|
64
92
|
}
|
|
65
93
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
// protected abstract maxDeposit(amount?: Web3Number): Promise<PositionInfo[]>;
|
|
95
|
-
|
|
96
|
-
// /**
|
|
97
|
-
// * Implemented by child adapters to calculate maximum withdraw positions
|
|
98
|
-
// */
|
|
99
|
-
// protected abstract maxWithdraw(): Promise<PositionInfo[]>;
|
|
100
|
-
|
|
101
|
-
// /**
|
|
102
|
-
// * Uses pricer to convert an amount of an asset to USD value
|
|
103
|
-
// */
|
|
104
|
-
// protected async getUSDValue(asset: TokenInfo, amount: Web3Number): Promise<number> {
|
|
105
|
-
// const priceInfo = await this.config.pricer.getPrice(asset.symbol);
|
|
106
|
-
// return amount.toNumber() * priceInfo.price;
|
|
107
|
-
// }
|
|
94
|
+
/**
|
|
95
|
+
* Implemented by child adapters to compute APY for a given supported position
|
|
96
|
+
*/
|
|
97
|
+
protected abstract getAPY(supportedPosition: SupportedPosition): Promise<PositionAPY>;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Implemented by child adapters to fetch amount for a given supported position
|
|
101
|
+
*/
|
|
102
|
+
protected abstract getPosition(supportedPosition: SupportedPosition): Promise<PositionAmount>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Implemented by child adapters to calculate maximum deposit positions
|
|
106
|
+
* @param amount Optional amount in baseToken to deposit
|
|
107
|
+
*/
|
|
108
|
+
abstract maxDeposit(amount?: Web3Number): Promise<PositionInfo>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Implemented by child adapters to calculate maximum withdraw positions
|
|
112
|
+
*/
|
|
113
|
+
abstract maxWithdraw(): Promise<PositionInfo>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Uses pricer to convert an amount of an asset to USD value
|
|
117
|
+
*/
|
|
118
|
+
protected async getUSDValue(asset: TokenInfo, amount: Web3Number): Promise<number> {
|
|
119
|
+
const priceInfo = await this.config.pricer.getPrice(asset.symbol);
|
|
120
|
+
return amount.toNumber() * priceInfo.price;
|
|
121
|
+
}
|
|
108
122
|
|
|
109
123
|
|
|
110
124
|
protected constructSimpleLeafData(params: {
|
|
@@ -127,97 +141,111 @@ export type PositionInfo = {
|
|
|
127
141
|
};
|
|
128
142
|
}
|
|
129
143
|
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
144
|
+
/**
|
|
145
|
+
* Implementor must provide target/method/packedArguments/sanitizer for deposit leaf construction
|
|
146
|
+
*/
|
|
147
|
+
protected abstract _getDepositLeaf(): {
|
|
148
|
+
target: ContractAddr,
|
|
149
|
+
method: string,
|
|
150
|
+
packedArguments: bigint[],
|
|
151
|
+
sanitizer: ContractAddr,
|
|
152
|
+
id: string
|
|
153
|
+
}[];
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Implementor must provide target/method/packedArguments/sanitizer for withdraw leaf construction
|
|
157
|
+
*/
|
|
158
|
+
protected abstract _getWithdrawLeaf(): {
|
|
159
|
+
target: ContractAddr,
|
|
160
|
+
method: string,
|
|
161
|
+
packedArguments: bigint[],
|
|
162
|
+
sanitizer: ContractAddr,
|
|
163
|
+
id: string
|
|
164
|
+
}[];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Returns deposit leaf adapter using configured proof id
|
|
168
|
+
*/
|
|
169
|
+
getDepositLeaf(): AdapterLeafType<DepositParams> {
|
|
170
|
+
const leafConfigs = this._getDepositLeaf();
|
|
171
|
+
const leaves = leafConfigs.map(config => {
|
|
172
|
+
const { target, method, packedArguments, sanitizer, id } = config;
|
|
173
|
+
const leaf = this.constructSimpleLeafData({
|
|
174
|
+
id: id,
|
|
175
|
+
target,
|
|
176
|
+
method,
|
|
177
|
+
packedArguments
|
|
178
|
+
}, sanitizer);
|
|
179
|
+
return leaf;
|
|
180
|
+
});
|
|
181
|
+
return { leaves, callConstructor: this.getDepositCall.bind(this) as unknown as GenerateCallFn<DepositParams> };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Returns withdraw leaf adapter using configured proof id
|
|
186
|
+
*/
|
|
187
|
+
getWithdrawLeaf(): AdapterLeafType<WithdrawParams> {
|
|
188
|
+
const leafConfigs = this._getWithdrawLeaf();
|
|
189
|
+
const leaves = leafConfigs.map(config => {
|
|
190
|
+
const { target, method, packedArguments, sanitizer, id } = config;
|
|
191
|
+
const leaf = this.constructSimpleLeafData({
|
|
192
|
+
id: id,
|
|
193
|
+
target,
|
|
194
|
+
method,
|
|
195
|
+
packedArguments
|
|
196
|
+
}, sanitizer ?? SIMPLE_SANITIZER);
|
|
197
|
+
return leaf;
|
|
198
|
+
});
|
|
199
|
+
return { leaves, callConstructor: this.getWithdrawCall.bind(this) as unknown as GenerateCallFn<WithdrawParams> };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Implementor must provide deposit call
|
|
204
|
+
* @param params
|
|
205
|
+
*/
|
|
206
|
+
abstract getDepositCall(params: DepositParams): Promise<ManageCall[]>;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Implementor must provide withdraw call
|
|
210
|
+
* @param params
|
|
211
|
+
*/
|
|
212
|
+
abstract getWithdrawCall(params: WithdrawParams): Promise<ManageCall[]>;
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
getProofs<T>(isDeposit: boolean, tree: StandardMerkleTree): { proofs: string[][], callConstructor: GenerateCallFn<DepositParams> | GenerateCallFn<WithdrawParams> } {
|
|
216
|
+
let proofGroups: string[][] = [];
|
|
217
|
+
|
|
218
|
+
const ids = isDeposit ? this.getDepositLeaf().leaves.map(l => l.readableId) : this.getWithdrawLeaf().leaves.map(l => l.readableId);
|
|
219
|
+
// console.log(`${this.name}::getProofs ids: ${ids}`);
|
|
220
|
+
for (const [i, v] of tree.entries()) {
|
|
221
|
+
// console.log(`${this.name}::getProofs v: ${v.readableId}`);
|
|
222
|
+
if (ids.includes(v.readableId)) {
|
|
223
|
+
// console.log(`${this.name}::getProofs found id: ${v.readableId}`);
|
|
224
|
+
proofGroups.push(tree.getProof(i));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (proofGroups.length != ids.length) {
|
|
228
|
+
throw new Error(`Not all proofs found for IDs: ${ids.join(', ')}`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// find leaf adapter
|
|
232
|
+
return {
|
|
233
|
+
proofs: proofGroups,
|
|
234
|
+
callConstructor: isDeposit ?
|
|
235
|
+
this.getDepositCall.bind(this) :
|
|
236
|
+
this.getWithdrawCall.bind(this)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async getNetAPY(): Promise<number> {
|
|
241
|
+
const positions = await this.getPositions();
|
|
242
|
+
logger.verbose(`${this.name}::getNetAPY: positions: ${JSON.stringify(positions)}`);
|
|
243
|
+
const netAmount = positions.reduce((acc, curr) => acc + curr.usdValue, 0);
|
|
244
|
+
const netAPY = positions.reduce((acc, curr) => acc + curr.apy.apy * curr.usdValue, 0) / netAmount;
|
|
245
|
+
logger.verbose(`${this.name}::getNetAPY: netAPY: ${netAPY}`);
|
|
246
|
+
return netAPY;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
abstract getHealthFactor(): Promise<number>;
|
|
250
|
+
}
|
|
251
|
+
|
|
@@ -24,15 +24,34 @@ export interface CommonAdapterConfig {
|
|
|
24
24
|
asset: ContractAddr
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export class CommonAdapter
|
|
27
|
+
export class CommonAdapter {
|
|
28
28
|
config: CommonAdapterConfig;
|
|
29
29
|
|
|
30
30
|
constructor(config: CommonAdapterConfig) {
|
|
31
|
-
super();
|
|
32
31
|
this.config = config;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
|
|
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>> {
|
|
36
55
|
const manageCall = this.getFlashloanCall.bind(this)({amount: Web3Number.fromWei('0', 6), data: []});
|
|
37
56
|
const packedArguments: bigint[] = [
|
|
38
57
|
this.config.manager.toBigInt(), // receiver
|
|
@@ -41,16 +60,16 @@ export class CommonAdapter extends BaseAdapter {
|
|
|
41
60
|
];
|
|
42
61
|
const leaf = this.constructSimpleLeafData({
|
|
43
62
|
id: this.config.id,
|
|
44
|
-
target: manageCall.call.contractAddress,
|
|
63
|
+
target: (await manageCall)[0].call.contractAddress,
|
|
45
64
|
method: 'flash_loan',
|
|
46
65
|
packedArguments
|
|
47
66
|
});
|
|
48
|
-
return { leaf, callConstructor: this.getFlashloanCall.bind(this) };
|
|
67
|
+
return { leaves: [leaf], callConstructor: this.getFlashloanCall.bind(this) };
|
|
49
68
|
}
|
|
50
69
|
|
|
51
|
-
getFlashloanCall(params: FlashloanCallParams): ManageCall {
|
|
70
|
+
async getFlashloanCall(params: FlashloanCallParams): Promise<ManageCall[]> {
|
|
52
71
|
const uint256Amount = uint256.bnToUint256(params.amount.toWei());
|
|
53
|
-
return {
|
|
72
|
+
return [{
|
|
54
73
|
sanitizer: SIMPLE_SANITIZER,
|
|
55
74
|
call: {
|
|
56
75
|
contractAddress: this.config.manager,
|
|
@@ -65,27 +84,40 @@ export class CommonAdapter extends BaseAdapter {
|
|
|
65
84
|
...params.data
|
|
66
85
|
]
|
|
67
86
|
}
|
|
68
|
-
}
|
|
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
|
+
});
|
|
69
100
|
}
|
|
70
101
|
|
|
71
102
|
getApproveAdapter(token: ContractAddr, spender: ContractAddr, id: string): () => AdapterLeafType<ApproveCallParams> {
|
|
72
103
|
return () => ({
|
|
73
|
-
|
|
104
|
+
leaves: [this.constructSimpleLeafData({
|
|
74
105
|
id: id,
|
|
75
106
|
target: token,
|
|
76
107
|
method: 'approve',
|
|
77
108
|
packedArguments: [
|
|
78
109
|
spender.toBigInt(), // spender
|
|
79
110
|
]
|
|
80
|
-
}),
|
|
111
|
+
})],
|
|
81
112
|
callConstructor: this.getApproveCall(token, spender).bind(this)
|
|
82
113
|
});
|
|
83
114
|
}
|
|
84
115
|
|
|
85
116
|
getApproveCall(token: ContractAddr, spender: ContractAddr) {
|
|
86
|
-
return (params: ApproveCallParams) => {
|
|
117
|
+
return async (params: ApproveCallParams) => {
|
|
87
118
|
const uint256Amount = uint256.bnToUint256(params.amount.toWei());
|
|
88
|
-
|
|
119
|
+
console.log(`${CommonAdapter.name}::getApproveCall token: ${token}, spender: ${spender}, amount: ${params.amount}`);
|
|
120
|
+
return [{
|
|
89
121
|
sanitizer: SIMPLE_SANITIZER,
|
|
90
122
|
call: {
|
|
91
123
|
contractAddress: token,
|
|
@@ -96,26 +128,15 @@ export class CommonAdapter extends BaseAdapter {
|
|
|
96
128
|
toBigInt(uint256Amount.high.toString()), // amount high
|
|
97
129
|
]
|
|
98
130
|
}
|
|
99
|
-
}
|
|
131
|
+
}]
|
|
100
132
|
}
|
|
101
133
|
}
|
|
102
134
|
|
|
103
|
-
getBringLiquidityAdapter(id: string): () => AdapterLeafType<ApproveCallParams> {
|
|
104
|
-
return () => ({
|
|
105
|
-
leaf: this.constructSimpleLeafData({
|
|
106
|
-
id: id,
|
|
107
|
-
target: this.config.vaultAddress,
|
|
108
|
-
method: 'bring_liquidity',
|
|
109
|
-
packedArguments: []
|
|
110
|
-
}),
|
|
111
|
-
callConstructor: this.getBringLiquidityCall().bind(this)
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
135
|
|
|
115
|
-
getBringLiquidityCall() {
|
|
116
|
-
return (params: ApproveCallParams) => {
|
|
136
|
+
getBringLiquidityCall(): GenerateCallFn<ApproveCallParams> {
|
|
137
|
+
return async (params: ApproveCallParams) => {
|
|
117
138
|
const uint256Amount = uint256.bnToUint256(params.amount.toWei());
|
|
118
|
-
return {
|
|
139
|
+
return [{
|
|
119
140
|
sanitizer: SIMPLE_SANITIZER,
|
|
120
141
|
call: {
|
|
121
142
|
contractAddress: this.config.vaultAddress,
|
|
@@ -125,59 +146,59 @@ export class CommonAdapter extends BaseAdapter {
|
|
|
125
146
|
toBigInt(uint256Amount.high.toString()), // amount high
|
|
126
147
|
]
|
|
127
148
|
}
|
|
128
|
-
}
|
|
149
|
+
}]
|
|
129
150
|
}
|
|
130
151
|
}
|
|
131
152
|
|
|
132
|
-
getAvnuAdapter(fromToken: ContractAddr, toToken: ContractAddr, id: string, isMiddleware: boolean): () => AdapterLeafType<AvnuSwapCallParams> {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
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
|
+
// }
|
|
147
168
|
|
|
148
|
-
getAvnuCall(fromToken: ContractAddr, toToken: ContractAddr, isMiddleware: boolean): GenerateCallFn<AvnuSwapCallParams> {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
|
167
188
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
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
|
+
// }
|
|
183
204
|
}
|