@dhedge/v2-sdk 1.11.1 → 2.0.1

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.
Files changed (38) hide show
  1. package/dist/entities/pool.d.ts +91 -91
  2. package/dist/services/flatmoney/stableLp.d.ts +4 -4
  3. package/dist/services/odos/index.d.ts +5 -1
  4. package/dist/services/pendle/index.d.ts +4 -1
  5. package/dist/services/toros/completeWithdrawal.d.ts +7 -0
  6. package/dist/services/toros/easySwapper.d.ts +2 -2
  7. package/dist/services/toros/initWithdrawal.d.ts +3 -0
  8. package/dist/services/toros/retry.d.ts +5 -0
  9. package/dist/services/toros/swapData.d.ts +11 -0
  10. package/dist/types.d.ts +5 -0
  11. package/dist/utils/contract.d.ts +3 -2
  12. package/dist/v2-sdk.cjs.development.js +5716 -2693
  13. package/dist/v2-sdk.cjs.development.js.map +1 -1
  14. package/dist/v2-sdk.cjs.production.min.js +1 -1
  15. package/dist/v2-sdk.cjs.production.min.js.map +1 -1
  16. package/dist/v2-sdk.esm.js +5716 -2693
  17. package/dist/v2-sdk.esm.js.map +1 -1
  18. package/package.json +1 -1
  19. package/src/abi/IAaveLendingPoolAssetGuard.json +645 -0
  20. package/src/abi/IEasySwapperV2.json +1507 -0
  21. package/src/abi/pendle/PT.json +15 -0
  22. package/src/abi/pendle/SY.json +1 -0
  23. package/src/entities/pool.ts +240 -149
  24. package/src/services/flatmoney/stableLp.ts +27 -21
  25. package/src/services/odos/index.ts +6 -3
  26. package/src/services/pendle/index.ts +43 -8
  27. package/src/services/toros/completeWithdrawal.ts +209 -0
  28. package/src/services/toros/easySwapper.ts +16 -84
  29. package/src/services/toros/initWithdrawal.ts +166 -0
  30. package/src/services/toros/retry.ts +28 -0
  31. package/src/services/toros/swapData.ts +70 -0
  32. package/src/test/constants.ts +1 -1
  33. package/src/test/odos.test.ts +8 -7
  34. package/src/test/oneInch.test.ts +20 -22
  35. package/src/test/pendle.test.ts +63 -37
  36. package/src/test/toros.test.ts +10 -8
  37. package/src/types.ts +8 -0
  38. package/src/utils/contract.ts +70 -16
@@ -3,7 +3,7 @@
3
3
  import set from "lodash/set";
4
4
  import { Interface } from "@ethersproject/abi";
5
5
  import { multiCallAddress } from "../config";
6
- import { ethers, Network, Pool } from "..";
6
+ import { ethers, Network, Pool, SDKOptions } from "..";
7
7
 
8
8
  export async function call(
9
9
  provider: ethers.Signer,
@@ -94,30 +94,84 @@ export class Multicaller {
94
94
  }
95
95
  }
96
96
 
97
+ const getGasEstimateData = async (
98
+ estimateFunc: ethers.ContractFunction<ethers.BigNumber>,
99
+ txInfoData: { to: string; txData: string; minAmountOut: any },
100
+ txOptions: any = {}
101
+ ) => {
102
+ let gas = null;
103
+ let gasEstimationError = null;
104
+ try {
105
+ gas = await estimateFunc(txInfoData.to, txInfoData.txData, txOptions);
106
+ } catch (e) {
107
+ gasEstimationError = e;
108
+ }
109
+ return {
110
+ gas,
111
+ gasEstimationError,
112
+ ...txInfoData
113
+ };
114
+ };
115
+
116
+ export const isSdkOptionsBoolean = (
117
+ sdkOptions: SDKOptions
118
+ ): sdkOptions is boolean => {
119
+ return typeof sdkOptions === "boolean";
120
+ };
121
+
97
122
  export const getPoolTxOrGasEstimate = async (
98
123
  pool: Pool,
99
124
  args: any[],
100
- estimateGas: boolean
125
+ sdkOptions: SDKOptions
101
126
  ): Promise<any> => {
102
- if (pool.isDhedge) {
103
- if (estimateGas) {
104
- return await pool.poolLogic.estimateGas.execTransaction(
105
- args[0],
106
- args[1],
107
- args[2]
127
+ const txInfoData = {
128
+ txData: args[1],
129
+ to: args[0],
130
+ minAmountOut: args[3] || null
131
+ };
132
+
133
+ if (!isSdkOptionsBoolean(sdkOptions) && sdkOptions.onlyGetTxData) {
134
+ return txInfoData;
135
+ }
136
+
137
+ const txOptions = args[2];
138
+
139
+ if (
140
+ !pool.isDhedge ||
141
+ (!isSdkOptionsBoolean(sdkOptions) && sdkOptions.useTraderAddressAsFrom)
142
+ ) {
143
+ if (
144
+ sdkOptions === true ||
145
+ (!isSdkOptionsBoolean(sdkOptions) && sdkOptions.estimateGas)
146
+ ) {
147
+ return await getGasEstimateData(
148
+ pool.signer.estimateGas,
149
+ txInfoData,
150
+ txOptions
108
151
  );
109
152
  } else {
110
- return await pool.poolLogic.execTransaction(args[0], args[1], args[2]);
153
+ return await pool.signer.sendTransaction({
154
+ to: txInfoData.to,
155
+ data: txInfoData.txData,
156
+ ...txOptions
157
+ });
111
158
  }
112
159
  } else {
113
- if (estimateGas) {
114
- return await pool.signer.estimateGas({ to: args[0], data: args[1] });
160
+ if (
161
+ sdkOptions === true ||
162
+ (!isSdkOptionsBoolean(sdkOptions) && sdkOptions.estimateGas)
163
+ ) {
164
+ return await getGasEstimateData(
165
+ pool.poolLogic.estimateGas.execTransaction,
166
+ txInfoData,
167
+ txOptions
168
+ );
115
169
  } else {
116
- return await pool.signer.sendTransaction({
117
- to: args[0],
118
- data: args[1],
119
- ...args[2]
120
- });
170
+ return await pool.poolLogic.execTransaction(
171
+ txInfoData.to,
172
+ txInfoData.txData,
173
+ txOptions
174
+ );
121
175
  }
122
176
  }
123
177
  };