@curvefi/llamalend-api 1.0.8 → 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.js CHANGED
@@ -537,71 +537,73 @@ class Llamalend {
537
537
  }
538
538
  // TODO Put it in a separate method
539
539
  // Fetch new llammas
540
- this.setContract(this.constants.FACTORY, FactoryABI);
541
- const factoryContract = this.contracts[this.constants.FACTORY].contract;
542
- const factoryMulticallContract = this.contracts[this.constants.FACTORY].multicallContract;
543
- const N1 = Object.keys(this.constants.LLAMMAS).length;
544
- const N2 = yield factoryContract.n_collaterals(this.constantOptions);
545
- let calls = [];
546
- for (let i = N1; i < N2; i++) {
547
- calls.push(factoryMulticallContract.collaterals(i), factoryMulticallContract.amms(i), factoryMulticallContract.controllers(i));
548
- }
549
- const res = (yield this.multicallProvider.all(calls)).map((c) => c.toLowerCase());
550
- const collaterals = res.filter((a, i) => i % 3 == 0);
551
- const amms = res.filter((a, i) => i % 3 == 1);
552
- const controllers = res.filter((a, i) => i % 3 == 2);
553
- if (collaterals.length > 0) {
554
- for (const collateral of collaterals)
555
- this.setContract(collateral, ERC20ABI);
556
- calls = [];
557
- for (const collateral of collaterals) {
558
- calls.push(this.contracts[collateral].multicallContract.symbol(), this.contracts[collateral].multicallContract.decimals());
559
- }
560
- const res = (yield this.multicallProvider.all(calls)).map((x) => {
561
- if (typeof x === "string")
562
- return x.toLowerCase();
563
- return x;
564
- });
565
- calls = [];
566
- for (const amm of amms) {
567
- this.setContract(amm, llammaABI);
568
- 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));
569
549
  }
570
- const AParams = (yield this.multicallProvider.all(calls)).map((x) => {
571
- return Number(x);
572
- });
573
- for (let i = 0; i < collaterals.length; i++) {
574
- const is_eth = collaterals[i] === this.constants.WETH;
575
- const [collateral_symbol, collateral_decimals] = res.splice(0, 2);
576
- if (i >= collaterals.length - 3) {
577
- this.setContract(controllers[i], controllerV2ABI);
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());
578
560
  }
579
- else {
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
+ }
580
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
+ };
581
606
  }
582
- this.setContract(controllers[i], controllerABI);
583
- const monetary_policy_address = (yield this.contracts[controllers[i]].contract.monetary_policy(this.constantOptions)).toLowerCase();
584
- this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
585
- const _llammaId = is_eth ? "eth" : collateral_symbol.toLowerCase();
586
- let llammaId = _llammaId;
587
- let j = 2;
588
- while (llammaId in this.constants.LLAMMAS)
589
- llammaId = _llammaId + j++;
590
- this.constants.LLAMMAS[llammaId] = {
591
- amm_address: amms[i],
592
- controller_address: controllers[i],
593
- monetary_policy_address,
594
- collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i],
595
- leverage_zap: "0x0000000000000000000000000000000000000000",
596
- deleverage_zap: "0x0000000000000000000000000000000000000000",
597
- collateral_symbol: is_eth ? "ETH" : collateral_symbol,
598
- collateral_decimals,
599
- min_bands: 4,
600
- max_bands: 50,
601
- default_bands: 10,
602
- A: AParams[i],
603
- monetary_policy_abi: MonetaryPolicy2ABI,
604
- };
605
607
  }
606
608
  }
607
609
  this.constants.DECIMALS = extractDecimals(this.constants.LLAMMAS);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
