@dhedge/v2-sdk 1.11.0 → 2.0.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.
@@ -8,8 +8,7 @@ import {
8
8
  TestingRunParams,
9
9
  setTokenAmount,
10
10
  setUSDCAmount,
11
- testingHelper,
12
- wait
11
+ testingHelper
13
12
  } from "./utils/testingHelper";
14
13
 
15
14
  import { getTxOptions } from "./txOptions";
@@ -19,7 +18,7 @@ import { balanceDelta } from "./utils/token";
19
18
  const testPendle = ({ wallet, network, provider }: TestingRunParams) => {
20
19
  const USDC = CONTRACT_ADDRESS[network].USDC;
21
20
  const weETH = "0x35751007a407ca6feffe80b3cb397736d2cf4dbe";
22
- const PTweETH = "0xb33808ea0e883138680ba29311a220a7377cdb92";
21
+ // const PTweETH = "0xb33808ea0e883138680ba29311a220a7377cdb92";
23
22
  const PTweETH_matured = "0xe2b2d203577c7cb3d043e89ccf90b5e24d19b66f";
24
23
 
25
24
  let dhedge: Dhedge;
@@ -54,33 +53,62 @@ const testPendle = ({ wallet, network, provider }: TestingRunParams) => {
54
53
  );
55
54
  });
56
55
 
57
- it("swaps weETH to PTweETH on Pendle", async () => {
58
- await pool.approve(Dapp.PENDLE, weETH, MAX_AMOUNT);
59
- const weEthBalance = await pool.utils.getBalance(weETH, pool.address);
60
- await pool.trade(
61
- Dapp.PENDLE,
62
- weETH,
63
- PTweETH,
64
- weEthBalance,
65
- 0.5,
66
- await getTxOptions(network)
67
- );
68
- const ptWeEthBalanceDelta = await balanceDelta(
69
- pool.address,
70
- PTweETH,
71
- pool.signer
72
- );
73
- expect(ptWeEthBalanceDelta.gt(0));
74
- });
56
+ // it("swaps weETH to PTweETH on Pendle", async () => {
57
+ // await pool.approve(Dapp.PENDLE, weETH, MAX_AMOUNT);
58
+ // const weEthBalance = await pool.utils.getBalance(weETH, pool.address);
59
+ // await pool.trade(
60
+ // Dapp.PENDLE,
61
+ // weETH,
62
+ // PTweETH,
63
+ // weEthBalance,
64
+ // 0.5,
65
+ // await getTxOptions(network)
66
+ // );
67
+ // const ptWeEthBalanceDelta = await balanceDelta(
68
+ // pool.address,
69
+ // PTweETH,
70
+ // pool.signer
71
+ // );
72
+ // expect(ptWeEthBalanceDelta.gt(0));
73
+ // });
74
+
75
+ // it("swaps PTweETH to weETH on Pendle", async () => {
76
+ // await pool.approve(Dapp.PENDLE, PTweETH, MAX_AMOUNT);
77
+ // const PTweEthBalance = await pool.utils.getBalance(PTweETH, pool.address);
78
+ // console.log("PTweEthBalance", PTweEthBalance.toString());
79
+ // await wait(3);
80
+ // await pool.trade(
81
+ // Dapp.PENDLE,
82
+ // PTweETH,
83
+ // weETH,
84
+ // PTweEthBalance,
85
+ // 0.5,
86
+ // await getTxOptions(network)
87
+ // );
88
+ // const weEthBalanceDelta = await balanceDelta(
89
+ // pool.address,
90
+ // weETH,
91
+ // pool.signer
92
+ // );
93
+ // expect(weEthBalanceDelta.gt(0));
94
+ // });
75
95
 
