@curvefi/llamalend-api 1.0.2
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/.eslintrc.json +40 -0
- package/.github/workflows/lint.yml +15 -0
- package/.github/workflows/publish.yml +55 -0
- package/LICENSE +21 -0
- package/README.md +1976 -0
- package/lib/cache/index.d.ts +14 -0
- package/lib/cache/index.js +31 -0
- package/lib/constants/L2Networks.d.ts +1 -0
- package/lib/constants/L2Networks.js +1 -0
- package/lib/constants/abis/Controller.json +1027 -0
- package/lib/constants/abis/ERC20.json +222 -0
- package/lib/constants/abis/ERC4626.json +1674 -0
- package/lib/constants/abis/GaugeController.json +794 -0
- package/lib/constants/abis/GaugeFactoryMainnet.json +1 -0
- package/lib/constants/abis/GaugeFactorySidechain.json +475 -0
- package/lib/constants/abis/GaugeV5.json +958 -0
- package/lib/constants/abis/LeverageZap.json +35 -0
- package/lib/constants/abis/Llamma.json +984 -0
- package/lib/constants/abis/Minter.json +1 -0
- package/lib/constants/abis/MonetaryPolicy.json +221 -0
- package/lib/constants/abis/OneWayLendingFactoryABI.json +899 -0
- package/lib/constants/abis/SidechainGauge.json +939 -0
- package/lib/constants/abis/Vault.json +721 -0
- package/lib/constants/abis/crvUSD/DeleverageZap.json +248 -0
- package/lib/constants/abis/crvUSD/Factory.json +514 -0
- package/lib/constants/abis/crvUSD/HealthCalculatorZap.json +54 -0
- package/lib/constants/abis/crvUSD/LeverageZap.json +312 -0
- package/lib/constants/abis/crvUSD/MonetaryPolicy.json +294 -0
- package/lib/constants/abis/crvUSD/MonetaryPolicy2.json +299 -0
- package/lib/constants/abis/crvUSD/PegKeeper.json +411 -0
- package/lib/constants/abis/crvUSD/controller.json +991 -0
- package/lib/constants/abis/crvUSD/llamma.json +984 -0
- package/lib/constants/abis/gas_oracle_optimism.json +149 -0
- package/lib/constants/abis/gas_oracle_optimism_blob.json +203 -0
- package/lib/constants/aliases.d.ts +16 -0
- package/lib/constants/aliases.js +124 -0
- package/lib/constants/coins.d.ts +16 -0
- package/lib/constants/coins.js +24 -0
- package/lib/constants/llammas.d.ts +2 -0
- package/lib/constants/llammas.js +96 -0
- package/lib/constants/utils.d.ts +4 -0
- package/lib/constants/utils.js +27 -0
- package/lib/external-api.d.ts +13 -0
- package/lib/external-api.js +436 -0
- package/lib/index.d.ts +104 -0
- package/lib/index.js +123 -0
- package/lib/interfaces.d.ts +228 -0
- package/lib/interfaces.js +1 -0
- package/lib/lendMarkets/LendMarketTemplate.d.ts +510 -0
- package/lib/lendMarkets/LendMarketTemplate.js +4682 -0
- package/lib/lendMarkets/index.d.ts +3 -0
- package/lib/lendMarkets/index.js +3 -0
- package/lib/lendMarkets/lendMarketConstructor.d.ts +2 -0
- package/lib/lendMarkets/lendMarketConstructor.js +6 -0
- package/lib/llamalend.d.ts +80 -0
- package/lib/llamalend.js +878 -0
- package/lib/mintMarkets/MintMarketTemplate.d.ts +308 -0
- package/lib/mintMarkets/MintMarketTemplate.js +2998 -0
- package/lib/mintMarkets/index.d.ts +3 -0
- package/lib/mintMarkets/index.js +3 -0
- package/lib/mintMarkets/mintMarketConstructor.d.ts +2 -0
- package/lib/mintMarkets/mintMarketConstructor.js +4 -0
- package/lib/st-crvUSD.d.ts +35 -0
- package/lib/st-crvUSD.js +505 -0
- package/lib/utils.d.ts +58 -0
- package/lib/utils.js +661 -0
- package/package.json +42 -0
- package/src/cache/index.ts +41 -0
- package/src/constants/L2Networks.ts +1 -0
- package/src/constants/abis/Controller.json +1027 -0
- package/src/constants/abis/ERC20.json +222 -0
- package/src/constants/abis/ERC4626.json +1674 -0
- package/src/constants/abis/GaugeController.json +794 -0
- package/src/constants/abis/GaugeFactoryMainnet.json +1 -0
- package/src/constants/abis/GaugeFactorySidechain.json +475 -0
- package/src/constants/abis/GaugeV5.json +958 -0
- package/src/constants/abis/LeverageZap.json +35 -0
- package/src/constants/abis/Llamma.json +984 -0
- package/src/constants/abis/Minter.json +1 -0
- package/src/constants/abis/MonetaryPolicy.json +221 -0
- package/src/constants/abis/OneWayLendingFactoryABI.json +899 -0
- package/src/constants/abis/SidechainGauge.json +939 -0
- package/src/constants/abis/Vault.json +721 -0
- package/src/constants/abis/crvUSD/DeleverageZap.json +248 -0
- package/src/constants/abis/crvUSD/ERC20.json +222 -0
- package/src/constants/abis/crvUSD/Factory.json +514 -0
- package/src/constants/abis/crvUSD/HealthCalculatorZap.json +54 -0
- package/src/constants/abis/crvUSD/LeverageZap.json +312 -0
- package/src/constants/abis/crvUSD/MonetaryPolicy.json +294 -0
- package/src/constants/abis/crvUSD/MonetaryPolicy2.json +299 -0
- package/src/constants/abis/crvUSD/PegKeeper.json +411 -0
- package/src/constants/abis/crvUSD/controller.json +991 -0
- package/src/constants/abis/crvUSD/llamma.json +984 -0
- package/src/constants/abis/gas_oracle_optimism.json +149 -0
- package/src/constants/abis/gas_oracle_optimism_blob.json +203 -0
- package/src/constants/aliases.ts +141 -0
- package/src/constants/coins.ts +41 -0
- package/src/constants/llammas.ts +99 -0
- package/src/constants/utils.ts +33 -0
- package/src/external-api.ts +325 -0
- package/src/index.ts +128 -0
- package/src/interfaces.ts +237 -0
- package/src/lendMarkets/LendMarketTemplate.ts +3022 -0
- package/src/lendMarkets/index.ts +7 -0
- package/src/lendMarkets/lendMarketConstructor.ts +7 -0
- package/src/llamalend.ts +785 -0
- package/src/mintMarkets/MintMarketTemplate.ts +1781 -0
- package/src/mintMarkets/index.ts +7 -0
- package/src/mintMarkets/mintMarketConstructor.ts +5 -0
- package/src/st-crvUSD.ts +244 -0
- package/src/utils.ts +497 -0
- package/test/fetch.test.ts +152 -0
- package/test/general.test.ts +216 -0
- package/test/leverageBorrowMore.test.ts +245 -0
- package/test/leverageCreateLoan.test.ts +236 -0
- package/test/leverageRepay.test.ts +240 -0
- package/test/readme.test.ts +475 -0
- package/test/selfLiquidate.test.ts +57 -0
- package/test/selfLiquidateCrvUSD.test.ts +54 -0
- package/test/st_crvUSD.test.ts +68 -0
- package/test/swap.test.ts +62 -0
- package/test/swapCrvUSD.test.ts +56 -0
- package/test/vault.test.ts +112 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +72 -0
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import llamalend from "../src/index.js";
|
|
2
|
+
|
|
3
|
+
const generalMethodsTest = async () => {
|
|
4
|
+
await llamalend.init('JsonRpc', {}); // Polygon network
|
|
5
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
6
|
+
|
|
7
|
+
const balances1 = await llamalend.getBalances(['sdt', 'weth']);
|
|
8
|
+
// OR const balances1 = await llamalend.getBalances(['0x361a5a4993493ce00f61c32d4ecca5512b82ce90', '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619']);
|
|
9
|
+
console.log(balances1);
|
|
10
|
+
|
|
11
|
+
// You can specify address
|
|
12
|
+
const balances2 = await llamalend.getBalances(['sdt', 'weth'], "0x0063046686E46Dc6F15918b61AE2B121458534a5");
|
|
13
|
+
// OR const balances2 = await llamalend.getBalances(['0x361a5a4993493ce00f61c32d4ecca5512b82ce90', '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'], '0x0063046686E46Dc6F15918b61AE2B121458534a5');
|
|
14
|
+
console.log(balances2);
|
|
15
|
+
|
|
16
|
+
const spender = "0x136e783846ef68C8Bd00a3369F787dF8d683a696"
|
|
17
|
+
|
|
18
|
+
console.log(await llamalend.getAllowance(['sdt', 'weth'], llamalend.signerAddress, spender));
|
|
19
|
+
console.log(await llamalend.hasAllowance(['sdt', 'weth'], ['1000', '1000'], llamalend.signerAddress, spender));
|
|
20
|
+
console.log(await llamalend.ensureAllowance(['sdt', 'weth'], ['1000', '1000'], spender));
|
|
21
|
+
|
|
22
|
+
console.log(await llamalend.getUsdRate('0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const oneWayMarketFieldsTest = async () => {
|
|
26
|
+
await llamalend.init('JsonRpc', {});
|
|
27
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
28
|
+
|
|
29
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
30
|
+
|
|
31
|
+
console.log(oneWayMarket.id);
|
|
32
|
+
console.log(oneWayMarket.name);
|
|
33
|
+
console.log(oneWayMarket.addresses);
|
|
34
|
+
console.log(oneWayMarket.borrowed_token);
|
|
35
|
+
console.log(oneWayMarket.collateral_token);
|
|
36
|
+
console.log(oneWayMarket.coinAddresses);
|
|
37
|
+
console.log(oneWayMarket.coinDecimals);
|
|
38
|
+
console.log(oneWayMarket.defaultBands);
|
|
39
|
+
console.log(oneWayMarket.minBands);
|
|
40
|
+
console.log(oneWayMarket.maxBands);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const walletBalancesTest = async () => {
|
|
44
|
+
await llamalend.init('JsonRpc', {});
|
|
45
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
46
|
+
|
|
47
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
48
|
+
|
|
49
|
+
// 1. Current address (signer) balances
|
|
50
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
51
|
+
|
|
52
|
+
// 2. You can specify the address
|
|
53
|
+
console.log(await oneWayMarket.wallet.balances("0x0063046686E46Dc6F15918b61AE2B121458534a5"));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const statsTest = async () => {
|
|
57
|
+
await llamalend.init('JsonRpc', {});
|
|
58
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
59
|
+
|
|
60
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
61
|
+
|
|
62
|
+
console.log(await oneWayMarket.stats.parameters());
|
|
63
|
+
console.log(await oneWayMarket.stats.rates());
|
|
64
|
+
console.log(await oneWayMarket.stats.futureRates(10000, 0));
|
|
65
|
+
console.log(await oneWayMarket.stats.futureRates(0, 10000));
|
|
66
|
+
console.log(await oneWayMarket.stats.balances());
|
|
67
|
+
const { activeBand, maxBand, minBand, liquidationBand } = await oneWayMarket.stats.bandsInfo();
|
|
68
|
+
console.log({ activeBand, maxBand, minBand, liquidationBand });
|
|
69
|
+
console.log(await oneWayMarket.stats.bandBalances(liquidationBand ?? 0));
|
|
70
|
+
console.log(await oneWayMarket.stats.bandsBalances());
|
|
71
|
+
console.log(await oneWayMarket.stats.totalDebt());
|
|
72
|
+
console.log(await oneWayMarket.stats.ammBalances());
|
|
73
|
+
console.log(await oneWayMarket.stats.capAndAvailable());
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const vaultTest = async () => {
|
|
77
|
+
await llamalend.init('JsonRpc', {});
|
|
78
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
79
|
+
|
|
80
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-1');
|
|
81
|
+
|
|
82
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
83
|
+
|
|
84
|
+
// ------------ DEPOSIT ------------
|
|
85
|
+
|
|
86
|
+
console.log(await oneWayMarket.vault.maxDeposit());
|
|
87
|
+
console.log(await oneWayMarket.vault.previewDeposit(20000)); // Shares to receive
|
|
88
|
+
console.log(await oneWayMarket.vault.depositIsApproved(20000));
|
|
89
|
+
console.log(await oneWayMarket.vault.depositApprove(20000));
|
|
90
|
+
console.log(await oneWayMarket.vault.deposit(20000));
|
|
91
|
+
|
|
92
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
93
|
+
|
|
94
|
+
// ------------ MINT ------------
|
|
95
|
+
|
|
96
|
+
console.log(await oneWayMarket.vault.maxMint());
|
|
97
|
+
console.log(await oneWayMarket.vault.previewMint(20000)); // Assets to send
|
|
98
|
+
console.log(await oneWayMarket.vault.mintIsApproved(20000));
|
|
99
|
+
console.log(await oneWayMarket.vault.mintApprove(20000));
|
|
100
|
+
console.log(await oneWayMarket.vault.mint(20000));
|
|
101
|
+
|
|
102
|
+
let balances = await oneWayMarket.wallet.balances();
|
|
103
|
+
console.log(balances);
|
|
104
|
+
|
|
105
|
+
// ------------ UTILS ------------
|
|
106
|
+
|
|
107
|
+
console.log(await oneWayMarket.vault.convertToAssets(100000));
|
|
108
|
+
console.log(await oneWayMarket.vault.convertToShares(100));
|
|
109
|
+
|
|
110
|
+
// ------------ STAKE ------------
|
|
111
|
+
|
|
112
|
+
console.log(await oneWayMarket.vault.stakeIsApproved(balances.vaultShares));
|
|
113
|
+
console.log(await oneWayMarket.vault.stakeApprove(balances.vaultShares));
|
|
114
|
+
console.log(await oneWayMarket.vault.stake(balances.vaultShares));
|
|
115
|
+
balances = await oneWayMarket.wallet.balances();
|
|
116
|
+
console.log(balances);
|
|
117
|
+
|
|
118
|
+
// ------------ UNSTAKE ------------
|
|
119
|
+
|
|
120
|
+
console.log(await oneWayMarket.vault.unstake(balances.gauge));
|
|
121
|
+
|
|
122
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
123
|
+
|
|
124
|
+
// ------------ WITHDRAW ------------
|
|
125
|
+
|
|
126
|
+
console.log(await oneWayMarket.vault.maxWithdraw());
|
|
127
|
+
console.log(await oneWayMarket.vault.previewWithdraw(10000)); // Shares to send
|
|
128
|
+
console.log(await oneWayMarket.vault.withdraw(10000));
|
|
129
|
+
|
|
130
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
131
|
+
|
|
132
|
+
console.log(await oneWayMarket.vault.maxRedeem());
|
|
133
|
+
console.log(await oneWayMarket.vault.previewRedeem(10000)); // Assets to receive
|
|
134
|
+
console.log(await oneWayMarket.vault.redeem(10000));
|
|
135
|
+
|
|
136
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
// ------------ REWARDS ------------
|
|
140
|
+
|
|
141
|
+
console.log(oneWayMarket.vault.rewardsOnly());
|
|
142
|
+
console.log(await oneWayMarket.vault.totalLiquidity());
|
|
143
|
+
console.log(await oneWayMarket.vault.crvApr());
|
|
144
|
+
console.log(await oneWayMarket.vault.rewardTokens());
|
|
145
|
+
console.log(await oneWayMarket.vault.rewardsApr());
|
|
146
|
+
console.log(await oneWayMarket.vault.claimableCrv());
|
|
147
|
+
console.log(await oneWayMarket.vault.claimCrv());
|
|
148
|
+
console.log(await oneWayMarket.vault.claimableRewards());
|
|
149
|
+
console.log(await oneWayMarket.vault.claimRewards());
|
|
150
|
+
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const generalTest = async () => {
|
|
154
|
+
await llamalend.init('JsonRpc', {});
|
|
155
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
156
|
+
|
|
157
|
+
console.log(llamalend.oneWayfactory.getMarketList());
|
|
158
|
+
|
|
159
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
console.log("\n--- CREATE LOAN ---\n");
|
|
163
|
+
|
|
164
|
+
console.log(await oneWayMarket.oraclePrice());
|
|
165
|
+
console.log(await oneWayMarket.price());
|
|
166
|
+
console.log(await oneWayMarket.basePrice());
|
|
167
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
168
|
+
console.log(await oneWayMarket.createLoanMaxRecv(1, 5));
|
|
169
|
+
console.log(await oneWayMarket.createLoanBands(1, 1000, 5));
|
|
170
|
+
console.log(await oneWayMarket.createLoanPrices(1, 1000, 5));
|
|
171
|
+
console.log(await oneWayMarket.createLoanHealth(1, 1000, 5)); // FULL
|
|
172
|
+
console.log(await oneWayMarket.createLoanHealth(1, 1000, 5, false)); // NOT FULL
|
|
173
|
+
|
|
174
|
+
console.log(await oneWayMarket.createLoanIsApproved(1));
|
|
175
|
+
// false
|
|
176
|
+
console.log(await oneWayMarket.createLoanApprove(1));
|
|
177
|
+
// [
|
|
178
|
+
// '0xc111e471715ae6f5437e12d3b94868a5b6542cd7304efca18b5782d315760ae5'
|
|
179
|
+
// ]
|
|
180
|
+
console.log(await oneWayMarket.createLoan(1, 1000, 5));
|
|
181
|
+
|
|
182
|
+
console.log(await oneWayMarket.userLoanExists());
|
|
183
|
+
console.log(await oneWayMarket.userState());
|
|
184
|
+
console.log(await oneWayMarket.userHealth()); // FULL
|
|
185
|
+
console.log(await oneWayMarket.userHealth(false)); // NOT FULL
|
|
186
|
+
console.log(await oneWayMarket.userRange());
|
|
187
|
+
console.log(await oneWayMarket.userBands());
|
|
188
|
+
console.log(await oneWayMarket.userPrices());
|
|
189
|
+
console.log(await oneWayMarket.userBandsBalances());
|
|
190
|
+
|
|
191
|
+
console.log("\n--- BORROW MORE ---\n");
|
|
192
|
+
|
|
193
|
+
console.log(await oneWayMarket.borrowMoreMaxRecv(0.5));
|
|
194
|
+
console.log(await oneWayMarket.borrowMoreBands(0.5, 500));
|
|
195
|
+
console.log(await oneWayMarket.borrowMorePrices(0.5, 500));
|
|
196
|
+
console.log(await oneWayMarket.borrowMoreHealth(0.5, 500)); // FULL
|
|
197
|
+
console.log(await oneWayMarket.borrowMoreHealth(0.5, 500, false)); // NOT FULL
|
|
198
|
+
|
|
199
|
+
console.log(await oneWayMarket.borrowMoreIsApproved(0.5));
|
|
200
|
+
console.log(await oneWayMarket.borrowMoreApprove(0.5));
|
|
201
|
+
|
|
202
|
+
console.log(await oneWayMarket.borrowMore(0.5, 500));
|
|
203
|
+
|
|
204
|
+
console.log(await oneWayMarket.userState());
|
|
205
|
+
console.log(await oneWayMarket.userHealth()); // FULL
|
|
206
|
+
console.log(await oneWayMarket.userHealth(false)); // NOT FULL
|
|
207
|
+
console.log(await oneWayMarket.userBands());
|
|
208
|
+
console.log(await oneWayMarket.userPrices());
|
|
209
|
+
|
|
210
|
+
console.log("\n--- ADD COLLATERAL ---\n");
|
|
211
|
+
|
|
212
|
+
console.log(await oneWayMarket.addCollateralBands(0.2));
|
|
213
|
+
console.log(await oneWayMarket.addCollateralPrices(0.2));
|
|
214
|
+
console.log(await oneWayMarket.addCollateralHealth(0.2)); // FULL
|
|
215
|
+
console.log(await oneWayMarket.addCollateralHealth(0.2, false)); // NOT FULL
|
|
216
|
+
|
|
217
|
+
console.log(await oneWayMarket.addCollateralIsApproved(0.2));
|
|
218
|
+
console.log(await oneWayMarket.addCollateralApprove(0.2));
|
|
219
|
+
|
|
220
|
+
console.log(await oneWayMarket.addCollateral(0.2)); // OR await oneWayMarket.addCollateral(0.2, forAddress);
|
|
221
|
+
|
|
222
|
+
console.log(await oneWayMarket.userState());
|
|
223
|
+
console.log(await oneWayMarket.userHealth()); // FULL
|
|
224
|
+
console.log(await oneWayMarket.userHealth(false)); // NOT FULL
|
|
225
|
+
console.log(await oneWayMarket.userBands());
|
|
226
|
+
console.log(await oneWayMarket.userPrices());
|
|
227
|
+
|
|
228
|
+
console.log("\n--- REMOVE COLLATERAL ---\n")
|
|
229
|
+
|
|
230
|
+
console.log(await oneWayMarket.maxRemovable());
|
|
231
|
+
console.log(await oneWayMarket.removeCollateralBands(0.1));
|
|
232
|
+
console.log(await oneWayMarket.removeCollateralPrices(0.1));
|
|
233
|
+
console.log(await oneWayMarket.removeCollateralHealth(0.1)); // FULL
|
|
234
|
+
console.log(await oneWayMarket.removeCollateralHealth(0.1, false)); // NOT FULL
|
|
235
|
+
|
|
236
|
+
console.log(await oneWayMarket.removeCollateral(0.1));
|
|
237
|
+
|
|
238
|
+
console.log(await oneWayMarket.userState());
|
|
239
|
+
console.log(await oneWayMarket.userHealth()); // FULL
|
|
240
|
+
console.log(await oneWayMarket.userHealth(false)); // NOT FULL
|
|
241
|
+
console.log(await oneWayMarket.userBands());
|
|
242
|
+
console.log(await oneWayMarket.userPrices());
|
|
243
|
+
|
|
244
|
+
console.log("\n--- REPAY ---\n");
|
|
245
|
+
|
|
246
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
247
|
+
|
|
248
|
+
console.log(await oneWayMarket.repayBands(1000));
|
|
249
|
+
console.log(await oneWayMarket.repayPrices(1000));
|
|
250
|
+
console.log(await oneWayMarket.repayHealth(1000)); // FULL
|
|
251
|
+
console.log(await oneWayMarket.repayHealth(1000, false)); // NOT FULL
|
|
252
|
+
|
|
253
|
+
console.log(await oneWayMarket.repayIsApproved(1000));
|
|
254
|
+
console.log(await oneWayMarket.repayApprove(1000));
|
|
255
|
+
|
|
256
|
+
console.log(await oneWayMarket.repay(1000));
|
|
257
|
+
|
|
258
|
+
console.log(await oneWayMarket.userLoanExists());
|
|
259
|
+
console.log(await oneWayMarket.userState());
|
|
260
|
+
console.log(await oneWayMarket.userHealth()); // FULL
|
|
261
|
+
console.log(await oneWayMarket.userHealth(false)); // NOT FULL
|
|
262
|
+
console.log(await oneWayMarket.userBands());
|
|
263
|
+
console.log(await oneWayMarket.userPrices());
|
|
264
|
+
|
|
265
|
+
console.log("\n--- FULL REPAY ---\n");
|
|
266
|
+
|
|
267
|
+
console.log(await oneWayMarket.fullRepayIsApproved());
|
|
268
|
+
console.log(await oneWayMarket.fullRepayApprove());
|
|
269
|
+
|
|
270
|
+
console.log(await oneWayMarket.fullRepay());
|
|
271
|
+
|
|
272
|
+
console.log(await oneWayMarket.userLoanExists());
|
|
273
|
+
console.log(await oneWayMarket.userState());
|
|
274
|
+
|
|
275
|
+
console.log(await oneWayMarket.userLoss());
|
|
276
|
+
console.log(await oneWayMarket.currentLeverage());
|
|
277
|
+
console.log(await oneWayMarket.currentPnL());
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const createLoanAllRangesTest = async () => {
|
|
281
|
+
await llamalend.init('JsonRpc', {});
|
|
282
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
283
|
+
|
|
284
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
285
|
+
|
|
286
|
+
console.log(await oneWayMarket.createLoanMaxRecvAllRanges(1));
|
|
287
|
+
console.log(await oneWayMarket.createLoanBandsAllRanges(1, 1600));
|
|
288
|
+
console.log(await oneWayMarket.createLoanPricesAllRanges(1, 1600));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const swapTest = async () => {
|
|
292
|
+
await llamalend.init('JsonRpc', {});
|
|
293
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
294
|
+
|
|
295
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
296
|
+
|
|
297
|
+
// Load liquidity
|
|
298
|
+
await oneWayMarket.vault.deposit(10000);
|
|
299
|
+
const maxDebt = await oneWayMarket.createLoanMaxRecv(0.3, 10);
|
|
300
|
+
await oneWayMarket.createLoan(0.3, maxDebt, 10)
|
|
301
|
+
|
|
302
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
303
|
+
|
|
304
|
+
console.log(await oneWayMarket.maxSwappable(0, 1));
|
|
305
|
+
console.log(await oneWayMarket.swapExpected(0, 1, 100));
|
|
306
|
+
console.log(await oneWayMarket.swapRequired(0, 1, 0.1));
|
|
307
|
+
console.log(await oneWayMarket.swapPriceImpact(0, 1, 100));
|
|
308
|
+
console.log(await oneWayMarket.swapIsApproved(0, 100));
|
|
309
|
+
console.log(await oneWayMarket.swapApprove(0, 100));
|
|
310
|
+
console.log(await oneWayMarket.swap(0, 1, 100, 0.1));
|
|
311
|
+
|
|
312
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const selfLiquidationTest = async () => {
|
|
316
|
+
await llamalend.init('JsonRpc', {});
|
|
317
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
318
|
+
|
|
319
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
320
|
+
|
|
321
|
+
// Load liquidity
|
|
322
|
+
await oneWayMarket.vault.deposit(10000);
|
|
323
|
+
const maxDebt = await oneWayMarket.createLoanMaxRecv(0.3, 10);
|
|
324
|
+
await oneWayMarket.createLoan(0.3, maxDebt, 10);
|
|
325
|
+
await oneWayMarket.swap(0, 1, Number(maxDebt) * 10, 0.05);
|
|
326
|
+
|
|
327
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
328
|
+
console.log(await oneWayMarket.userState());
|
|
329
|
+
|
|
330
|
+
console.log(await oneWayMarket.tokensToLiquidate());
|
|
331
|
+
console.log(await oneWayMarket.selfLiquidateIsApproved());
|
|
332
|
+
console.log(await oneWayMarket.selfLiquidateApprove());
|
|
333
|
+
console.log(await oneWayMarket.selfLiquidate(0.1));
|
|
334
|
+
|
|
335
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
336
|
+
console.log(await oneWayMarket.userState());
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const leverageTest = async () => {
|
|
340
|
+
await llamalend.init('JsonRpc', {}, {});
|
|
341
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
342
|
+
|
|
343
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
344
|
+
console.log(oneWayMarket.collateral_token, oneWayMarket.borrowed_token);
|
|
345
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
346
|
+
|
|
347
|
+
if (Number(await oneWayMarket.vault.totalLiquidity()) === 0) {
|
|
348
|
+
const maxDeposit = Number(await oneWayMarket.vault.maxDeposit()) * 0.7;
|
|
349
|
+
await oneWayMarket.vault.deposit(maxDeposit);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
console.log("\n- Create Loan -\n")
|
|
353
|
+
|
|
354
|
+
let userCollateral = 1;
|
|
355
|
+
let userBorrowed = 1000;
|
|
356
|
+
let debt = 2000;
|
|
357
|
+
const range = 10;
|
|
358
|
+
const slippage = 0.5; // %
|
|
359
|
+
console.log(await oneWayMarket.leverage.maxLeverage(range));
|
|
360
|
+
console.log(await oneWayMarket.leverage.createLoanMaxRecv(userCollateral, userBorrowed, range));
|
|
361
|
+
console.log(await oneWayMarket.leverage.createLoanExpectedCollateral(userCollateral, userBorrowed, debt, slippage));
|
|
362
|
+
console.log(await oneWayMarket.leverage.createLoanPriceImpact(userBorrowed, debt));
|
|
363
|
+
console.log(await oneWayMarket.leverage.createLoanMaxRange(userCollateral, userBorrowed, debt));
|
|
364
|
+
console.log(await oneWayMarket.leverage.createLoanBands(userCollateral, userBorrowed, debt, range));
|
|
365
|
+
console.log(await oneWayMarket.leverage.createLoanPrices(userCollateral, userBorrowed, debt, range));
|
|
366
|
+
console.log(await oneWayMarket.leverage.createLoanHealth(userCollateral, userBorrowed, debt, range));
|
|
367
|
+
console.log(await oneWayMarket.leverage.createLoanHealth(userCollateral, userBorrowed, debt, range, false));
|
|
368
|
+
console.log(await oneWayMarket.leverage.createLoanIsApproved(userCollateral, userBorrowed));
|
|
369
|
+
console.log(await oneWayMarket.leverage.createLoanApprove(userCollateral, userBorrowed));
|
|
370
|
+
console.log(oneWayMarket.leverage.createLoanRouteImage(userBorrowed, debt));
|
|
371
|
+
|
|
372
|
+
console.log(await oneWayMarket.leverage.createLoan(userCollateral, userBorrowed, debt, range, slippage));
|
|
373
|
+
|
|
374
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
375
|
+
console.log(await oneWayMarket.userState());
|
|
376
|
+
console.log(await oneWayMarket.userBands());
|
|
377
|
+
console.log(await oneWayMarket.userPrices());
|
|
378
|
+
console.log(await oneWayMarket.userHealth());
|
|
379
|
+
console.log(await oneWayMarket.userHealth(false));
|
|
380
|
+
|
|
381
|
+
console.log("\n- Borrow More -\n")
|
|
382
|
+
|
|
383
|
+
userCollateral = 2;
|
|
384
|
+
userBorrowed = 2000;
|
|
385
|
+
debt = 10000;
|
|
386
|
+
console.log(await oneWayMarket.leverage.borrowMoreMaxRecv(userCollateral, userBorrowed));
|
|
387
|
+
console.log(await oneWayMarket.leverage.borrowMoreExpectedCollateral(userCollateral, userBorrowed, debt, slippage));
|
|
388
|
+
console.log(await oneWayMarket.leverage.borrowMorePriceImpact(userBorrowed, debt));
|
|
389
|
+
console.log(await oneWayMarket.leverage.borrowMoreBands(userCollateral, userBorrowed, debt));
|
|
390
|
+
console.log(await oneWayMarket.leverage.borrowMorePrices(userCollateral, userBorrowed, debt));
|
|
391
|
+
console.log(await oneWayMarket.leverage.borrowMoreHealth(userCollateral, userBorrowed, debt, true));
|
|
392
|
+
console.log(await oneWayMarket.leverage.borrowMoreHealth(userCollateral, userBorrowed, debt, false));
|
|
393
|
+
console.log(await oneWayMarket.leverage.borrowMoreIsApproved(userCollateral, userBorrowed));
|
|
394
|
+
console.log(await oneWayMarket.leverage.borrowMoreApprove(userCollateral, userBorrowed));
|
|
395
|
+
console.log(await oneWayMarket.leverage.borrowMoreRouteImage(userBorrowed, debt));
|
|
396
|
+
|
|
397
|
+
console.log(await oneWayMarket.leverage.borrowMore(userCollateral, userBorrowed, debt, slippage));
|
|
398
|
+
|
|
399
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
400
|
+
console.log(await oneWayMarket.userState());
|
|
401
|
+
console.log(await oneWayMarket.userBands());
|
|
402
|
+
console.log(await oneWayMarket.userPrices());
|
|
403
|
+
console.log(await oneWayMarket.userHealth());
|
|
404
|
+
console.log(await oneWayMarket.userHealth(false));
|
|
405
|
+
|
|
406
|
+
console.log("\n- Repay -\n")
|
|
407
|
+
|
|
408
|
+
const stateCollateral = 1;
|
|
409
|
+
userCollateral = 1;
|
|
410
|
+
userBorrowed = 1500;
|
|
411
|
+
console.log(await oneWayMarket.leverage.repayExpectedBorrowed(stateCollateral, userCollateral, userBorrowed, slippage));
|
|
412
|
+
console.log(await oneWayMarket.leverage.repayPriceImpact(stateCollateral, userCollateral));
|
|
413
|
+
console.log(await oneWayMarket.leverage.repayIsFull(stateCollateral, userCollateral, userBorrowed));
|
|
414
|
+
console.log(await oneWayMarket.leverage.repayIsAvailable(stateCollateral, userCollateral, userBorrowed));
|
|
415
|
+
console.log(await oneWayMarket.leverage.repayBands(stateCollateral, userCollateral, userBorrowed));
|
|
416
|
+
console.log(await oneWayMarket.leverage.repayPrices(stateCollateral, userCollateral, userBorrowed));
|
|
417
|
+
console.log(await oneWayMarket.leverage.repayHealth(stateCollateral, userCollateral, userBorrowed, true));
|
|
418
|
+
console.log(await oneWayMarket.leverage.repayHealth(stateCollateral, userCollateral, userBorrowed, false));
|
|
419
|
+
console.log(await oneWayMarket.leverage.repayIsApproved(userCollateral, userBorrowed));
|
|
420
|
+
console.log(await oneWayMarket.leverage.repayApprove(userCollateral, userBorrowed));
|
|
421
|
+
console.log(await oneWayMarket.leverage.repayRouteImage(stateCollateral, userCollateral));
|
|
422
|
+
|
|
423
|
+
console.log(await oneWayMarket.leverage.repay(stateCollateral, userCollateral, userBorrowed, slippage));
|
|
424
|
+
|
|
425
|
+
console.log(await oneWayMarket.wallet.balances());
|
|
426
|
+
console.log(await oneWayMarket.userState());
|
|
427
|
+
console.log(await oneWayMarket.userBands());
|
|
428
|
+
console.log(await oneWayMarket.userPrices());
|
|
429
|
+
console.log(await oneWayMarket.userHealth());
|
|
430
|
+
console.log(await oneWayMarket.userHealth(false));
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const leverageAllRangesTest = async () => {
|
|
434
|
+
await llamalend.init('JsonRpc', {}, {});
|
|
435
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
436
|
+
|
|
437
|
+
const oneWayMarket = llamalend.getOneWayMarket('one-way-market-0');
|
|
438
|
+
|
|
439
|
+
if (Number(await oneWayMarket.vault.totalLiquidity()) === 0) {
|
|
440
|
+
const maxDeposit = Number(await oneWayMarket.vault.maxDeposit()) * 0.7;
|
|
441
|
+
await oneWayMarket.vault.deposit(maxDeposit);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
const userCollateral = 1;
|
|
445
|
+
const userBorrowed = 1000;
|
|
446
|
+
const debt = 2000;
|
|
447
|
+
console.log(await oneWayMarket.leverage.createLoanMaxRecvAllRanges(userCollateral, userBorrowed));
|
|
448
|
+
console.log(await oneWayMarket.leverage.createLoanBandsAllRanges(userCollateral, userBorrowed, debt));
|
|
449
|
+
console.log(await oneWayMarket.leverage.createLoanPricesAllRanges(userCollateral, userBorrowed, debt));
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
(async () => {
|
|
453
|
+
console.log("\n--- generalMethodsTest ---\n")
|
|
454
|
+
await generalMethodsTest();
|
|
455
|
+
console.log("\n--- llammaFieldsTest ---\n")
|
|
456
|
+
await oneWayMarketFieldsTest();
|
|
457
|
+
console.log("\n--- walletBalancesTest ---\n")
|
|
458
|
+
await walletBalancesTest();
|
|
459
|
+
console.log("\n--- statsTest ---\n")
|
|
460
|
+
await statsTest();
|
|
461
|
+
console.log("\n--- vaultTest ---\n")
|
|
462
|
+
await vaultTest();
|
|
463
|
+
console.log("\n--- generalTest ---\n")
|
|
464
|
+
await generalTest();
|
|
465
|
+
console.log("\n--- createLoanAllRangesTest ---\n")
|
|
466
|
+
await createLoanAllRangesTest();
|
|
467
|
+
console.log("\n--- swapTest ---\n")
|
|
468
|
+
await swapTest();
|
|
469
|
+
console.log("\n--- selfLiquidationTest ---\n")
|
|
470
|
+
await selfLiquidationTest();
|
|
471
|
+
console.log("\n--- leverageTest ---\n")
|
|
472
|
+
await leverageTest();
|
|
473
|
+
console.log("\n--- leverageAllRangesTest ---\n")
|
|
474
|
+
await leverageAllRangesTest();
|
|
475
|
+
})()
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import llamalend from "../src/index.js";
|
|
3
|
+
import { getOneWayMarket, OneWayMarketTemplate } from "../src/markets/index.js";
|
|
4
|
+
|
|
5
|
+
const ONE_WAY_MARKETS = ['one-way-market-0'];
|
|
6
|
+
|
|
7
|
+
const selfLiquidationTest = (id: string) => {
|
|
8
|
+
describe(`${id} self-liquidation test`, function () {
|
|
9
|
+
let oneWayMarket: OneWayMarketTemplate;
|
|
10
|
+
|
|
11
|
+
before(async function () {
|
|
12
|
+
oneWayMarket = getOneWayMarket(id);
|
|
13
|
+
const maxDeposit = Number(await oneWayMarket.vault.maxDeposit()) * 0.05;
|
|
14
|
+
await oneWayMarket.vault.deposit(maxDeposit);
|
|
15
|
+
const maxDebt = await oneWayMarket.createLoanMaxRecv(0.3, 10);
|
|
16
|
+
await oneWayMarket.createLoan(0.3, maxDebt, 10);
|
|
17
|
+
await oneWayMarket.swap(0, 1, Number(maxDebt), 0.05);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('Self-liquidations', async function () {
|
|
21
|
+
const initialBalances = await oneWayMarket.wallet.balances();
|
|
22
|
+
const initialState = await oneWayMarket.userState();
|
|
23
|
+
const initialTokensToLiquidate = await oneWayMarket.tokensToLiquidate();
|
|
24
|
+
|
|
25
|
+
assert.isAbove(Number(initialState.collateral), 0, "initial state collateral");
|
|
26
|
+
assert.isAbove(Number(initialState.borrowed), 0, "initial state borrowed");
|
|
27
|
+
assert.isAbove(Number(initialState.debt), 0, "initial state");
|
|
28
|
+
assert.isAtLeast(Number(initialBalances.borrowed), Number(initialTokensToLiquidate));
|
|
29
|
+
|
|
30
|
+
await oneWayMarket.selfLiquidate(0.1);
|
|
31
|
+
|
|
32
|
+
const balances = await oneWayMarket.wallet.balances();
|
|
33
|
+
const state = await oneWayMarket.userState();
|
|
34
|
+
|
|
35
|
+
const tokensToLiquidate = await oneWayMarket.tokensToLiquidate();
|
|
36
|
+
assert.equal(Number(tokensToLiquidate), 0, 'tokens to liquidate');
|
|
37
|
+
assert.equal(Number(balances.collateral), Number(initialBalances.collateral) + Number(initialState.collateral), 'wallet collateral');
|
|
38
|
+
assert.approximately(Number(balances.borrowed), Number(initialBalances.borrowed) - Number(initialTokensToLiquidate), 1e-4, 'wallet stablecoin');
|
|
39
|
+
assert.equal(Number(state.collateral), 0, 'state callateral');
|
|
40
|
+
assert.equal(Number(state.borrowed), 0, 'state stablecoin');
|
|
41
|
+
assert.equal(Number(state.debt), 0, 'state debt');
|
|
42
|
+
});
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('Self-liquidation test', async function () {
|
|
47
|
+
this.timeout(120000);
|
|
48
|
+
|
|
49
|
+
before(async function () {
|
|
50
|
+
await llamalend.init('JsonRpc', {},{ gasPrice: 0 });
|
|
51
|
+
await llamalend.oneWayfactory.fetchMarkets();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
for (const oneWayMarketId of ONE_WAY_MARKETS) {
|
|
55
|
+
selfLiquidationTest(oneWayMarketId);
|
|
56
|
+
}
|
|
57
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import llamalend from "../src/index.js";
|
|
3
|
+
import {getLlamma, LlammaTemplate} from "../src/llammas/index.js";
|
|
4
|
+
|
|
5
|
+
const LLAMMAS = ['sfrxeth'];
|
|
6
|
+
|
|
7
|
+
const selfLiquidationTest = (id: string) => {
|
|
8
|
+
describe(`${id} self-liquidation test`, function () {
|
|
9
|
+
let llamma: LlammaTemplate;
|
|
10
|
+
|
|
11
|
+
before(async function () {
|
|
12
|
+
llamma = getLlamma(id);
|
|
13
|
+
const maxDebt = await llamma.createLoanMaxRecv(0.3, 10);
|
|
14
|
+
await llamma.createLoan(0.3, maxDebt, 10);
|
|
15
|
+
await llamma.swap(0, 1, Number(maxDebt) * 10, 0.05);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('Self-liquidations', async function () {
|
|
19
|
+
const initialBalances = await llamma.wallet.balances();
|
|
20
|
+
const initialState = await llamma.userState();
|
|
21
|
+
const initialTokensToLiquidate = await llamma.tokensToLiquidate();
|
|
22
|
+
|
|
23
|
+
assert.isAbove(Number(initialState.collateral), 0);
|
|
24
|
+
assert.isAbove(Number(initialState.stablecoin), 0);
|
|
25
|
+
assert.isAbove(Number(initialState.debt), 0);
|
|
26
|
+
assert.isAtLeast(Number(initialBalances.stablecoin), Number(initialTokensToLiquidate));
|
|
27
|
+
|
|
28
|
+
await llamma.selfLiquidate(0.1);
|
|
29
|
+
|
|
30
|
+
const balances = await llamma.wallet.balances();
|
|
31
|
+
const state = await llamma.userState();
|
|
32
|
+
|
|
33
|
+
const tokensToLiquidate = await llamma.tokensToLiquidate();
|
|
34
|
+
assert.equal(Number(tokensToLiquidate), 0, 'tokens to liquidate');
|
|
35
|
+
assert.equal(Number(balances.collateral), Number(initialBalances.collateral) + Number(initialState.collateral), 'wallet collateral');
|
|
36
|
+
assert.approximately(Number(balances.stablecoin), Number(initialBalances.stablecoin) - Number(initialTokensToLiquidate), 1e-4, 'wallet stablecoin');
|
|
37
|
+
assert.equal(Number(state.collateral), 0, 'state callateral');
|
|
38
|
+
assert.equal(Number(state.stablecoin), 0, 'state stablecoin');
|
|
39
|
+
assert.equal(Number(state.debt), 0, 'state debt');
|
|
40
|
+
});
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('Self-liquidation test', async function () {
|
|
45
|
+
this.timeout(120000);
|
|
46
|
+
|
|
47
|
+
before(async function () {
|
|
48
|
+
await llamalend.init('JsonRpc', {},{ gasPrice: 0 });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
for (const llammaId of LLAMMAS) {
|
|
52
|
+
selfLiquidationTest(llammaId);
|
|
53
|
+
}
|
|
54
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import llamalend from "../src/index.js";
|
|
3
|
+
import { BN } from "../src/utils.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('st-crvUSD test', async function () {
|
|
7
|
+
this.timeout(120000);
|
|
8
|
+
|
|
9
|
+
before(async function () {
|
|
10
|
+
await llamalend.init('JsonRpc', {},{ gasPrice: 0 });
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("deposit", async function () {
|
|
14
|
+
const initialBalances = await llamalend.st_crvUSD.userBalances();
|
|
15
|
+
const depositAmount = Number(await llamalend.st_crvUSD.maxDeposit()) / 2;
|
|
16
|
+
const expectedShares = await llamalend.st_crvUSD.previewDeposit(depositAmount);
|
|
17
|
+
|
|
18
|
+
await llamalend.st_crvUSD.deposit(depositAmount);
|
|
19
|
+
|
|
20
|
+
const balances = await llamalend.st_crvUSD.userBalances();
|
|
21
|
+
|
|
22
|
+
assert.deepStrictEqual(BN(balances.crvUSD).toString(), BN(initialBalances.crvUSD).minus(depositAmount).toString(), 'assets');
|
|
23
|
+
const delta = Number(balances.st_crvUSD) - (Number(initialBalances.st_crvUSD) + Number(expectedShares));
|
|
24
|
+
assert.isAtMost(Math.abs(delta) / Number(balances.st_crvUSD), 1e-7, 'shares');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("mint", async function () {
|
|
28
|
+
const initialBalances = await llamalend.st_crvUSD.userBalances();
|
|
29
|
+
const mintAmount = Number(await llamalend.st_crvUSD.maxMint()) / 2;
|
|
30
|
+
const expectedAssets = await llamalend.st_crvUSD.previewMint(mintAmount);
|
|
31
|
+
|
|
32
|
+
await llamalend.st_crvUSD.mint(mintAmount);
|
|
33
|
+
|
|
34
|
+
const balances = await llamalend.st_crvUSD.userBalances();
|
|
35
|
+
|
|
36
|
+
const delta = Number(balances.crvUSD) - (Number(initialBalances.crvUSD) - Number(expectedAssets));
|
|
37
|
+
assert.isAtMost(Math.abs(delta) / Number(balances.crvUSD), 1e-10, 'assets');
|
|
38
|
+
assert.deepStrictEqual(BN(balances.st_crvUSD).toString(), BN(initialBalances.st_crvUSD).plus(mintAmount).toString(), 'shares');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("withdraw", async function () {
|
|
42
|
+
const initialBalances = await llamalend.st_crvUSD.userBalances();
|
|
43
|
+
const withdrawAmount = Number(await llamalend.st_crvUSD.maxWithdraw()) / 2;
|
|
44
|
+
const expectedShares = await llamalend.st_crvUSD.previewWithdraw(withdrawAmount);
|
|
45
|
+
|
|
46
|
+
await llamalend.st_crvUSD.withdraw(withdrawAmount);
|
|
47
|
+
|
|
48
|
+
const balances = await llamalend.st_crvUSD.userBalances();
|
|
49
|
+
|
|
50
|
+
assert.deepStrictEqual(BN(balances.crvUSD).toString(), BN(initialBalances.crvUSD).plus(BN(withdrawAmount)).toString(), 'assets');
|
|
51
|
+
const delta = Number(balances.st_crvUSD) - (Number(initialBalances.st_crvUSD) - Number(expectedShares));
|
|
52
|
+
assert.isAtMost(Math.abs(delta) / Number(balances.st_crvUSD), 1e-8, 'shares');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("redeem", async function () {
|
|
56
|
+
const initialBalances = await llamalend.st_crvUSD.userBalances();
|
|
57
|
+
const redeemAmount = await llamalend.st_crvUSD.maxRedeem();
|
|
58
|
+
const expectedAssets = await llamalend.st_crvUSD.previewRedeem(redeemAmount);
|
|
59
|
+
|
|
60
|
+
await llamalend.st_crvUSD.redeem(redeemAmount);
|
|
61
|
+
|
|
62
|
+
const balances = await llamalend.st_crvUSD.userBalances();
|
|
63
|
+
|
|
64
|
+
const delta = Number(balances.crvUSD) - (Number(initialBalances.crvUSD) + Number(expectedAssets));
|
|
65
|
+
assert.isAtMost(Math.abs(delta) / Number(balances.crvUSD), 1e-10, 'assets');
|
|
66
|
+
assert.deepStrictEqual(BN(balances.st_crvUSD).toString(), BN(initialBalances.st_crvUSD).minus(redeemAmount).toString(), 'shares');
|
|
67
|
+
});
|
|
68
|
+
})
|