@dhedge/v2-sdk 1.9.1 → 1.9.3
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/entities/pool.d.ts +11 -0
- package/dist/services/oneInch/index.d.ts +3 -0
- package/dist/test/constants.d.ts +1 -0
- package/dist/test/utils/testingHelper.d.ts +20 -0
- package/dist/test/wallet.d.ts +10 -0
- package/dist/v2-sdk.cjs.development.js +166 -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 +166 -107
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +4 -4
- package/src/entities/pool.ts +27 -22
- package/src/services/oneInch/index.ts +33 -0
- package/src/test/constants.ts +1 -0
- package/src/test/oneInch.test.ts +40 -32
- package/src/test/pool.test.ts +90 -46
- package/src/test/utils/testingHelper.ts +42 -0
- package/src/test/utils.test.ts +70 -49
- package/src/test/wallet.ts +22 -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/src/test/zeroEx.test.ts
CHANGED
|
@@ -3,44 +3,52 @@ import { Dhedge, Pool } from "..";
|
|
|
3
3
|
import { routerAddress } from "../config";
|
|
4
4
|
import { Dapp, Network } from "../types";
|
|
5
5
|
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
6
|
+
import { TestingRunParams, testingHelper } from "./utils/testingHelper";
|
|
6
7
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
const testZeroEx = ({ wallet, network }: TestingRunParams) => {
|
|
10
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
11
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
14
|
-
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
13
|
+
let dhedge: Dhedge;
|
|
14
|
+
let pool: Pool;
|
|
15
|
+
jest.setTimeout(100000);
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
describe(`[${network}] 0x trade`, () => {
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
dhedge = new Dhedge(wallet, network);
|
|
20
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
21
|
+
});
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
it("approves unlimited USDC on 0x", async () => {
|
|
24
|
+
await pool.approve(Dapp.ZEROEX, USDC, MAX_AMOUNT);
|
|
25
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
26
|
+
pool.address,
|
|
27
|
+
USDC,
|
|
28
|
+
routerAddress[network]["0x"]!,
|
|
29
|
+
pool.signer
|
|
30
|
+
);
|
|
31
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
32
|
+
});
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
it("trades 2 USDC into WETH on 0x", async () => {
|
|
35
|
+
await pool.trade(Dapp.ZEROEX, USDC, WETH, "2000000", 0.5);
|
|
36
|
+
const wethBalanceDelta = await balanceDelta(
|
|
37
|
+
pool.address,
|
|
38
|
+
WETH,
|
|
39
|
+
pool.signer
|
|
40
|
+
);
|
|
41
|
+
expect(wethBalanceDelta.gt(0));
|
|
42
|
+
});
|
|
35
43
|
});
|
|
44
|
+
};
|
|
36
45
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
+
testingHelper({
|
|
47
|
+
network: Network.OPTIMISM,
|
|
48
|
+
testingRun: testZeroEx
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
testingHelper({
|
|
52
|
+
network: Network.POLYGON,
|
|
53
|
+
testingRun: testZeroEx
|
|
46
54
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getOneInchProtocols(chainId: number): Promise<string>;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
export async function getOneInchProtocols(chainId: number): Promise<string> {
|
|
4
|
-
try {
|
|
5
|
-
const response = await axios.get(
|
|
6
|
-
`https://api.1inch.io/v5.0/${chainId}/liquidity-sources`
|
|
7
|
-
);
|
|
8
|
-
const protocols = response.data.protocols.map((e: { id: string }) => e.id);
|
|
9
|
-
const filteredProtocols = protocols.filter(
|
|
10
|
-
(e: string) => !e.includes("PMM")
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
return `&protocols=${filteredProtocols.join(",")}`;
|
|
14
|
-
} catch {
|
|
15
|
-
return "";
|
|
16
|
-
}
|
|
17
|
-
}
|