Skip to content

Commit 1ff0994

Browse files
authoredOct 21, 2024
Merge pull request #39 from curvefi/market-template
feat: allow late initialization of OneWayMarketTemplate
2 parents 8c42768 + 40721a8 commit 1ff0994

File tree

5 files changed

+10
-38
lines changed

5 files changed

+10
-38
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curvefi/lending-api",
3-
"version": "2.3.3",
3+
"version": "2.3.4",
44
"description": "JavaScript library for Curve Lending",
55
"main": "lib/index.js",
66
"author": "Macket",

‎src/constants/utils.ts

+3-32
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
import {IDict, ILlamma} from "../interfaces";
1+
import {IDict} from "../interfaces";
22

3-
export const lowerCaseLlammasAddresses = (llammas: IDict<ILlamma>): IDict<ILlamma> => {
4-
for (const llammaId in llammas) {
5-
if (!Object.prototype.hasOwnProperty.call(llammas, llammaId)) continue;
6-
const llamma = llammas[llammaId];
7-
llamma.amm_address = llamma.amm_address.toLowerCase();
8-
llamma.controller_address = llamma.controller_address.toLowerCase();
9-
llamma.collateral_address = llamma.collateral_address.toLowerCase();
10-
llamma.monetary_policy_address = llamma.monetary_policy_address.toLowerCase();
11-
llamma.leverage_zap = llamma.leverage_zap.toLowerCase();
12-
}
13-
14-
return llammas
15-
}
16-
17-
export const extractDecimals = (llammas: IDict<ILlamma>): IDict<number> => {
18-
const DECIMALS: IDict<number> = {};
19-
for (const llammaId in llammas) {
20-
if (!Object.prototype.hasOwnProperty.call(llammas, llammaId)) continue;
21-
const llamma = llammas[llammaId];
22-
23-
// Collateral
24-
DECIMALS[llamma.collateral_address] = llamma.collateral_decimals;
25-
}
26-
27-
return DECIMALS
28-
}
29-
30-
export const lowerCaseValues = (dict: IDict<string>): IDict<string> => {
31-
// @ts-ignore
32-
return Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()]))
33-
}
3+
export const lowerCaseValues = (dict: IDict<string>): IDict<string> =>
4+
Object.fromEntries(Object.entries(dict).map((entry) => [entry[0], entry[1].toLowerCase()]))

‎src/lending.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class Lending implements ILending {
525525
}
526526

527527
amms.forEach((amm: string, index: number) => {
528-
this.setContract(amms[index], LlammaABI);
528+
this.setContract(amm, LlammaABI);
529529
this.setContract(controllers[index], ControllerABI);
530530
this.setContract(monetary_policies[index], MonetaryPolicyABI);
531531
this.setContract(vaults[index], VaultABI);

‎src/markets/MarketConstructor.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { OneWayMarketTemplate} from "./OneWayMarketTemplate.js";
2+
import {lending} from "../lending";
23

34
export const getOneWayMarket = (oneWayMarketId: string): OneWayMarketTemplate => {
4-
return new OneWayMarketTemplate(oneWayMarketId)
5+
const marketData = lending.constants.ONE_WAY_MARKETS[oneWayMarketId];
6+
return new OneWayMarketTemplate(oneWayMarketId, marketData)
57
}

‎src/markets/OneWayMarketTemplate.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
DIGas,
2323
smartNumber,
2424
} from "../utils.js";
25-
import {IDict, TGas, TAmount, IReward, I1inchRoute, I1inchSwapData} from "../interfaces.js";
25+
import {IDict, TGas, TAmount, IReward, I1inchRoute, I1inchSwapData, IOneWayMarket} from "../interfaces.js";
2626
import {
2727
_getExpected1inch,
2828
_getSwapData1inch,
@@ -239,9 +239,8 @@ export class OneWayMarketTemplate {
239239
}
240240
};
241241

242-
constructor(id: string) {
242+
constructor(id: string, marketData: IOneWayMarket) {
243243
this.id = id;
244-
const marketData = lending.constants.ONE_WAY_MARKETS[id];
245244
this.name = marketData.name;
246245
this.addresses = marketData.addresses;
247246
this.borrowed_token = marketData.borrowed_token;

0 commit comments

Comments
 (0)