@dhedge/v2-sdk 1.9.1 → 1.9.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/README.md +2 -2
- package/dist/services/oneInch/index.d.ts +3 -0
- package/dist/test/utils/testingHelper.d.ts +13 -0
- package/dist/test/wallet.d.ts +7 -0
- package/dist/v2-sdk.cjs.development.js +89 -107
- 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 +89 -107
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/entities/pool.ts +8 -22
- package/src/services/oneInch/index.ts +33 -0
- package/src/test/oneInch.test.ts +40 -32
- package/src/test/utils/testingHelper.ts +20 -0
- package/src/test/wallet.ts +14 -1
- package/src/test/zeroEx.test.ts +40 -32
- package/dist/services/oneInch/protocols.d.ts +0 -1
- package/src/services/oneInch/protocols.ts +0 -17
package/README.md
CHANGED
|
@@ -28,11 +28,11 @@ yarn add @dhedge/v2-sdk
|
|
|
28
28
|
|
|
29
29
|
### Initial setup
|
|
30
30
|
|
|
31
|
-
If you want to use 1Inch to trade pool assets you need to apply for an
|
|
31
|
+
If you want to use 1Inch to trade pool assets you need to apply for an API key at [1Inch Dev Portal](https://docs.1inch.io/docs/aggregation-protocol/introduction).
|
|
32
32
|
Then you need to copy .env.example file to .env and set your url there.
|
|
33
33
|
|
|
34
34
|
```
|
|
35
|
-
|
|
35
|
+
ONEINCH_API_KEY=YOUR_API_KEY_FROM_1INCH
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Initialize the sdk with an [ethers wallet](https://docs.ethers.io/v5/api/signer/#Wallet) and the network.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { Network } from "../../types";
|
|
3
|
+
export declare type TestingRunParams = {
|
|
4
|
+
network: Network;
|
|
5
|
+
wallet: ethers.Wallet;
|
|
6
|
+
};
|
|
7
|
+
declare type TestHelperParams = {
|
|
8
|
+
testingRun: (testingRunParams: TestingRunParams) => void;
|
|
9
|
+
} & {
|
|
10
|
+
network: Network;
|
|
11
|
+
};
|
|
12
|
+
export declare const testingHelper: ({ network, testingRun }: TestHelperParams) => void;
|
|
13
|
+
export {};
|
package/dist/test/wallet.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
import { ethers } from "ethers";
|
|
2
|
+
import { Network } from "../types";
|
|
2
3
|
export declare const wallet: ethers.Wallet;
|
|
4
|
+
export declare const networkPortMap: {
|
|
5
|
+
polygon: number;
|
|
6
|
+
optimism: number;
|
|
7
|
+
arbitrum: number;
|
|
8
|
+
};
|
|
9
|
+
export declare const getWallet: (network: Network) => ethers.Wallet;
|
|
@@ -7,12 +7,12 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
7
7
|
var ethers = require('ethers');
|
|
8
8
|
var Lyra = require('@lyrafinance/lyra-js');
|
|
9
9
|
var Lyra__default = _interopDefault(Lyra);
|
|
10
|
-
var axios = _interopDefault(require('axios'));
|
|
11
10
|
var sdkCore = require('@uniswap/sdk-core');
|
|
12
11
|
var v3Sdk = require('@uniswap/v3-sdk');
|
|
13
12
|
var JSBI = _interopDefault(require('jsbi'));
|
|
14
13
|
require('lodash/set');
|
|
15
14
|
require('@ethersproject/abi');
|
|
15
|
+
var axios = _interopDefault(require('axios'));
|
|
16
16
|
var sdk = require('@sushiswap/sdk');
|
|
17
17
|
var sor = require('@balancer-labs/sor');
|
|
18
18
|
|
|
@@ -9750,46 +9750,6 @@ function _getEasySwapperTxData() {
|
|
|
9750
9750
|
return _getEasySwapperTxData.apply(this, arguments);
|
|
9751
9751
|
}
|
|
9752
9752
|
|
|
9753
|
-
function getOneInchProtocols(_x) {
|
|
9754
|
-
return _getOneInchProtocols.apply(this, arguments);
|
|
9755
|
-
}
|
|
9756
|
-
|
|
9757
|
-
function _getOneInchProtocols() {
|
|
9758
|
-
_getOneInchProtocols = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(chainId) {
|
|
9759
|
-
var response, protocols, filteredProtocols;
|
|
9760
|
-
return runtime_1.wrap(function _callee$(_context) {
|
|
9761
|
-
while (1) {
|
|
9762
|
-
switch (_context.prev = _context.next) {
|
|
9763
|
-
case 0:
|
|
9764
|
-
_context.prev = 0;
|
|
9765
|
-
_context.next = 3;
|
|
9766
|
-
return axios.get("https://api.1inch.io/v5.0/" + chainId + "/liquidity-sources");
|
|
9767
|
-
|
|
9768
|
-
case 3:
|
|
9769
|
-
response = _context.sent;
|
|
9770
|
-
protocols = response.data.protocols.map(function (e) {
|
|
9771
|
-
return e.id;
|
|
9772
|
-
});
|
|
9773
|
-
filteredProtocols = protocols.filter(function (e) {
|
|
9774
|
-
return !e.includes("PMM");
|
|
9775
|
-
});
|
|
9776
|
-
return _context.abrupt("return", "&protocols=" + filteredProtocols.join(","));
|
|
9777
|
-
|
|
9778
|
-
case 9:
|
|
9779
|
-
_context.prev = 9;
|
|
9780
|
-
_context.t0 = _context["catch"](0);
|
|
9781
|
-
return _context.abrupt("return", "");
|
|
9782
|
-
|
|
9783
|
-
case 12:
|
|
9784
|
-
case "end":
|
|
9785
|
-
return _context.stop();
|
|
9786
|
-
}
|
|
9787
|
-
}
|
|
9788
|
-
}, _callee, null, [[0, 9]]);
|
|
9789
|
-
}));
|
|
9790
|
-
return _getOneInchProtocols.apply(this, arguments);
|
|
9791
|
-
}
|
|
9792
|
-
|
|
9793
9753
|
var abi$i = [
|
|
9794
9754
|
{
|
|
9795
9755
|
inputs: [
|
|
@@ -19608,6 +19568,55 @@ var getZeroExTradeTxData = /*#__PURE__*/function () {
|
|
|
19608
19568
|
};
|
|
19609
19569
|
}();
|
|
19610
19570
|
|
|
19571
|
+
var oneInchBaseUrl = "https://api.1inch.dev/swap/v5.2/";
|
|
19572
|
+
function getOneInchSwapTxData(_x, _x2, _x3, _x4, _x5) {
|
|
19573
|
+
return _getOneInchSwapTxData.apply(this, arguments);
|
|
19574
|
+
}
|
|
19575
|
+
|
|
19576
|
+
function _getOneInchSwapTxData() {
|
|
19577
|
+
_getOneInchSwapTxData = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(pool, assetFrom, assetTo, amountIn, slippage) {
|
|
19578
|
+
var chainId, apiUrl, response;
|
|
19579
|
+
return runtime_1.wrap(function _callee$(_context) {
|
|
19580
|
+
while (1) {
|
|
19581
|
+
switch (_context.prev = _context.next) {
|
|
19582
|
+
case 0:
|
|
19583
|
+
if (process.env.ONEINCH_API_KEY) {
|
|
19584
|
+
_context.next = 2;
|
|
19585
|
+
break;
|
|
19586
|
+
}
|
|
19587
|
+
|
|
19588
|
+
throw new Error("ONEINCH_API_KEY not configured in .env file");
|
|
19589
|
+
|
|
19590
|
+
case 2:
|
|
19591
|
+
chainId = networkChainIdMap[pool.network];
|
|
19592
|
+
apiUrl = "" + oneInchBaseUrl + chainId + "/swap?src=" + assetFrom + "&dst=" + assetTo + "&amount=" + amountIn.toString() + "&from=" + pool.address + "&slippage=" + slippage.toString() + "&disableEstimate=true";
|
|
19593
|
+
_context.prev = 4;
|
|
19594
|
+
_context.next = 7;
|
|
19595
|
+
return axios.get(apiUrl, {
|
|
19596
|
+
headers: {
|
|
19597
|
+
Authorization: "Bearer " + process.env.ONEINCH_API_KEY
|
|
19598
|
+
}
|
|
19599
|
+
});
|
|
19600
|
+
|
|
19601
|
+
case 7:
|
|
19602
|
+
response = _context.sent;
|
|
19603
|
+
return _context.abrupt("return", response.data.tx.data);
|
|
19604
|
+
|
|
19605
|
+
case 11:
|
|
19606
|
+
_context.prev = 11;
|
|
19607
|
+
_context.t0 = _context["catch"](4);
|
|
19608
|
+
throw new ApiError("Swap api request of 1inch failed");
|
|
19609
|
+
|
|
19610
|
+
case 14:
|
|
19611
|
+
case "end":
|
|
19612
|
+
return _context.stop();
|
|
19613
|
+
}
|
|
19614
|
+
}
|
|
19615
|
+
}, _callee, null, [[4, 11]]);
|
|
19616
|
+
}));
|
|
19617
|
+
return _getOneInchSwapTxData.apply(this, arguments);
|
|
19618
|
+
}
|
|
19619
|
+
|
|
19611
19620
|
var Pool = /*#__PURE__*/function () {
|
|
19612
19621
|
function Pool(network, signer, poolLogic, mangerLogic, utils, factory) {
|
|
19613
19622
|
this.network = network;
|
|
@@ -19997,7 +20006,7 @@ var Pool = /*#__PURE__*/function () {
|
|
|
19997
20006
|
/*#__PURE__*/
|
|
19998
20007
|
function () {
|
|
19999
20008
|
var _trade = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(dapp, assetFrom, assetTo, amountIn, slippage, options) {
|
|
20000
|
-
var swapTxData,
|
|
20009
|
+
var swapTxData, iSynthetix, assets, daoAddress, iUniswapV2Router, minAmountOut, tx;
|
|
20001
20010
|
return runtime_1.wrap(function _callee9$(_context9) {
|
|
20002
20011
|
while (1) {
|
|
20003
20012
|
switch (_context9.prev = _context9.next) {
|
|
@@ -20011,7 +20020,7 @@ var Pool = /*#__PURE__*/function () {
|
|
|
20011
20020
|
}
|
|
20012
20021
|
|
|
20013
20022
|
_context9.t0 = dapp;
|
|
20014
|
-
_context9.next = _context9.t0 === exports.Dapp.ZEROEX ? 5 : _context9.t0 === exports.Dapp.ONEINCH ? 9 : _context9.t0 === exports.Dapp.BALANCER ?
|
|
20023
|
+
_context9.next = _context9.t0 === exports.Dapp.ZEROEX ? 5 : _context9.t0 === exports.Dapp.ONEINCH ? 9 : _context9.t0 === exports.Dapp.BALANCER ? 13 : _context9.t0 === exports.Dapp.SYNTHETIX ? 17 : _context9.t0 === exports.Dapp.TOROS ? 24 : 28;
|
|
20015
20024
|
break;
|
|
20016
20025
|
|
|
20017
20026
|
case 5:
|
|
@@ -20020,107 +20029,80 @@ var Pool = /*#__PURE__*/function () {
|
|
|
20020
20029
|
|
|
20021
20030
|
case 7:
|
|
20022
20031
|
swapTxData = _context9.sent;
|
|
20023
|
-
return _context9.abrupt("break",
|
|
20032
|
+
return _context9.abrupt("break", 43);
|
|
20024
20033
|
|
|
20025
20034
|
case 9:
|
|
20026
|
-
|
|
20027
|
-
|
|
20028
|
-
return getOneInchProtocols(chainId);
|
|
20029
|
-
|
|
20030
|
-
case 12:
|
|
20031
|
-
protocols = _context9.sent;
|
|
20032
|
-
|
|
20033
|
-
if (process.env.ONEINCH_API_URL) {
|
|
20034
|
-
_context9.next = 15;
|
|
20035
|
-
break;
|
|
20036
|
-
}
|
|
20037
|
-
|
|
20038
|
-
throw new Error("ONEINCH_API_URL not configured in .env file");
|
|
20039
|
-
|
|
20040
|
-
case 15:
|
|
20041
|
-
apiUrl = process.env.ONEINCH_API_URL + "/" + chainId + "/swap?fromTokenAddress=" + assetFrom + "&toTokenAddress=" + assetTo + "&amount=" + amountIn.toString() + "&fromAddress=" + this.address + "&destReceiver=" + this.address + "&slippage=" + slippage.toString() + "&disableEstimate=true" + protocols;
|
|
20042
|
-
_context9.prev = 16;
|
|
20043
|
-
_context9.next = 19;
|
|
20044
|
-
return axios.get(apiUrl);
|
|
20045
|
-
|
|
20046
|
-
case 19:
|
|
20047
|
-
response = _context9.sent;
|
|
20048
|
-
swapTxData = response.data.tx.data;
|
|
20049
|
-
_context9.next = 26;
|
|
20050
|
-
break;
|
|
20035
|
+
_context9.next = 11;
|
|
20036
|
+
return getOneInchSwapTxData(this, assetFrom, assetTo, amountIn, slippage);
|
|
20051
20037
|
|
|
20052
|
-
case
|
|
20053
|
-
|
|
20054
|
-
_context9.
|
|
20055
|
-
throw new ApiError("Swap api request of 1inch failed");
|
|
20056
|
-
|
|
20057
|
-
case 26:
|
|
20058
|
-
return _context9.abrupt("break", 57);
|
|
20038
|
+
case 11:
|
|
20039
|
+
swapTxData = _context9.sent;
|
|
20040
|
+
return _context9.abrupt("break", 43);
|
|
20059
20041
|
|
|
20060
|
-
case
|
|
20061
|
-
_context9.next =
|
|
20042
|
+
case 13:
|
|
20043
|
+
_context9.next = 15;
|
|
20062
20044
|
return this.utils.getBalancerSwapTx(this, assetFrom, assetTo, amountIn, slippage);
|
|
20063
20045
|
|
|
20064
|
-
case
|
|
20046
|
+
case 15:
|
|
20065
20047
|
swapTxData = _context9.sent;
|
|
20066
|
-
return _context9.abrupt("break",
|
|
20048
|
+
return _context9.abrupt("break", 43);
|
|
20067
20049
|
|
|
20068
|
-
case
|
|
20050
|
+
case 17:
|
|
20069
20051
|
iSynthetix = new ethers.ethers.utils.Interface(ISynthetix.abi);
|
|
20070
20052
|
assets = [assetFrom, assetTo].map(function (asset) {
|
|
20071
20053
|
return ethers.ethers.utils.formatBytes32String(asset);
|
|
20072
20054
|
});
|
|
20073
|
-
_context9.next =
|
|
20055
|
+
_context9.next = 21;
|
|
20074
20056
|
return this.factory.owner();
|
|
20075
20057
|
|
|
20076
|
-
case
|
|
20058
|
+
case 21:
|
|
20077
20059
|
daoAddress = _context9.sent;
|
|
20078
20060
|
swapTxData = iSynthetix.encodeFunctionData(exports.Transaction.SWAP_SYNTHS, [assets[0], amountIn, assets[1], daoAddress, SYNTHETIX_TRACKING_CODE]);
|
|
20079
|
-
return _context9.abrupt("break",
|
|
20061
|
+
return _context9.abrupt("break", 43);
|
|
20080
20062
|
|
|
20081
|
-
case
|
|
20082
|
-
_context9.next =
|
|
20063
|
+
case 24:
|
|
20064
|
+
_context9.next = 26;
|
|
20083
20065
|
return getEasySwapperTxData(this, assetFrom, assetTo, ethers.ethers.BigNumber.from(amountIn), slippage);
|
|
20084
20066
|
|
|
20085
|
-
case
|
|
20067
|
+
case 26:
|
|
20086
20068
|
swapTxData = _context9.sent;
|
|
20087
|
-
return _context9.abrupt("break",
|
|
20069
|
+
return _context9.abrupt("break", 43);
|
|
20088
20070
|
|
|
20089
|
-
case
|
|
20071
|
+
case 28:
|
|
20090
20072
|
iUniswapV2Router = new ethers.ethers.utils.Interface(IUniswapV2Router.abi);
|
|
20091
|
-
_context9.next =
|
|
20073
|
+
_context9.next = 31;
|
|
20092
20074
|
return this.utils.getMinAmountOut(dapp, assetFrom, assetTo, amountIn, slippage);
|
|
20093
20075
|
|
|
20094
|
-
case
|
|
20076
|
+
case 31:
|
|
20095
20077
|
minAmountOut = _context9.sent;
|
|
20096
|
-
_context9.
|
|
20097
|
-
_context9.
|
|
20098
|
-
_context9.
|
|
20099
|
-
_context9.
|
|
20100
|
-
_context9.
|
|
20101
|
-
_context9.
|
|
20102
|
-
_context9.next =
|
|
20078
|
+
_context9.t1 = iUniswapV2Router;
|
|
20079
|
+
_context9.t2 = exports.Transaction.SWAP;
|
|
20080
|
+
_context9.t3 = amountIn;
|
|
20081
|
+
_context9.t4 = minAmountOut;
|
|
20082
|
+
_context9.t5 = [assetFrom, assetTo];
|
|
20083
|
+
_context9.t6 = this.address;
|
|
20084
|
+
_context9.next = 40;
|
|
20103
20085
|
return getDeadline(this);
|
|
20104
20086
|
|
|
20105
|
-
case
|
|
20106
|
-
_context9.
|
|
20107
|
-
_context9.
|
|
20108
|
-
swapTxData = _context9.
|
|
20087
|
+
case 40:
|
|
20088
|
+
_context9.t7 = _context9.sent;
|
|
20089
|
+
_context9.t8 = [_context9.t3, _context9.t4, _context9.t5, _context9.t6, _context9.t7];
|
|
20090
|
+
swapTxData = _context9.t1.encodeFunctionData.call(_context9.t1, _context9.t2, _context9.t8);
|
|
20109
20091
|
|
|
20110
|
-
case
|
|
20111
|
-
_context9.next =
|
|
20092
|
+
case 43:
|
|
20093
|
+
_context9.next = 45;
|
|
20112
20094
|
return this.poolLogic.execTransaction(routerAddress[this.network][dapp], swapTxData, options);
|
|
20113
20095
|
|
|
20114
|
-
case
|
|
20096
|
+
case 45:
|
|
20115
20097
|
tx = _context9.sent;
|
|
20116
20098
|
return _context9.abrupt("return", tx);
|
|
20117
20099
|
|
|
20118
|
-
case
|
|
20100
|
+
case 47:
|
|
20119
20101
|
case "end":
|
|
20120
20102
|
return _context9.stop();
|
|
20121
20103
|
}
|
|
20122
20104
|
}
|
|
20123
|
-
}, _callee9, this
|
|
20105
|
+
}, _callee9, this);
|
|
20124
20106
|
}));
|
|
20125
20107
|
|
|
20126
20108
|
function trade(_x24, _x25, _x26, _x27, _x28, _x29) {
|