Skip to content

Commit

Permalink
Merge pull request #39 from curvefi/market-template
Browse files Browse the repository at this point in the history
feat: allow late initialization of OneWayMarketTemplate
  • Loading branch information
Macket authored Oct 21, 2024
2 parents 8c42768 + 40721a8 commit 1ff0994
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
35 changes: 3 additions & 32 deletions src/constants/utils.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,4 @@
import {IDict, ILlamma} from "../interfaces";
import {IDict} from "../interfaces";

export const lowerCaseLlammasAddresses = (llammas: IDict<ILlamma>): IDict<ILlamma> => {
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<ILlamma>): IDict<number> => {
const DECIMALS: IDict<number> = {};
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<string>): IDict<string> => {
// @ts-ignore
return Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()]))
}
export const lowerCaseValues = (dict: IDict<string>): IDict<string> =>
Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()]))
2 changes: 1 addition & 1 deletion src/lending.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/markets/MarketConstructor.ts
Original file line number Diff line number Diff line change
@@ -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)
}
5 changes: 2 additions & 3 deletions src/markets/OneWayMarketTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1ff0994

Please sign in to comment.