@curvefi/llamalend-api 1.0.7 → 1.0.9
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/lib/llamalend.d.ts +1 -0
- package/lib/llamalend.js +67 -63
- package/lib/mintMarkets/MintMarketTemplate.js +11 -11
- package/package.json +1 -1
- package/src/llamalend.ts +77 -72
- package/src/mintMarkets/MintMarketTemplate.ts +11 -11
package/lib/llamalend.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const NETWORK_CONSTANTS: {
|
|
|
6
6
|
};
|
|
7
7
|
declare class Llamalend implements ILlamalend {
|
|
8
8
|
address: string;
|
|
9
|
+
crvUsdAddress: string;
|
|
9
10
|
provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
|
|
10
11
|
multicallProvider: MulticallProvider;
|
|
11
12
|
signer: ethers.Signer | null;
|
package/lib/llamalend.js
CHANGED
|
@@ -342,7 +342,8 @@ class Llamalend {
|
|
|
342
342
|
};
|
|
343
343
|
});
|
|
344
344
|
});
|
|
345
|
-
this.address = '00000';
|
|
345
|
+
this.address = '00000';
|
|
346
|
+
this.crvUsdAddress = COINS_ETHEREUM.crvusd;
|
|
346
347
|
// @ts-ignore
|
|
347
348
|
this.provider = null;
|
|
348
349
|
this.signer = null;
|
|
@@ -510,6 +511,7 @@ class Llamalend {
|
|
|
510
511
|
}
|
|
511
512
|
}
|
|
512
513
|
// crvUSD contracts
|
|
514
|
+
this.setContract(this.crvUsdAddress, ERC20ABI);
|
|
513
515
|
if (this.chainId === 1) {
|
|
514
516
|
this.setContract(this.constants.COINS.crvusd.toLowerCase(), ERC20ABI);
|
|
515
517
|
for (const llamma of Object.values(this.constants.LLAMMAS)) {
|
|
@@ -535,75 +537,77 @@ class Llamalend {
|
|
|
535
537
|
}
|
|
536
538
|
// TODO Put it in a separate method
|
|
537
539
|
// Fetch new llammas
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
const res = (yield this.multicallProvider.all(calls)).map((c) => c.toLowerCase());
|
|
548
|
-
const collaterals = res.filter((a, i) => i % 3 == 0);
|
|
549
|
-
const amms = res.filter((a, i) => i % 3 == 1);
|
|
550
|
-
const controllers = res.filter((a, i) => i % 3 == 2);
|
|
551
|
-
if (collaterals.length > 0) {
|
|
552
|
-
for (const collateral of collaterals)
|
|
553
|
-
this.setContract(collateral, ERC20ABI);
|
|
554
|
-
calls = [];
|
|
555
|
-
for (const collateral of collaterals) {
|
|
556
|
-
calls.push(this.contracts[collateral].multicallContract.symbol(), this.contracts[collateral].multicallContract.decimals());
|
|
557
|
-
}
|
|
558
|
-
const res = (yield this.multicallProvider.all(calls)).map((x) => {
|
|
559
|
-
if (typeof x === "string")
|
|
560
|
-
return x.toLowerCase();
|
|
561
|
-
return x;
|
|
562
|
-
});
|
|
563
|
-
calls = [];
|
|
564
|
-
for (const amm of amms) {
|
|
565
|
-
this.setContract(amm, llammaABI);
|
|
566
|
-
calls.push(this.contracts[amm].multicallContract.A());
|
|
540
|
+
if (this.chainId === 1) {
|
|
541
|
+
this.setContract(this.constants.FACTORY, FactoryABI);
|
|
542
|
+
const factoryContract = this.contracts[this.constants.FACTORY].contract;
|
|
543
|
+
const factoryMulticallContract = this.contracts[this.constants.FACTORY].multicallContract;
|
|
544
|
+
const N1 = Object.keys(this.constants.LLAMMAS).length;
|
|
545
|
+
const N2 = yield factoryContract.n_collaterals(this.constantOptions);
|
|
546
|
+
let calls = [];
|
|
547
|
+
for (let i = N1; i < N2; i++) {
|
|
548
|
+
calls.push(factoryMulticallContract.collaterals(i), factoryMulticallContract.amms(i), factoryMulticallContract.controllers(i));
|
|
567
549
|
}
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
550
|
+
const res = (yield this.multicallProvider.all(calls)).map((c) => c.toLowerCase());
|
|
551
|
+
const collaterals = res.filter((a, i) => i % 3 == 0);
|
|
552
|
+
const amms = res.filter((a, i) => i % 3 == 1);
|
|
553
|
+
const controllers = res.filter((a, i) => i % 3 == 2);
|
|
554
|
+
if (collaterals.length > 0) {
|
|
555
|
+
for (const collateral of collaterals)
|
|
556
|
+
this.setContract(collateral, ERC20ABI);
|
|
557
|
+
calls = [];
|
|
558
|
+
for (const collateral of collaterals) {
|
|
559
|
+
calls.push(this.contracts[collateral].multicallContract.symbol(), this.contracts[collateral].multicallContract.decimals());
|
|
576
560
|
}
|
|
577
|
-
|
|
561
|
+
const res = (yield this.multicallProvider.all(calls)).map((x) => {
|
|
562
|
+
if (typeof x === "string")
|
|
563
|
+
return x.toLowerCase();
|
|
564
|
+
return x;
|
|
565
|
+
});
|
|
566
|
+
calls = [];
|
|
567
|
+
for (const amm of amms) {
|
|
568
|
+
this.setContract(amm, llammaABI);
|
|
569
|
+
calls.push(this.contracts[amm].multicallContract.A());
|
|
570
|
+
}
|
|
571
|
+
const AParams = (yield this.multicallProvider.all(calls)).map((x) => {
|
|
572
|
+
return Number(x);
|
|
573
|
+
});
|
|
574
|
+
for (let i = 0; i < collaterals.length; i++) {
|
|
575
|
+
const is_eth = collaterals[i] === this.constants.WETH;
|
|
576
|
+
const [collateral_symbol, collateral_decimals] = res.splice(0, 2);
|
|
577
|
+
if (i >= collaterals.length - 3) {
|
|
578
|
+
this.setContract(controllers[i], controllerV2ABI);
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
this.setContract(controllers[i], controllerABI);
|
|
582
|
+
}
|
|
578
583
|
this.setContract(controllers[i], controllerABI);
|
|
584
|
+
const monetary_policy_address = (yield this.contracts[controllers[i]].contract.monetary_policy(this.constantOptions)).toLowerCase();
|
|
585
|
+
this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
|
|
586
|
+
const _llammaId = is_eth ? "eth" : collateral_symbol.toLowerCase();
|
|
587
|
+
let llammaId = _llammaId;
|
|
588
|
+
let j = 2;
|
|
589
|
+
while (llammaId in this.constants.LLAMMAS)
|
|
590
|
+
llammaId = _llammaId + j++;
|
|
591
|
+
this.constants.LLAMMAS[llammaId] = {
|
|
592
|
+
amm_address: amms[i],
|
|
593
|
+
controller_address: controllers[i],
|
|
594
|
+
monetary_policy_address,
|
|
595
|
+
collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i],
|
|
596
|
+
leverage_zap: "0x0000000000000000000000000000000000000000",
|
|
597
|
+
deleverage_zap: "0x0000000000000000000000000000000000000000",
|
|
598
|
+
collateral_symbol: is_eth ? "ETH" : collateral_symbol,
|
|
599
|
+
collateral_decimals,
|
|
600
|
+
min_bands: 4,
|
|
601
|
+
max_bands: 50,
|
|
602
|
+
default_bands: 10,
|
|
603
|
+
A: AParams[i],
|
|
604
|
+
monetary_policy_abi: MonetaryPolicy2ABI,
|
|
605
|
+
};
|
|
579
606
|
}
|
|
580
|
-
this.setContract(controllers[i], controllerABI);
|
|
581
|
-
const monetary_policy_address = (yield this.contracts[controllers[i]].contract.monetary_policy(this.constantOptions)).toLowerCase();
|
|
582
|
-
this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
|
|
583
|
-
const _llammaId = is_eth ? "eth" : collateral_symbol.toLowerCase();
|
|
584
|
-
let llammaId = _llammaId;
|
|
585
|
-
let j = 2;
|
|
586
|
-
while (llammaId in this.constants.LLAMMAS)
|
|
587
|
-
llammaId = _llammaId + j++;
|
|
588
|
-
this.constants.LLAMMAS[llammaId] = {
|
|
589
|
-
amm_address: amms[i],
|
|
590
|
-
controller_address: controllers[i],
|
|
591
|
-
monetary_policy_address,
|
|
592
|
-
collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i],
|
|
593
|
-
leverage_zap: "0x0000000000000000000000000000000000000000",
|
|
594
|
-
deleverage_zap: "0x0000000000000000000000000000000000000000",
|
|
595
|
-
collateral_symbol: is_eth ? "ETH" : collateral_symbol,
|
|
596
|
-
collateral_decimals,
|
|
597
|
-
min_bands: 4,
|
|
598
|
-
max_bands: 50,
|
|
599
|
-
default_bands: 10,
|
|
600
|
-
A: AParams[i],
|
|
601
|
-
monetary_policy_abi: MonetaryPolicy2ABI,
|
|
602
|
-
};
|
|
603
607
|
}
|
|
604
608
|
}
|
|
605
609
|
this.constants.DECIMALS = extractDecimals(this.constants.LLAMMAS);
|
|
606
|
-
this.constants.DECIMALS[this.
|
|
610
|
+
this.constants.DECIMALS[this.crvUsdAddress] = 18;
|
|
607
611
|
if (L2Networks.includes(this.chainId)) {
|
|
608
612
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
609
613
|
const lendingInstance = this;
|
|
@@ -72,7 +72,7 @@ export class MintMarketTemplate {
|
|
|
72
72
|
maxAge: 60 * 1000, // 1m
|
|
73
73
|
});
|
|
74
74
|
this.statsTotalStablecoin = memoize(() => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
const stablecoinContract = llamalend.contracts[llamalend.
|
|
75
|
+
const stablecoinContract = llamalend.contracts[llamalend.crvUsdAddress].multicallContract;
|
|
76
76
|
const ammContract = llamalend.contracts[this.address].multicallContract;
|
|
77
77
|
const [_balance, _fee] = yield llamalend.multicallProvider.all([
|
|
78
78
|
stablecoinContract.balanceOf(this.address),
|
|
@@ -97,7 +97,7 @@ export class MintMarketTemplate {
|
|
|
97
97
|
});
|
|
98
98
|
this.statsCapAndAvailable = memoize(() => __awaiter(this, void 0, void 0, function* () {
|
|
99
99
|
const factoryContract = llamalend.contracts[llamalend.constants.FACTORY].multicallContract;
|
|
100
|
-
const crvusdContract = llamalend.contracts[llamalend.
|
|
100
|
+
const crvusdContract = llamalend.contracts[llamalend.crvUsdAddress].multicallContract;
|
|
101
101
|
const [_cap, _available] = yield llamalend.multicallProvider.all([
|
|
102
102
|
factoryContract.debt_ceiling(this.controller),
|
|
103
103
|
crvusdContract.balanceOf(this.controller),
|
|
@@ -247,7 +247,7 @@ export class MintMarketTemplate {
|
|
|
247
247
|
this.collateralSymbol = llammaData.collateral_symbol;
|
|
248
248
|
this.collateralDecimals = llammaData.collateral_decimals;
|
|
249
249
|
this.coins = ["crvUSD", llammaData.collateral_symbol];
|
|
250
|
-
this.coinAddresses = [llamalend.
|
|
250
|
+
this.coinAddresses = [llamalend.crvUsdAddress, llammaData.collateral_address];
|
|
251
251
|
this.coinDecimals = [18, llammaData.collateral_decimals];
|
|
252
252
|
this.minBands = llammaData.min_bands;
|
|
253
253
|
this.maxBands = llammaData.max_bands;
|
|
@@ -326,7 +326,7 @@ export class MintMarketTemplate {
|
|
|
326
326
|
}
|
|
327
327
|
statsBalances() {
|
|
328
328
|
return __awaiter(this, void 0, void 0, function* () {
|
|
329
|
-
const crvusdContract = llamalend.contracts[llamalend.
|
|
329
|
+
const crvusdContract = llamalend.contracts[llamalend.crvUsdAddress].multicallContract;
|
|
330
330
|
const collateralContract = llamalend.contracts[isEth(this.collateral) ? llamalend.constants.WETH : this.collateral].multicallContract;
|
|
331
331
|
const contract = llamalend.contracts[this.address].multicallContract;
|
|
332
332
|
const calls = [
|
|
@@ -550,7 +550,7 @@ export class MintMarketTemplate {
|
|
|
550
550
|
// ---------------- WALLET BALANCES ----------------
|
|
551
551
|
walletBalances() {
|
|
552
552
|
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
553
|
-
const [collateral, stablecoin] = yield getBalances([this.collateral, llamalend.
|
|
553
|
+
const [collateral, stablecoin] = yield getBalances([this.collateral, llamalend.crvUsdAddress], address);
|
|
554
554
|
return { stablecoin, collateral };
|
|
555
555
|
});
|
|
556
556
|
}
|
|
@@ -1006,17 +1006,17 @@ export class MintMarketTemplate {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
repayIsApproved(debt) {
|
|
1008
1008
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1009
|
-
return yield hasAllowance([llamalend.
|
|
1009
|
+
return yield hasAllowance([llamalend.crvUsdAddress], [debt], llamalend.signerAddress, this.controller);
|
|
1010
1010
|
});
|
|
1011
1011
|
}
|
|
1012
1012
|
repayApproveEstimateGas(debt) {
|
|
1013
1013
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1014
|
-
return yield ensureAllowanceEstimateGas([llamalend.
|
|
1014
|
+
return yield ensureAllowanceEstimateGas([llamalend.crvUsdAddress], [debt], this.controller);
|
|
1015
1015
|
});
|
|
1016
1016
|
}
|
|
1017
1017
|
repayApprove(debt) {
|
|
1018
1018
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1019
|
-
return yield ensureAllowance([llamalend.
|
|
1019
|
+
return yield ensureAllowance([llamalend.crvUsdAddress], [debt], this.controller);
|
|
1020
1020
|
});
|
|
1021
1021
|
}
|
|
1022
1022
|
repayHealth(debt_1) {
|
|
@@ -1240,19 +1240,19 @@ export class MintMarketTemplate {
|
|
|
1240
1240
|
liquidateIsApproved() {
|
|
1241
1241
|
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
1242
1242
|
const tokensToLiquidate = yield this.tokensToLiquidate(address);
|
|
1243
|
-
return yield hasAllowance([llamalend.
|
|
1243
|
+
return yield hasAllowance([llamalend.crvUsdAddress], [tokensToLiquidate], llamalend.signerAddress, this.controller);
|
|
1244
1244
|
});
|
|
1245
1245
|
}
|
|
1246
1246
|
liquidateApproveEstimateGas() {
|
|
1247
1247
|
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
1248
1248
|
const tokensToLiquidate = yield this.tokensToLiquidate(address);
|
|
1249
|
-
return yield ensureAllowanceEstimateGas([llamalend.
|
|
1249
|
+
return yield ensureAllowanceEstimateGas([llamalend.crvUsdAddress], [tokensToLiquidate], this.controller);
|
|
1250
1250
|
});
|
|
1251
1251
|
}
|
|
1252
1252
|
liquidateApprove() {
|
|
1253
1253
|
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
1254
1254
|
const tokensToLiquidate = yield this.tokensToLiquidate(address);
|
|
1255
|
-
return yield ensureAllowance([llamalend.
|
|
1255
|
+
return yield ensureAllowance([llamalend.crvUsdAddress], [tokensToLiquidate], this.controller);
|
|
1256
1256
|
});
|
|
1257
1257
|
}
|
|
1258
1258
|
_liquidate(address, slippage, estimateGas) {
|
package/package.json
CHANGED
package/src/llamalend.ts
CHANGED
|
@@ -171,6 +171,7 @@ export const NETWORK_CONSTANTS: { [index: number]: any } = {
|
|
|
171
171
|
|
|
172
172
|
class Llamalend implements ILlamalend {
|
|
173
173
|
address: string;
|
|
174
|
+
crvUsdAddress: string;
|
|
174
175
|
provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
|
|
175
176
|
multicallProvider: MulticallProvider;
|
|
176
177
|
signer: ethers.Signer | null;
|
|
@@ -196,7 +197,8 @@ class Llamalend implements ILlamalend {
|
|
|
196
197
|
};
|
|
197
198
|
|
|
198
199
|
constructor() {
|
|
199
|
-
this.address = '00000'
|
|
200
|
+
this.address = '00000'
|
|
201
|
+
this.crvUsdAddress = COINS_ETHEREUM.crvusd;
|
|
200
202
|
// @ts-ignore
|
|
201
203
|
this.provider = null;
|
|
202
204
|
this.signer = null;
|
|
@@ -368,6 +370,7 @@ class Llamalend implements ILlamalend {
|
|
|
368
370
|
}
|
|
369
371
|
|
|
370
372
|
// crvUSD contracts
|
|
373
|
+
this.setContract(this.crvUsdAddress, ERC20ABI);
|
|
371
374
|
if(this.chainId === 1) {
|
|
372
375
|
this.setContract(this.constants.COINS.crvusd.toLowerCase(), ERC20ABI);
|
|
373
376
|
for (const llamma of Object.values(this.constants.LLAMMAS)) {
|
|
@@ -392,90 +395,92 @@ class Llamalend implements ILlamalend {
|
|
|
392
395
|
|
|
393
396
|
// TODO Put it in a separate method
|
|
394
397
|
// Fetch new llammas
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
factoryMulticallContract.collaterals(i),
|
|
405
|
-
factoryMulticallContract.amms(i),
|
|
406
|
-
factoryMulticallContract.controllers(i)
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
const res: string[] = (await this.multicallProvider.all(calls) as string[]).map((c) => c.toLowerCase());
|
|
410
|
-
const collaterals = res.filter((a, i) => i % 3 == 0) as string[];
|
|
411
|
-
const amms = res.filter((a, i) => i % 3 == 1) as string[];
|
|
412
|
-
const controllers = res.filter((a, i) => i % 3 == 2) as string[];
|
|
413
|
-
|
|
414
|
-
if (collaterals.length > 0) {
|
|
415
|
-
for (const collateral of collaterals) this.setContract(collateral, ERC20ABI);
|
|
416
|
-
|
|
417
|
-
calls = [];
|
|
418
|
-
for (const collateral of collaterals) {
|
|
398
|
+
if(this.chainId === 1) {
|
|
399
|
+
this.setContract(this.constants.FACTORY, FactoryABI);
|
|
400
|
+
const factoryContract = this.contracts[this.constants.FACTORY].contract;
|
|
401
|
+
const factoryMulticallContract = this.contracts[this.constants.FACTORY].multicallContract;
|
|
402
|
+
|
|
403
|
+
const N1 = Object.keys(this.constants.LLAMMAS).length;
|
|
404
|
+
const N2 = await factoryContract.n_collaterals(this.constantOptions);
|
|
405
|
+
let calls = [];
|
|
406
|
+
for (let i = N1; i < N2; i++) {
|
|
419
407
|
calls.push(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
408
|
+
factoryMulticallContract.collaterals(i),
|
|
409
|
+
factoryMulticallContract.amms(i),
|
|
410
|
+
factoryMulticallContract.controllers(i)
|
|
411
|
+
);
|
|
423
412
|
}
|
|
424
|
-
const res = (await this.multicallProvider.all(calls)).map((
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
413
|
+
const res: string[] = (await this.multicallProvider.all(calls) as string[]).map((c) => c.toLowerCase());
|
|
414
|
+
const collaterals = res.filter((a, i) => i % 3 == 0) as string[];
|
|
415
|
+
const amms = res.filter((a, i) => i % 3 == 1) as string[];
|
|
416
|
+
const controllers = res.filter((a, i) => i % 3 == 2) as string[];
|
|
417
|
+
|
|
418
|
+
if (collaterals.length > 0) {
|
|
419
|
+
for (const collateral of collaterals) this.setContract(collateral, ERC20ABI);
|
|
420
|
+
|
|
421
|
+
calls = [];
|
|
422
|
+
for (const collateral of collaterals) {
|
|
423
|
+
calls.push(
|
|
424
|
+
this.contracts[collateral].multicallContract.symbol(),
|
|
425
|
+
this.contracts[collateral].multicallContract.decimals()
|
|
426
|
+
)
|
|
427
|
+
}
|
|
428
|
+
const res = (await this.multicallProvider.all(calls)).map((x) => {
|
|
429
|
+
if (typeof x === "string") return x.toLowerCase();
|
|
430
|
+
return x;
|
|
431
|
+
});
|
|
428
432
|
|
|
429
|
-
|
|
433
|
+
calls = [];
|
|
430
434
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
435
|
+
for(const amm of amms) {
|
|
436
|
+
this.setContract(amm, llammaABI);
|
|
437
|
+
calls.push(
|
|
438
|
+
this.contracts[amm].multicallContract.A()
|
|
439
|
+
)
|
|
440
|
+
}
|
|
437
441
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
442
|
+
const AParams = (await this.multicallProvider.all(calls)).map((x) => {
|
|
443
|
+
return Number(x)
|
|
444
|
+
});
|
|
441
445
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
446
|
+
for (let i = 0; i < collaterals.length; i++) {
|
|
447
|
+
const is_eth = collaterals[i] === this.constants.WETH;
|
|
448
|
+
const [collateral_symbol, collateral_decimals] = res.splice(0, 2) as [string, number];
|
|
445
449
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
450
|
+
if (i >= collaterals.length - 3) {
|
|
451
|
+
this.setContract(controllers[i], controllerV2ABI);
|
|
452
|
+
} else {
|
|
453
|
+
this.setContract(controllers[i], controllerABI);
|
|
454
|
+
}
|
|
451
455
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
456
|
+
this.setContract(controllers[i], controllerABI);
|
|
457
|
+
const monetary_policy_address = (await this.contracts[controllers[i]].contract.monetary_policy(this.constantOptions)).toLowerCase();
|
|
458
|
+
this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
|
|
459
|
+
const _llammaId: string = is_eth ? "eth" : collateral_symbol.toLowerCase();
|
|
460
|
+
let llammaId = _llammaId
|
|
461
|
+
let j = 2;
|
|
462
|
+
while (llammaId in this.constants.LLAMMAS) llammaId = _llammaId + j++;
|
|
463
|
+
this.constants.LLAMMAS[llammaId] = {
|
|
464
|
+
amm_address: amms[i],
|
|
465
|
+
controller_address: controllers[i],
|
|
466
|
+
monetary_policy_address,
|
|
467
|
+
collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i],
|
|
468
|
+
leverage_zap: "0x0000000000000000000000000000000000000000",
|
|
469
|
+
deleverage_zap: "0x0000000000000000000000000000000000000000",
|
|
470
|
+
collateral_symbol: is_eth ? "ETH" : collateral_symbol,
|
|
471
|
+
collateral_decimals,
|
|
472
|
+
min_bands: 4,
|
|
473
|
+
max_bands: 50,
|
|
474
|
+
default_bands: 10,
|
|
475
|
+
A: AParams[i],
|
|
476
|
+
monetary_policy_abi: MonetaryPolicy2ABI,
|
|
477
|
+
}
|
|
473
478
|
}
|
|
474
479
|
}
|
|
475
480
|
}
|
|
476
481
|
|
|
477
482
|
this.constants.DECIMALS = extractDecimals(this.constants.LLAMMAS);
|
|
478
|
-
this.constants.DECIMALS[this.
|
|
483
|
+
this.constants.DECIMALS[this.crvUsdAddress] = 18;
|
|
479
484
|
|
|
480
485
|
if(L2Networks.includes(this.chainId)) {
|
|
481
486
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
@@ -131,7 +131,7 @@ export class MintMarketTemplate {
|
|
|
131
131
|
this.collateralSymbol = llammaData.collateral_symbol;
|
|
132
132
|
this.collateralDecimals = llammaData.collateral_decimals;
|
|
133
133
|
this.coins = ["crvUSD", llammaData.collateral_symbol];
|
|
134
|
-
this.coinAddresses = [llamalend.
|
|
134
|
+
this.coinAddresses = [llamalend.crvUsdAddress, llammaData.collateral_address];
|
|
135
135
|
this.coinDecimals = [18, llammaData.collateral_decimals];
|
|
136
136
|
this.minBands = llammaData.min_bands;
|
|
137
137
|
this.maxBands = llammaData.max_bands;
|
|
@@ -248,7 +248,7 @@ export class MintMarketTemplate {
|
|
|
248
248
|
});
|
|
249
249
|
|
|
250
250
|
private async statsBalances(): Promise<[string, string]> {
|
|
251
|
-
const crvusdContract = llamalend.contracts[llamalend.
|
|
251
|
+
const crvusdContract = llamalend.contracts[llamalend.crvUsdAddress].multicallContract;
|
|
252
252
|
const collateralContract = llamalend.contracts[isEth(this.collateral) ? llamalend.constants.WETH : this.collateral].multicallContract;
|
|
253
253
|
const contract = llamalend.contracts[this.address].multicallContract;
|
|
254
254
|
const calls = [
|
|
@@ -357,7 +357,7 @@ export class MintMarketTemplate {
|
|
|
357
357
|
});
|
|
358
358
|
|
|
359
359
|
private statsTotalStablecoin = memoize(async (): Promise<string> => {
|
|
360
|
-
const stablecoinContract = llamalend.contracts[llamalend.
|
|
360
|
+
const stablecoinContract = llamalend.contracts[llamalend.crvUsdAddress].multicallContract;
|
|
361
361
|
const ammContract = llamalend.contracts[this.address].multicallContract;
|
|
362
362
|
|
|
363
363
|
const [_balance, _fee]: bigint[] = await llamalend.multicallProvider.all([
|
|
@@ -390,7 +390,7 @@ export class MintMarketTemplate {
|
|
|
390
390
|
|
|
391
391
|
private statsCapAndAvailable = memoize(async (): Promise<{ "cap": string, "available": string }> => {
|
|
392
392
|
const factoryContract = llamalend.contracts[llamalend.constants.FACTORY].multicallContract;
|
|
393
|
-
const crvusdContract = llamalend.contracts[llamalend.
|
|
393
|
+
const crvusdContract = llamalend.contracts[llamalend.crvUsdAddress].multicallContract;
|
|
394
394
|
|
|
395
395
|
const [_cap, _available]: bigint[] = await llamalend.multicallProvider.all([
|
|
396
396
|
factoryContract.debt_ceiling(this.controller),
|
|
@@ -577,7 +577,7 @@ export class MintMarketTemplate {
|
|
|
577
577
|
// ---------------- WALLET BALANCES ----------------
|
|
578
578
|
|
|
579
579
|
private async walletBalances(address = ""): Promise<{ collateral: string, stablecoin: string }> {
|
|
580
|
-
const [collateral, stablecoin] = await getBalances([this.collateral, llamalend.
|
|
580
|
+
const [collateral, stablecoin] = await getBalances([this.collateral, llamalend.crvUsdAddress], address);
|
|
581
581
|
return { stablecoin, collateral }
|
|
582
582
|
}
|
|
583
583
|
|
|
@@ -1028,15 +1028,15 @@ export class MintMarketTemplate {
|
|
|
1028
1028
|
}
|
|
1029
1029
|
|
|
1030
1030
|
public async repayIsApproved(debt: number | string): Promise<boolean> {
|
|
1031
|
-
return await hasAllowance([llamalend.
|
|
1031
|
+
return await hasAllowance([llamalend.crvUsdAddress], [debt], llamalend.signerAddress, this.controller);
|
|
1032
1032
|
}
|
|
1033
1033
|
|
|
1034
1034
|
private async repayApproveEstimateGas (debt: number | string): Promise<TGas> {
|
|
1035
|
-
return await ensureAllowanceEstimateGas([llamalend.
|
|
1035
|
+
return await ensureAllowanceEstimateGas([llamalend.crvUsdAddress], [debt], this.controller);
|
|
1036
1036
|
}
|
|
1037
1037
|
|
|
1038
1038
|
public async repayApprove(debt: number | string): Promise<string[]> {
|
|
1039
|
-
return await ensureAllowance([llamalend.
|
|
1039
|
+
return await ensureAllowance([llamalend.crvUsdAddress], [debt], this.controller);
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
1042
1042
|
public async repayHealth(debt: number | string, full = true, address = ""): Promise<string> {
|
|
@@ -1241,17 +1241,17 @@ export class MintMarketTemplate {
|
|
|
1241
1241
|
|
|
1242
1242
|
public async liquidateIsApproved(address = ""): Promise<boolean> {
|
|
1243
1243
|
const tokensToLiquidate = await this.tokensToLiquidate(address);
|
|
1244
|
-
return await hasAllowance([llamalend.
|
|
1244
|
+
return await hasAllowance([llamalend.crvUsdAddress], [tokensToLiquidate], llamalend.signerAddress, this.controller);
|
|
1245
1245
|
}
|
|
1246
1246
|
|
|
1247
1247
|
private async liquidateApproveEstimateGas (address = ""): Promise<TGas> {
|
|
1248
1248
|
const tokensToLiquidate = await this.tokensToLiquidate(address);
|
|
1249
|
-
return await ensureAllowanceEstimateGas([llamalend.
|
|
1249
|
+
return await ensureAllowanceEstimateGas([llamalend.crvUsdAddress], [tokensToLiquidate], this.controller);
|
|
1250
1250
|
}
|
|
1251
1251
|
|
|
1252
1252
|
public async liquidateApprove(address = ""): Promise<string[]> {
|
|
1253
1253
|
const tokensToLiquidate = await this.tokensToLiquidate(address);
|
|
1254
|
-
return await ensureAllowance([llamalend.
|
|
1254
|
+
return await ensureAllowance([llamalend.crvUsdAddress], [tokensToLiquidate], this.controller);
|
|
1255
1255
|
}
|
|
1256
1256
|
|
|
1257
1257
|
private async _liquidate(address: string, slippage: number, estimateGas: boolean): Promise<string | TGas> {
|