@dhedge/v2-sdk 2.0.2 → 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/v2-sdk.cjs.development.js +33 -13
- 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 +33 -13
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/test/flatmoney.test.ts +22 -0
- package/src/utils/contract.ts +25 -5
package/package.json
CHANGED
|
@@ -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/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(
|