package/src/llamalend.ts CHANGED
@@ -395,84 +395,86 @@ class Llamalend implements ILlamalend {
395
395
 
396
396
  // TODO Put it in a separate method
397
397
  // Fetch new llammas
398
- this.setContract(this.constants.FACTORY, FactoryABI);
399
- const factoryContract = this.contracts[this.constants.FACTORY].contract;
400
- const factoryMulticallContract = this.contracts[this.constants.FACTORY].multicallContract;
401
-
402
- const N1 = Object.keys(this.constants.LLAMMAS).length;
403
- const N2 = await factoryContract.n_collaterals(this.constantOptions);
404
- let calls = [];
405
- for (let i = N1; i < N2; i++) {
406
- calls.push(
407
- factoryMulticallContract.collaterals(i),
408
- factoryMulticallContract.amms(i),
409
- factoryMulticallContract.controllers(i)
410
- );
411
- }
412
- const res: string[] = (await this.multicallProvider.all(calls) as string[]).map((c) => c.toLowerCase());
413
- const collaterals = res.filter((a, i) => i % 3 == 0) as string[];
414
- const amms = res.filter((a, i) => i % 3 == 1) as string[];
415
- const controllers = res.filter((a, i) => i % 3 == 2) as string[];
416
-
417
- if (collaterals.length > 0) {
418
- for (const collateral of collaterals) this.setContract(collateral, ERC20ABI);
419
-
420
- calls = [];
421
- 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++) {
422
407
  calls.push(
423
- this.contracts[collateral].multicallContract.symbol(),
424
- this.contracts[collateral].multicallContract.decimals()
425
- )
408
+ factoryMulticallContract.collaterals(i),
409
+ factoryMulticallContract.amms(i),
410
+ factoryMulticallContract.controllers(i)
411
+ );
426
412
  }
427
- const res = (await this.multicallProvider.all(calls)).map((x) => {
428
- if (typeof x === "string") return x.toLowerCase();
429
- return x;
430
- });
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
+ });
431
432
 
432
- calls = [];
433
+ calls = [];
433
434
 
434
- for(const amm of amms) {
435
- this.setContract(amm, llammaABI);
436
- calls.push(
437
- this.contracts[amm].multicallContract.A()
438
- )
439
- }
435
+ for(const amm of amms) {
436
+ this.setContract(amm, llammaABI);
437
+ calls.push(
438
+ this.contracts[amm].multicallContract.A()
439
+ )
440
+ }
440
441
 
441
- const AParams = (await this.multicallProvider.all(calls)).map((x) => {
442
- return Number(x)
443
- });
442
+ const AParams = (await this.multicallProvider.all(calls)).map((x) => {
443
+ return Number(x)
444
+ });
444
445
 
445
- for (let i = 0; i < collaterals.length; i++) {
446
- const is_eth = collaterals[i] === this.constants.WETH;
447
- const [collateral_symbol, collateral_decimals] = res.splice(0, 2) as [string, number];
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];
448
449
 
449
- if (i >= collaterals.length - 3) {
450
- this.setContract(controllers[i], controllerV2ABI);
451
- } else {
452
- this.setContract(controllers[i], controllerABI);
453
- }
450
+ if (i >= collaterals.length - 3) {
451
+ this.setContract(controllers[i], controllerV2ABI);
452
+ } else {
453
+ this.setContract(controllers[i], controllerABI);
454
+ }
454
455
 
455
- this.setContract(controllers[i], controllerABI);
456
- const monetary_policy_address = (await this.contracts[controllers[i]].contract.monetary_policy(this.constantOptions)).toLowerCase();
457
- this.setContract(monetary_policy_address, MonetaryPolicy2ABI);
458
- const _llammaId: string = is_eth ? "eth" : collateral_symbol.toLowerCase();
459
- let llammaId = _llammaId
460
- let j = 2;
461
- while (llammaId in this.constants.LLAMMAS) llammaId = _llammaId + j++;
462
- this.constants.LLAMMAS[llammaId] = {
463
- amm_address: amms[i],
464
- controller_address: controllers[i],
465
- monetary_policy_address,
466
- collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i],
467
- leverage_zap: "0x0000000000000000000000000000000000000000",
468
- deleverage_zap: "0x0000000000000000000000000000000000000000",
469
- collateral_symbol: is_eth ? "ETH" : collateral_symbol,
470
- collateral_decimals,
471
- min_bands: 4,
472
- max_bands: 50,
473
- default_bands: 10,
474
- A: AParams[i],
475
- monetary_policy_abi: MonetaryPolicy2ABI,
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
+ }
476
478
  }
477
479
  }
478
480
  }