@dhedge/v2-sdk 2.0.1 → 2.0.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/dist/entities/pool.d.ts +8 -0
- package/dist/v2-sdk.cjs.development.js +486 -393
- 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 +486 -393
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/PoolManagerLogic.json +13 -0
- package/src/entities/pool.ts +22 -0
- package/src/test/flatmoney.test.ts +22 -0
- package/src/test/pool.test.ts +77 -74
- package/src/utils/contract.ts +25 -5
package/package.json
CHANGED
|
@@ -812,6 +812,19 @@
|
|
|
812
812
|
],
|
|
813
813
|
"stateMutability": "view",
|
|
814
814
|
"type": "function"
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
"inputs": [
|
|
818
|
+
{
|
|
819
|
+
"internalType": "bool",
|
|
820
|
+
"name": "_privatePool",
|
|
821
|
+
"type": "bool"
|
|
822
|
+
}
|
|
823
|
+
],
|
|
824
|
+
"name": "setPoolPrivate",
|
|
825
|
+
"outputs": [],
|
|
826
|
+
"stateMutability": "nonpayable",
|
|
827
|
+
"type": "function"
|
|
815
828
|
}
|
|
816
829
|
]
|
|
817
830
|
}
|
package/src/entities/pool.ts
CHANGED
|
@@ -993,6 +993,28 @@ export class Pool {
|
|
|
993
993
|
return tx;
|
|
994
994
|
}
|
|
995
995
|
|
|
996
|
+
/**
|
|
997
|
+
* Sets a pool private or public
|
|
998
|
+
* @param {boolean} _private True for private, false for public
|
|
999
|
+
* @param {any} options Transaction options
|
|
1000
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1001
|
+
* @returns {Promise<any>} Transaction
|
|
1002
|
+
*/
|
|
1003
|
+
async setPrivate(
|
|
1004
|
+
_private: boolean,
|
|
1005
|
+
options: any = null,
|
|
1006
|
+
estimateGas = false
|
|
1007
|
+
): Promise<any> {
|
|
1008
|
+
if (estimateGas) {
|
|
1009
|
+
return await this.managerLogic.estimateGas.setPoolPrivate(
|
|
1010
|
+
_private,
|
|
1011
|
+
options
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
1014
|
+
const tx = await this.managerLogic.setPoolPrivate(_private, options);
|
|
1015
|
+
return tx;
|
|
1016
|
+
}
|
|
1017
|
+
|
|
996
1018
|
/**
|
|
997
1019
|
* Invest into a Balancer pool
|
|
998
1020
|
* @param {string} poolId Balancer pool id
|
|
@@ -118,6 +118,14 @@ const testFlatMoney = ({
|
|
|
118
118
|
await expect(collateralAllowanceDelta.gt(0));
|
|
119
119
|
|
|
120
120
|
const depositAmountStr = new BigNumber(1).times(1e18).toString();
|
|
121
|
+
const estimateData = await pool.mintUnitViaFlatMoney(
|
|
122
|
+
depositAmountStr,
|
|
123
|
+
0.5,
|
|
124
|
+
10, // set higher to tolerate high gasPrice returned by forked local chain
|
|
125
|
+
null,
|
|
126
|
+
true
|
|
127
|
+
);
|
|
128
|
+
expect(estimateData.gasEstimationError).toBe(null);
|
|
121
129
|
const tx = await pool.mintUnitViaFlatMoney(
|
|
122
130
|
depositAmountStr,
|
|
123
131
|
0.5,
|
|
@@ -132,6 +140,12 @@ const testFlatMoney = ({
|
|
|
132
140
|
expect(existingOrder.orderType).toBe(1);
|
|
133
141
|
});
|
|
134
142
|
|
|
143
|
+
it("cancel order(estimate)", async () => {
|
|
144
|
+
await provider.send("evm_increaseTime", [60 * 2]); // more than 1 min
|
|
145
|
+
const res = await pool.cancelOrderViaFlatMoney({}, true);
|
|
146
|
+
expect(res.gasEstimationError).toBe(null);
|
|
147
|
+
});
|
|
148
|
+
|
|
135
149
|
it("cancel order", async () => {
|
|
136
150
|
await provider.send("evm_increaseTime", [60 * 2]); // more than 1 min
|
|
137
151
|
await pool.cancelOrderViaFlatMoney();
|
|
@@ -148,6 +162,14 @@ const testFlatMoney = ({
|
|
|
148
162
|
} else {
|
|
149
163
|
withdrawAmountStr = new BigNumber(2).times(1e18).toString();
|
|
150
164
|
}
|
|
165
|
+
const estimateData = await pool.redeemUnitViaFlatMoney(
|
|
166
|
+
withdrawAmountStr,
|
|
167
|
+
0.5,
|
|
168
|
+
10, // set higher to tolerate high gasPrice returned by forked local chain
|
|
169
|
+
null,
|
|
170
|
+
true
|
|
171
|
+
);
|
|
172
|
+
expect(estimateData.gasEstimationError).toBe(null);
|
|
151
173
|
|
|
152
174
|
const tx = await pool.redeemUnitViaFlatMoney(
|
|
153
175
|
withdrawAmountStr,
|
package/src/test/pool.test.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
beforeAfterReset,
|
|
8
|
-
testingHelper,
|
|
9
|
-
TestingRunParams
|
|
10
|
-
} from "./utils/testingHelper";
|
|
11
|
-
import { allowanceDelta, balanceDelta } from "./utils/token";
|
|
1
|
+
import { Dhedge, Pool } from "..";
|
|
2
|
+
import { Network } from "../types";
|
|
3
|
+
import { TEST_POOL } from "./constants";
|
|
4
|
+
|
|
5
|
+
import { testingHelper, TestingRunParams } from "./utils/testingHelper";
|
|
12
6
|
|
|
13
7
|
const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
14
8
|
let dhedge: Dhedge;
|
|
@@ -20,85 +14,94 @@ const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
20
14
|
beforeAll(async () => {
|
|
21
15
|
dhedge = new Dhedge(wallet, network);
|
|
22
16
|
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
17
|
+
|
|
18
|
+
await provider.send("hardhat_setBalance", [
|
|
19
|
+
wallet.address,
|
|
20
|
+
"0x10000000000000000"
|
|
21
|
+
]);
|
|
23
22
|
});
|
|
24
|
-
beforeAfterReset({ beforeAll, afterAll, provider });
|
|
25
23
|
|
|
26
24
|
it("checks fund composition", async () => {
|
|
27
25
|
const result = await pool.getComposition();
|
|
28
26
|
expect(result.length).toBeGreaterThan(0);
|
|
29
27
|
});
|
|
30
28
|
|
|
31
|
-
it("
|
|
32
|
-
await pool.
|
|
33
|
-
|
|
34
|
-
ethers.constants.MaxUint256
|
|
35
|
-
);
|
|
36
|
-
const UsdcAllowanceDelta = await allowanceDelta(
|
|
37
|
-
pool.signer.address,
|
|
38
|
-
CONTRACT_ADDRESS[network].USDC,
|
|
39
|
-
pool.address,
|
|
40
|
-
pool.signer
|
|
41
|
-
);
|
|
42
|
-
expect(UsdcAllowanceDelta.gt(0));
|
|
29
|
+
it("sets pool private", async () => {
|
|
30
|
+
const result = await pool.setPrivate(true);
|
|
31
|
+
expect(result).not.toBeNull();
|
|
43
32
|
});
|
|
44
33
|
|
|
45
|
-
it("
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
34
|
+
// it("approves USDC balance of User for Deposit", async () => {
|
|
35
|
+
// await pool.approveDeposit(
|
|
36
|
+
// CONTRACT_ADDRESS[network].USDC,
|
|
37
|
+
// ethers.constants.MaxUint256
|
|
38
|
+
// );
|
|
39
|
+
// const UsdcAllowanceDelta = await allowanceDelta(
|
|
40
|
+
// pool.signer.address,
|
|
41
|
+
// CONTRACT_ADDRESS[network].USDC,
|
|
42
|
+
// pool.address,
|
|
43
|
+
// pool.signer
|
|
44
|
+
// );
|
|
45
|
+
// expect(UsdcAllowanceDelta.gt(0));
|
|
46
|
+
// });
|
|
54
47
|
|
|
55
|
-
it("
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const assetsAfter = await pool.getComposition();
|
|
65
|
-
if (assetsBefore.length < newAssets.length) {
|
|
66
|
-
expect(assetsAfter.length).toBeGreaterThan(assetsBefore.length);
|
|
67
|
-
} else {
|
|
68
|
-
expect(assetsAfter.length).toBeLessThanOrEqual(assetsBefore.length);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
48
|
+
// it("deposits 1 USDC into Pool", async () => {
|
|
49
|
+
// await pool.deposit(CONTRACT_ADDRESS[network].USDC, (1e6).toString());
|
|
50
|
+
// const poolTokenDelta = await balanceDelta(
|
|
51
|
+
// pool.signer.address,
|
|
52
|
+
// pool.address,
|
|
53
|
+
// pool.signer
|
|
54
|
+
// );
|
|
55
|
+
// expect(poolTokenDelta.gt(0));
|
|
56
|
+
// });
|
|
71
57
|
|
|
72
|
-
it("
|
|
73
|
-
|
|
74
|
-
expect(result).toBeInstanceOf(BigNumber);
|
|
75
|
-
});
|
|
58
|
+
// it("adds WBTC to enabled assets", async () => {
|
|
59
|
+
// const assetsBefore = await pool.getComposition();
|
|
76
60
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
61
|
+
// const newAssets: AssetEnabled[] = [
|
|
62
|
+
// { asset: CONTRACT_ADDRESS[network].USDC, isDeposit: true },
|
|
63
|
+
// { asset: CONTRACT_ADDRESS[network].WETH, isDeposit: false },
|
|
64
|
+
// { asset: CONTRACT_ADDRESS[network].WBTC, isDeposit: false }
|
|
65
|
+
// ];
|
|
66
|
+
// await pool.changeAssets(newAssets);
|
|
67
|
+
// const assetsAfter = await pool.getComposition();
|
|
68
|
+
// if (assetsBefore.length < newAssets.length) {
|
|
69
|
+
// expect(assetsAfter.length).toBeGreaterThan(assetsBefore.length);
|
|
70
|
+
// } else {
|
|
71
|
+
// expect(assetsAfter.length).toBeLessThanOrEqual(assetsBefore.length);
|
|
72
|
+
// }
|
|
73
|
+
// });
|
|
81
74
|
|
|
82
|
-
it("
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
// it("get available Manager Fee", async () => {
|
|
76
|
+
// const result = await pool.getAvailableManagerFee();
|
|
77
|
+
// expect(result).toBeInstanceOf(BigNumber);
|
|
78
|
+
// });
|
|
79
|
+
|
|
80
|
+
// it("mintManagerFee; should not revert", async () => {
|
|
81
|
+
// const tx = await pool.mintManagerFee();
|
|
82
|
+
// expect(tx).toHaveProperty("wait");
|
|
83
|
+
// });
|
|
84
|
+
|
|
85
|
+
// it("withdraw 0.1 pool token into Pool", async () => {
|
|
86
|
+
// await provider.send("evm_increaseTime", [24 * 60 * 60]);
|
|
87
|
+
// await provider.send("evm_mine", []);
|
|
88
|
+
// await pool.withdraw((0.1 * 1e18).toString());
|
|
89
|
+
// const poolTokenDelta = await balanceDelta(
|
|
90
|
+
// pool.signer.address,
|
|
91
|
+
// pool.address,
|
|
92
|
+
// pool.signer
|
|
93
|
+
// );
|
|
94
|
+
// expect(poolTokenDelta.lt(0));
|
|
95
|
+
// });
|
|
93
96
|
});
|
|
94
97
|
};
|
|
95
98
|
|
|
96
|
-
testingHelper({
|
|
97
|
-
network: Network.POLYGON,
|
|
98
|
-
testingRun: testPool
|
|
99
|
-
});
|
|
100
|
-
|
|
101
99
|
// testingHelper({
|
|
102
|
-
// network: Network.
|
|
100
|
+
// network: Network.POLYGON,
|
|
103
101
|
// testingRun: testPool
|
|
104
102
|
// });
|
|
103
|
+
|
|
104
|
+
testingHelper({
|
|
105
|
+
network: Network.OPTIMISM,
|
|
106
|
+
testingRun: testPool
|
|
107
|
+
});
|
package/src/utils/contract.ts
CHANGED
|
@@ -4,6 +4,7 @@ import set from "lodash/set";
|
|
|
4
4
|
import { Interface } from "@ethersproject/abi";
|
|
5
5
|
import { multiCallAddress } from "../config";
|
|
6
6
|
import { ethers, Network, Pool, SDKOptions } from "..";
|
|
7
|
+
import { Signer } from "ethers";
|
|
7
8
|
|
|
8
9
|
export async function call(
|
|
9
10
|
provider: ethers.Signer,
|
|
@@ -95,14 +96,29 @@ export class Multicaller {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
const getGasEstimateData = async (
|
|
99
|
+
pool: Pool,
|
|
98
100
|
estimateFunc: ethers.ContractFunction<ethers.BigNumber>,
|
|
99
101
|
txInfoData: { to: string; txData: string; minAmountOut: any },
|
|
100
|
-
txOptions: any = {}
|
|
102
|
+
txOptions: any = {},
|
|
103
|
+
sdkOptions: SDKOptions
|
|
101
104
|
) => {
|
|
102
105
|
let gas = null;
|
|
103
106
|
let gasEstimationError = null;
|
|
104
107
|
try {
|
|
105
|
-
|
|
108
|
+
if (
|
|
109
|
+
!pool.isDhedge ||
|
|
110
|
+
(!isSdkOptionsBoolean(sdkOptions) && sdkOptions.useTraderAddressAsFrom)
|
|
111
|
+
) {
|
|
112
|
+
// for pool.signer.estimateGas
|
|
113
|
+
gas = await (estimateFunc as Signer["estimateGas"])({
|
|
114
|
+
to: txInfoData.to,
|
|
115
|
+
data: txInfoData.txData,
|
|
116
|
+
...txOptions
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
// for pool.poolLogic.estimateGas.execTransaction
|
|
120
|
+
gas = await estimateFunc(txInfoData.to, txInfoData.txData, txOptions);
|
|
121
|
+
}
|
|
106
122
|
} catch (e) {
|
|
107
123
|
gasEstimationError = e;
|
|
108
124
|
}
|
|
@@ -145,9 +161,11 @@ export const getPoolTxOrGasEstimate = async (
|
|
|
145
161
|
(!isSdkOptionsBoolean(sdkOptions) && sdkOptions.estimateGas)
|
|
146
162
|
) {
|
|
147
163
|
return await getGasEstimateData(
|
|
148
|
-
pool
|
|
164
|
+
pool,
|
|
165
|
+
pool.signer.estimateGas.bind(pool.signer),
|
|
149
166
|
txInfoData,
|
|
150
|
-
txOptions
|
|
167
|
+
txOptions,
|
|
168
|
+
sdkOptions
|
|
151
169
|
);
|
|
152
170
|
} else {
|
|
153
171
|
return await pool.signer.sendTransaction({
|
|
@@ -162,9 +180,11 @@ export const getPoolTxOrGasEstimate = async (
|
|
|
162
180
|
(!isSdkOptionsBoolean(sdkOptions) && sdkOptions.estimateGas)
|
|
163
181
|
) {
|
|
164
182
|
return await getGasEstimateData(
|
|
183
|
+
pool,
|
|
165
184
|
pool.poolLogic.estimateGas.execTransaction,
|
|
166
185
|
txInfoData,
|
|
167
|
-
txOptions
|
|
186
|
+
txOptions,
|
|
187
|
+
sdkOptions
|
|
168
188
|
);
|
|
169
189
|
} else {
|
|
170
190
|
return await pool.poolLogic.execTransaction(
|