@dhedge/v2-sdk 1.11.0 → 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/entities/pool.d.ts +4 -4
- package/dist/services/compound/lending.d.ts +4 -3
- package/dist/services/odos/index.d.ts +4 -1
- package/dist/services/pendle/index.d.ts +4 -1
- package/dist/test/constants.d.ts +5 -0
- package/dist/v2-sdk.cjs.development.js +422 -125
- 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 +422 -125
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/fluid/IFToken.json +27 -0
- package/src/abi/pendle/PT.json +15 -0
- package/src/abi/pendle/SY.json +1 -0
- package/src/entities/pool.ts +25 -14
- package/src/services/compound/lending.ts +50 -11
- package/src/services/odos/index.ts +5 -2
- package/src/services/pendle/index.ts +43 -8
- package/src/test/constants.ts +5 -0
- package/src/test/fluid.test.ts +90 -0
- 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
|
@@ -10514,6 +10514,7 @@ var CONTRACT_ADDRESS = (_CONTRACT_ADDRESS = {}, _CONTRACT_ADDRESS[exports.Networ
|
|
|
10514
10514
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
10515
10515
|
VELO: "",
|
|
10516
10516
|
COMPOUNDV3_WETH: "",
|
|
10517
|
+
FLUID_WETH: "",
|
|
10517
10518
|
TOROS: "",
|
|
10518
10519
|
UNIT: ""
|
|
10519
10520
|
}, _CONTRACT_ADDRESS[exports.Network.OPTIMISM] = {
|
|
@@ -10535,6 +10536,7 @@ var CONTRACT_ADDRESS = (_CONTRACT_ADDRESS = {}, _CONTRACT_ADDRESS[exports.Networ
|
|
|
10535
10536
|
VELODROME_CL_USDC_WETH_GAUGE: "0xa75127121d28a9BF848F3B70e7Eea26570aa7700",
|
|
10536
10537
|
VELO: "0x9560e827aF36c94D2Ac33a39bCE1Fe78631088Db",
|
|
10537
10538
|
COMPOUNDV3_WETH: "",
|
|
10539
|
+
FLUID_WETH: "",
|
|
10538
10540
|
TOROS: "0x49bf093277bf4dde49c48c6aa55a3bda3eedef68" //USDmny
|
|
10539
10541
|
|
|
10540
10542
|
}, _CONTRACT_ADDRESS[exports.Network.ARBITRUM] = {
|
|
@@ -10558,6 +10560,7 @@ var CONTRACT_ADDRESS = (_CONTRACT_ADDRESS = {}, _CONTRACT_ADDRESS[exports.Networ
|
|
|
10558
10560
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
10559
10561
|
VELO: "",
|
|
10560
10562
|
COMPOUNDV3_WETH: "0x6f7D514bbD4aFf3BcD1140B7344b32f063dEe486",
|
|
10563
|
+
FLUID_WETH: "0x45df0656f8adf017590009d2f1898eeca4f0a205",
|
|
10561
10564
|
TOROS: ""
|
|
10562
10565
|
}, _CONTRACT_ADDRESS[exports.Network.BASE] = {
|
|
10563
10566
|
USDC: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
|
|
@@ -10577,6 +10580,7 @@ var CONTRACT_ADDRESS = (_CONTRACT_ADDRESS = {}, _CONTRACT_ADDRESS[exports.Networ
|
|
|
10577
10580
|
VELODROME_CL_USDC_WETH_GAUGE: "0xF33a96b5932D9E9B9A0eDA447AbD8C9d48d2e0c8",
|
|
10578
10581
|
VELO: "0x940181a94A35A4569E4529A3CDfB74e38FD98631",
|
|
10579
10582
|
COMPOUNDV3_WETH: "",
|
|
10583
|
+
FLUID_WETH: "",
|
|
10580
10584
|
TOROS: ""
|
|
10581
10585
|
}, _CONTRACT_ADDRESS[exports.Network.ETHEREUM] = {
|
|
10582
10586
|
USDC: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
|
|
@@ -10595,6 +10599,7 @@ var CONTRACT_ADDRESS = (_CONTRACT_ADDRESS = {}, _CONTRACT_ADDRESS[exports.Networ
|
|
|
10595
10599
|
VELODROME_CL_USDC_WETH_GAUGE: "",
|
|
10596
10600
|
VELO: "",
|
|
10597
10601
|
COMPOUNDV3_WETH: "",
|
|
10602
|
+
FLUID_WETH: "",
|
|
10598
10603
|
TOROS: "",
|
|
10599
10604
|
UNIT: ""
|
|
10600
10605
|
}, _CONTRACT_ADDRESS);
|
|
@@ -16124,68 +16129,108 @@ function _call() {
|
|
|
16124
16129
|
}
|
|
16125
16130
|
var getPoolTxOrGasEstimate = /*#__PURE__*/function () {
|
|
16126
16131
|
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(pool, args, estimateGas) {
|
|
16132
|
+
var gas, gasEstimationError, _gas, _gasEstimationError;
|
|
16133
|
+
|
|
16127
16134
|
return runtime_1.wrap(function _callee2$(_context2) {
|
|
16128
16135
|
while (1) {
|
|
16129
16136
|
switch (_context2.prev = _context2.next) {
|
|
16130
16137
|
case 0:
|
|
16131
16138
|
if (!pool.isDhedge) {
|
|
16132
|
-
_context2.next =
|
|
16139
|
+
_context2.next = 21;
|
|
16133
16140
|
break;
|
|
16134
16141
|
}
|
|
16135
16142
|
|
|
16136
16143
|
if (!estimateGas) {
|
|
16137
|
-
_context2.next =
|
|
16144
|
+
_context2.next = 16;
|
|
16138
16145
|
break;
|
|
16139
16146
|
}
|
|
16140
16147
|
|
|
16141
|
-
|
|
16148
|
+
gas = null;
|
|
16149
|
+
gasEstimationError = null;
|
|
16150
|
+
_context2.prev = 4;
|
|
16151
|
+
_context2.next = 7;
|
|
16142
16152
|
return pool.poolLogic.estimateGas.execTransaction(args[0], args[1], args[2]);
|
|
16143
16153
|
|
|
16144
|
-
case 4:
|
|
16145
|
-
return _context2.abrupt("return", _context2.sent);
|
|
16146
|
-
|
|
16147
16154
|
case 7:
|
|
16148
|
-
|
|
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;
|
|
16149
16175
|
return pool.poolLogic.execTransaction(args[0], args[1], args[2]);
|
|
16150
16176
|
|
|
16151
|
-
case
|
|
16177
|
+
case 18:
|
|
16152
16178
|
return _context2.abrupt("return", _context2.sent);
|
|
16153
16179
|
|
|
16154
|
-
case
|
|
16155
|
-
_context2.next =
|
|
16180
|
+
case 19:
|
|
16181
|
+
_context2.next = 39;
|
|
16156
16182
|
break;
|
|
16157
16183
|
|
|
16158
|
-
case
|
|
16184
|
+
case 21:
|
|
16159
16185
|
if (!estimateGas) {
|
|
16160
|
-
_context2.next =
|
|
16186
|
+
_context2.next = 36;
|
|
16161
16187
|
break;
|
|
16162
16188
|
}
|
|
16163
16189
|
|
|
16164
|
-
|
|
16190
|
+
_gas = null;
|
|
16191
|
+
_gasEstimationError = null;
|
|
16192
|
+
_context2.prev = 24;
|
|
16193
|
+
_context2.next = 27;
|
|
16165
16194
|
return pool.signer.estimateGas({
|
|
16166
16195
|
to: args[0],
|
|
16167
16196
|
data: args[1]
|
|
16168
16197
|
});
|
|
16169
16198
|
|
|
16170
|
-
case
|
|
16171
|
-
|
|
16199
|
+
case 27:
|
|
16200
|
+
_gas = _context2.sent;
|
|
16201
|
+
_context2.next = 33;
|
|
16202
|
+
break;
|
|
16172
16203
|
|
|
16173
|
-
case
|
|
16174
|
-
_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;
|
|
16175
16220
|
return pool.signer.sendTransaction(_extends({
|
|
16176
16221
|
to: args[0],
|
|
16177
16222
|
data: args[1]
|
|
16178
16223
|
}, args[2]));
|
|
16179
16224
|
|
|
16180
|
-
case
|
|
16225
|
+
case 38:
|
|
16181
16226
|
return _context2.abrupt("return", _context2.sent);
|
|
16182
16227
|
|
|
16183
|
-
case
|
|
16228
|
+
case 39:
|
|
16184
16229
|
case "end":
|
|
16185
16230
|
return _context2.stop();
|
|
16186
16231
|
}
|
|
16187
16232
|
}
|
|
16188
|
-
}, _callee2);
|
|
16233
|
+
}, _callee2, null, [[4, 10], [24, 30]]);
|
|
16189
16234
|
}));
|
|
16190
16235
|
|
|
16191
16236
|
return function getPoolTxOrGasEstimate(_x12, _x13, _x14) {
|
|
@@ -23908,11 +23953,162 @@ var ICompoundV3Comet = [
|
|
|
23908
23953
|
}
|
|
23909
23954
|
];
|
|
23910
23955
|
|
|
23911
|
-
|
|
23912
|
-
|
|
23956
|
+
var IFToken = [
|
|
23957
|
+
{
|
|
23958
|
+
inputs: [
|
|
23959
|
+
{
|
|
23960
|
+
internalType: "uint256",
|
|
23961
|
+
name: "assets_",
|
|
23962
|
+
type: "uint256"
|
|
23963
|
+
},
|
|
23964
|
+
{
|
|
23965
|
+
internalType: "address",
|
|
23966
|
+
name: "receiver_",
|
|
23967
|
+
type: "address"
|
|
23968
|
+
}
|
|
23969
|
+
],
|
|
23970
|
+
name: "deposit",
|
|
23971
|
+
outputs: [
|
|
23972
|
+
{
|
|
23973
|
+
internalType: "uint256",
|
|
23974
|
+
name: "shares_",
|
|
23975
|
+
type: "uint256"
|
|
23976
|
+
}
|
|
23977
|
+
],
|
|
23978
|
+
stateMutability: "nonpayable",
|
|
23979
|
+
type: "function"
|
|
23980
|
+
},
|
|
23981
|
+
{
|
|
23982
|
+
inputs: [
|
|
23983
|
+
{
|
|
23984
|
+
internalType: "uint256",
|
|
23985
|
+
name: "shares_",
|
|
23986
|
+
type: "uint256"
|
|
23987
|
+
},
|
|
23988
|
+
{
|
|
23989
|
+
internalType: "address",
|
|
23990
|
+
name: "receiver_",
|
|
23991
|
+
type: "address"
|
|
23992
|
+
},
|
|
23993
|
+
{
|
|
23994
|
+
internalType: "address",
|
|
23995
|
+
name: "owner_",
|
|
23996
|
+
type: "address"
|
|
23997
|
+
}
|
|
23998
|
+
],
|
|
23999
|
+
name: "redeem",
|
|
24000
|
+
outputs: [
|
|
24001
|
+
{
|
|
24002
|
+
internalType: "uint256",
|
|
24003
|
+
name: "assets_",
|
|
24004
|
+
type: "uint256"
|
|
24005
|
+
}
|
|
24006
|
+
],
|
|
24007
|
+
stateMutability: "nonpayable",
|
|
24008
|
+
type: "function"
|
|
24009
|
+
}
|
|
24010
|
+
];
|
|
24011
|
+
|
|
24012
|
+
function getCompoundV3LendTxData(_x, _x2, _x3, _x4) {
|
|
24013
|
+
return _getCompoundV3LendTxData.apply(this, arguments);
|
|
24014
|
+
}
|
|
24015
|
+
|
|
24016
|
+
function _getCompoundV3LendTxData() {
|
|
24017
|
+
_getCompoundV3LendTxData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(pool, market, asset, amount) {
|
|
24018
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
24019
|
+
while (1) {
|
|
24020
|
+
switch (_context.prev = _context.next) {
|
|
24021
|
+
case 0:
|
|
24022
|
+
_context.next = 2;
|
|
24023
|
+
return isCompoundV3Market(pool, market);
|
|
24024
|
+
|
|
24025
|
+
case 2:
|
|
24026
|
+
if (!_context.sent) {
|
|
24027
|
+
_context.next = 6;
|
|
24028
|
+
break;
|
|
24029
|
+
}
|
|
24030
|
+
|
|
24031
|
+
return _context.abrupt("return", new ethers.ethers.utils.Interface(ICompoundV3Comet).encodeFunctionData("supply", [asset, amount]));
|
|
24032
|
+
|
|
24033
|
+
case 6:
|
|
24034
|
+
return _context.abrupt("return", new ethers.ethers.utils.Interface(IFToken).encodeFunctionData("deposit", [amount, pool.address]));
|
|
24035
|
+
|
|
24036
|
+
case 7:
|
|
24037
|
+
case "end":
|
|
24038
|
+
return _context.stop();
|
|
24039
|
+
}
|
|
24040
|
+
}
|
|
24041
|
+
}, _callee);
|
|
24042
|
+
}));
|
|
24043
|
+
return _getCompoundV3LendTxData.apply(this, arguments);
|
|
24044
|
+
}
|
|
24045
|
+
|
|
24046
|
+
function getCompoundV3WithdrawTxData(_x5, _x6, _x7, _x8) {
|
|
24047
|
+
return _getCompoundV3WithdrawTxData.apply(this, arguments);
|
|
24048
|
+
}
|
|
24049
|
+
|
|
24050
|
+
function _getCompoundV3WithdrawTxData() {
|
|
24051
|
+
_getCompoundV3WithdrawTxData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(pool, market, asset, amount) {
|
|
24052
|
+
return runtime_1.wrap(function _callee2$(_context2) {
|
|
24053
|
+
while (1) {
|
|
24054
|
+
switch (_context2.prev = _context2.next) {
|
|
24055
|
+
case 0:
|
|
24056
|
+
_context2.next = 2;
|
|
24057
|
+
return isCompoundV3Market(pool, market);
|
|
24058
|
+
|
|
24059
|
+
case 2:
|
|
24060
|
+
if (!_context2.sent) {
|
|
24061
|
+
_context2.next = 6;
|
|
24062
|
+
break;
|
|
24063
|
+
}
|
|
24064
|
+
|
|
24065
|
+
return _context2.abrupt("return", new ethers.ethers.utils.Interface(ICompoundV3Comet).encodeFunctionData("withdraw", [asset, amount]));
|
|
24066
|
+
|
|
24067
|
+
case 6:
|
|
24068
|
+
return _context2.abrupt("return", new ethers.ethers.utils.Interface(IFToken).encodeFunctionData("redeem", [amount, pool.address, pool.address]));
|
|
24069
|
+
|
|
24070
|
+
case 7:
|
|
24071
|
+
case "end":
|
|
24072
|
+
return _context2.stop();
|
|
24073
|
+
}
|
|
24074
|
+
}
|
|
24075
|
+
}, _callee2);
|
|
24076
|
+
}));
|
|
24077
|
+
return _getCompoundV3WithdrawTxData.apply(this, arguments);
|
|
23913
24078
|
}
|
|
23914
|
-
|
|
23915
|
-
|
|
24079
|
+
|
|
24080
|
+
function isCompoundV3Market(_x9, _x10) {
|
|
24081
|
+
return _isCompoundV3Market.apply(this, arguments);
|
|
24082
|
+
}
|
|
24083
|
+
|
|
24084
|
+
function _isCompoundV3Market() {
|
|
24085
|
+
_isCompoundV3Market = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(pool, market) {
|
|
24086
|
+
var marketContract;
|
|
24087
|
+
return runtime_1.wrap(function _callee3$(_context3) {
|
|
24088
|
+
while (1) {
|
|
24089
|
+
switch (_context3.prev = _context3.next) {
|
|
24090
|
+
case 0:
|
|
24091
|
+
marketContract = new ethers.ethers.Contract(market, ICompoundV3Comet, pool.signer);
|
|
24092
|
+
_context3.prev = 1;
|
|
24093
|
+
_context3.next = 4;
|
|
24094
|
+
return marketContract.baseToken();
|
|
24095
|
+
|
|
24096
|
+
case 4:
|
|
24097
|
+
return _context3.abrupt("return", true);
|
|
24098
|
+
|
|
24099
|
+
case 7:
|
|
24100
|
+
_context3.prev = 7;
|
|
24101
|
+
_context3.t0 = _context3["catch"](1);
|
|
24102
|
+
return _context3.abrupt("return", false);
|
|
24103
|
+
|
|
24104
|
+
case 10:
|
|
24105
|
+
case "end":
|
|
24106
|
+
return _context3.stop();
|
|
24107
|
+
}
|
|
24108
|
+
}
|
|
24109
|
+
}, _callee3, null, [[1, 7]]);
|
|
24110
|
+
}));
|
|
24111
|
+
return _isCompoundV3Market.apply(this, arguments);
|
|
23916
24112
|
}
|
|
23917
24113
|
|
|
23918
24114
|
var ICometRewards = [
|
|
@@ -24404,7 +24600,10 @@ function _getOdosSwapTxData() {
|
|
|
24404
24600
|
|
|
24405
24601
|
case 10:
|
|
24406
24602
|
assembleResult = _context.sent;
|
|
24407
|
-
return _context.abrupt("return",
|
|
24603
|
+
return _context.abrupt("return", {
|
|
24604
|
+
swapTxData: assembleResult.data.transaction.data,
|
|
24605
|
+
minAmountOut: assembleResult.data.outputTokens[0].amount
|
|
24606
|
+
});
|
|
24408
24607
|
|
|
24409
24608
|
case 14:
|
|
24410
24609
|
_context.prev = 14;
|
|
@@ -24545,66 +24744,111 @@ var ActionMiscV3Abi = [
|
|
|
24545
24744
|
}
|
|
24546
24745
|
];
|
|
24547
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
|
+
|
|
24548
24781
|
var pendleBaseUrl = "https://api-v2.pendle.finance/core/v1";
|
|
24549
24782
|
function getPendleSwapTxData(_x, _x2, _x3, _x4, _x5) {
|
|
24550
24783
|
return _getPendleSwapTxData.apply(this, arguments);
|
|
24551
24784
|
}
|
|
24552
24785
|
|
|
24553
24786
|
function _getPendleSwapTxData() {
|
|
24554
|
-
_getPendleSwapTxData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
24555
|
-
var expiredMarket, params, market, swapResult;
|
|
24556
|
-
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) {
|
|
24557
24790
|
while (1) {
|
|
24558
|
-
switch (
|
|
24791
|
+
switch (_context3.prev = _context3.next) {
|
|
24559
24792
|
case 0:
|
|
24560
|
-
|
|
24793
|
+
_context3.next = 2;
|
|
24561
24794
|
return checkExitPostExpPT(pool, tokenIn, tokenOut);
|
|
24562
24795
|
|
|
24563
24796
|
case 2:
|
|
24564
|
-
expiredMarket =
|
|
24797
|
+
expiredMarket = _context3.sent;
|
|
24565
24798
|
|
|
24566
24799
|
if (!expiredMarket) {
|
|
24567
|
-
|
|
24800
|
+
_context3.next = 8;
|
|
24568
24801
|
break;
|
|
24569
24802
|
}
|
|
24570
24803
|
|
|
24571
|
-
|
|
24804
|
+
_context3.next = 6;
|
|
24805
|
+
return getExitExpPTTxData(pool, tokenIn, tokenOut, amountIn, expiredMarket);
|
|
24572
24806
|
|
|
24573
|
-
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:
|
|
24574
24815
|
params = {
|
|
24575
24816
|
receiver: pool.address,
|
|
24576
24817
|
tokenIn: tokenIn,
|
|
24577
24818
|
tokenOut: tokenOut,
|
|
24578
24819
|
amountIn: amountIn.toString(),
|
|
24579
|
-
slippage: slippage
|
|
24820
|
+
slippage: slippage / 100
|
|
24580
24821
|
};
|
|
24581
|
-
|
|
24822
|
+
_context3.next = 11;
|
|
24582
24823
|
return getMarket(pool, tokenIn, tokenOut);
|
|
24583
24824
|
|
|
24584
|
-
case
|
|
24585
|
-
market =
|
|
24586
|
-
|
|
24587
|
-
|
|
24825
|
+
case 11:
|
|
24826
|
+
market = _context3.sent;
|
|
24827
|
+
_context3.prev = 12;
|
|
24828
|
+
_context3.next = 15;
|
|
24588
24829
|
return axios.get(pendleBaseUrl + "/sdk/" + networkChainIdMap[pool.network] + "/markets/" + market + "/swap", {
|
|
24589
24830
|
params: params
|
|
24590
24831
|
});
|
|
24591
24832
|
|
|
24592
|
-
case
|
|
24593
|
-
swapResult =
|
|
24594
|
-
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
|
+
});
|
|
24595
24839
|
|
|
24596
|
-
case
|
|
24597
|
-
|
|
24598
|
-
|
|
24599
|
-
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);
|
|
24600
24844
|
throw new ApiError("Pendle api request failed");
|
|
24601
24845
|
|
|
24602
|
-
case
|
|
24846
|
+
case 23:
|
|
24603
24847
|
case "end":
|
|
24604
|
-
return
|
|
24848
|
+
return _context3.stop();
|
|
24605
24849
|
}
|
|
24606
24850
|
}
|
|
24607
|
-
},
|
|
24851
|
+
}, _callee3, null, [[12, 19]]);
|
|
24608
24852
|
}));
|
|
24609
24853
|
return _getPendleSwapTxData.apply(this, arguments);
|
|
24610
24854
|
}
|
|
@@ -24620,26 +24864,26 @@ function getMarket(_x6, _x7, _x8) {
|
|
|
24620
24864
|
}
|
|
24621
24865
|
|
|
24622
24866
|
function _getMarket() {
|
|
24623
|
-
_getMarket = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function
|
|
24867
|
+
_getMarket = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(pool, tokenIn, tokenOut) {
|
|
24624
24868
|
var networkId, marketResult, allMarkets, markets;
|
|
24625
|
-
return runtime_1.wrap(function
|
|
24869
|
+
return runtime_1.wrap(function _callee4$(_context4) {
|
|
24626
24870
|
while (1) {
|
|
24627
|
-
switch (
|
|
24871
|
+
switch (_context4.prev = _context4.next) {
|
|
24628
24872
|
case 0:
|
|
24629
24873
|
networkId = networkChainIdMap[pool.network];
|
|
24630
|
-
|
|
24631
|
-
|
|
24874
|
+
_context4.prev = 1;
|
|
24875
|
+
_context4.next = 4;
|
|
24632
24876
|
return axios.get(pendleBaseUrl + "/" + networkId + "/markets/active");
|
|
24633
24877
|
|
|
24634
24878
|
case 4:
|
|
24635
|
-
marketResult =
|
|
24636
|
-
|
|
24879
|
+
marketResult = _context4.sent;
|
|
24880
|
+
_context4.next = 11;
|
|
24637
24881
|
break;
|
|
24638
24882
|
|
|
24639
24883
|
case 7:
|
|
24640
|
-
|
|
24641
|
-
|
|
24642
|
-
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);
|
|
24643
24887
|
throw new ApiError("Pendle api request failed");
|
|
24644
24888
|
|
|
24645
24889
|
case 11:
|
|
@@ -24651,31 +24895,31 @@ function _getMarket() {
|
|
|
24651
24895
|
});
|
|
24652
24896
|
|
|
24653
24897
|
if (!markets[0]) {
|
|
24654
|
-
|
|
24898
|
+
_context4.next = 18;
|
|
24655
24899
|
break;
|
|
24656
24900
|
}
|
|
24657
24901
|
|
|
24658
24902
|
checkUnderlying(markets[0], tokenOut, networkId);
|
|
24659
|
-
return
|
|
24903
|
+
return _context4.abrupt("return", markets[0].address);
|
|
24660
24904
|
|
|
24661
24905
|
case 18:
|
|
24662
24906
|
if (!markets[1]) {
|
|
24663
|
-
|
|
24907
|
+
_context4.next = 23;
|
|
24664
24908
|
break;
|
|
24665
24909
|
}
|
|
24666
24910
|
|
|
24667
24911
|
checkUnderlying(markets[1], tokenIn, networkId);
|
|
24668
|
-
return
|
|
24912
|
+
return _context4.abrupt("return", markets[1].address);
|
|
24669
24913
|
|
|
24670
24914
|
case 23:
|
|
24671
24915
|
throw new Error("Can only trade PT assets");
|
|
24672
24916
|
|
|
24673
24917
|
case 24:
|
|
24674
24918
|
case "end":
|
|
24675
|
-
return
|
|
24919
|
+
return _context4.stop();
|
|
24676
24920
|
}
|
|
24677
24921
|
}
|
|
24678
|
-
},
|
|
24922
|
+
}, _callee4, null, [[1, 7]]);
|
|
24679
24923
|
}));
|
|
24680
24924
|
return _getMarket.apply(this, arguments);
|
|
24681
24925
|
}
|
|
@@ -24743,13 +24987,52 @@ var checkExitPostExpPT = /*#__PURE__*/function () {
|
|
|
24743
24987
|
};
|
|
24744
24988
|
}();
|
|
24745
24989
|
|
|
24746
|
-
var getExitExpPTTxData = function
|
|
24747
|
-
var
|
|
24748
|
-
|
|
24749
|
-
|
|
24750
|
-
|
|
24751
|
-
|
|
24752
|
-
|
|
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
|
+
}();
|
|
24753
25036
|
|
|
24754
25037
|
var Pool = /*#__PURE__*/function () {
|
|
24755
25038
|
function Pool(network, signer, poolLogic, mangerLogic, utils, factory, isDhedge) {
|
|
@@ -25269,7 +25552,7 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25269
25552
|
/*#__PURE__*/
|
|
25270
25553
|
function () {
|
|
25271
25554
|
var _trade = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(dapp, assetFrom, assetTo, amountIn, slippage, options, estimateGas) {
|
|
25272
|
-
var swapTxData, _yield$getOneInchSwap, iSynthetix, assets, daoAddress, iUniswapV2Router,
|
|
25555
|
+
var swapTxData, minAmountOut, _yield$getOneInchSwap, iSynthetix, assets, daoAddress, _yield$getOdosSwapTxD, _yield$getPendleSwapT, iUniswapV2Router, calculatedMinAmountOut, tx;
|
|
25273
25556
|
|
|
25274
25557
|
return runtime_1.wrap(function _callee10$(_context10) {
|
|
25275
25558
|
while (1) {
|
|
@@ -25287,94 +25570,100 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25287
25570
|
estimateGas = false;
|
|
25288
25571
|
}
|
|
25289
25572
|
|
|
25573
|
+
minAmountOut = null;
|
|
25290
25574
|
_context10.t0 = dapp;
|
|
25291
|
-
_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;
|
|
25292
25576
|
break;
|
|
25293
25577
|
|
|
25294
|
-
case
|
|
25295
|
-
_context10.next =
|
|
25578
|
+
case 7:
|
|
25579
|
+
_context10.next = 9;
|
|
25296
25580
|
return getOneInchSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
25297
25581
|
|
|
25298
|
-
case
|
|
25582
|
+
case 9:
|
|
25299
25583
|
_yield$getOneInchSwap = _context10.sent;
|
|
25300
25584
|
swapTxData = _yield$getOneInchSwap.swapTxData;
|
|
25301
|
-
|
|
25585
|
+
minAmountOut = _yield$getOneInchSwap.dstAmount;
|
|
25586
|
+
return _context10.abrupt("break", 55);
|
|
25302
25587
|
|
|
25303
|
-
case
|
|
25304
|
-
_context10.next =
|
|
25588
|
+
case 13:
|
|
25589
|
+
_context10.next = 15;
|
|
25305
25590
|
return this.utils.getBalancerSwapTx(this, assetFrom, assetTo, amountIn, slippage);
|
|
25306
25591
|
|
|
25307
|
-
case
|
|
25592
|
+
case 15:
|
|
25308
25593
|
swapTxData = _context10.sent;
|
|
25309
|
-
return _context10.abrupt("break",
|
|
25594
|
+
return _context10.abrupt("break", 55);
|
|
25310
25595
|
|
|
25311
|
-
case
|
|
25596
|
+
case 17:
|
|
25312
25597
|
iSynthetix = new ethers.ethers.utils.Interface(ISynthetix.abi);
|
|
25313
25598
|
assets = [assetFrom, assetTo].map(function (asset) {
|
|
25314
25599
|
return ethers.ethers.utils.formatBytes32String(asset);
|
|
25315
25600
|
});
|
|
25316
|
-
_context10.next =
|
|
25601
|
+
_context10.next = 21;
|
|
25317
25602
|
return this.factory.owner();
|
|
25318
25603
|
|
|
25319
|
-
case
|
|
25604
|
+
case 21:
|
|
25320
25605
|
daoAddress = _context10.sent;
|
|
25321
25606
|
swapTxData = iSynthetix.encodeFunctionData(exports.Transaction.SWAP_SYNTHS, [assets[0], amountIn, assets[1], daoAddress, SYNTHETIX_TRACKING_CODE]);
|
|
25322
|
-
return _context10.abrupt("break",
|
|
25323
|
-
|
|
25324
|
-
case 22:
|
|
25325
|
-
_context10.next = 24;
|
|
25326
|
-
return getEasySwapperTxData(this, assetFrom, assetTo, ethers.ethers.BigNumber.from(amountIn), slippage);
|
|
25607
|
+
return _context10.abrupt("break", 55);
|
|
25327
25608
|
|
|
25328
25609
|
case 24:
|
|
25329
|
-
|
|
25330
|
-
return
|
|
25610
|
+
_context10.next = 26;
|
|
25611
|
+
return getEasySwapperTxData(this, assetFrom, assetTo, ethers.ethers.BigNumber.from(amountIn), slippage);
|
|
25331
25612
|
|
|
25332
25613
|
case 26:
|
|
25333
|
-
|
|
25334
|
-
return
|
|
25614
|
+
swapTxData = _context10.sent;
|
|
25615
|
+
return _context10.abrupt("break", 55);
|
|
25335
25616
|
|
|
25336
25617
|
case 28:
|
|
25337
|
-
|
|
25338
|
-
return
|
|
25618
|
+
_context10.next = 30;
|
|
25619
|
+
return getOdosSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
25339
25620
|
|
|
25340
25621
|
case 30:
|
|
25341
|
-
|
|
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;
|
|
25342
25629
|
return getPendleSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
25343
25630
|
|
|
25344
|
-
case
|
|
25345
|
-
|
|
25346
|
-
|
|
25631
|
+
case 36:
|
|
25632
|
+
_yield$getPendleSwapT = _context10.sent;
|
|
25633
|
+
swapTxData = _yield$getPendleSwapT.swapTxData;
|
|
25634
|
+
minAmountOut = _yield$getPendleSwapT.minAmountOut;
|
|
25635
|
+
return _context10.abrupt("break", 55);
|
|
25347
25636
|
|
|
25348
|
-
case
|
|
25637
|
+
case 40:
|
|
25349
25638
|
iUniswapV2Router = new ethers.ethers.utils.Interface(IUniswapV2Router.abi);
|
|
25350
|
-
_context10.next =
|
|
25639
|
+
_context10.next = 43;
|
|
25351
25640
|
return this.utils.getMinAmountOut(dapp, assetFrom, assetTo, amountIn, slippage);
|
|
25352
25641
|
|
|
25353
|
-
case
|
|
25354
|
-
|
|
25642
|
+
case 43:
|
|
25643
|
+
calculatedMinAmountOut = _context10.sent;
|
|
25355
25644
|
_context10.t1 = iUniswapV2Router;
|
|
25356
25645
|
_context10.t2 = exports.Transaction.SWAP;
|
|
25357
25646
|
_context10.t3 = amountIn;
|
|
25358
|
-
_context10.t4 =
|
|
25647
|
+
_context10.t4 = calculatedMinAmountOut;
|
|
25359
25648
|
_context10.t5 = [assetFrom, assetTo];
|
|
25360
25649
|
_context10.t6 = this.address;
|
|
25361
|
-
_context10.next =
|
|
25650
|
+
_context10.next = 52;
|
|
25362
25651
|
return getDeadline(this);
|
|
25363
25652
|
|
|
25364
|
-
case
|
|
25653
|
+
case 52:
|
|
25365
25654
|
_context10.t7 = _context10.sent;
|
|
25366
25655
|
_context10.t8 = [_context10.t3, _context10.t4, _context10.t5, _context10.t6, _context10.t7];
|
|
25367
25656
|
swapTxData = _context10.t1.encodeFunctionData.call(_context10.t1, _context10.t2, _context10.t8);
|
|
25368
25657
|
|
|
25369
|
-
case
|
|
25370
|
-
_context10.next =
|
|
25371
|
-
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);
|
|
25372
25661
|
|
|
25373
|
-
case
|
|
25662
|
+
case 57:
|
|
25374
25663
|
tx = _context10.sent;
|
|
25375
25664
|
return _context10.abrupt("return", tx);
|
|
25376
25665
|
|
|
25377
|
-
case
|
|
25666
|
+
case 59:
|
|
25378
25667
|
case "end":
|
|
25379
25668
|
return _context10.stop();
|
|
25380
25669
|
}
|
|
@@ -25820,8 +26109,8 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25820
26109
|
return lend;
|
|
25821
26110
|
}()
|
|
25822
26111
|
/**
|
|
25823
|
-
* Lend asset to a Compound V3
|
|
25824
|
-
* @param {string} market Address of
|
|
26112
|
+
* Lend asset to a Compound V3 or Fluid lending pool
|
|
26113
|
+
* @param {string} market Address of cToken or fToken
|
|
25825
26114
|
* @param {string} asset Asset
|
|
25826
26115
|
* @param {BigNumber | string} amount Amount of asset to lend
|
|
25827
26116
|
* @param {any} options Transaction options
|
|
@@ -25847,15 +26136,19 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25847
26136
|
estimateGas = false;
|
|
25848
26137
|
}
|
|
25849
26138
|
|
|
25850
|
-
|
|
25851
|
-
|
|
26139
|
+
_context18.next = 4;
|
|
26140
|
+
return getCompoundV3LendTxData(this, market, asset, amount);
|
|
26141
|
+
|
|
26142
|
+
case 4:
|
|
26143
|
+
supplyTxData = _context18.sent;
|
|
26144
|
+
_context18.next = 7;
|
|
25852
26145
|
return getPoolTxOrGasEstimate(this, [market, supplyTxData, options], estimateGas);
|
|
25853
26146
|
|
|
25854
|
-
case
|
|
26147
|
+
case 7:
|
|
25855
26148
|
tx = _context18.sent;
|
|
25856
26149
|
return _context18.abrupt("return", tx);
|
|
25857
26150
|
|
|
25858
|
-
case
|
|
26151
|
+
case 9:
|
|
25859
26152
|
case "end":
|
|
25860
26153
|
return _context18.stop();
|
|
25861
26154
|
}
|
|
@@ -25921,8 +26214,8 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25921
26214
|
return withdrawDeposit;
|
|
25922
26215
|
}()
|
|
25923
26216
|
/**
|
|
25924
|
-
* Witdraw asset from a
|
|
25925
|
-
* @param {string} market Address of
|
|
26217
|
+
* Witdraw asset from a Compound V3 or Fluid lending pool
|
|
26218
|
+
* @param {string} market Address of cToken or fToken
|
|
25926
26219
|
* @param {string} asset Asset
|
|
25927
26220
|
* @param {BigNumber | string} amount Amount of asset to withdraw
|
|
25928
26221
|
* @param {any} options Transaction options
|
|
@@ -25948,15 +26241,19 @@ var Pool = /*#__PURE__*/function () {
|
|
|
25948
26241
|
estimateGas = false;
|
|
25949
26242
|
}
|
|
25950
26243
|
|
|
25951
|
-
|
|
25952
|
-
|
|
26244
|
+
_context20.next = 4;
|
|
26245
|
+
return getCompoundV3WithdrawTxData(this, market, asset, amount);
|
|
26246
|
+
|
|
26247
|
+
case 4:
|
|
26248
|
+
withdrawTxData = _context20.sent;
|
|
26249
|
+
_context20.next = 7;
|
|
25953
26250
|
return getPoolTxOrGasEstimate(this, [market, withdrawTxData, options], estimateGas);
|
|
25954
26251
|
|
|
25955
|
-
case
|
|
26252
|
+
case 7:
|
|
25956
26253
|
tx = _context20.sent;
|
|
25957
26254
|
return _context20.abrupt("return", tx);
|
|
25958
26255
|
|
|
25959
|
-
case
|
|
26256
|
+
case 9:
|
|
25960
26257
|
case "end":
|
|
25961
26258
|
return _context20.stop();
|
|
25962
26259
|
}
|