@dhedge/v2-sdk 2.1.3 → 2.1.4
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 +11 -0
- package/dist/services/pendle/index.d.ts +4 -0
- package/dist/v2-sdk.cjs.development.js +152 -19
- 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 +152 -19
- package/dist/v2-sdk.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/abi/pendle/PT.json +13 -0
- package/src/entities/pool.ts +41 -1
- package/src/services/pendle/index.ts +33 -0
- package/src/test/pendleMint.test.ts +59 -0
package/package.json
CHANGED
package/src/abi/pendle/PT.json
CHANGED
|
@@ -11,5 +11,18 @@
|
|
|
11
11
|
],
|
|
12
12
|
"stateMutability": "view",
|
|
13
13
|
"type": "function"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"inputs": [],
|
|
17
|
+
"name": "YT",
|
|
18
|
+
"outputs": [
|
|
19
|
+
{
|
|
20
|
+
"internalType": "address",
|
|
21
|
+
"name": "",
|
|
22
|
+
"type": "address"
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
"stateMutability": "view",
|
|
26
|
+
"type": "function"
|
|
14
27
|
}
|
|
15
28
|
]
|
package/src/entities/pool.ts
CHANGED
|
@@ -84,7 +84,7 @@ import {
|
|
|
84
84
|
getPancakeUnStakeTxData
|
|
85
85
|
} from "../services/pancake/staking";
|
|
86
86
|
import { getOdosSwapTxData } from "../services/odos";
|
|
87
|
-
import { getPendleSwapTxData } from "../services/pendle";
|
|
87
|
+
import { getPendleMintTxData, getPendleSwapTxData } from "../services/pendle";
|
|
88
88
|
import { getCompleteWithdrawalTxData } from "../services/toros/completeWithdrawal";
|
|
89
89
|
import { getKyberSwapTxData } from "../services/kyberSwap";
|
|
90
90
|
|
|
@@ -2107,4 +2107,44 @@ export class Pool {
|
|
|
2107
2107
|
);
|
|
2108
2108
|
return tx;
|
|
2109
2109
|
}
|
|
2110
|
+
|
|
2111
|
+
/**
|
|
2112
|
+
* Mint PT and YT tokens on Pendle
|
|
2113
|
+
* @param {string} assetFrom Asset to mint from (only underlying asset)
|
|
2114
|
+
* @param {string} pt PT address
|
|
2115
|
+
* @param {BigNumber | string} amountIn Amount underlying asset
|
|
2116
|
+
* @param {number} slippage Slippage tolerance in %
|
|
2117
|
+
* @param {any} options Transaction options
|
|
2118
|
+
* @param {SDKOptions} sdkOptions SDK options including estimateGas
|
|
2119
|
+
* @returns {Promise<any>} Transaction
|
|
2120
|
+
*/
|
|
2121
|
+
async mintPendle(
|
|
2122
|
+
assetFrom: string,
|
|
2123
|
+
pt: string,
|
|
2124
|
+
amountIn: BigNumber | string,
|
|
2125
|
+
slippage = 0.5,
|
|
2126
|
+
options: any = null,
|
|
2127
|
+
sdkOptions: SDKOptions = {
|
|
2128
|
+
estimateGas: false
|
|
2129
|
+
}
|
|
2130
|
+
): Promise<any> {
|
|
2131
|
+
const { swapTxData, minAmountOut } = await getPendleMintTxData(
|
|
2132
|
+
this,
|
|
2133
|
+
assetFrom,
|
|
2134
|
+
pt,
|
|
2135
|
+
amountIn,
|
|
2136
|
+
slippage
|
|
2137
|
+
);
|
|
2138
|
+
const tx = await getPoolTxOrGasEstimate(
|
|
2139
|
+
this,
|
|
2140
|
+
[
|
|
2141
|
+
routerAddress[this.network][Dapp.PENDLE],
|
|
2142
|
+
swapTxData,
|
|
2143
|
+
options,
|
|
2144
|
+
minAmountOut
|
|
2145
|
+
],
|
|
2146
|
+
sdkOptions
|
|
2147
|
+
);
|
|
2148
|
+
return tx;
|
|
2149
|
+
}
|
|
2110
2150
|
}
|
|
@@ -56,6 +56,39 @@ export async function getPendleSwapTxData(
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
export async function getPendleMintTxData(
|
|
60
|
+
pool: Pool,
|
|
61
|
+
tokenIn: string,
|
|
62
|
+
pt: string,
|
|
63
|
+
amountIn: ethers.BigNumber | string,
|
|
64
|
+
slippage: number
|
|
65
|
+
): Promise<{ swapTxData: string; minAmountOut: string | null }> {
|
|
66
|
+
const PTcontract = new ethers.Contract(pt, PTAbi, pool.signer);
|
|
67
|
+
const ytAddress = await PTcontract.YT();
|
|
68
|
+
const params = {
|
|
69
|
+
receiver: pool.address,
|
|
70
|
+
tokensIn: tokenIn,
|
|
71
|
+
tokensOut: `${pt},${ytAddress}`,
|
|
72
|
+
amountsIn: amountIn.toString(),
|
|
73
|
+
slippage: slippage / 100
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
const swapResult = await axios.get(
|
|
77
|
+
`${pendleBaseUrl}/v2/sdk/${networkChainIdMap[pool.network]}/convert`,
|
|
78
|
+
{ params }
|
|
79
|
+
);
|
|
80
|
+
return {
|
|
81
|
+
swapTxData: swapResult.data.routes[0].tx.data,
|
|
82
|
+
minAmountOut: swapResult.data.routes[0].outputs.filter(
|
|
83
|
+
(e: { token: string }) => e.token === pt.toLowerCase()
|
|
84
|
+
)[0].amount
|
|
85
|
+
};
|
|
86
|
+
} catch (e) {
|
|
87
|
+
console.error("Error in Pendle API request:", e);
|
|
88
|
+
throw new ApiError("Pendle api request failed");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
59
92
|
const checkUnderlying = (market: any, token: string, networkId: number) => {
|
|
60
93
|
if (market.underlyingAsset !== `${networkId}-${token.toLocaleLowerCase()}`) {
|
|
61
94
|
throw new Error("Can only trade in or out of the underlying asset");
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
2
|
+
|
|
3
|
+
import { Dhedge, Pool } from "..";
|
|
4
|
+
|
|
5
|
+
import { Network } from "../types";
|
|
6
|
+
import { CONTRACT_ADDRESS } from "./constants";
|
|
7
|
+
import { getTxOptions } from "./txOptions";
|
|
8
|
+
import { TestingRunParams, testingHelper } from "./utils/testingHelper";
|
|
9
|
+
|
|
10
|
+
const testPendle = ({ wallet, network }: TestingRunParams) => {
|
|
11
|
+
const USDE = CONTRACT_ADDRESS[network].USDE;
|
|
12
|
+
const PTJan26Usde = "0x93b544c330f60a2aa05ced87aeeffb8d38fd8c9a";
|
|
13
|
+
|
|
14
|
+
let dhedge: Dhedge;
|
|
15
|
+
let pool: Pool;
|
|
16
|
+
jest.setTimeout(100000);
|
|
17
|
+
|
|
18
|
+
describe(`pool on ${network}`, () => {
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
dhedge = new Dhedge(wallet, network);
|
|
21
|
+
pool = await dhedge.loadPool(
|
|
22
|
+
"0xdad21646ebb0997eb59de1f6a68a67059daf4c31"
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("can get TX Data for mint PT and SY", async () => {
|
|
27
|
+
const usdeBalance = await pool.utils.getBalance(USDE, pool.address);
|
|
28
|
+
const { txData, minAmountOut } = await pool.mintPendle(
|
|
29
|
+
USDE,
|
|
30
|
+
PTJan26Usde,
|
|
31
|
+
usdeBalance,
|
|
32
|
+
0.5,
|
|
33
|
+
null,
|
|
34
|
+
{ onlyGetTxData: true, estimateGas: true }
|
|
35
|
+
);
|
|
36
|
+
expect(txData).not.toBeNull();
|
|
37
|
+
expect(minAmountOut).not.toBeNull();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("can get for mint PT and SY", async () => {
|
|
41
|
+
const usdeBalance = await pool.utils.getBalance(USDE, pool.address);
|
|
42
|
+
await pool.mintPendle(
|
|
43
|
+
USDE,
|
|
44
|
+
PTJan26Usde,
|
|
45
|
+
usdeBalance,
|
|
46
|
+
0.5,
|
|
47
|
+
await getTxOptions(network)
|
|
48
|
+
);
|
|
49
|
+
const ptBalance = await pool.utils.getBalance(PTJan26Usde, pool.address);
|
|
50
|
+
expect(ptBalance.gt(0)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
testingHelper({
|
|
56
|
+
network: Network.PLASMA,
|
|
57
|
+
onFork: false,
|
|
58
|
+
testingRun: testPendle
|
|
59
|
+
});
|