@dhedge/v2-sdk 1.11.1 → 2.0.0
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/services/odos/index.d.ts +4 -1
- package/dist/services/pendle/index.d.ts +4 -1
- package/dist/v2-sdk.cjs.development.js +242 -109
- 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 +242 -109
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/pendle/PT.json +15 -0
- package/src/abi/pendle/SY.json +1 -0
- package/src/entities/pool.ts +9 -8
- package/src/services/odos/index.ts +5 -2
- package/src/services/pendle/index.ts +43 -8
- package/src/test/odos.test.ts +8 -7
- package/src/test/oneInch.test.ts +20 -22
- package/src/test/pendle.test.ts +63 -37
- package/src/utils/contract.ts +32 -6
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { ethers } from "../..";
|
|
2
2
|
import { Pool } from "../../entities";
|
|
3
|
-
export declare function getOdosSwapTxData(pool: Pool, assetFrom: string, assetTo: string, amountIn: ethers.BigNumber | string, slippage: number): Promise<
|
|
3
|
+
export declare function getOdosSwapTxData(pool: Pool, assetFrom: string, assetTo: string, amountIn: ethers.BigNumber | string, slippage: number): Promise<{
|
|
4
|
+
swapTxData: string;
|
|
5
|
+
minAmountOut: string;
|
|
6
|
+
}>;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ethers } from "../..";
|
|
2
2
|
import { Pool } from "../../entities";
|
|
3
|
-
export declare function getPendleSwapTxData(pool: Pool, tokenIn: string, tokenOut: string, amountIn: ethers.BigNumber | string, slippage: number): Promise<
|
|
3
|
+
export declare function getPendleSwapTxData(pool: Pool, tokenIn: string, tokenOut: string, amountIn: ethers.BigNumber | string, slippage: number): Promise<{
|
|
4
|
+
swapTxData: string;
|
|
5
|
+
minAmountOut: string | null;
|
|
6
|
+
}>;
|
|
4
7
|
export declare function getMarket(pool: Pool, tokenIn: string, tokenOut: string): Promise<string>;
|
|
@@ -16129,68 +16129,108 @@ function _call() {
|
|
|
16129
16129
|
}
|
|
16130
16130
|
var getPoolTxOrGasEstimate = /*#__PURE__*/function () {
|
|
16131
16131
|
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(pool, args, estimateGas) {
|
|
16132
|
+
var gas, gasEstimationError, _gas, _gasEstimationError;
|
|
16133
|
+
|
|
16132
16134
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
16133
16135
|
while (1) {
|
|
16134
16136
|
switch (_context2.prev = _context2.next) {
|
|
16135
16137
|
case 0:
|
|
16136
16138
|
if (!pool.isDhedge) {
|
|
16137
|
-
_context2.next =
|
|
16139
|
+
_context2.next = 21;
|
|
16138
16140
|
break;
|
|
16139
16141
|
}
|
|
16140
16142
|
|
|
16141
16143
|
if (!estimateGas) {
|
|
16142
|
-
_context2.next =
|
|
16144
|
+
_context2.next = 16;
|
|
16143
16145
|
break;
|
|
16144
16146
|
}
|
|
16145
16147
|
|
|
16146
|
-
|
|
16148
|
+
gas = null;
|
|
16149
|
+
gasEstimationError = null;
|
|
16150
|
+
_context2.prev = 4;
|
|
16151
|
+
_context2.next = 7;
|
|
16147
16152
|
return pool.poolLogic.estimateGas.execTransaction(args[0], args[1], args[2]);
|
|
16148
16153
|
|
|
16149
|
-
case 4:
|
|
16150
|
-
return _context2.abrupt("return", _context2.sent);
|
|
16151
|
-
|
|
16152
16154
|
case 7:
|
|
16153
|
-
|
|
16155
|
+
gas = _context2.sent;
|
|
16156
|
+
_context2.next = 13;
|
|
16157
|
+
break;
|
|
16158
|
+
|
|
16159
|
+
case 10:
|
|
16160
|
+
_context2.prev = 10;
|
|
16161
|
+
_context2.t0 = _context2["catch"](4);
|
|
16162
|
+
gasEstimationError = _context2.t0;
|
|
16163
|
+
|
|
16164
|
+
case 13:
|
|
16165
|
+
return _context2.abrupt("return", {
|
|
16166
|
+
gas: gas,
|
|
16167
|
+
txData: args[1],
|
|
16168
|
+
to: args[0],
|
|
16169
|
+
gasEstimationError: gasEstimationError,
|
|
16170
|
+
minAmountOut: args[3] || null
|
|
16171
|
+
});
|
|
16172
|
+
|
|
16173
|
+
case 16:
|
|
16174
|
+
_context2.next = 18;
|
|
16154
16175
|
return pool.poolLogic.execTransaction(args[0], args[1], args[2]);
|
|
16155
16176
|
|
|
16156
|
-
case
|
|
16177
|
+
case 18:
|
|
16157
16178
|
return _context2.abrupt("return", _context2.sent);
|
|
16158
16179
|
|
|
16159
|
-
case
|
|
16160
|
-
_context2.next =
|
|
16180
|
+
case 19:
|
|
16181
|
+
_context2.next = 39;
|
|
16161
16182
|
break;
|
|
16162
16183
|
|
|
16163
|
-
case
|
|
16184
|
+
case 21:
|
|
16164
16185
|
if (!estimateGas) {
|
|
16165
|
-
_context2.next =
|
|
16186
|
+
_context2.next = 36;
|
|
16166
16187
|
break;
|
|
16167
16188
|
}
|
|
16168
16189
|
|
|
16169
|
-
|
|
16190
|
+
_gas = null;
|
|
16191
|
+
_gasEstimationError = null;
|
|
16192
|
+
_context2.prev = 24;
|
|
16193
|
+
_context2.next = 27;
|
|
16170
16194
|
return pool.signer.estimateGas({
|
|
16171
16195
|
to: args[0],
|
|
16172
16196
|
data: args[1]
|
|
16173
16197
|
});
|
|
16174
16198
|
|
|
16175
|
-
case
|
|
16176
|
-
|
|
16199
|
+
case 27:
|
|
16200
|
+
_gas = _context2.sent;
|
|
16201
|
+
_context2.next = 33;
|
|
16202
|
+
break;
|
|
16177
16203
|
|
|
16178
|
-
case
|
|
16179
|
-
_context2.
|
|
16204
|
+
case 30:
|
|
16205
|
+
_context2.prev = 30;
|
|
16206
|
+
_context2.t1 = _context2["catch"](24);
|
|
16207
|
+
_gasEstimationError = _context2.t1;
|
|
16208
|
+
|
|
16209
|
+
case 33:
|
|
16210
|
+
return _context2.abrupt("return", {
|
|
16211
|
+
gas: _gas,
|
|
16212
|
+
txData: args[1],
|
|
16213
|
+
to: args[0],
|
|
16214
|
+
gasEstimationError: _gasEstimationError,
|
|
16215
|
+
minAmountOut: args[3] || null
|
|
16216
|
+
});
|
|
16217
|
+
|
|
16218
|
+
case 36:
|
|
16219
|
+
_context2.next = 38;
|
|
16180
16220
|
return pool.signer.sendTransaction(_extends({
|
|
16181
16221
|
to: args[0],
|
|
16182
16222
|
data: args[1]
|
|
16183
16223
|
}, args[2]));
|
|
16184
16224
|
|
|
16185
|
-
case
|
|
16225
|
+
case 38:
|
|
16186
16226
|
return _context2.abrupt("return", _context2.sent);
|
|
16187
16227
|
|
|
16188
|
-
case
|
|
16228
|
+
case 39:
|
|
16189
16229
|
case "end":
|
|
16190
16230
|
return _context2.stop();
|
|
16191
16231
|
}
|
|
16192
16232
|
}
|
|
16193
|
-
}, _callee2);
|
|
16233
|
+
}, _callee2, null, [[4, 10], [24, 30]]);
|
|
16194
16234
|
}));
|
|
16195
16235
|
|
|
16196
16236
|
return function getPoolTxOrGasEstimate(_x12, _x13, _x14) {
|
|
@@ -24560,7 +24600,10 @@ function _getOdosSwapTxData() {
|
|
|
24560
24600
|
|
|
24561
24601
|
case 10:
|
|
24562
24602
|
assembleResult = _context.sent;
|
|
24563
|
-
return _context.abrupt("return",
|
|
24603
|
+
return _context.abrupt("return", {
|
|
24604
|
+
swapTxData: assembleResult.data.transaction.data,
|
|
24605
|
+
minAmountOut: assembleResult.data.outputTokens[0].amount
|
|
24606
|
+
});
|
|
24564
24607
|
|
|
24565
24608
|
case 14:
|
|
24566
24609
|
_context.prev = 14;
|
|
@@ -24701,66 +24744,111 @@ var ActionMiscV3Abi = [
|
|
|
24701
24744
|
}
|
|
24702
24745
|
];
|
|
24703
24746
|
|
|
24747
|
+
var PTAbi = [
|
|
24748
|
+
{
|
|
24749
|
+
inputs: [
|
|
24750
|
+
],
|
|
24751
|
+
name: "SY",
|
|
24752
|
+
outputs: [
|
|
24753
|
+
{
|
|
24754
|
+
internalType: "address",
|
|
24755
|
+
name: "",
|
|
24756
|
+
type: "address"
|
|
24757
|
+
}
|
|
24758
|
+
],
|
|
24759
|
+
stateMutability: "view",
|
|
24760
|
+
type: "function"
|
|
24761
|
+
}
|
|
24762
|
+
];
|
|
24763
|
+
|
|
24764
|
+
var SYAbi = [
|
|
24765
|
+
{
|
|
24766
|
+
inputs: [
|
|
24767
|
+
],
|
|
24768
|
+
name: "exchangeRate",
|
|
24769
|
+
outputs: [
|
|
24770
|
+
{
|
|
24771
|
+
internalType: "uint256",
|
|
24772
|
+
name: "",
|
|
24773
|
+
type: "uint256"
|
|
24774
|
+
}
|
|
24775
|
+
],
|
|
24776
|
+
stateMutability: "view",
|
|
24777
|
+
type: "function"
|
|
24778
|
+
}
|
|
24779
|
+
];
|
|
24780
|
+
|
|
24704
24781
|
var pendleBaseUrl = "https://api-v2.pendle.finance/core/v1";
|
|
24705
24782
|
function getPendleSwapTxData(_x, _x2, _x3, _x4, _x5) {
|
|
24706
24783
|
return _getPendleSwapTxData.apply(this, arguments);
|
|
24707
24784
|
}
|
|
24708
24785
|
|
|
24709
24786
|
function _getPendleSwapTxData() {
|
|
24710
|
-
_getPendleSwapTxData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
24711
|
-
var expiredMarket, params, market, swapResult;
|
|
24712
|
-
return runtime_1.wrap(function
|
|
24787
|
+
_getPendleSwapTxData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(pool, tokenIn, tokenOut, amountIn, slippage) {
|
|
24788
|
+
var expiredMarket, result, params, market, swapResult;
|
|
24789
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
24713
24790
|
while (1) {
|
|
24714
|
-
switch (
|
|
24791
|
+
switch (_context3.prev = _context3.next) {
|
|
24715
24792
|
case 0:
|
|
24716
|
-
|
|
24793
|
+
_context3.next = 2;
|
|
24717
24794
|
return checkExitPostExpPT(pool, tokenIn, tokenOut);
|
|
24718
24795
|
|
|
24719
24796
|
case 2:
|
|
24720
|
-
expiredMarket =
|
|
24797
|
+
expiredMarket = _context3.sent;
|
|
24721
24798
|
|
|
24722
24799
|
if (!expiredMarket) {
|
|
24723
|
-
|
|
24800
|
+
_context3.next = 8;
|
|
24724
24801
|
break;
|
|
24725
24802
|
}
|
|
24726
24803
|
|
|
24727
|
-
|
|
24804
|
+
_context3.next = 6;
|
|
24805
|
+
return getExitExpPTTxData(pool, tokenIn, tokenOut, amountIn, expiredMarket);
|
|
24728
24806
|
|
|
24729
|
-
case
|
|
24807
|
+
case 6:
|
|
24808
|
+
result = _context3.sent;
|
|
24809
|
+
return _context3.abrupt("return", {
|
|
24810
|
+
swapTxData: result.txData,
|
|
24811
|
+
minAmountOut: result.minAmountOut
|
|
24812
|
+
});
|
|
24813
|
+
|
|
24814
|
+
case 8:
|
|
24730
24815
|
params = {
|
|
24731
24816
|
receiver: pool.address,
|
|
24732
24817
|
tokenIn: tokenIn,
|
|
24733
24818
|
tokenOut: tokenOut,
|
|
24734
24819
|
amountIn: amountIn.toString(),
|
|
24735
|
-
slippage: slippage
|
|
24820
|
+
slippage: slippage / 100
|
|
24736
24821
|
};
|
|
24737
|
-
|
|
24822
|
+
_context3.next = 11;
|
|
24738
24823
|
return getMarket(pool, tokenIn, tokenOut);
|
|
24739
24824
|
|
|
24740
|
-
case
|
|
24741
|
-
market =
|
|
24742
|
-
|
|
24743
|
-
|
|
24825
|
+
case 11:
|
|
24826
|
+
market = _context3.sent;
|
|
24827
|
+
_context3.prev = 12;
|
|
24828
|
+
_context3.next = 15;
|
|
24744
24829
|
return axios.get(pendleBaseUrl + "/sdk/" + networkChainIdMap[pool.network] + "/markets/" + market + "/swap", {
|
|
24745
24830
|
params: params
|
|
24746
24831
|
});
|
|
24747
24832
|
|
|
24748
|
-
case
|
|
24749
|
-
swapResult =
|
|
24750
|
-
return
|
|
24833
|
+
case 15:
|
|
24834
|
+
swapResult = _context3.sent;
|
|
24835
|
+
return _context3.abrupt("return", {
|
|
24836
|
+
swapTxData: swapResult.data.tx.data,
|
|
24837
|
+
minAmountOut: swapResult.data.data.amountOut
|
|
24838
|
+
});
|
|
24751
24839
|
|
|
24752
|
-
case
|
|
24753
|
-
|
|
24754
|
-
|
|
24755
|
-
console.error("Error in Pendle API request:",
|
|
24840
|
+
case 19:
|
|
24841
|
+
_context3.prev = 19;
|
|
24842
|
+
_context3.t0 = _context3["catch"](12);
|
|
24843
|
+
console.error("Error in Pendle API request:", _context3.t0);
|
|
24756
24844
|
throw new ApiError("Pendle api request failed");
|
|
24757
24845
|
|
|
24758
|
-
case
|
|
24846
|
+
case 23:
|
|
24759
24847
|
case "end":
|
|
24760
|
-
return
|
|
24848
|
+
return _context3.stop();
|
|
24761
24849
|
}
|
|
24762
24850
|
}
|
|
24763
|
-
},
|
|
24851
|
+
}, _callee3, null, [[12, 19]]);
|
|
24764
24852
|
}));
|
|
24765
24853
|
return _getPendleSwapTxData.apply(this, arguments);
|
|
24766
24854
|
}
|
|
@@ -24776,26 +24864,26 @@ function getMarket(_x6, _x7, _x8) {
|
|
|
24776
24864
|
}
|
|
24777
24865
|
|
|
24778
24866
|
function _getMarket() {
|
|
24779
|
-
_getMarket = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
24867
|
+
_getMarket = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(pool, tokenIn, tokenOut) {
|
|
24780
24868
|
var networkId, marketResult, allMarkets, markets;
|
|
24781
|
-
return runtime_1.wrap(function
|
|
24869
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
24782
24870
|
while (1) {
|
|
24783
|
-
switch (
|
|
24871
|
+
switch (_context4.prev = _context4.next) {
|
|
24784
24872
|
case 0:
|
|
24785
24873
|
networkId = networkChainIdMap[pool.network];
|
|
24786
|
-
|
|
24787
|
-
|
|
24874
|
+
_context4.prev = 1;
|
|
24875
|
+
_context4.next = 4;
|
|
24788
24876
|
return axios.get(pendleBaseUrl + "/" + networkId + "/markets/active");
|
|
24789
24877
|
|
|
24790
24878
|
case 4:
|
|
24791
|
-
marketResult =
|
|
24792
|
-
|
|
24879
|
+
marketResult = _context4.sent;
|
|
24880
|
+
_context4.next = 11;
|
|
24793
24881
|
break;
|
|
24794
24882
|
|
|
24795
24883
|
case 7:
|
|
24796
|
-
|
|
24797
|
-
|
|
24798
|
-
console.error("Error in Pendle API request:",
|
|
24884
|
+
_context4.prev = 7;
|
|
24885
|
+
_context4.t0 = _context4["catch"](1);
|
|
24886
|
+
console.error("Error in Pendle API request:", _context4.t0);
|
|
24799
24887
|
throw new ApiError("Pendle api request failed");
|
|
24800
24888
|
|
|
24801
24889
|
case 11:
|
|
@@ -24807,31 +24895,31 @@ function _getMarket() {
|
|
|
24807
24895
|
});
|
|
24808
24896
|
|
|
24809
24897
|
if (!markets[0]) {
|
|
24810
|
-
|
|
24898
|
+
_context4.next = 18;
|
|
24811
24899
|
break;
|
|
24812
24900
|
}
|
|
24813
24901
|
|
|
24814
24902
|
checkUnderlying(markets[0], tokenOut, networkId);
|
|
24815
|
-
return
|
|
24903
|
+
return _context4.abrupt("return", markets[0].address);
|
|
24816
24904
|
|
|
24817
24905
|
case 18:
|
|
24818
24906
|
if (!markets[1]) {
|
|
24819
|
-
|
|
24907
|
+
_context4.next = 23;
|
|
24820
24908
|
break;
|
|
24821
24909
|
}
|
|
24822
24910
|
|
|
24823
24911
|
checkUnderlying(markets[1], tokenIn, networkId);
|
|
24824
|
-
return
|
|
24912
|
+
return _context4.abrupt("return", markets[1].address);
|
|
24825
24913
|
|
|
24826
24914
|
case 23:
|
|
24827
24915
|
throw new Error("Can only trade PT assets");
|
|
24828
24916
|
|
|
24829
24917
|
case 24:
|
|
24830
24918
|
case "end":
|
|
24831
|
-
return
|
|
24919
|
+
return _context4.stop();
|
|
24832
24920
|
}
|
|
24833
24921
|
}
|
|
24834
|
-
},
|
|
24922
|
+
}, _callee4, null, [[1, 7]]);
|
|
24835
24923
|
}));
|
|
24836
24924
|
return _getMarket.apply(this, arguments);
|
|
24837
24925
|
}
|
|
@@ -24899,13 +24987,52 @@ var checkExitPostExpPT = /*#__PURE__*/function () {
|
|
|
24899
24987
|
};
|
|
24900
24988
|
}();
|
|
24901
24989
|
|
|
24902
|
-
var getExitExpPTTxData = function
|
|
24903
|
-
var
|
|
24904
|
-
|
|
24905
|
-
|
|
24906
|
-
|
|
24907
|
-
|
|
24908
|
-
|
|
24990
|
+
var getExitExpPTTxData = /*#__PURE__*/function () {
|
|
24991
|
+
var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(pool, tokenIn, tokenOut, amountIn, market) {
|
|
24992
|
+
var actionMiscV3, txData, PTcontract, SYcontract, exchangeRate, minAmountOut;
|
|
24993
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
24994
|
+
while (1) {
|
|
24995
|
+
switch (_context2.prev = _context2.next) {
|
|
24996
|
+
case 0:
|
|
24997
|
+
actionMiscV3 = new ethers.ethers.utils.Interface(ActionMiscV3Abi);
|
|
24998
|
+
txData = actionMiscV3.encodeFunctionData("exitPostExpToToken", [pool.address, market, amountIn.toString(), 0, [tokenOut, 0, tokenOut, ethers.ethers.constants.AddressZero, // swapData
|
|
24999
|
+
[0, ethers.ethers.constants.AddressZero, ethers.ethers.constants.HashZero, false // needScale
|
|
25000
|
+
]]]); // Get the PT contract instance
|
|
25001
|
+
|
|
25002
|
+
PTcontract = new ethers.ethers.Contract(tokenIn, PTAbi, pool.signer); // Get the SY contract instance
|
|
25003
|
+
|
|
25004
|
+
_context2.t0 = ethers.ethers.Contract;
|
|
25005
|
+
_context2.next = 6;
|
|
25006
|
+
return PTcontract.SY();
|
|
25007
|
+
|
|
25008
|
+
case 6:
|
|
25009
|
+
_context2.t1 = _context2.sent;
|
|
25010
|
+
_context2.t2 = SYAbi;
|
|
25011
|
+
_context2.t3 = pool.signer;
|
|
25012
|
+
SYcontract = new _context2.t0(_context2.t1, _context2.t2, _context2.t3);
|
|
25013
|
+
_context2.next = 12;
|
|
25014
|
+
return SYcontract.exchangeRate();
|
|
25015
|
+
|
|
25016
|
+
case 12:
|
|
25017
|
+
exchangeRate = _context2.sent;
|
|
25018
|
+
minAmountOut = new BigNumber(amountIn.toString()).times(1e18).div(exchangeRate.toString()).decimalPlaces(0, BigNumber.ROUND_DOWN).toFixed(0);
|
|
25019
|
+
return _context2.abrupt("return", {
|
|
25020
|
+
txData: txData,
|
|
25021
|
+
minAmountOut: minAmountOut
|
|
25022
|
+
});
|
|
25023
|
+
|
|
25024
|
+
case 15:
|
|
25025
|
+
case "end":
|
|
25026
|
+
return _context2.stop();
|
|
25027
|
+
}
|
|
25028
|
+
}
|
|
25029
|
+
}, _callee2);
|
|
25030
|
+
}));
|
|
25031
|
+
|
|
25032
|
+
return function getExitExpPTTxData(_x12, _x13, _x14, _x15, _x16) {
|
|
25033
|
+
return _ref2.apply(this, arguments);
|
|
25034
|
+
};
|
|
25035
|
+
}();
|
|
24909
25036
|
|
|
24910
25037
|
var Pool = /*#__PURE__*/function () {
|
|
24911
25038
|
function Pool(network, signer, poolLogic, mangerLogic, utils, factory, isDhedge) {
|
|
@@ -25425,7 +25552,7 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25425
25552
|
/*#__PURE__*/
|
|
25426
25553
|
function () {
|
|
25427
25554
|
var _trade = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(dapp, assetFrom, assetTo, amountIn, slippage, options, estimateGas) {
|
|
25428
|
-
var swapTxData, _yield$getOneInchSwap, iSynthetix, assets, daoAddress, iUniswapV2Router,
|
|
25555
|
+
var swapTxData, minAmountOut, _yield$getOneInchSwap, iSynthetix, assets, daoAddress, _yield$getOdosSwapTxD, _yield$getPendleSwapT, iUniswapV2Router, calculatedMinAmountOut, tx;
|
|
25429
25556
|
|
|
25430
25557
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
25431
25558
|
while (1) {
|
|
@@ -25443,94 +25570,100 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25443
25570
|
estimateGas = false;
|
|
25444
25571
|
}
|
|
25445
25572
|
|
|
25573
|
+
minAmountOut = null;
|
|
25446
25574
|
_context10.t0 = dapp;
|
|
25447
|
-
_context10.next = _context10.t0 === exports.Dapp.ONEINCH ?
|
|
25575
|
+
_context10.next = _context10.t0 === exports.Dapp.ONEINCH ? 7 : _context10.t0 === exports.Dapp.BALANCER ? 13 : _context10.t0 === exports.Dapp.SYNTHETIX ? 17 : _context10.t0 === exports.Dapp.TOROS ? 24 : _context10.t0 === exports.Dapp.ODOS ? 28 : _context10.t0 === exports.Dapp.PENDLE ? 34 : 40;
|
|
25448
25576
|
break;
|
|
25449
25577
|
|
|
25450
|
-
case
|
|
25451
|
-
_context10.next =
|
|
25578
|
+
case 7:
|
|
25579
|
+
_context10.next = 9;
|
|
25452
25580
|
return getOneInchSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
25453
25581
|
|
|
25454
|
-
case
|
|
25582
|
+
case 9:
|
|
25455
25583
|
_yield$getOneInchSwap = _context10.sent;
|
|
25456
25584
|
swapTxData = _yield$getOneInchSwap.swapTxData;
|
|
25457
|
-
|
|
25585
|
+
minAmountOut = _yield$getOneInchSwap.dstAmount;
|
|
25586
|
+
return _context10.abrupt("break", 55);
|
|
25458
25587
|
|
|
25459
|
-
case
|
|
25460
|
-
_context10.next =
|
|
25588
|
+
case 13:
|
|
25589
|
+
_context10.next = 15;
|
|
25461
25590
|
return this.utils.getBalancerSwapTx(this, assetFrom, assetTo, amountIn, slippage);
|
|
25462
25591
|
|
|
25463
|
-
case
|
|
25592
|
+
case 15:
|
|
25464
25593
|
swapTxData = _context10.sent;
|
|
25465
|
-
return _context10.abrupt("break",
|
|
25594
|
+
return _context10.abrupt("break", 55);
|
|
25466
25595
|
|
|
25467
|
-
case
|
|
25596
|
+
case 17:
|
|
25468
25597
|
iSynthetix = new ethers.ethers.utils.Interface(ISynthetix.abi);
|
|
25469
25598
|
assets = [assetFrom, assetTo].map(function (asset) {
|
|
25470
25599
|
return ethers.ethers.utils.formatBytes32String(asset);
|
|
25471
25600
|
});
|
|
25472
|
-
_context10.next =
|
|
25601
|
+
_context10.next = 21;
|
|
25473
25602
|
return this.factory.owner();
|
|
25474
25603
|
|
|
25475
|
-
case
|
|
25604
|
+
case 21:
|
|
25476
25605
|
daoAddress = _context10.sent;
|
|
25477
25606
|
swapTxData = iSynthetix.encodeFunctionData(exports.Transaction.SWAP_SYNTHS, [assets[0], amountIn, assets[1], daoAddress, SYNTHETIX_TRACKING_CODE]);
|
|
25478
|
-
return _context10.abrupt("break",
|
|
25479
|
-
|
|
25480
|
-
case 22:
|
|
25481
|
-
_context10.next = 24;
|
|
25482
|
-
return getEasySwapperTxData(this, assetFrom, assetTo, ethers.ethers.BigNumber.from(amountIn), slippage);
|
|
25607
|
+
return _context10.abrupt("break", 55);
|
|
25483
25608
|
|
|
25484
25609
|
case 24:
|
|
25485
|
-
|
|
25486
|
-
return
|
|
25610
|
+
_context10.next = 26;
|
|
25611
|
+
return getEasySwapperTxData(this, assetFrom, assetTo, ethers.ethers.BigNumber.from(amountIn), slippage);
|
|
25487
25612
|
|
|
25488
25613
|
case 26:
|
|
25489
|
-
|
|
25490
|
-
return
|
|
25614
|
+
swapTxData = _context10.sent;
|
|
25615
|
+
return _context10.abrupt("break", 55);
|
|
25491
25616
|
|
|
25492
25617
|
case 28:
|
|
25493
|
-
|
|
25494
|
-
return
|
|
25618
|
+
_context10.next = 30;
|
|
25619
|
+
return getOdosSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
25495
25620
|
|
|
25496
25621
|
case 30:
|
|
25497
|
-
|
|
25622
|
+
_yield$getOdosSwapTxD = _context10.sent;
|
|
25623
|
+
swapTxData = _yield$getOdosSwapTxD.swapTxData;
|
|
25624
|
+
minAmountOut = _yield$getOdosSwapTxD.minAmountOut;
|
|
25625
|
+
return _context10.abrupt("break", 55);
|
|
25626
|
+
|
|
25627
|
+
case 34:
|
|
25628
|
+
_context10.next = 36;
|
|
25498
25629
|
return getPendleSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
25499
25630
|
|
|
25500
|
-
case
|
|
25501
|
-
|
|
25502
|
-
|
|
25631
|
+
case 36:
|
|
25632
|
+
_yield$getPendleSwapT = _context10.sent;
|
|
25633
|
+
swapTxData = _yield$getPendleSwapT.swapTxData;
|
|
25634
|
+
minAmountOut = _yield$getPendleSwapT.minAmountOut;
|
|
25635
|
+
return _context10.abrupt("break", 55);
|
|
25503
25636
|
|
|
25504
|
-
case
|
|
25637
|
+
case 40:
|
|
25505
25638
|
iUniswapV2Router = new ethers.ethers.utils.Interface(IUniswapV2Router.abi);
|
|
25506
|
-
_context10.next =
|
|
25639
|
+
_context10.next = 43;
|
|
25507
25640
|
return this.utils.getMinAmountOut(dapp, assetFrom, assetTo, amountIn, slippage);
|
|
25508
25641
|
|
|
25509
|
-
case
|
|
25510
|
-
|
|
25642
|
+
case 43:
|
|
25643
|
+
calculatedMinAmountOut = _context10.sent;
|
|
25511
25644
|
_context10.t1 = iUniswapV2Router;
|
|
25512
25645
|
_context10.t2 = exports.Transaction.SWAP;
|
|
25513
25646
|
_context10.t3 = amountIn;
|
|
25514
|
-
_context10.t4 =
|
|
25647
|
+
_context10.t4 = calculatedMinAmountOut;
|
|
25515
25648
|
_context10.t5 = [assetFrom, assetTo];
|
|
25516
25649
|
_context10.t6 = this.address;
|
|
25517
|
-
_context10.next =
|
|
25650
|
+
_context10.next = 52;
|
|
25518
25651
|
return getDeadline(this);
|
|
25519
25652
|
|
|
25520
|
-
case
|
|
25653
|
+
case 52:
|
|
25521
25654
|
_context10.t7 = _context10.sent;
|
|
25522
25655
|
_context10.t8 = [_context10.t3, _context10.t4, _context10.t5, _context10.t6, _context10.t7];
|
|
25523
25656
|
swapTxData = _context10.t1.encodeFunctionData.call(_context10.t1, _context10.t2, _context10.t8);
|
|
25524
25657
|
|
|
25525
|
-
case
|
|
25526
|
-
_context10.next =
|
|
25527
|
-
return getPoolTxOrGasEstimate(this, [routerAddress[this.network][dapp], swapTxData, options], estimateGas);
|
|
25658
|
+
case 55:
|
|
25659
|
+
_context10.next = 57;
|
|
25660
|
+
return getPoolTxOrGasEstimate(this, [routerAddress[this.network][dapp], swapTxData, options, minAmountOut], estimateGas);
|
|
25528
25661
|
|
|
25529
|
-
case
|
|
25662
|
+
case 57:
|
|
25530
25663
|
tx = _context10.sent;
|
|
25531
25664
|
return _context10.abrupt("return", tx);
|
|
25532
25665
|
|
|
25533
|
-
case
|
|
25666
|
+
case 59:
|
|
25534
25667
|
case "end":
|
|
25535
25668
|
return _context10.stop();
|
|
25536
25669
|
}
|