76
- it("swaps PTweETH to weETH on Pendle", async () => {
77
- await pool.approve(Dapp.PENDLE, PTweETH, MAX_AMOUNT);
78
- const PTweEthBalance = await pool.utils.getBalance(PTweETH, pool.address);
79
- console.log("PTweEthBalance", PTweEthBalance.toString());
80
- await wait(3);
96
+ it("exit matured PTweETH to weETH on Pendle", async () => {
97
+ await setTokenAmount({
98
+ amount: new BigNumber(1).times(1e18).toString(),
99
+ provider,
100
+ tokenAddress: PTweETH_matured,
101
+ slot: 0,
102
+ userAddress: pool.address
103
+ });
104
+ await pool.approve(Dapp.PENDLE, PTweETH_matured, MAX_AMOUNT);
105
+ const PTweEthBalance = await pool.utils.getBalance(
106
+ PTweETH_matured,
107
+ pool.address
108
+ );
81
109
  await pool.trade(
82
110
  Dapp.PENDLE,
83
- PTweETH,
111
+ PTweETH_matured,
84
112
  weETH,
85
113
  PTweEthBalance,
86
114
  0.5,
@@ -91,7 +119,7 @@ const testPendle = ({ wallet, network, provider }: TestingRunParams) => {
91
119
  weETH,
92
120
  pool.signer
93
121
  );
94
- expect(weEthBalanceDelta.gt(0));
122
+ expect(weEthBalanceDelta.eq(PTweEthBalance));
95
123
  });
96
124
 
97
125
  it("exit matured PTweETH to weETH on Pendle", async () => {
@@ -107,21 +135,19 @@ const testPendle = ({ wallet, network, provider }: TestingRunParams) => {
107
135
  PTweETH_matured,
108
136
  pool.address
109
137
  );
110
- await wait(3);
111
- await pool.trade(
138
+ const result = await pool.trade(
112
139
  Dapp.PENDLE,
113
140
  PTweETH_matured,
114
141
  weETH,
115
142
  PTweEthBalance,
116
143
  0.5,
117
- await getTxOptions(network)
118
- );
119
- const weEthBalanceDelta = await balanceDelta(
120
- pool.address,
121
- weETH,
122
- pool.signer
144
+ await getTxOptions(network),
145
+ true
123
146
  );
124
- expect(weEthBalanceDelta.eq(PTweEthBalance));
147
+
148
+ expect(result.gas).not.toBeNull();
149
+ expect(result.minAmountOut).not.toBeNull();
150
+ expect(result.gasEstimationError).toBeNull();
125
151
  });
126
152
  });
127
153
  };
@@ -101,17 +101,43 @@ export const getPoolTxOrGasEstimate = async (
101
101
  ): Promise<any> => {
102
102
  if (pool.isDhedge) {
103
103
  if (estimateGas) {
104
- return await pool.poolLogic.estimateGas.execTransaction(
105
- args[0],
106
- args[1],
107
- args[2]
108
- );
104
+ let gas = null;
105
+ let gasEstimationError = null;
106
+ try {
107
+ gas = await pool.poolLogic.estimateGas.execTransaction(
108
+ args[0],
109
+ args[1],
110
+ args[2]
111
+ );
112
+ } catch (e) {
113
+ gasEstimationError = e;
114
+ }
115
+ return {
116
+ gas,
117
+ txData: args[1],
118
+ to: args[0],
119
+ gasEstimationError,
120
+ minAmountOut: args[3] || null
121
+ };
109
122
  } else {
110
123
  return await pool.poolLogic.execTransaction(args[0], args[1], args[2]);
111
124
  }
112
125
  } else {
113
126
  if (estimateGas) {
114
- return await pool.signer.estimateGas({ to: args[0], data: args[1] });
127
+ let gas = null;
128
+ let gasEstimationError = null;
129
+ try {
130
+ gas = await pool.signer.estimateGas({ to: args[0], data: args[1] });
131
+ } catch (e) {
132
+ gasEstimationError = e;
133
+ }
134
+ return {
135
+ gas,
136
+ txData: args[1],
137
+ to: args[0],
138
+ gasEstimationError,
139
+ minAmountOut: args[3] || null
140
+ };
115
141
  } else {
116
142
  return await pool.signer.sendTransaction({
117
143
  to: args[0],