@dhedge/v2-sdk 2.2.1 → 2.2.2
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/config.d.ts +3 -0
- package/dist/entities/pool.d.ts +3 -1
- package/dist/services/dytm/index.d.ts +7 -0
- package/dist/services/toros/completeWithdrawal.d.ts +2 -2
- package/dist/services/toros/easySwapper.d.ts +4 -1
- package/dist/services/toros/initWithdrawal.d.ts +4 -1
- package/dist/types.d.ts +1 -0
- package/dist/v2-sdk.cjs.development.js +474 -123
- package/dist/v2-sdk.cjs.development.js.map +1 -1
- package/dist/v2-sdk.cjs.production.min.js +1 -1
- package/dist/v2-sdk.cjs.production.min.js.map +1 -1
- package/dist/v2-sdk.esm.js +474 -123
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/dytm/IOffice.json +191 -0
- package/src/config.ts +20 -2
- package/src/entities/pool.ts +66 -32
- package/src/services/dytm/index.ts +77 -0
- package/src/services/toros/completeWithdrawal.ts +23 -7
- package/src/services/toros/easySwapper.ts +9 -7
- package/src/services/toros/initWithdrawal.ts +10 -6
- package/src/test/dytm.test.ts +241 -0
- package/src/types.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"inputs": [
|
|
4
|
+
{
|
|
5
|
+
"components": [
|
|
6
|
+
{
|
|
7
|
+
"internalType": "AccountId",
|
|
8
|
+
"name": "account",
|
|
9
|
+
"type": "uint256"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"internalType": "ReserveKey",
|
|
13
|
+
"name": "key",
|
|
14
|
+
"type": "uint248"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"internalType": "address",
|
|
18
|
+
"name": "receiver",
|
|
19
|
+
"type": "address"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"internalType": "uint256",
|
|
23
|
+
"name": "assets",
|
|
24
|
+
"type": "uint256"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"internalType": "bytes",
|
|
28
|
+
"name": "extraData",
|
|
29
|
+
"type": "bytes"
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"internalType": "struct BorrowParams",
|
|
33
|
+
"name": "params",
|
|
34
|
+
"type": "tuple"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"name": "borrow",
|
|
38
|
+
"outputs": [
|
|
39
|
+
{
|
|
40
|
+
"internalType": "uint256",
|
|
41
|
+
"name": "debtShares",
|
|
42
|
+
"type": "uint256"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"stateMutability": "nonpayable",
|
|
46
|
+
"type": "function"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"inputs": [
|
|
50
|
+
{
|
|
51
|
+
"components": [
|
|
52
|
+
{
|
|
53
|
+
"internalType": "AccountId",
|
|
54
|
+
"name": "account",
|
|
55
|
+
"type": "uint256"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"internalType": "ReserveKey",
|
|
59
|
+
"name": "key",
|
|
60
|
+
"type": "uint248"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"internalType": "enum TokenType",
|
|
64
|
+
"name": "withCollateralType",
|
|
65
|
+
"type": "uint8"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"internalType": "uint256",
|
|
69
|
+
"name": "assets",
|
|
70
|
+
"type": "uint256"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"internalType": "uint256",
|
|
74
|
+
"name": "shares",
|
|
75
|
+
"type": "uint256"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"internalType": "bytes",
|
|
79
|
+
"name": "extraData",
|
|
80
|
+
"type": "bytes"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"internalType": "struct RepayParams",
|
|
84
|
+
"name": "params",
|
|
85
|
+
"type": "tuple"
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"name": "repay",
|
|
89
|
+
"outputs": [
|
|
90
|
+
{
|
|
91
|
+
"internalType": "uint256",
|
|
92
|
+
"name": "assetsRepaid",
|
|
93
|
+
"type": "uint256"
|
|
94
|
+
}
|
|
95
|
+
],
|
|
96
|
+
"stateMutability": "nonpayable",
|
|
97
|
+
"type": "function"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"inputs": [
|
|
101
|
+
{
|
|
102
|
+
"components": [
|
|
103
|
+
{
|
|
104
|
+
"internalType": "AccountId",
|
|
105
|
+
"name": "account",
|
|
106
|
+
"type": "uint256"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"internalType": "uint256",
|
|
110
|
+
"name": "tokenId",
|
|
111
|
+
"type": "uint256"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"internalType": "uint256",
|
|
115
|
+
"name": "assets",
|
|
116
|
+
"type": "uint256"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"internalType": "bytes",
|
|
120
|
+
"name": "extraData",
|
|
121
|
+
"type": "bytes"
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
"internalType": "struct SupplyParams",
|
|
125
|
+
"name": "params",
|
|
126
|
+
"type": "tuple"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"name": "supply",
|
|
130
|
+
"outputs": [
|
|
131
|
+
{
|
|
132
|
+
"internalType": "uint256",
|
|
133
|
+
"name": "shares",
|
|
134
|
+
"type": "uint256"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"stateMutability": "nonpayable",
|
|
138
|
+
"type": "function"
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
"inputs": [
|
|
142
|
+
{
|
|
143
|
+
"components": [
|
|
144
|
+
{
|
|
145
|
+
"internalType": "AccountId",
|
|
146
|
+
"name": "account",
|
|
147
|
+
"type": "uint256"
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"internalType": "uint256",
|
|
151
|
+
"name": "tokenId",
|
|
152
|
+
"type": "uint256"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"internalType": "address",
|
|
156
|
+
"name": "receiver",
|
|
157
|
+
"type": "address"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"internalType": "uint256",
|
|
161
|
+
"name": "assets",
|
|
162
|
+
"type": "uint256"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"internalType": "uint256",
|
|
166
|
+
"name": "shares",
|
|
167
|
+
"type": "uint256"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"internalType": "bytes",
|
|
171
|
+
"name": "extraData",
|
|
172
|
+
"type": "bytes"
|
|
173
|
+
}
|
|
174
|
+
],
|
|
175
|
+
"internalType": "struct WithdrawParams",
|
|
176
|
+
"name": "params",
|
|
177
|
+
"type": "tuple"
|
|
178
|
+
}
|
|
179
|
+
],
|
|
180
|
+
"name": "withdraw",
|
|
181
|
+
"outputs": [
|
|
182
|
+
{
|
|
183
|
+
"internalType": "uint256",
|
|
184
|
+
"name": "assets",
|
|
185
|
+
"type": "uint256"
|
|
186
|
+
}
|
|
187
|
+
],
|
|
188
|
+
"stateMutability": "nonpayable",
|
|
189
|
+
"type": "function"
|
|
190
|
+
}
|
|
191
|
+
]
|
package/src/config.ts
CHANGED
|
@@ -61,7 +61,8 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
61
61
|
[Dapp.TOROS]: "0xA5679C4272A056Bb83f039961fae7D99C48529F5",
|
|
62
62
|
[Dapp.ODOS]: "0x0D05a7D3448512B78fa8A9e46c4872C88C4a0D05",
|
|
63
63
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
64
|
-
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
|
|
64
|
+
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
|
|
65
|
+
[Dapp.DYTM]: "0x0fF1CEE337d7af25eEF4c1a7A2CaF83f98d80001"
|
|
65
66
|
},
|
|
66
67
|
[Network.BASE]: {
|
|
67
68
|
[Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
|
|
@@ -78,7 +79,8 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
78
79
|
[Dapp.PENDLE]: "0x888888888889758F76e7103c6CbF23ABbF58F946",
|
|
79
80
|
[Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
|
|
80
81
|
[Dapp.KYBERSWAP]: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5",
|
|
81
|
-
[Dapp.ONDO]: "0xde41399145F23936b03dD1474eC16c1519c0DC2a"
|
|
82
|
+
[Dapp.ONDO]: "0xde41399145F23936b03dD1474eC16c1519c0DC2a",
|
|
83
|
+
[Dapp.DYTM]: "0x0ff1ce991105DD1a8e26bC8a974Fd0154398Df0f"
|
|
82
84
|
},
|
|
83
85
|
[Network.PLASMA]: {
|
|
84
86
|
[Dapp.AAVEV3]: "0x925a2A7214Ed92428B5b1B090F80b25700095e12",
|
|
@@ -276,3 +278,19 @@ export const OdosSwapFeeRecipient = {
|
|
|
276
278
|
[Network.PLASMA]: "",
|
|
277
279
|
[Network.HYPERLIQUID]: ""
|
|
278
280
|
};
|
|
281
|
+
|
|
282
|
+
export const dytmContractAddresses: Readonly<Partial<
|
|
283
|
+
Record<
|
|
284
|
+
Network,
|
|
285
|
+
{
|
|
286
|
+
Periphery?: string;
|
|
287
|
+
}
|
|
288
|
+
>
|
|
289
|
+
>> = {
|
|
290
|
+
[Network.ARBITRUM]: {
|
|
291
|
+
Periphery: "0x1FBe7Bb394BE505C08e9ee419Dd166c71004e51B"
|
|
292
|
+
},
|
|
293
|
+
[Network.ETHEREUM]: {
|
|
294
|
+
Periphery: "0xbc632a1A4bD878D7e7D14ea6CfE0DDe3Fc291D1a"
|
|
295
|
+
}
|
|
296
|
+
};
|
package/src/entities/pool.ts
CHANGED
|
@@ -77,7 +77,17 @@ import {
|
|
|
77
77
|
} from "../services/pancake/staking";
|
|
78
78
|
import { getOdosSwapTxData } from "../services/odos";
|
|
79
79
|
import { getPendleMintTxData, getPendleSwapTxData } from "../services/pendle";
|
|
80
|
-
import {
|
|
80
|
+
import {
|
|
81
|
+
getCompleteWithdrawalTxData,
|
|
82
|
+
TrackedAsset
|
|
83
|
+
} from "../services/toros/completeWithdrawal";
|
|
84
|
+
import {
|
|
85
|
+
getDytmBorrowTxData,
|
|
86
|
+
getDytmDepositTxData,
|
|
87
|
+
getDytmRepayTxData,
|
|
88
|
+
getDytmWithdrawTxData
|
|
89
|
+
} from "../services/dytm";
|
|
90
|
+
|
|
81
91
|
import {
|
|
82
92
|
getCreateLimitOrderTxData,
|
|
83
93
|
getModifyLimitOrderTxData,
|
|
@@ -417,13 +427,13 @@ export class Pool {
|
|
|
417
427
|
);
|
|
418
428
|
break;
|
|
419
429
|
case Dapp.TOROS:
|
|
420
|
-
swapTxData = await getEasySwapperTxData(
|
|
430
|
+
({ swapTxData, minAmountOut } = await getEasySwapperTxData(
|
|
421
431
|
this,
|
|
422
432
|
assetFrom,
|
|
423
433
|
assetTo,
|
|
424
434
|
ethers.BigNumber.from(amountIn),
|
|
425
435
|
slippage
|
|
426
|
-
);
|
|
436
|
+
));
|
|
427
437
|
break;
|
|
428
438
|
case Dapp.ODOS:
|
|
429
439
|
({ swapTxData, minAmountOut } = await getOdosSwapTxData(
|
|
@@ -796,13 +806,18 @@ export class Pool {
|
|
|
796
806
|
estimateGas: false
|
|
797
807
|
}
|
|
798
808
|
): Promise<any> {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
asset,
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
809
|
+
let depositTxData: string;
|
|
810
|
+
if (dapp === Dapp.DYTM) {
|
|
811
|
+
depositTxData = getDytmDepositTxData(this, asset, amount);
|
|
812
|
+
} else {
|
|
813
|
+
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
814
|
+
depositTxData = iLendingPool.encodeFunctionData(Transaction.DEPOSIT, [
|
|
815
|
+
asset,
|
|
816
|
+
amount,
|
|
817
|
+
this.address,
|
|
818
|
+
referralCode
|
|
819
|
+
]);
|
|
820
|
+
}
|
|
806
821
|
|
|
807
822
|
const tx = await getPoolTxOrGasEstimate(
|
|
808
823
|
this,
|
|
@@ -863,11 +878,17 @@ export class Pool {
|
|
|
863
878
|
estimateGas: false
|
|
864
879
|
}
|
|
865
880
|
): Promise<any> {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
881
|
+
let withdrawTxData: string;
|
|
882
|
+
if (dapp === Dapp.DYTM) {
|
|
883
|
+
withdrawTxData = await getDytmWithdrawTxData(this, asset, amount);
|
|
884
|
+
} else {
|
|
885
|
+
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
886
|
+
withdrawTxData = iLendingPool.encodeFunctionData(Transaction.WITHDRAW, [
|
|
887
|
+
asset,
|
|
888
|
+
amount,
|
|
889
|
+
this.address
|
|
890
|
+
]);
|
|
891
|
+
}
|
|
871
892
|
|
|
872
893
|
const tx = await getPoolTxOrGasEstimate(
|
|
873
894
|
this,
|
|
@@ -930,14 +951,19 @@ export class Pool {
|
|
|
930
951
|
estimateGas: false
|
|
931
952
|
}
|
|
932
953
|
): Promise<any> {
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
asset,
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
954
|
+
let borrowTxData: string;
|
|
955
|
+
if (dapp === Dapp.DYTM) {
|
|
956
|
+
borrowTxData = getDytmBorrowTxData(this, asset, amount);
|
|
957
|
+
} else {
|
|
958
|
+
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
959
|
+
borrowTxData = iLendingPool.encodeFunctionData(Transaction.BORROW, [
|
|
960
|
+
asset,
|
|
961
|
+
amount,
|
|
962
|
+
2,
|
|
963
|
+
referralCode,
|
|
964
|
+
this.address
|
|
965
|
+
]);
|
|
966
|
+
}
|
|
941
967
|
const tx = await getPoolTxOrGasEstimate(
|
|
942
968
|
this,
|
|
943
969
|
[routerAddress[this.network][dapp], borrowTxData, options],
|
|
@@ -964,13 +990,18 @@ export class Pool {
|
|
|
964
990
|
estimateGas: false
|
|
965
991
|
}
|
|
966
992
|
): Promise<any> {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
asset,
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
993
|
+
let repayTxData: string;
|
|
994
|
+
if (dapp === Dapp.DYTM) {
|
|
995
|
+
repayTxData = await getDytmRepayTxData(this, asset, amount);
|
|
996
|
+
} else {
|
|
997
|
+
const iLendingPool = new ethers.utils.Interface(ILendingPool.abi);
|
|
998
|
+
repayTxData = iLendingPool.encodeFunctionData(Transaction.REPAY, [
|
|
999
|
+
asset,
|
|
1000
|
+
amount,
|
|
1001
|
+
2,
|
|
1002
|
+
this.address
|
|
1003
|
+
]);
|
|
1004
|
+
}
|
|
974
1005
|
const tx = await getPoolTxOrGasEstimate(
|
|
975
1006
|
this,
|
|
976
1007
|
[routerAddress[this.network][dapp], repayTxData, options],
|
|
@@ -1963,6 +1994,7 @@ export class Pool {
|
|
|
1963
1994
|
* @param {number} slippage Slippage tolerance in %
|
|
1964
1995
|
* @param {any} options Transaction options
|
|
1965
1996
|
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
1997
|
+
* @param {any} trackedAssets Tracked assets information (only for tx data generation)
|
|
1966
1998
|
* @returns {Promise<any>} Transaction
|
|
1967
1999
|
*/
|
|
1968
2000
|
async completeTorosWithdrawal(
|
|
@@ -1971,13 +2003,15 @@ export class Pool {
|
|
|
1971
2003
|
options: any = null,
|
|
1972
2004
|
sdkOptions: SDKOptions = {
|
|
1973
2005
|
estimateGas: false
|
|
1974
|
-
}
|
|
2006
|
+
},
|
|
2007
|
+
trackedAssets: TrackedAsset[] = []
|
|
1975
2008
|
): Promise<any> {
|
|
1976
2009
|
const txData = await getCompleteWithdrawalTxData(
|
|
1977
2010
|
this,
|
|
1978
2011
|
destinationToken,
|
|
1979
2012
|
slippage * 100,
|
|
1980
|
-
false
|
|
2013
|
+
false,
|
|
2014
|
+
trackedAssets
|
|
1981
2015
|
);
|
|
1982
2016
|
const tx = await getPoolTxOrGasEstimate(
|
|
1983
2017
|
this,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import IOffice from "../../abi/dytm/IOffice.json";
|
|
3
|
+
import { Pool } from "../../entities";
|
|
4
|
+
|
|
5
|
+
const iOffice = new ethers.utils.Interface(IOffice);
|
|
6
|
+
|
|
7
|
+
export function toDebtId(key: ethers.BigNumber): ethers.BigNumber {
|
|
8
|
+
const tokenTypeBits = ethers.BigNumber.from(3).shl(248);
|
|
9
|
+
return tokenTypeBits.or(key);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const getDytmDepositTxData = (
|
|
13
|
+
pool: Pool,
|
|
14
|
+
asset: string,
|
|
15
|
+
amount: ethers.BigNumber | string
|
|
16
|
+
): string => {
|
|
17
|
+
return iOffice.encodeFunctionData("supply", [
|
|
18
|
+
{
|
|
19
|
+
account: ethers.BigNumber.from(pool.address), // uint256 (converted address)
|
|
20
|
+
tokenId: asset,
|
|
21
|
+
assets: amount,
|
|
22
|
+
extraData: "0x"
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getDytmBorrowTxData = (
|
|
28
|
+
pool: Pool,
|
|
29
|
+
asset: string,
|
|
30
|
+
amount: ethers.BigNumber | string
|
|
31
|
+
): string => {
|
|
32
|
+
return iOffice.encodeFunctionData("borrow", [
|
|
33
|
+
{
|
|
34
|
+
account: ethers.BigNumber.from(pool.address), // uint256 (converted address)
|
|
35
|
+
key: asset,
|
|
36
|
+
receiver: pool.address,
|
|
37
|
+
assets: amount,
|
|
38
|
+
extraData: "0x"
|
|
39
|
+
}
|
|
40
|
+
]);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const getDytmRepayTxData = async (
|
|
44
|
+
pool: Pool,
|
|
45
|
+
asset: string,
|
|
46
|
+
amount: ethers.BigNumber | string
|
|
47
|
+
): Promise<string> => {
|
|
48
|
+
return iOffice.encodeFunctionData("repay", [
|
|
49
|
+
{
|
|
50
|
+
account: ethers.BigNumber.from(pool.address), // uint256 (converted address)
|
|
51
|
+
key: asset,
|
|
52
|
+
withCollateralType: "0",
|
|
53
|
+
assets: amount,
|
|
54
|
+
shares: "0",
|
|
55
|
+
extraData: "0x"
|
|
56
|
+
}
|
|
57
|
+
]);
|
|
58
|
+
};
|
|
59
|
+
export const getDytmWithdrawTxData = async (
|
|
60
|
+
pool: Pool,
|
|
61
|
+
asset: string,
|
|
62
|
+
amount: ethers.BigNumber | string
|
|
63
|
+
): Promise<string> => {
|
|
64
|
+
const isMaxAmount = ethers.BigNumber.from(amount).eq(
|
|
65
|
+
ethers.constants.MaxUint256
|
|
66
|
+
);
|
|
67
|
+
return iOffice.encodeFunctionData("withdraw", [
|
|
68
|
+
{
|
|
69
|
+
account: ethers.BigNumber.from(pool.address), // uint256 (converted address)
|
|
70
|
+
tokenId: asset,
|
|
71
|
+
assets: isMaxAmount ? 0 : amount,
|
|
72
|
+
shares: isMaxAmount ? amount : 0,
|
|
73
|
+
receiver: pool.address,
|
|
74
|
+
extraData: "0x"
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
};
|
|
@@ -70,19 +70,23 @@ const getSwapWithdrawData = async (
|
|
|
70
70
|
}
|
|
71
71
|
throw new Error("All swap routers failed for complete withdrawal");
|
|
72
72
|
};
|
|
73
|
+
|
|
73
74
|
export const createCompleteWithdrawalTxArguments = async (
|
|
74
75
|
pool: Pool,
|
|
75
76
|
receiveToken: string,
|
|
76
|
-
slippage: number
|
|
77
|
+
slippage: number,
|
|
78
|
+
_trackedAssets: TrackedAsset[]
|
|
77
79
|
): Promise<any> => {
|
|
78
80
|
const easySwapper = new ethers.Contract(
|
|
79
81
|
routerAddress[pool.network][Dapp.TOROS] as string,
|
|
80
82
|
IEasySwapperV2,
|
|
81
83
|
pool.signer
|
|
82
84
|
);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
)
|
|
85
|
+
|
|
86
|
+
let trackedAssets: TrackedAsset[] = _trackedAssets;
|
|
87
|
+
if (trackedAssets.length === 0) {
|
|
88
|
+
trackedAssets = await easySwapper.getTrackedAssets(pool.address);
|
|
89
|
+
}
|
|
86
90
|
|
|
87
91
|
if (
|
|
88
92
|
trackedAssets.length === 0 ||
|
|
@@ -170,10 +174,20 @@ export const createCompleteWithdrawalTxArguments = async (
|
|
|
170
174
|
const withdrawalVaultAddress = await easySwapper.withdrawalContracts(
|
|
171
175
|
pool.address
|
|
172
176
|
);
|
|
173
|
-
|
|
177
|
+
let balanceOfReceiveToken = await receiveTokenErc20.balanceOf(
|
|
174
178
|
withdrawalVaultAddress
|
|
175
179
|
);
|
|
176
180
|
|
|
181
|
+
if (trackedAssets.length !== 0) {
|
|
182
|
+
// finds the receiveTokenErc20's balance inside trackedAssets
|
|
183
|
+
const trackedAsset = trackedAssets.find(
|
|
184
|
+
({ token }) => token.toLowerCase() === receiveToken.toLowerCase()
|
|
185
|
+
);
|
|
186
|
+
if (trackedAsset) {
|
|
187
|
+
balanceOfReceiveToken = balanceOfReceiveToken.add(trackedAsset.balance);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
177
191
|
// complete withdraw _expectedDestTokenAmount
|
|
178
192
|
const estimatedMinReceiveAmount = swapDestMinDestAmount.plus(
|
|
179
193
|
balanceOfReceiveToken.toString()
|
|
@@ -201,12 +215,14 @@ export const getCompleteWithdrawalTxData = async (
|
|
|
201
215
|
pool: Pool,
|
|
202
216
|
receiveToken: string,
|
|
203
217
|
slippage: number,
|
|
204
|
-
useOnChainSwap: boolean
|
|
218
|
+
useOnChainSwap: boolean,
|
|
219
|
+
trackedAssets: TrackedAsset[]
|
|
205
220
|
): Promise<string> => {
|
|
206
221
|
const completeWithdrawTxArguments = await createCompleteWithdrawalTxArguments(
|
|
207
222
|
pool,
|
|
208
223
|
receiveToken,
|
|
209
|
-
slippage
|
|
224
|
+
slippage,
|
|
225
|
+
trackedAssets
|
|
210
226
|
);
|
|
211
227
|
|
|
212
228
|
const isSwapNeeded = completeWithdrawTxArguments.isSwapNeeded;
|
|
@@ -70,7 +70,7 @@ export async function getEasySwapperTxData(
|
|
|
70
70
|
amountIn: ethers.BigNumber,
|
|
71
71
|
slippage: number
|
|
72
72
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
73
|
-
): Promise<any> {
|
|
73
|
+
): Promise<{ swapTxData: string; minAmountOut?: any }> {
|
|
74
74
|
const isWithdrawal = await isPool(pool, assetFrom);
|
|
75
75
|
const [torosAsset, investAsset] = isWithdrawal
|
|
76
76
|
? [assetFrom, assetTo]
|
|
@@ -99,11 +99,13 @@ export async function getEasySwapperTxData(
|
|
|
99
99
|
investAsset,
|
|
100
100
|
amountIn
|
|
101
101
|
);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
const _minAmountOut = minAmountOut.mul(10000 - slippage * 100).div(10000);
|
|
103
|
+
return {
|
|
104
|
+
swapTxData: iEasySwapperV2.encodeFunctionData(
|
|
105
|
+
"depositWithCustomCooldown",
|
|
106
|
+
[torosAsset, depositAsset, amountIn, _minAmountOut]
|
|
107
|
+
),
|
|
108
|
+
minAmountOut: _minAmountOut
|
|
109
|
+
};
|
|
108
110
|
}
|
|
109
111
|
}
|
|
@@ -157,7 +157,7 @@ export const getInitWithdrawalTxData = async (
|
|
|
157
157
|
amountIn: string,
|
|
158
158
|
slippage: number,
|
|
159
159
|
useOnChainSwap: boolean
|
|
160
|
-
): Promise<string> => {
|
|
160
|
+
): Promise<{ swapTxData: string; minAmountOut?: any }> => {
|
|
161
161
|
const complexAssetsData = await createWithdrawTxArguments(
|
|
162
162
|
pool,
|
|
163
163
|
torosAsset,
|
|
@@ -166,9 +166,13 @@ export const getInitWithdrawalTxData = async (
|
|
|
166
166
|
useOnChainSwap
|
|
167
167
|
);
|
|
168
168
|
const iEasySwapperV2 = new ethers.utils.Interface(IEasySwapperV2);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
swapTxData: iEasySwapperV2.encodeFunctionData("initWithdrawal", [
|
|
172
|
+
torosAsset,
|
|
173
|
+
amountIn,
|
|
174
|
+
complexAssetsData
|
|
175
|
+
]),
|
|
176
|
+
minAmountOut: null // not be used when building multicall tx data
|
|
177
|
+
};
|
|
174
178
|
};
|