@dhedge/v2-sdk 1.8.3 → 1.9.0
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 +7 -0
- package/dist/entities/pool.d.ts +7 -0
- package/dist/services/futures/trade.d.ts +1 -0
- package/dist/test/constants.d.ts +9 -2
- package/dist/test/utils/futures.d.ts +2 -0
- package/dist/types.d.ts +2 -1
- package/dist/v2-sdk.cjs.development.js +115 -36
- 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 +115 -36
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +3 -2
- package/src/config.ts +23 -7
- package/src/entities/pool.ts +18 -1
- package/src/services/futures/trade.ts +6 -0
- package/src/test/aave.test.ts +71 -112
- package/src/test/balancer.test.ts +108 -200
- package/src/test/constants.ts +11 -4
- package/src/test/futures.test.ts +5 -2
- package/src/test/oneInch.test.ts +4 -3
- package/src/test/utils/futures.ts +14 -0
- package/src/test/wallet.ts +1 -1
- package/src/types.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhedge/v2-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "🛠 An SDK for building applications on top of dHEDGE V2",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"size": "size-limit",
|
|
22
22
|
"analyze": "size-limit --why",
|
|
23
23
|
"fork:polygon": "hardhat node --fork $(grep POLYGON_URL .env | cut -d '=' -f2)",
|
|
24
|
-
"fork:optimism": "hardhat node --fork $(grep OPTIMISM_URL .env | cut -d '=' -f2)"
|
|
24
|
+
"fork:optimism": "hardhat node --fork $(grep OPTIMISM_URL .env | cut -d '=' -f2)",
|
|
25
|
+
"fork:arbitrum": "hardhat node --fork $(grep ARBITRUM_URL .env | cut -d '=' -f2)"
|
|
25
26
|
},
|
|
26
27
|
"husky": {
|
|
27
28
|
"hooks": {
|
package/src/config.ts
CHANGED
|
@@ -15,7 +15,8 @@ export const factoryAddress: AddressNetworkMap = {
|
|
|
15
15
|
[Network.POLYGON]: process.env.STAGING_CONTRACTS
|
|
16
16
|
? "0xDd87eCdB10cFF7004276AAbAbd30e7a08F69bb53"
|
|
17
17
|
: "0xfdc7b8bFe0DD3513Cc669bB8d601Cb83e2F69cB0",
|
|
18
|
-
[Network.OPTIMISM]: "0x5e61a079A178f0E5784107a4963baAe0c5a680c6"
|
|
18
|
+
[Network.OPTIMISM]: "0x5e61a079A178f0E5784107a4963baAe0c5a680c6",
|
|
19
|
+
[Network.ARBITRUM]: "0xfffb5fb14606eb3a548c113026355020ddf27535"
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export const routerAddress: AddressDappNetworkMap = {
|
|
@@ -39,6 +40,12 @@ export const routerAddress: AddressDappNetworkMap = {
|
|
|
39
40
|
[Dapp.VELODROME]: "0x9c12939390052919aF3155f41Bf4160Fd3666A6f",
|
|
40
41
|
[Dapp.LYRA]: "0xCCE7819d65f348c64B7Beb205BA367b3fE33763B",
|
|
41
42
|
[Dapp.ARRAKIS]: "0x9ce88a56d120300061593eF7AD074A1B710094d5"
|
|
43
|
+
},
|
|
44
|
+
[Network.ARBITRUM]: {
|
|
45
|
+
[Dapp.ONEINCH]: "0x1111111254EEB25477B68fb85Ed929f73A960582",
|
|
46
|
+
[Dapp.UNISWAPV3]: "0xe592427a0aece92de3edee1f18e0157c05861564",
|
|
47
|
+
[Dapp.AAVEV3]: "0x794a61358D6845594F94dc1DB02A252b5b4814aD",
|
|
48
|
+
[Dapp.BALANCER]: "0xBA12222222228d8Ba445958a75a0704d566BF2C8"
|
|
42
49
|
}
|
|
43
50
|
};
|
|
44
51
|
|
|
@@ -47,7 +54,8 @@ export const dappFactoryAddress: AddressDappNetworkMap = {
|
|
|
47
54
|
[Dapp.SUSHISWAP]: "0xc35DADB65012eC5796536bD9864eD8773aBc74C4",
|
|
48
55
|
[Dapp.QUICKSWAP]: "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32"
|
|
49
56
|
},
|
|
50
|
-
[Network.OPTIMISM]: {}
|
|
57
|
+
[Network.OPTIMISM]: {},
|
|
58
|
+
[Network.ARBITRUM]: {}
|
|
51
59
|
};
|
|
52
60
|
|
|
53
61
|
export const stakingAddress: AddressDappNetworkMap = {
|
|
@@ -57,7 +65,8 @@ export const stakingAddress: AddressDappNetworkMap = {
|
|
|
57
65
|
[Dapp.AAVE]: "0x357D51124f59836DeD84c8a1730D72B749d8BC23",
|
|
58
66
|
[Dapp.AAVEV3]: "0x929EC64c34a17401F460460D4B9390518E5B473e"
|
|
59
67
|
},
|
|
60
|
-
[Network.OPTIMISM]: {}
|
|
68
|
+
[Network.OPTIMISM]: {},
|
|
69
|
+
[Network.ARBITRUM]: {}
|
|
61
70
|
};
|
|
62
71
|
|
|
63
72
|
export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
@@ -67,27 +76,34 @@ export const aaveAddressProvider: AddressDappNetworkMap = {
|
|
|
67
76
|
},
|
|
68
77
|
[Network.OPTIMISM]: {
|
|
69
78
|
[Dapp.AAVEV3]: "0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb"
|
|
79
|
+
},
|
|
80
|
+
[Network.ARBITRUM]: {
|
|
81
|
+
[Dapp.AAVEV3]: "0xa97684ead0e402dc232d5a977953df7ecbab3cdb"
|
|
70
82
|
}
|
|
71
83
|
};
|
|
72
84
|
export const nonfungiblePositionManagerAddress: AddressNetworkMap = {
|
|
73
85
|
[Network.POLYGON]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
74
|
-
[Network.OPTIMISM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
86
|
+
[Network.OPTIMISM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
|
|
87
|
+
[Network.ARBITRUM]: "0xC36442b4a4522E871399CD717aBDD847Ab11FE88"
|
|
75
88
|
};
|
|
76
89
|
|
|
77
90
|
export const networkChainIdMap: NetworkChainIdMap = {
|
|
78
91
|
[Network.POLYGON]: 137,
|
|
79
|
-
[Network.OPTIMISM]: 10
|
|
92
|
+
[Network.OPTIMISM]: 10,
|
|
93
|
+
[Network.ARBITRUM]: 42161
|
|
80
94
|
};
|
|
81
95
|
|
|
82
96
|
export const balancerSubgraph: AddressNetworkMap = {
|
|
83
97
|
[Network.POLYGON]:
|
|
84
98
|
"https://api.thegraph.com/subgraphs/name/balancer-labs/balancer-polygon-v2",
|
|
85
|
-
[Network.OPTIMISM]: ""
|
|
99
|
+
[Network.OPTIMISM]: "",
|
|
100
|
+
[Network.ARBITRUM]: ""
|
|
86
101
|
};
|
|
87
102
|
|
|
88
103
|
export const multiCallAddress: AddressNetworkMap = {
|
|
89
104
|
[Network.POLYGON]: "0x275617327c958bD06b5D6b871E7f491D76113dd8",
|
|
90
|
-
[Network.OPTIMISM]: ""
|
|
105
|
+
[Network.OPTIMISM]: "",
|
|
106
|
+
[Network.ARBITRUM]: ""
|
|
91
107
|
};
|
|
92
108
|
|
|
93
109
|
export const lyraNetworkMap: LyraNetworkMap = {
|
package/src/entities/pool.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
getFuturesChangePositionTxData,
|
|
60
60
|
getFuturesChangeMarginTxData
|
|
61
61
|
} from "../services/futures";
|
|
62
|
+
import { getFuturesCancelOrderTxData } from "../services/futures/trade";
|
|
62
63
|
|
|
63
64
|
export class Pool {
|
|
64
65
|
public readonly poolLogic: Contract;
|
|
@@ -288,7 +289,11 @@ export class Pool {
|
|
|
288
289
|
case Dapp.ONEINCH:
|
|
289
290
|
const chainId = networkChainIdMap[this.network];
|
|
290
291
|
const protocols = await getOneInchProtocols(chainId);
|
|
291
|
-
|
|
292
|
+
if (!process.env.ONEINCH_API_URL)
|
|
293
|
+
throw new Error("ONEINCH_API_URL not configured in .env file");
|
|
294
|
+
const apiUrl = `${
|
|
295
|
+
process.env.ONEINCH_API_URL
|
|
296
|
+
}/${chainId}/swap?fromTokenAddress=${assetFrom}&toTokenAddress=${assetTo}&amount=${amountIn.toString()}&fromAddress=${
|
|
292
297
|
this.address
|
|
293
298
|
}&destReceiver=${
|
|
294
299
|
this.address
|
|
@@ -1251,4 +1256,16 @@ export class Pool {
|
|
|
1251
1256
|
const tx = await this.poolLogic.execTransaction(market, txData, options);
|
|
1252
1257
|
return tx;
|
|
1253
1258
|
}
|
|
1259
|
+
|
|
1260
|
+
/** Cancels an open oder on Synthetix futures market
|
|
1261
|
+
*
|
|
1262
|
+
* @param {string} market Address of futures market
|
|
1263
|
+
* @param {any} options Transaction options
|
|
1264
|
+
* @returns {Promise<any>} Transaction
|
|
1265
|
+
*/
|
|
1266
|
+
async cancelFuturesOrder(market: string, options: any = null): Promise<any> {
|
|
1267
|
+
const txData = await getFuturesCancelOrderTxData(this);
|
|
1268
|
+
const tx = await this.poolLogic.execTransaction(market, txData, options);
|
|
1269
|
+
return tx;
|
|
1270
|
+
}
|
|
1254
1271
|
}
|
|
@@ -24,3 +24,9 @@ export async function getFuturesChangePositionTxData(
|
|
|
24
24
|
ethers.utils.formatBytes32String(FUTURES_TRACKING)
|
|
25
25
|
]);
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
export async function getFuturesCancelOrderTxData(pool: Pool): Promise<string> {
|
|
29
|
+
return new ethers.utils.Interface(
|
|
30
|
+
ISynthetixFuturesMarketV2.abi
|
|
31
|
+
).encodeFunctionData("cancelOffchainDelayedOrder", [pool.address]);
|
|
32
|
+
}
|
package/src/test/aave.test.ts
CHANGED
|
@@ -1,128 +1,87 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
import { Dhedge, Pool } from "..";
|
|
3
|
+
import { routerAddress } from "../config";
|
|
4
|
+
import { Dapp, Network } from "../types";
|
|
5
|
+
import { CONTRACT_ADDRESS, MAX_AMOUNT, TEST_POOL } from "./constants";
|
|
6
|
+
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
4
7
|
|
|
5
8
|
import { wallet } from "./wallet";
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
// const network = Network.OPTIMISM;
|
|
11
|
+
// const network = Network.POLYGON;
|
|
12
|
+
const network = Network.ARBITRUM;
|
|
13
|
+
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
14
|
+
const WETH = CONTRACT_ADDRESS[network].WETH;
|
|
8
15
|
|
|
16
|
+
let dhedge: Dhedge;
|
|
17
|
+
let pool: Pool;
|
|
9
18
|
jest.setTimeout(100000);
|
|
10
19
|
|
|
11
|
-
// const options = {
|
|
12
|
-
// gasLimit: 5000000,
|
|
13
|
-
// gasPrice: ethers.utils.parseUnits("100", "gwei")
|
|
14
|
-
// };
|
|
15
|
-
|
|
16
20
|
describe("pool", () => {
|
|
17
|
-
beforeAll(() => {
|
|
18
|
-
dhedge = new Dhedge(wallet,
|
|
21
|
+
beforeAll(async () => {
|
|
22
|
+
dhedge = new Dhedge(wallet, network);
|
|
23
|
+
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
19
24
|
});
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// } catch (e) {
|
|
32
|
-
// console.log(e);
|
|
33
|
-
// }
|
|
34
|
-
// expect(result).not.toBe(null);
|
|
35
|
-
// });
|
|
36
|
-
|
|
37
|
-
// it("withdraws 1 USDC from Aave lending pool", async () => {
|
|
38
|
-
// let result;
|
|
39
|
-
// const pool = await dhedge.loadPool(myPool);
|
|
40
|
-
// try {
|
|
41
|
-
// result = await pool.withdrawDeposit(
|
|
42
|
-
// Dapp.AAVE,
|
|
43
|
-
// weth,
|
|
44
|
-
// "86567951006165",
|
|
45
|
-
// options
|
|
46
|
-
// );
|
|
47
|
-
// console.log(result);
|
|
48
|
-
// } catch (e) {
|
|
49
|
-
// console.log(e);
|
|
50
|
-
// }
|
|
51
|
-
// expect(result).not.toBe(null);
|
|
52
|
-
// });
|
|
53
|
-
|
|
54
|
-
// it("borrows 0.001 WETH from Aave lending pool", async () => {
|
|
55
|
-
// let result;
|
|
56
|
-
// const pool = await dhedge.loadPool(TEST_POOL);
|
|
57
|
-
// try {
|
|
58
|
-
// result = await pool.borrow(Dapp.AAVEV3, WETH, "1000000000000000");
|
|
59
|
-
// console.log(result);
|
|
60
|
-
// } catch (e) {
|
|
61
|
-
// console.log(e);
|
|
62
|
-
// }
|
|
63
|
-
// expect(result).not.toBe(null);
|
|
64
|
-
// });
|
|
26
|
+
it("approves unlimited USDC on Aave Lending pool", async () => {
|
|
27
|
+
await pool.approve(Dapp.AAVEV3, USDC, MAX_AMOUNT);
|
|
28
|
+
const usdcAllowanceDelta = await allowanceDelta(
|
|
29
|
+
pool.address,
|
|
30
|
+
USDC,
|
|
31
|
+
routerAddress[network]["aavev3"]!,
|
|
32
|
+
pool.signer
|
|
33
|
+
);
|
|
34
|
+
await expect(usdcAllowanceDelta.gt(0));
|
|
35
|
+
});
|
|
65
36
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// });
|
|
37
|
+
it("approves unlimited WETH on Aave Lending pool", async () => {
|
|
38
|
+
await pool.approve(Dapp.AAVEV3, WETH, MAX_AMOUNT);
|
|
39
|
+
const wethAllowanceDelta = await allowanceDelta(
|
|
40
|
+
pool.address,
|
|
41
|
+
USDC,
|
|
42
|
+
routerAddress[network]["aavev3"]!,
|
|
43
|
+
pool.signer
|
|
44
|
+
);
|
|
45
|
+
await expect(wethAllowanceDelta.gt(0));
|
|
46
|
+
});
|
|
77
47
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// expect(result).not.toBe(null);
|
|
88
|
-
// });
|
|
48
|
+
it("lends 5 USDC into Aave lending pool", async () => {
|
|
49
|
+
await pool.lend(Dapp.AAVEV3, USDC, "5000000");
|
|
50
|
+
const usdcBalanceDelta = await balanceDelta(
|
|
51
|
+
pool.address,
|
|
52
|
+
USDC,
|
|
53
|
+
pool.signer
|
|
54
|
+
);
|
|
55
|
+
expect(usdcBalanceDelta.eq("-5000000"));
|
|
56
|
+
});
|
|
89
57
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// expect(result).not.toBe(null);
|
|
100
|
-
// });
|
|
58
|
+
it("it borrows 0.001 WETH from Aave lending pool", async () => {
|
|
59
|
+
await pool.borrow(Dapp.AAVEV3, WETH, "1000000000000000");
|
|
60
|
+
const wethBalanceDelta = await balanceDelta(
|
|
61
|
+
pool.address,
|
|
62
|
+
WETH,
|
|
63
|
+
pool.signer
|
|
64
|
+
);
|
|
65
|
+
expect(wethBalanceDelta.eq("1000000000000000"));
|
|
66
|
+
});
|
|
101
67
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
// } catch (e) {
|
|
112
|
-
// console.log(e);
|
|
113
|
-
// }
|
|
114
|
-
// expect(result).not.toBe(null);
|
|
115
|
-
// });
|
|
68
|
+
it("it repays 0.001 WETH to Aave lending pool", async () => {
|
|
69
|
+
await pool.repay(Dapp.AAVEV3, WETH, "1000000000000000");
|
|
70
|
+
const wethBalanceDelta = await balanceDelta(
|
|
71
|
+
pool.address,
|
|
72
|
+
WETH,
|
|
73
|
+
pool.signer
|
|
74
|
+
);
|
|
75
|
+
expect(wethBalanceDelta.eq("-1000000000000000"));
|
|
76
|
+
});
|
|
116
77
|
|
|
117
|
-
it("
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
expect(result).not.toBe(null);
|
|
78
|
+
it("it withdraws 4 USDC from Aave lending pool", async () => {
|
|
79
|
+
await pool.withdrawDeposit(Dapp.AAVEV3, USDC, "4000000");
|
|
80
|
+
const usdcBalanceDelta = await balanceDelta(
|
|
81
|
+
pool.address,
|
|
82
|
+
WETH,
|
|
83
|
+
pool.signer
|
|
84
|
+
);
|
|
85
|
+
expect(usdcBalanceDelta.eq("4000000"));
|
|
127
86
|
});
|
|
128
87
|
});
|