@dhedge/v2-sdk 1.4.1 → 1.4.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/dist/entities/dhedge.d.ts +0 -6
- package/dist/test/constants.d.ts +3 -14
- package/dist/test/txOptions.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +3 -47
- 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 +3 -47
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/entities/dhedge.ts +0 -11
- package/src/test/1inch.test.ts +54 -0
- package/src/test/constants.ts +18 -18
- package/src/test/txOptions.ts +16 -10
package/package.json
CHANGED
package/src/entities/dhedge.ts
CHANGED
|
@@ -88,7 +88,6 @@ export class Dhedge {
|
|
|
88
88
|
* @returns {Pool} Loaded Pool
|
|
89
89
|
*/
|
|
90
90
|
public async loadPool(address: string): Promise<Pool> {
|
|
91
|
-
this.validatePool(address);
|
|
92
91
|
const poolLogic = new Contract(address, PoolLogic.abi, this.signer);
|
|
93
92
|
const managerLogicAddress = await poolLogic.poolManagerLogic();
|
|
94
93
|
const managerLogic = new Contract(
|
|
@@ -106,14 +105,4 @@ export class Dhedge {
|
|
|
106
105
|
this.factory
|
|
107
106
|
);
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Check if pool address is valid
|
|
112
|
-
* @param {string} address Pool address
|
|
113
|
-
* @returns {boolean} Is valid pool address
|
|
114
|
-
*/
|
|
115
|
-
private async validatePool(address: string): Promise<void> {
|
|
116
|
-
const isPool = await this.factory.isPool(address);
|
|
117
|
-
if (!isPool) throw new Error("Given address not a pool");
|
|
118
|
-
}
|
|
119
108
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Dhedge } from "..";
|
|
2
|
+
import { Dapp, Network } from "../types";
|
|
3
|
+
import { TEST_POOL, USDC, WETH } from "./constants";
|
|
4
|
+
import { getTxOptions } from "./txOptions";
|
|
5
|
+
|
|
6
|
+
import { wallet } from "./wallet";
|
|
7
|
+
|
|
8
|
+
let dhedge: Dhedge;
|
|
9
|
+
let options: any;
|
|
10
|
+
|
|
11
|
+
jest.setTimeout(100000);
|
|
12
|
+
|
|
13
|
+
describe("pool", () => {
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
dhedge = new Dhedge(wallet, Network.OPTIMISM);
|
|
16
|
+
options = await getTxOptions(Network.OPTIMISM);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// it("approves unlimited USDC on 1Inch", async () => {
|
|
20
|
+
// let result;
|
|
21
|
+
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
22
|
+
// try {
|
|
23
|
+
// result = await pool.approve(
|
|
24
|
+
// Dapp.ONEINCH,
|
|
25
|
+
// USDC,
|
|
26
|
+
// ethers.constants.MaxInt256,
|
|
27
|
+
// options
|
|
28
|
+
// );
|
|
29
|
+
// console.log(result);
|
|
30
|
+
// } catch (e) {
|
|
31
|
+
// console.log(e);
|
|
32
|
+
// }
|
|
33
|
+
// expect(result).not.toBe(null);
|
|
34
|
+
// });
|
|
35
|
+
|
|
36
|
+
it("trades 1 USDC into WETH on 1Inch", async () => {
|
|
37
|
+
let result;
|
|
38
|
+
const pool = await dhedge.loadPool(TEST_POOL);
|
|
39
|
+
try {
|
|
40
|
+
result = await pool.trade(
|
|
41
|
+
Dapp.ONEINCH,
|
|
42
|
+
USDC,
|
|
43
|
+
WETH,
|
|
44
|
+
"1000000",
|
|
45
|
+
0.5,
|
|
46
|
+
options
|
|
47
|
+
);
|
|
48
|
+
console.log(result);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log(e);
|
|
51
|
+
}
|
|
52
|
+
expect(result).not.toBe(null);
|
|
53
|
+
});
|
|
54
|
+
});
|
package/src/test/constants.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
//Polygon
|
|
2
|
-
export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
3
|
-
export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
4
|
-
export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
5
|
-
export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
6
|
-
export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
|
|
7
|
-
export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
8
|
-
export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
|
|
9
|
-
export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
10
|
-
export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
|
|
11
|
-
export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
|
|
12
|
-
export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
|
|
13
|
-
export const ARRAKIS_USDC_WETH_GAUGE =
|
|
14
|
-
|
|
15
|
-
export const STMATIC = "0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4";
|
|
16
|
-
export const WMATIC_STMATIC_LP = "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D";
|
|
2
|
+
// export const USDC = "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174";
|
|
3
|
+
// export const WETH = "0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619";
|
|
4
|
+
// export const USDT = "0xc2132D05D31c914a87C6611C10748AEb04B58e8F";
|
|
5
|
+
// export const DAI = "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063";
|
|
6
|
+
// export const TUSD = "0x2e1ad108ff1d8c782fcbbb89aad783ac49586756";
|
|
7
|
+
// export const WBTC = "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6";
|
|
8
|
+
// export const SUSHI = "0x0b3f868e0be5597d5db7feb59e1cadbb0fdda50a";
|
|
9
|
+
// export const WMATIC = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270";
|
|
10
|
+
// export const BAL = "0x9a71012B13CA4d3D0Cdc72A177DF3ef03b0E76A3";
|
|
11
|
+
// export const AMUSDC = "0x1a13f4ca1d028320a707d99520abfefca3998b7f";
|
|
12
|
+
// export const VDEBTWETH = "0xede17e9d79fc6f9ff9250d9eefbdb88cc18038b5";
|
|
13
|
+
// export const ARRAKIS_USDC_WETH_GAUGE =
|
|
14
|
+
// "0x33d1ad9Cd88A509397CD924C2d7613C285602C20";
|
|
15
|
+
// export const STMATIC = "0x3A58a54C066FdC0f2D55FC9C89F0415C92eBf3C4";
|
|
16
|
+
// export const WMATIC_STMATIC_LP = "0xaF5E0B5425dE1F5a630A8cB5AA9D97B8141C908D";
|
|
17
17
|
|
|
18
18
|
//Optimism
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export const WETH = "0x4200000000000000000000000000000000000006";
|
|
20
|
+
export const USDC = "0x7F5c764cBc14f9669B88837ca1490cCa17c31607";
|
|
21
|
+
export const DAI = "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1";
|
|
22
22
|
|
|
23
23
|
export const TEST_POOL = "TEST_POOL_ADDRESS";
|
package/src/test/txOptions.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
|
+
import { Network } from "../types";
|
|
3
4
|
|
|
4
5
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
export const getTxOptions = async (): Promise<any> => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
export const getTxOptions = async (network: Network): Promise<any> => {
|
|
7
|
+
if (network === Network.POLYGON) {
|
|
8
|
+
const result = await axios("https://gasstation-mainnet.matic.network/v2");
|
|
9
|
+
return {
|
|
10
|
+
gasLimit: "3000000",
|
|
11
|
+
maxPriorityFeePerGas: new BigNumber(result.data.fast.maxPriorityFee)
|
|
12
|
+
.shiftedBy(9)
|
|
13
|
+
.toFixed(0),
|
|
14
|
+
maxFeePerGas: new BigNumber(result.data.fast.maxFee)
|
|
15
|
+
.shiftedBy(9)
|
|
16
|
+
.toFixed(0),
|
|
17
|
+
};
|
|
18
|
+
} else {
|
|
19
|
+
return { gasLimit: "3000000" };
|
|
20
|
+
}
|
|
15
21
|
};
|