@dhedge/v2-sdk 1.10.5 → 1.10.7
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 +20 -0
- package/dist/entities/pool.d.ts +17 -0
- package/dist/services/compound/rewards.d.ts +2 -0
- package/dist/services/oneInch/index.d.ts +4 -1
- package/dist/services/toros/easySwapper.d.ts +2 -1
- package/dist/test/constants.d.ts +7 -0
- package/dist/test/utils/testingHelper.d.ts +0 -1
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +1330 -1640
- 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 +1330 -1640
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/IDhedgeEasySwapper.json +184 -303
- package/src/abi/compound/ICometRewards.json +241 -0
- package/src/config.ts +11 -6
- package/src/entities/pool.ts +59 -3
- package/src/services/compound/rewards.ts +9 -0
- package/src/services/oneInch/index.ts +9 -6
- package/src/services/toros/easySwapper.ts +64 -22
- package/src/test/compoundV3.test.ts +4 -0
- package/src/test/constants.ts +11 -4
- package/src/test/toros.test.ts +81 -53
- package/src/test/utils/testingHelper.ts +3 -2
- package/src/types.ts +2 -1
package/src/test/toros.test.ts
CHANGED
|
@@ -1,69 +1,97 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { Dhedge, Pool } from "..";
|
|
4
4
|
import { routerAddress } from "../config";
|
|
5
|
+
|
|
5
6
|
import { Dapp, Network } from "../types";
|
|
6
7
|
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
8
|
+
import {
|
|
9
|
+
TestingRunParams,
|
|
10
|
+
setChainlinkTimeout,
|
|
11
|
+
setUSDCAmount,
|
|
12
|
+
testingHelper
|
|
13
|
+
} from "./utils/testingHelper";
|
|
7
14
|
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
15
|
+
import BigNumber from "bignumber.js";
|
|
8
16
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const network = Network.OPTIMISM;
|
|
13
|
-
const SUSD = CONTRACT_ADDRESS[network].SUSD;
|
|
17
|
+
const testToros = ({ wallet, network, provider }: TestingRunParams) => {
|
|
18
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
19
|
+
const TOROS = CONTRACT_ADDRESS[network].TOROS;
|
|
14
20
|
|
|
15
|
-
let dhedge: Dhedge;
|
|
16
|
-
let pool: Pool;
|
|
17
|
-
jest.setTimeout(100000);
|
|
21
|
+
let dhedge: Dhedge;
|
|
22
|
+
let pool: Pool;
|
|
23
|
+
jest.setTimeout(100000);
|
|
18
24
|
|
|
19
|
-
describe(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
describe(`pool on ${network}`, () => {
|
|
26
|
+
beforeAll(async () => {
|
|
27
|
+
dhedge = new Dhedge(wallet, network);
|
|
28
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
29
|
+
await setChainlinkTimeout({ pool, provider }, 86400 * 365);
|
|
30
|
+
// top up gas
|
|
31
|
+
await provider.send("hardhat_setBalance", [
|
|
32
|
+
wallet.address,
|
|
33
|
+
"0x10000000000000000"
|
|
34
|
+
]);
|
|
35
|
+
await provider.send("evm_mine", []);
|
|
36
|
+
// top up USDC
|
|
37
|
+
const amount = new BigNumber(1000).times(1e6).toFixed(0);
|
|
38
|
+
await setUSDCAmount({
|
|
39
|
+
amount,
|
|
40
|
+
userAddress: pool.address,
|
|
41
|
+
network,
|
|
42
|
+
provider
|
|
43
|
+
});
|
|
44
|
+
});
|
|
24
45
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
46
|
+
it("approves unlimited USDC on Toros", async () => {
|
|
47
|
+
await pool.approve(Dapp.TOROS, USDC, MAX_AMOUNT);
|
|
48
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
49
|
+
pool.address,
|
|
50
|
+
USDC,
|
|
51
|
+
routerAddress[network].toros!,
|
|
52
|
+
pool.signer
|
|
53
|
+
);
|
|
54
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
55
|
+
});
|
|
35
56
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
57
|
+
it("trades USDC balance into Toros Token", async () => {
|
|
58
|
+
const usdcBalance = await pool.utils.getBalance(USDC, pool.address);
|
|
59
|
+
await pool.trade(Dapp.TOROS, USDC, TOROS, usdcBalance, 1);
|
|
60
|
+
const torosBalanceDelta = await balanceDelta(
|
|
61
|
+
pool.address,
|
|
62
|
+
TOROS,
|
|
63
|
+
pool.signer
|
|
64
|
+
);
|
|
65
|
+
expect(torosBalanceDelta.gt(0));
|
|
66
|
+
});
|
|
46
67
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pool.address
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
68
|
+
it("init Toros Token for withdrawal", async () => {
|
|
69
|
+
await provider.send("evm_increaseTime", [86400]);
|
|
70
|
+
await provider.send("evm_mine", []);
|
|
71
|
+
const torosBalance = await pool.utils.getBalance(TOROS, pool.address);
|
|
72
|
+
await pool.approve(Dapp.TOROS, TOROS, MAX_AMOUNT);
|
|
73
|
+
await pool.trade(Dapp.TOROS, TOROS, USDC, torosBalance, 1);
|
|
74
|
+
const torosBalanceDelta = await balanceDelta(
|
|
75
|
+
pool.address,
|
|
76
|
+
TOROS,
|
|
77
|
+
pool.signer
|
|
78
|
+
);
|
|
79
|
+
expect(torosBalanceDelta.lt(0));
|
|
80
|
+
});
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
82
|
+
it("complete withdrawal from Toros asset", async () => {
|
|
83
|
+
await pool.completeTorosWithdrawal(USDC, 1);
|
|
84
|
+
const usdcBalanceDelta = await balanceDelta(
|
|
85
|
+
pool.address,
|
|
86
|
+
USDC,
|
|
87
|
+
pool.signer
|
|
88
|
+
);
|
|
89
|
+
expect(usdcBalanceDelta.gt(0));
|
|
61
90
|
});
|
|
62
|
-
const ETHyBalanceDelta = await balanceDelta(
|
|
63
|
-
pool.address,
|
|
64
|
-
ETHy,
|
|
65
|
-
pool.signer
|
|
66
|
-
);
|
|
67
|
-
expect(ETHyBalanceDelta.gt(0));
|
|
68
91
|
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
testingHelper({
|
|
95
|
+
network: Network.OPTIMISM,
|
|
96
|
+
testingRun: testToros
|
|
69
97
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
import { BigNumber, Contract, ethers } from "ethers";
|
|
2
3
|
import { Network } from "../../types";
|
|
3
4
|
import { getWalletData } from "../wallet";
|
|
@@ -34,8 +35,8 @@ export const beforeAfterReset = ({
|
|
|
34
35
|
afterAll,
|
|
35
36
|
provider
|
|
36
37
|
}: {
|
|
37
|
-
beforeAll:
|
|
38
|
-
afterAll:
|
|
38
|
+
beforeAll: any;
|
|
39
|
+
afterAll: any;
|
|
39
40
|
provider: ethers.providers.JsonRpcProvider;
|
|
40
41
|
}): void => {
|
|
41
42
|
let snapshot = "";
|