@dhedge/v2-sdk 1.10.11 → 1.10.12
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/types.d.ts +0 -1
- package/dist/v2-sdk.cjs.development.js +46 -126
- 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 +46 -126
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/config.ts +0 -4
- package/src/entities/pool.ts +0 -11
- package/src/types.ts +0 -1
- package/dist/services/zeroEx/zeroExTrade.d.ts +0 -3
- package/src/services/zeroEx/zeroExTrade.ts +0 -52
- package/src/test/zeroEx.test.ts +0 -95
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -31,7 +31,6 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
31
31
|
[Dapp.UNISWAPV3]: "0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45",
|
|
32
32
|
[Dapp.ARRAKIS]: "0xc73fb100a995b33f9fa181d420f4c8d74506df66",
|
|
33
33
|
[Dapp.TOROS]: "0x45b90480D6F643dE2f128db091A357C3c90399f2",
|
|
34
|
-
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
|
|
35
34
|
[Dapp.ODOS]: "0x4e3288c9ca110bcc82bf38f09a7b425c095d92bf"
|
|
36
35
|
},
|
|
37
36
|
[Network.OPTIMISM]: {
|
|
@@ -44,7 +43,6 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
44
43
|
[Dapp.VELODROMEV2]: "0xa062ae8a9c5e11aaa026fc2670b0d65ccc8b2858",
|
|
45
44
|
[Dapp.LYRA]: "0xCCE7819d65f348c64B7Beb205BA367b3fE33763B",
|
|
46
45
|
[Dapp.ARRAKIS]: "0x9ce88a56d120300061593eF7AD074A1B710094d5",
|
|
47
|
-
[Dapp.ZEROEX]: "0xdef1abe32c034e558cdd535791643c58a13acc10",
|
|
48
46
|
[Dapp.ODOS]: "0xca423977156bb05b13a2ba3b76bc5419e2fe9680"
|
|
49
47
|
},
|
|
50
48
|
[Network.ARBITRUM]: {
|
|
@@ -53,13 +51,11 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
53
51
|
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
54
52
|
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8",
|
|
55
53
|
[Dapp.RAMSES]: "0xaaa87963efeb6f7e0a2711f397663105acb1805e",
|
|
56
|
-
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
|
|
57
54
|
[Dapp.TOROS]: "0xA5679C4272A056Bb83f039961fae7D99C48529F5",
|
|
58
55
|
[Dapp.ODOS]: "0xa669e7A0d4b3e4Fa48af2dE86BD4CD7126Be4e13"
|
|
59
56
|
},
|
|
60
57
|
[Network.BASE]: {
|
|
61
58
|
[Dapp.ONEINCH]: "0x111111125421ca6dc452d289314280a0f8842a65",
|
|
62
|
-
[Dapp.ZEROEX]: "0xdef1c0ded9bec7f1a1670819833240f027b25eff",
|
|
63
59
|
[Dapp.AERODROME]: "0xcF77a3Ba9A5CA399B7c97c74d54e5b1Beb874E43",
|
|
64
60
|
[Dapp.AAVEV3]: "0xA238Dd80C259a72e81d7e4664a9801593F98d1c5",
|
|
65
61
|
[Dapp.TOROS]: "0xf067575Eb60c7587C11e867907AA7284833704d1",
|
package/src/entities/pool.ts
CHANGED
|
@@ -63,7 +63,6 @@ import {
|
|
|
63
63
|
getFuturesChangeMarginTxData
|
|
64
64
|
} from "../services/futures";
|
|
65
65
|
import { getFuturesCancelOrderTxData } from "../services/futures/trade";
|
|
66
|
-
import { getZeroExTradeTxData } from "../services/zeroEx/zeroExTrade";
|
|
67
66
|
import { getOneInchSwapTxData } from "../services/oneInch";
|
|
68
67
|
import {
|
|
69
68
|
getCreateVestTxData,
|
|
@@ -373,16 +372,6 @@ export class Pool {
|
|
|
373
372
|
): Promise<any> {
|
|
374
373
|
let swapTxData: string;
|
|
375
374
|
switch (dapp) {
|
|
376
|
-
case Dapp.ZEROEX:
|
|
377
|
-
swapTxData = await getZeroExTradeTxData(
|
|
378
|
-
this.network,
|
|
379
|
-
assetFrom,
|
|
380
|
-
assetTo,
|
|
381
|
-
amountIn,
|
|
382
|
-
slippage,
|
|
383
|
-
this.address
|
|
384
|
-
);
|
|
385
|
-
break;
|
|
386
375
|
case Dapp.ONEINCH:
|
|
387
376
|
({ swapTxData } = await getOneInchSwapTxData(
|
|
388
377
|
this,
|
package/src/types.ts
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { BigNumber } from "ethers";
|
|
2
|
-
import { Network } from "../../types";
|
|
3
|
-
export declare const getZeroExTradeTxData: (network: Network, assetFrom: string, assetTo: string, amountIn: BigNumber | string, slippage: number | undefined, takerAddress: string) => Promise<string>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
import { BigNumber } from "ethers";
|
|
3
|
-
import { Network } from "../../types";
|
|
4
|
-
import { ApiError } from "../../errors";
|
|
5
|
-
|
|
6
|
-
// slippage of 0x is different from that of 1Inch
|
|
7
|
-
// in 0x, e.g. 0.03 for 3% slippage allowed
|
|
8
|
-
// 1inch slippage 0.5% represented by 0.5
|
|
9
|
-
// 0x slippage 0.5% represented by 0.005
|
|
10
|
-
const getZeroExSlippage = (slippage: number): number => {
|
|
11
|
-
return Number(slippage) / 100;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const getZeroExTradeTxData = async (
|
|
15
|
-
network: Network,
|
|
16
|
-
assetFrom: string,
|
|
17
|
-
assetTo: string,
|
|
18
|
-
amountIn: BigNumber | string,
|
|
19
|
-
slippage = 0.5,
|
|
20
|
-
takerAddress: string
|
|
21
|
-
): Promise<string> => {
|
|
22
|
-
if (!process.env.ZEROEX_API_KEY)
|
|
23
|
-
throw new Error("ZEROEX_API_KEY not configured in .env file");
|
|
24
|
-
try {
|
|
25
|
-
const slippagePercentage = getZeroExSlippage(slippage);
|
|
26
|
-
const params = {
|
|
27
|
-
buyToken: assetTo,
|
|
28
|
-
sellToken: assetFrom,
|
|
29
|
-
sellAmount: amountIn.toString(),
|
|
30
|
-
// necessary to skip quote validation is that in which the takerAddress refers to a smart contract
|
|
31
|
-
skipValidation: true,
|
|
32
|
-
// Used to enable RFQ-T liquidity
|
|
33
|
-
intentOnFilling: true,
|
|
34
|
-
takerAddress,
|
|
35
|
-
slippagePercentage
|
|
36
|
-
// excludedSourcesParam
|
|
37
|
-
};
|
|
38
|
-
const response = await axios.get(
|
|
39
|
-
`https://${network}.api.0x.org/swap/v1/quote`,
|
|
40
|
-
{
|
|
41
|
-
params,
|
|
42
|
-
headers: {
|
|
43
|
-
"0x-api-key": process.env.ZEROEX_API_KEY
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
return response.data.data;
|
|
49
|
-
} catch (e) {
|
|
50
|
-
throw new ApiError("Swap api request of 0x failed");
|
|
51
|
-
}
|
|
52
|
-
};
|
package/src/test/zeroEx.test.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
import BigNumber from "bignumber.js";
|
|
3
|
-
import { Dhedge, Pool } from "..";
|
|
4
|
-
import { routerAddress } from "../config";
|
|
5
|
-
import { Dapp, Network } from "../types";
|
|
6
|
-
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
7
|
-
import {
|
|
8
|
-
TestingRunParams,
|
|
9
|
-
setUSDCAmount,
|
|
10
|
-
testingHelper
|
|
11
|
-
} from "./utils/testingHelper";
|
|
12
|
-
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
13
|
-
import { getTxOptions } from "./txOptions";
|
|
14
|
-
|
|
15
|
-
const testZeroEx = ({ wallet, network, provider }: TestingRunParams) => {
|
|
16
|
-
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
17
|
-
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
18
|
-
|
|
19
|
-
let dhedge: Dhedge;
|
|
20
|
-
let pool: Pool;
|
|
21
|
-
jest.setTimeout(100000);
|
|
22
|
-
|
|
23
|
-
describe(`[${network}] 0x trade`, () => {
|
|
24
|
-
beforeAll(async () => {
|
|
25
|
-
dhedge = new Dhedge(wallet, network);
|
|
26
|
-
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
27
|
-
// top up gas
|
|
28
|
-
await provider.send("hardhat_setBalance", [
|
|
29
|
-
wallet.address,
|
|
30
|
-
"0x10000000000000000"
|
|
31
|
-
]);
|
|
32
|
-
await provider.send("evm_mine", []);
|
|
33
|
-
// top up USDC
|
|
34
|
-
await setUSDCAmount({
|
|
35
|
-
amount: new BigNumber(100).times(1e18).toFixed(0),
|
|
36
|
-
userAddress: pool.address,
|
|
37
|
-
network,
|
|
38
|
-
provider
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("approves unlimited USDC on 0x", async () => {
|
|
43
|
-
await pool.approve(
|
|
44
|
-
Dapp.ZEROEX,
|
|
45
|
-
USDC,
|
|
46
|
-
MAX_AMOUNT,
|
|
47
|
-
await getTxOptions(network)
|
|
48
|
-
);
|
|
49
|
-
const usdcAllowanceDelta = await allowanceDelta(
|
|
50
|
-
pool.address,
|
|
51
|
-
USDC,
|
|
52
|
-
routerAddress[network]["0x"]!,
|
|
53
|
-
pool.signer
|
|
54
|
-
);
|
|
55
|
-
await expect(usdcAllowanceDelta.gt(0));
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("trades 2 USDC into WETH on 0x", async () => {
|
|
59
|
-
await pool.trade(
|
|
60
|
-
Dapp.ZEROEX,
|
|
61
|
-
USDC,
|
|
62
|
-
WETH,
|
|
63
|
-
"2000000",
|
|
64
|
-
0.5,
|
|
65
|
-
await getTxOptions(network)
|
|
66
|
-
);
|
|
67
|
-
const wethBalanceDelta = await balanceDelta(
|
|
68
|
-
pool.address,
|
|
69
|
-
WETH,
|
|
70
|
-
pool.signer
|
|
71
|
-
);
|
|
72
|
-
expect(wethBalanceDelta.gt(0));
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
testingHelper({
|
|
78
|
-
network: Network.OPTIMISM,
|
|
79
|
-
testingRun: testZeroEx
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
testingHelper({
|
|
83
|
-
network: Network.POLYGON,
|
|
84
|
-
testingRun: testZeroEx
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
testingHelper({
|
|
88
|
-
network: Network.BASE,
|
|
89
|
-
testingRun: testZeroEx
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
testingHelper({
|
|
93
|
-
network: Network.ARBITRUM,
|
|
94
|
-
testingRun: testZeroEx
|
|
95
|
-
});
|