@dhedge/v2-sdk 2.1.1 → 2.1.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 +9 -1
- package/dist/v2-sdk.cjs.development.js +504 -405
- 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 +504 -405
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/PoolManagerLogic.json +27 -1
- package/src/entities/pool.ts +26 -1
- package/src/services/pendle/index.ts +10 -8
- package/src/test/pendle.test.ts +19 -19
- package/src/test/pool.test.ts +35 -24
package/package.json
CHANGED
|
@@ -825,6 +825,32 @@
|
|
|
825
825
|
"outputs": [],
|
|
826
826
|
"stateMutability": "nonpayable",
|
|
827
827
|
"type": "function"
|
|
828
|
+
},
|
|
829
|
+
{
|
|
830
|
+
"inputs": [
|
|
831
|
+
{
|
|
832
|
+
"internalType": "uint256",
|
|
833
|
+
"name": "_maxSupplyCapD18",
|
|
834
|
+
"type": "uint256"
|
|
835
|
+
}
|
|
836
|
+
],
|
|
837
|
+
"name": "setMaxSupplyCap",
|
|
838
|
+
"outputs": [],
|
|
839
|
+
"stateMutability": "nonpayable",
|
|
840
|
+
"type": "function"
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
"inputs": [],
|
|
844
|
+
"name": "maxSupplyCap",
|
|
845
|
+
"outputs": [
|
|
846
|
+
{
|
|
847
|
+
"internalType": "uint256",
|
|
848
|
+
"name": "",
|
|
849
|
+
"type": "uint256"
|
|
850
|
+
}
|
|
851
|
+
],
|
|
852
|
+
"stateMutability": "view",
|
|
853
|
+
"type": "function"
|
|
828
854
|
}
|
|
829
855
|
]
|
|
830
|
-
}
|
|
856
|
+
}
|
package/src/entities/pool.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
-
import { Contract, ethers, Wallet, BigNumber } from "ethers";
|
|
3
|
+
import { Contract, ethers, Wallet, BigNumber, BigNumberish } from "ethers";
|
|
4
4
|
|
|
5
5
|
import IERC20 from "../abi/IERC20.json";
|
|
6
6
|
|
|
@@ -1025,6 +1025,31 @@ export class Pool {
|
|
|
1025
1025
|
return tx;
|
|
1026
1026
|
}
|
|
1027
1027
|
|
|
1028
|
+
/**
|
|
1029
|
+
* Sets max supply cap for a pool
|
|
1030
|
+
* @param {BigNumberish} _maxSupplyCapD18 Max supply cap with 18 decimals
|
|
1031
|
+
* @param {any} options Transaction options
|
|
1032
|
+
* @param {boolean} estimateGas Simulate/estimate gas
|
|
1033
|
+
* @returns {Promise<any>} Transaction
|
|
1034
|
+
*/
|
|
1035
|
+
async setMaxCap(
|
|
1036
|
+
_maxSupplyCapD18: BigNumberish,
|
|
1037
|
+
options: any = null,
|
|
1038
|
+
estimateGas = false
|
|
1039
|
+
): Promise<any> {
|
|
1040
|
+
if (estimateGas) {
|
|
1041
|
+
return await this.managerLogic.estimateGas.setMaxSupplyCap(
|
|
1042
|
+
_maxSupplyCapD18,
|
|
1043
|
+
options
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
const tx = await this.managerLogic.setMaxSupplyCap(
|
|
1047
|
+
_maxSupplyCapD18,
|
|
1048
|
+
options
|
|
1049
|
+
);
|
|
1050
|
+
return tx;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1028
1053
|
/**
|
|
1029
1054
|
* Invest into a Balancer pool
|
|
1030
1055
|
* @param {string} poolId Balancer pool id
|
|
@@ -8,7 +8,7 @@ import PTAbi from "../../abi/pendle/PT.json";
|
|
|
8
8
|
import SYAbi from "../../abi/pendle/SY.json";
|
|
9
9
|
import BigNumber from "bignumber.js";
|
|
10
10
|
|
|
11
|
-
const pendleBaseUrl = "https://api-v2.pendle.finance/core
|
|
11
|
+
const pendleBaseUrl = "https://api-v2.pendle.finance/core";
|
|
12
12
|
|
|
13
13
|
export async function getPendleSwapTxData(
|
|
14
14
|
pool: Pool,
|
|
@@ -41,7 +41,7 @@ export async function getPendleSwapTxData(
|
|
|
41
41
|
const market = await getMarket(pool, tokenIn, tokenOut);
|
|
42
42
|
try {
|
|
43
43
|
const swapResult = await axios.get(
|
|
44
|
-
`${pendleBaseUrl}/sdk/${
|
|
44
|
+
`${pendleBaseUrl}/v2/sdk/${
|
|
45
45
|
networkChainIdMap[pool.network]
|
|
46
46
|
}/markets/${market}/swap`,
|
|
47
47
|
{ params }
|
|
@@ -70,9 +70,10 @@ export async function getMarket(
|
|
|
70
70
|
const networkId = networkChainIdMap[pool.network];
|
|
71
71
|
let marketResult;
|
|
72
72
|
try {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
const params = { isActive: true, chainId: networkId };
|
|
74
|
+
marketResult = await axios.get(`${pendleBaseUrl}/v1/markets/all`, {
|
|
75
|
+
params
|
|
76
|
+
});
|
|
76
77
|
} catch (e) {
|
|
77
78
|
console.error("Error in Pendle API request:", e);
|
|
78
79
|
throw new ApiError("Pendle api request failed");
|
|
@@ -103,9 +104,10 @@ const checkExitPostExpPT = async (
|
|
|
103
104
|
const networkId = networkChainIdMap[pool.network];
|
|
104
105
|
let inactiveMarketResult;
|
|
105
106
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
const params = { isActive: false, chainId: networkId };
|
|
108
|
+
inactiveMarketResult = await axios.get(`${pendleBaseUrl}/v1/markets/all`, {
|
|
109
|
+
params
|
|
110
|
+
});
|
|
109
111
|
} catch (e) {
|
|
110
112
|
console.error("Error in Pendle API request:", e);
|
|
111
113
|
throw new ApiError("Pendle api request failed");
|
package/src/test/pendle.test.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { balanceDelta } from "./utils/token";
|
|
|
18
18
|
const testPendle = ({ wallet, network, provider }: TestingRunParams) => {
|
|
19
19
|
const USDC = CONTRACT_ADDRESS[network].USDC;
|
|
20
20
|
const weETH = "0x35751007a407ca6feffe80b3cb397736d2cf4dbe";
|
|
21
|
-
|
|
21
|
+
const PTweETH = "0xab7f3837e6e721abbc826927b655180af6a04388";
|
|
22
22
|
const PTweETH_matured = "0xe2b2d203577c7cb3d043e89ccf90b5e24d19b66f";
|
|
23
23
|
|
|
24
24
|
let dhedge: Dhedge;
|
|
@@ -53,24 +53,24 @@ const testPendle = ({ wallet, network, provider }: TestingRunParams) => {
|
|
|
53
53
|
);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
74
|
|
|
75
75
|
// it("swaps PTweETH to weETH on Pendle", async () => {
|
|
76
76
|
// await pool.approve(Dapp.PENDLE, PTweETH, MAX_AMOUNT);
|
package/src/test/pool.test.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
1
2
|
import { Dhedge, Pool } from "..";
|
|
2
3
|
import { Network } from "../types";
|
|
3
|
-
import {
|
|
4
|
+
import { TEST_POOL } from "./constants";
|
|
4
5
|
|
|
5
6
|
import { testingHelper, TestingRunParams } from "./utils/testingHelper";
|
|
6
|
-
import { balanceDelta } from "./utils/token";
|
|
7
|
+
// import { balanceDelta } from "./utils/token";
|
|
7
8
|
|
|
8
|
-
const testPool = ({ wallet, network }: TestingRunParams) => {
|
|
9
|
+
const testPool = ({ wallet, network, provider }: TestingRunParams) => {
|
|
9
10
|
let dhedge: Dhedge;
|
|
10
11
|
let pool: Pool;
|
|
11
12
|
|
|
12
|
-
const USDT = CONTRACT_ADDRESS[network].USDT;
|
|
13
|
-
|
|
14
13
|
jest.setTimeout(200000);
|
|
15
14
|
|
|
16
15
|
describe(`pool on ${network}`, () => {
|
|
@@ -18,18 +17,31 @@ const testPool = ({ wallet, network }: TestingRunParams) => {
|
|
|
18
17
|
dhedge = new Dhedge(wallet, network);
|
|
19
18
|
pool = await dhedge.loadPool(TEST_POOL[network]);
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
await provider.send("hardhat_setBalance", [
|
|
21
|
+
wallet.address,
|
|
22
|
+
"0x10000000000000000"
|
|
23
|
+
]);
|
|
25
24
|
});
|
|
26
25
|
|
|
27
26
|
it("checks fund composition", async () => {
|
|
28
27
|
const result = await pool.getComposition();
|
|
29
|
-
console.log(result);
|
|
28
|
+
// console.log(result);
|
|
30
29
|
expect(result.length).toBeGreaterThan(0);
|
|
31
30
|
});
|
|
32
31
|
|
|
32
|
+
it("sets max supply cap", async () => {
|
|
33
|
+
const totalSupply: BigNumber = await pool.poolLogic.totalSupply();
|
|
34
|
+
let initCap = totalSupply;
|
|
35
|
+
if (totalSupply.eq(0)) {
|
|
36
|
+
initCap = BigNumber.from(1000).mul(BigNumber.from(10).pow(18));
|
|
37
|
+
}
|
|
38
|
+
await pool.setMaxCap(initCap.mul(2), null, true);
|
|
39
|
+
const tx = await pool.setMaxCap(initCap.mul(2));
|
|
40
|
+
await tx.wait(1);
|
|
41
|
+
const maxCapAfter: BigNumber = await pool.managerLogic.maxSupplyCap();
|
|
42
|
+
expect(maxCapAfter).toEqual(initCap.mul(2));
|
|
43
|
+
});
|
|
44
|
+
|
|
33
45
|
// it("sets pool private", async () => {
|
|
34
46
|
// const result = await pool.setPrivate(true);
|
|
35
47
|
// expect(result).not.toBeNull();
|
|
@@ -65,18 +77,18 @@ const testPool = ({ wallet, network }: TestingRunParams) => {
|
|
|
65
77
|
// expect(usdtAllowanceDelta.gt(0));
|
|
66
78
|
// });
|
|
67
79
|
|
|
68
|
-
it("deposits 200 USDT into Pool", async () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
+
// it("deposits 200 USDT into Pool", async () => {
|
|
81
|
+
// await pool.deposit(
|
|
82
|
+
// CONTRACT_ADDRESS[network].USDT,
|
|
83
|
+
// (200000000).toString()
|
|
84
|
+
// );
|
|
85
|
+
// const poolTokenDelta = await balanceDelta(
|
|
86
|
+
// pool.address,
|
|
87
|
+
// USDT,
|
|
88
|
+
// pool.signer
|
|
89
|
+
// );
|
|
90
|
+
// expect(poolTokenDelta.gt(0));
|
|
91
|
+
// });
|
|
80
92
|
|
|
81
93
|
// it("get available Manager Fee", async () => {
|
|
82
94
|
// const result = await pool.getAvailableManagerFee();
|
|
@@ -108,7 +120,6 @@ const testPool = ({ wallet, network }: TestingRunParams) => {
|
|
|
108
120
|
// });
|
|
109
121
|
|
|
110
122
|
testingHelper({
|
|
111
|
-
network: Network.
|
|
112
|
-
onFork: false,
|
|
123
|
+
network: Network.ARBITRUM,
|
|
113
124
|
testingRun: testPool
|
|
114
125
|
});
|