From f35a0909b375332249def497a42dfc850b1ae7e4 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Fri, 11 Oct 2024 17:08:40 +0200 Subject: [PATCH 1/2] feat: allow late initialization of OneWayMarketTemplate --- src/constants/utils.ts | 35 +++-------------------------- src/lending.ts | 2 +- src/markets/MarketConstructor.ts | 4 +++- src/markets/OneWayMarketTemplate.ts | 5 ++--- 4 files changed, 9 insertions(+), 37 deletions(-) diff --git a/src/constants/utils.ts b/src/constants/utils.ts index 9f28924..a919375 100644 --- a/src/constants/utils.ts +++ b/src/constants/utils.ts @@ -1,33 +1,4 @@ -import {IDict, ILlamma} from "../interfaces"; +import {IDict} from "../interfaces"; -export const lowerCaseLlammasAddresses = (llammas: IDict): IDict => { - for (const llammaId in llammas) { - if (!Object.prototype.hasOwnProperty.call(llammas, llammaId)) continue; - const llamma = llammas[llammaId]; - llamma.amm_address = llamma.amm_address.toLowerCase(); - llamma.controller_address = llamma.controller_address.toLowerCase(); - llamma.collateral_address = llamma.collateral_address.toLowerCase(); - llamma.monetary_policy_address = llamma.monetary_policy_address.toLowerCase(); - llamma.leverage_zap = llamma.leverage_zap.toLowerCase(); - } - - return llammas -} - -export const extractDecimals = (llammas: IDict): IDict => { - const DECIMALS: IDict = {}; - for (const llammaId in llammas) { - if (!Object.prototype.hasOwnProperty.call(llammas, llammaId)) continue; - const llamma = llammas[llammaId]; - - // Collateral - DECIMALS[llamma.collateral_address] = llamma.collateral_decimals; - } - - return DECIMALS -} - -export const lowerCaseValues = (dict: IDict): IDict => { - // @ts-ignore - return Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()])) -} +export const lowerCaseValues = (dict: IDict): IDict => + Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()])) diff --git a/src/lending.ts b/src/lending.ts index c6c57be..e0306d9 100644 --- a/src/lending.ts +++ b/src/lending.ts @@ -525,7 +525,7 @@ class Lending implements ILending { } amms.forEach((amm: string, index: number) => { - this.setContract(amms[index], LlammaABI); + this.setContract(amm, LlammaABI); this.setContract(controllers[index], ControllerABI); this.setContract(monetary_policies[index], MonetaryPolicyABI); this.setContract(vaults[index], VaultABI); diff --git a/src/markets/MarketConstructor.ts b/src/markets/MarketConstructor.ts index 2940619..0171755 100644 --- a/src/markets/MarketConstructor.ts +++ b/src/markets/MarketConstructor.ts @@ -1,5 +1,7 @@ import { OneWayMarketTemplate} from "./OneWayMarketTemplate.js"; +import {lending} from "../lending"; export const getOneWayMarket = (oneWayMarketId: string): OneWayMarketTemplate => { - return new OneWayMarketTemplate(oneWayMarketId) + const marketData = lending.constants.ONE_WAY_MARKETS[oneWayMarketId]; + return new OneWayMarketTemplate(oneWayMarketId, marketData) } diff --git a/src/markets/OneWayMarketTemplate.ts b/src/markets/OneWayMarketTemplate.ts index 4f3edbb..1e6fbc2 100644 --- a/src/markets/OneWayMarketTemplate.ts +++ b/src/markets/OneWayMarketTemplate.ts @@ -22,7 +22,7 @@ import { DIGas, smartNumber, } from "../utils.js"; -import {IDict, TGas, TAmount, IReward, I1inchRoute, I1inchSwapData} from "../interfaces.js"; +import {IDict, TGas, TAmount, IReward, I1inchRoute, I1inchSwapData, IOneWayMarket} from "../interfaces.js"; import { _getExpected1inch, _getSwapData1inch, @@ -239,9 +239,8 @@ export class OneWayMarketTemplate { } }; - constructor(id: string) { + constructor(id: string, marketData: IOneWayMarket) { this.id = id; - const marketData = lending.constants.ONE_WAY_MARKETS[id]; this.name = marketData.name; this.addresses = marketData.addresses; this.borrowed_token = marketData.borrowed_token; From 40721a8dc6ed417d83fb2e023848e13353421894 Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Mon, 21 Oct 2024 15:59:13 +0200 Subject: [PATCH 2/2] build: v2.3.4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3dabbaf..399a6b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curvefi/lending-api", - "version": "2.3.3", + "version": "2.3.4", "description": "JavaScript library for Curve Lending", "main": "lib/index.js", "author": "Macket",