@curvefi/llamalend-api 1.0.30 → 1.0.31
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/lendMarkets/lendMarketConstructor.js +7 -2
- package/lib/llamalend.d.ts +8 -0
- package/lib/llamalend.js +2 -0
- package/lib/mintMarkets/MintMarketTemplate.d.ts +2 -2
- package/lib/mintMarkets/MintMarketTemplate.js +1 -2
- package/lib/mintMarkets/mintMarketConstructor.js +7 -1
- package/lib/mintMarkets/modules/leverageV2.js +4 -4
- package/package.json +1 -1
- package/src/lendMarkets/lendMarketConstructor.ts +6 -2
- package/src/llamalend.ts +6 -0
- package/src/mintMarkets/MintMarketTemplate.ts +2 -4
- package/src/mintMarkets/mintMarketConstructor.ts +6 -1
- package/src/mintMarkets/modules/leverageV2.ts +4 -5
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { LendMarketTemplate } from "./LendMarketTemplate.js";
|
|
2
2
|
export const getLendMarket = function (lendMarketId) {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
if (!(lendMarketId in this.lendMarkets)) {
|
|
4
|
+
const marketData = this.constants.ONE_WAY_MARKETS[lendMarketId];
|
|
5
|
+
if (!marketData)
|
|
6
|
+
throw new Error(`Lend market with id ${lendMarketId} not found`);
|
|
7
|
+
this.lendMarkets[lendMarketId] = new LendMarketTemplate(lendMarketId, marketData, this);
|
|
8
|
+
}
|
|
9
|
+
return this.lendMarkets[lendMarketId];
|
|
5
10
|
};
|
package/lib/llamalend.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ethers, Networkish, BigNumberish, Numeric } from "ethers";
|
|
2
2
|
import { Provider as MulticallProvider } from '@curvefi/ethcall';
|
|
3
3
|
import { IChainId, ILlamalend, ILlamma, IDict, INetworkName, ICurveContract, IOneWayMarket, ICoin } from "./interfaces.js";
|
|
4
|
+
import { MintMarketTemplate } from "./mintMarkets";
|
|
5
|
+
import { LendMarketTemplate } from "./lendMarkets";
|
|
4
6
|
export declare const NETWORK_CONSTANTS: {
|
|
5
7
|
[index: number]: any;
|
|
6
8
|
};
|
|
@@ -15,6 +17,12 @@ declare class Llamalend implements ILlamalend {
|
|
|
15
17
|
contracts: {
|
|
16
18
|
[index: string]: ICurveContract;
|
|
17
19
|
};
|
|
20
|
+
mintMarkets: {
|
|
21
|
+
[addres: string]: MintMarketTemplate;
|
|
22
|
+
};
|
|
23
|
+
lendMarkets: {
|
|
24
|
+
[addres: string]: LendMarketTemplate;
|
|
25
|
+
};
|
|
18
26
|
feeData: {
|
|
19
27
|
gasPrice?: number;
|
|
20
28
|
maxFeePerGas?: number;
|
package/lib/llamalend.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import memoize from "memoizee";
|
|
2
2
|
import type { Llamalend } from "../llamalend.js";
|
|
3
|
-
import { IDict, TGas } from "../interfaces";
|
|
3
|
+
import { IDict, ILlamma, TGas } from "../interfaces";
|
|
4
4
|
import { ILeverageV2 } from "./interfaces/leverage.js";
|
|
5
5
|
export declare class MintMarketTemplate {
|
|
6
6
|
private llamalend;
|
|
@@ -132,7 +132,7 @@ export declare class MintMarketTemplate {
|
|
|
132
132
|
repay: (collateral: number | string, slippage?: number) => Promise<number>;
|
|
133
133
|
};
|
|
134
134
|
};
|
|
135
|
-
constructor(id: string, llamalend: Llamalend);
|
|
135
|
+
constructor(id: string, llammaData: ILlamma, llamalend: Llamalend);
|
|
136
136
|
statsParameters: (() => Promise<{
|
|
137
137
|
fee: string;
|
|
138
138
|
admin_fee: string;
|
|
@@ -13,7 +13,7 @@ import { _getAddress, parseUnits, BN, toBN, fromBN, getBalances, ensureAllowance
|
|
|
13
13
|
import { _getUserCollateralCrvUsd } from "../external-api.js";
|
|
14
14
|
import { LeverageV2Module } from "./modules";
|
|
15
15
|
export class MintMarketTemplate {
|
|
16
|
-
constructor(id, llamalend) {
|
|
16
|
+
constructor(id, llammaData, llamalend) {
|
|
17
17
|
var _a;
|
|
18
18
|
// ---------------- STATS ----------------
|
|
19
19
|
this.statsParameters = memoize(() => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -237,7 +237,6 @@ export class MintMarketTemplate {
|
|
|
237
237
|
maxAge: 5 * 60 * 1000, // 5m
|
|
238
238
|
});
|
|
239
239
|
this.llamalend = llamalend;
|
|
240
|
-
const llammaData = this.llamalend.constants.LLAMMAS[id];
|
|
241
240
|
this.id = id;
|
|
242
241
|
this.address = llammaData.amm_address;
|
|
243
242
|
this.controller = llammaData.controller_address;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { MintMarketTemplate } from "./MintMarketTemplate";
|
|
2
2
|
export const getMintMarket = function (mintMarketId) {
|
|
3
|
-
|
|
3
|
+
if (!(mintMarketId in this.mintMarkets)) {
|
|
4
|
+
const llammaData = this.constants.LLAMMAS[mintMarketId];
|
|
5
|
+
if (!llammaData)
|
|
6
|
+
throw new Error(`No market with id ${mintMarketId} found`);
|
|
7
|
+
this.mintMarkets[mintMarketId] = new MintMarketTemplate(mintMarketId, llammaData, this);
|
|
8
|
+
}
|
|
9
|
+
return this.mintMarkets[mintMarketId];
|
|
4
10
|
};
|
|
@@ -93,7 +93,7 @@ export class LeverageV2Module {
|
|
|
93
93
|
const key = `${inputCoinAddress}-${_amount}`;
|
|
94
94
|
if (!(key in this.swapDataCache))
|
|
95
95
|
throw Error("You must call corresponding `expected` method first " +
|
|
96
|
-
"(
|
|
96
|
+
"(leverageV2.createLoanExpectedCollateral, leverageV2.borrowMoreExpectedCollateral or leverageV2.repayExpectedBorrowed)");
|
|
97
97
|
return this.swapDataCache[key];
|
|
98
98
|
};
|
|
99
99
|
this._leverageExpectedCollateral = (userCollateral, userBorrowed, debt, user) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -471,7 +471,7 @@ export class LeverageV2Module {
|
|
|
471
471
|
const _debt = parseUnits(debt, this.market.coinDecimals[0]);
|
|
472
472
|
const swapData = this._getSwapDataFromCache(this.market.coinAddresses[0], _debt + _userBorrowed);
|
|
473
473
|
if (slippage !== swapData.slippage)
|
|
474
|
-
throw Error(`You must call
|
|
474
|
+
throw Error(`You must call leverageV2.createLoanExpectedCollateral() with slippage=${slippage} first`);
|
|
475
475
|
const calldata = yield _assembleTxOdos.call(this.llamalend, swapData.pathId);
|
|
476
476
|
const contract = this.llamalend.contracts[this.market.controller].contract;
|
|
477
477
|
const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap, [1, parseUnits(this._getMarketId(), 0), _userBorrowed], calldata, Object.assign({}, this.llamalend.constantOptions));
|
|
@@ -616,7 +616,7 @@ export class LeverageV2Module {
|
|
|
616
616
|
const _debt = parseUnits(debt, this.market.coinDecimals[0]);
|
|
617
617
|
const swapData = this._getSwapDataFromCache(this.market.coinAddresses[0], _debt + _userBorrowed);
|
|
618
618
|
if (slippage !== swapData.slippage)
|
|
619
|
-
throw Error(`You must call
|
|
619
|
+
throw Error(`You must call leverageV2.borrowMoreExpectedCollateral() with slippage=${slippage} first`);
|
|
620
620
|
const calldata = yield _assembleTxOdos.call(this.llamalend, swapData.pathId);
|
|
621
621
|
const contract = this.llamalend.contracts[this.market.controller].contract;
|
|
622
622
|
const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap, [1, parseUnits(this._getMarketId(), 0), _userBorrowed], calldata, Object.assign({}, this.llamalend.constantOptions));
|
|
@@ -757,7 +757,7 @@ export class LeverageV2Module {
|
|
|
757
757
|
if (_stateCollateral + _userCollateral > BigInt(0)) {
|
|
758
758
|
const swapData = this._getSwapDataFromCache(this.market.coinAddresses[1], _stateCollateral + _userCollateral);
|
|
759
759
|
if (slippage !== swapData.slippage)
|
|
760
|
-
throw Error(`You must call
|
|
760
|
+
throw Error(`You must call leverageV2.repayExpectedBorrowed() with slippage=${slippage} first`);
|
|
761
761
|
calldata = yield _assembleTxOdos.call(this.llamalend, swapData.pathId);
|
|
762
762
|
}
|
|
763
763
|
console.log('params', [1, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed], calldata);
|
package/package.json
CHANGED
|
@@ -2,6 +2,10 @@ import { LendMarketTemplate} from "./LendMarketTemplate.js";
|
|
|
2
2
|
import type { Llamalend } from "../llamalend.js";
|
|
3
3
|
|
|
4
4
|
export const getLendMarket = function (this: Llamalend, lendMarketId: string): LendMarketTemplate {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
if (!(lendMarketId in this.lendMarkets)) {
|
|
6
|
+
const marketData = this.constants.ONE_WAY_MARKETS[lendMarketId];
|
|
7
|
+
if (!marketData) throw new Error(`Lend market with id ${lendMarketId} not found`);
|
|
8
|
+
this.lendMarkets[lendMarketId] = new LendMarketTemplate(lendMarketId, marketData, this);
|
|
9
|
+
}
|
|
10
|
+
return this.lendMarkets[lendMarketId];
|
|
7
11
|
}
|
package/src/llamalend.ts
CHANGED
|
@@ -81,6 +81,8 @@ import {createCall, handleMultiCallResponse} from "./utils.js";
|
|
|
81
81
|
import {cacheKey, cacheStats} from "./cache/index.js";
|
|
82
82
|
import {_getMarketsData, _getHiddenPools} from "./external-api.js";
|
|
83
83
|
import {extractDecimals} from "./constants/utils.js";
|
|
84
|
+
import {MintMarketTemplate} from "./mintMarkets";
|
|
85
|
+
import {LendMarketTemplate} from "./lendMarkets";
|
|
84
86
|
|
|
85
87
|
export const NETWORK_CONSTANTS: { [index: number]: any } = {
|
|
86
88
|
1: {
|
|
@@ -177,6 +179,8 @@ class Llamalend implements ILlamalend {
|
|
|
177
179
|
signerAddress: string;
|
|
178
180
|
chainId: IChainId;
|
|
179
181
|
contracts: { [index: string]: ICurveContract };
|
|
182
|
+
mintMarkets: { [addres: string]: MintMarketTemplate };
|
|
183
|
+
lendMarkets: { [addres: string]: LendMarketTemplate };
|
|
180
184
|
feeData: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number };
|
|
181
185
|
constantOptions: { gasLimit: number };
|
|
182
186
|
options: { gasPrice?: number | bigint, maxFeePerGas?: number | bigint, maxPriorityFeePerGas?: number | bigint };
|
|
@@ -204,6 +208,8 @@ class Llamalend implements ILlamalend {
|
|
|
204
208
|
this.chainId = 1;
|
|
205
209
|
this.multicallProvider = null as unknown as MulticallProvider;
|
|
206
210
|
this.contracts = {};
|
|
211
|
+
this.mintMarkets = {};
|
|
212
|
+
this.lendMarkets = {};
|
|
207
213
|
this.feeData = {}
|
|
208
214
|
this.constantOptions = { gasLimit: 12000000 }
|
|
209
215
|
this.options = {};
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
_mulBy1_3,
|
|
21
21
|
DIGas,
|
|
22
22
|
} from "../utils";
|
|
23
|
-
import {IDict, TGas} from "../interfaces";
|
|
23
|
+
import {IDict, ILlamma, TGas} from "../interfaces";
|
|
24
24
|
import {_getUserCollateralCrvUsd} from "../external-api.js";
|
|
25
25
|
import { ILeverageV2 } from "./interfaces/leverage.js";
|
|
26
26
|
import { LeverageV2Module } from "./modules";
|
|
@@ -126,10 +126,8 @@ export class MintMarketTemplate {
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
constructor(id: string, llamalend: Llamalend) {
|
|
129
|
+
constructor(id: string, llammaData: ILlamma, llamalend: Llamalend) {
|
|
130
130
|
this.llamalend = llamalend;
|
|
131
|
-
const llammaData = this.llamalend.constants.LLAMMAS[id];
|
|
132
|
-
|
|
133
131
|
this.id = id;
|
|
134
132
|
this.address = llammaData.amm_address;
|
|
135
133
|
this.controller = llammaData.controller_address;
|
|
@@ -2,5 +2,10 @@ import { MintMarketTemplate} from "./MintMarketTemplate";
|
|
|
2
2
|
import type { Llamalend } from "../llamalend.js";
|
|
3
3
|
|
|
4
4
|
export const getMintMarket = function (this: Llamalend, mintMarketId: string): MintMarketTemplate {
|
|
5
|
-
|
|
5
|
+
if (!(mintMarketId in this.mintMarkets)) {
|
|
6
|
+
const llammaData = this.constants.LLAMMAS[mintMarketId];
|
|
7
|
+
if (!llammaData) throw new Error(`No market with id ${mintMarketId} found`);
|
|
8
|
+
this.mintMarkets[mintMarketId] = new MintMarketTemplate(mintMarketId, llammaData, this)
|
|
9
|
+
}
|
|
10
|
+
return this.mintMarkets[mintMarketId]
|
|
6
11
|
}
|
|
@@ -238,9 +238,8 @@ export class LeverageV2Module {
|
|
|
238
238
|
const key = `${inputCoinAddress}-${_amount}`;
|
|
239
239
|
if (!(key in this.swapDataCache)) throw Error(
|
|
240
240
|
"You must call corresponding `expected` method first " +
|
|
241
|
-
"(
|
|
241
|
+
"(leverageV2.createLoanExpectedCollateral, leverageV2.borrowMoreExpectedCollateral or leverageV2.repayExpectedBorrowed)"
|
|
242
242
|
);
|
|
243
|
-
|
|
244
243
|
return this.swapDataCache[key]
|
|
245
244
|
}
|
|
246
245
|
|
|
@@ -494,7 +493,7 @@ export class LeverageV2Module {
|
|
|
494
493
|
const _userBorrowed = parseUnits(userBorrowed, this.market.coinDecimals[0]);
|
|
495
494
|
const _debt = parseUnits(debt, this.market.coinDecimals[0]);
|
|
496
495
|
const swapData = this._getSwapDataFromCache(this.market.coinAddresses[0], _debt + _userBorrowed);
|
|
497
|
-
if (slippage !== swapData.slippage) throw Error(`You must call
|
|
496
|
+
if (slippage !== swapData.slippage) throw Error(`You must call leverageV2.createLoanExpectedCollateral() with slippage=${slippage} first`);
|
|
498
497
|
const calldata = await _assembleTxOdos.call(this.llamalend, swapData.pathId as string);
|
|
499
498
|
const contract = this.llamalend.contracts[this.market.controller].contract;
|
|
500
499
|
const gas = await contract.create_loan_extended.estimateGas(
|
|
@@ -666,7 +665,7 @@ export class LeverageV2Module {
|
|
|
666
665
|
const _userBorrowed = parseUnits(userBorrowed, this.market.coinDecimals[0]);
|
|
667
666
|
const _debt = parseUnits(debt, this.market.coinDecimals[0]);
|
|
668
667
|
const swapData = this._getSwapDataFromCache(this.market.coinAddresses[0], _debt + _userBorrowed);
|
|
669
|
-
if (slippage !== swapData.slippage) throw Error(`You must call
|
|
668
|
+
if (slippage !== swapData.slippage) throw Error(`You must call leverageV2.borrowMoreExpectedCollateral() with slippage=${slippage} first`)
|
|
670
669
|
const calldata = await _assembleTxOdos.call(this.llamalend, swapData.pathId as string);
|
|
671
670
|
const contract = this.llamalend.contracts[this.market.controller].contract;
|
|
672
671
|
const gas = await contract.borrow_more_extended.estimateGas(
|
|
@@ -894,7 +893,7 @@ export class LeverageV2Module {
|
|
|
894
893
|
let calldata = "0x";
|
|
895
894
|
if (_stateCollateral + _userCollateral > BigInt(0)) {
|
|
896
895
|
const swapData = this._getSwapDataFromCache(this.market.coinAddresses[1], _stateCollateral + _userCollateral);
|
|
897
|
-
if (slippage !== swapData.slippage) throw Error(`You must call
|
|
896
|
+
if (slippage !== swapData.slippage) throw Error(`You must call leverageV2.repayExpectedBorrowed() with slippage=${slippage} first`)
|
|
898
897
|
calldata = await _assembleTxOdos.call(this.llamalend, swapData.pathId as string);
|
|
899
898
|
}
|
|
900
899
|
|