@curvefi/llamalend-api 1.0.30 → 1.0.32
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/README.md +41 -1
- package/lib/external-api.d.ts +1 -0
- package/lib/external-api.js +4 -0
- package/lib/lendMarkets/LendMarketTemplate.d.ts +1 -0
- package/lib/lendMarkets/LendMarketTemplate.js +9 -1
- 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/external-api.ts +11 -0
- package/src/lendMarkets/LendMarketTemplate.ts +13 -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
package/README.md
CHANGED
|
@@ -891,6 +891,45 @@ import llamalend from "@curvefi/llamalend-api";
|
|
|
891
891
|
})()
|
|
892
892
|
```
|
|
893
893
|
|
|
894
|
+
### Force Update User State for lendMarket
|
|
895
|
+
|
|
896
|
+
After executing certain transactions, it's recommended to force update the user's state in the cache to ensure data consistency:
|
|
897
|
+
|
|
898
|
+
```ts
|
|
899
|
+
// Methods after which you should call forceUpdateUserState:
|
|
900
|
+
// - createLoan()
|
|
901
|
+
// - leverage.createLoan()
|
|
902
|
+
// - borrowMore()
|
|
903
|
+
// - partialSelfLiquidate()
|
|
904
|
+
// - repay()
|
|
905
|
+
|
|
906
|
+
// Basic usage (after successful transaction):
|
|
907
|
+
const txHash = await lendMarket.createLoan(0.5, 1000, 5);
|
|
908
|
+
// Wait for transaction to be mined and confirmed
|
|
909
|
+
await lendMarket.forceUpdateUserState(txHash);
|
|
910
|
+
|
|
911
|
+
// With specific user address:
|
|
912
|
+
await lendMarket.forceUpdateUserState(txHash, "0x123...");
|
|
913
|
+
|
|
914
|
+
// The method sends a request with new_tx parameter and clears the cache
|
|
915
|
+
// to get fresh user state data
|
|
916
|
+
// Important: Only call after successful transaction confirmation
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
**Why use forceUpdateUserState?**
|
|
920
|
+
- Ensures data consistency after successful transactions
|
|
921
|
+
- Clears cached user state data
|
|
922
|
+
- Forces fresh API request with transaction hash
|
|
923
|
+
- Prevents stale data issues
|
|
924
|
+
- **Important**: Only call after transaction is successfully mined and confirmed
|
|
925
|
+
|
|
926
|
+
**When to use:**
|
|
927
|
+
- After `createLoan()` - when creating a new loan
|
|
928
|
+
- After `leverage.createLoan()` - when creating a leveraged position
|
|
929
|
+
- After `borrowMore()` - when increasing loan amount
|
|
930
|
+
- After `partialSelfLiquidate()` - when partially liquidating position
|
|
931
|
+
- After `repay()` - when repaying loan
|
|
932
|
+
|
|
894
933
|
### User loss for lendMarket
|
|
895
934
|
```ts
|
|
896
935
|
(async () => {
|
|
@@ -2360,4 +2399,5 @@ import llamalend from "@curvefi/llamalend-api";
|
|
|
2360
2399
|
//
|
|
2361
2400
|
// '50': [ '759.898822708156242647', '1560.282492846180089068' ]
|
|
2362
2401
|
// }
|
|
2363
|
-
```
|
|
2402
|
+
```
|
|
2403
|
+
|
package/lib/external-api.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ type UserCollateral = {
|
|
|
11
11
|
total_deposit_from_user_usd_value: number;
|
|
12
12
|
};
|
|
13
13
|
export declare const _getUserCollateral: ((network: INetworkName, controller: string, user: string) => Promise<UserCollateral>) & memoize.Memoized<(network: INetworkName, controller: string, user: string) => Promise<UserCollateral>>;
|
|
14
|
+
export declare const _getUserCollateralForce: (network: INetworkName, controller: string, user: string, newTx: string) => Promise<void>;
|
|
14
15
|
export declare const _getUserCollateralCrvUsd: ((network: INetworkName, controller: string, user: string) => Promise<string>) & memoize.Memoized<(network: INetworkName, controller: string, user: string) => Promise<string>>;
|
|
15
16
|
export declare const _getMarketsData: ((network: INetworkName) => Promise<IMarketData>) & memoize.Memoized<(network: INetworkName) => Promise<IMarketData>>;
|
|
16
17
|
export declare function _getQuoteOdos(this: Llamalend, fromToken: string, toToken: string, _amount: bigint, blacklist: string, pathVizImage: boolean, slippage?: number): Promise<IQuoteOdos>;
|
package/lib/external-api.js
CHANGED
|
@@ -124,6 +124,10 @@ export const _getUserCollateral = memoize((network, controller, user) => __await
|
|
|
124
124
|
promise: true,
|
|
125
125
|
maxAge: 60 * 1000, // 1m
|
|
126
126
|
});
|
|
127
|
+
export const _getUserCollateralForce = (network, controller, user, newTx) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
|
+
yield fetch(`https://prices.curve.finance/v1/lending/collateral_events/${network}/${controller}/${user}?new_tx=${newTx}`);
|
|
129
|
+
_getUserCollateral.delete(network, controller, user);
|
|
130
|
+
});
|
|
127
131
|
export const _getUserCollateralCrvUsd = memoize((network, controller, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
132
|
const url = `https://prices.curve.finance/v1/crvusd/collateral_events/${network}/${controller}/${user}`;
|
|
129
133
|
const response = yield fetch(url);
|
|
@@ -519,4 +519,5 @@ export declare class LendMarketTemplate {
|
|
|
519
519
|
currentLeverage(userAddress?: string): Promise<string>;
|
|
520
520
|
currentPnL(userAddress?: string): Promise<Record<string, string>>;
|
|
521
521
|
userBoost(address?: string): Promise<string>;
|
|
522
|
+
forceUpdateUserState(newTx: string, userAddress?: string): Promise<void>;
|
|
522
523
|
}
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
import BigNumber from "bignumber.js";
|
|
12
12
|
import { _getAddress, parseUnits, BN, toBN, fromBN, getBalances, _ensureAllowance, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, _cutZeros, formatUnits, formatNumber, MAX_ALLOWANCE, MAX_ACTIVE_BAND, _mulBy1_3, _getUsdRate, DIGas, smartNumber, } from "../utils.js";
|
|
13
|
-
import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getMarketsData } from "../external-api.js";
|
|
13
|
+
import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getUserCollateralForce, _getMarketsData } from "../external-api.js";
|
|
14
14
|
import ERC20Abi from '../constants/abis/ERC20.json' with { type: 'json' };
|
|
15
15
|
import { cacheKey, cacheStats } from "../cache/index.js";
|
|
16
16
|
const DAY = 86400;
|
|
@@ -2799,4 +2799,12 @@ export class LendMarketTemplate {
|
|
|
2799
2799
|
return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
|
|
2800
2800
|
});
|
|
2801
2801
|
}
|
|
2802
|
+
forceUpdateUserState(newTx, userAddress) {
|
|
2803
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2804
|
+
const address = userAddress || this.llamalend.signerAddress;
|
|
2805
|
+
if (!address)
|
|
2806
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
2807
|
+
yield _getUserCollateralForce(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, address, newTx);
|
|
2808
|
+
});
|
|
2809
|
+
}
|
|
2802
2810
|
}
|
|
@@ -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
package/src/external-api.ts
CHANGED
|
@@ -136,6 +136,17 @@ export const _getUserCollateral = memoize(
|
|
|
136
136
|
}
|
|
137
137
|
)
|
|
138
138
|
|
|
139
|
+
export const _getUserCollateralForce = async (
|
|
140
|
+
network: INetworkName,
|
|
141
|
+
controller: string,
|
|
142
|
+
user: string,
|
|
143
|
+
newTx: string
|
|
144
|
+
): Promise<void> => {
|
|
145
|
+
await fetch(`https://prices.curve.finance/v1/lending/collateral_events/${network}/${controller}/${user}?new_tx=${newTx}`);
|
|
146
|
+
|
|
147
|
+
_getUserCollateral.delete(network, controller, user);
|
|
148
|
+
}
|
|
149
|
+
|
|
139
150
|
export const _getUserCollateralCrvUsd = memoize(
|
|
140
151
|
async (network: INetworkName, controller: string, user: string): Promise<string> => {
|
|
141
152
|
const url = `https://prices.curve.finance/v1/crvusd/collateral_events/${network}/${controller}/${user}`;
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
smartNumber,
|
|
24
24
|
} from "../utils.js";
|
|
25
25
|
import {IDict, TGas, TAmount, IReward, IQuoteOdos, IOneWayMarket, IPartialFrac} from "../interfaces.js";
|
|
26
|
-
import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getMarketsData } from "../external-api.js";
|
|
26
|
+
import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getUserCollateralForce, _getMarketsData } from "../external-api.js";
|
|
27
27
|
import ERC20Abi from '../constants/abis/ERC20.json' with {type: 'json'};
|
|
28
28
|
import {cacheKey, cacheStats} from "../cache/index.js";
|
|
29
29
|
|
|
@@ -3160,4 +3160,16 @@ export class LendMarketTemplate {
|
|
|
3160
3160
|
|
|
3161
3161
|
return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
|
|
3162
3162
|
}
|
|
3163
|
+
|
|
3164
|
+
public async forceUpdateUserState(newTx: string, userAddress?: string): Promise<void> {
|
|
3165
|
+
const address = userAddress || this.llamalend.signerAddress;
|
|
3166
|
+
if (!address) throw Error("Need to connect wallet or pass address into args");
|
|
3167
|
+
|
|
3168
|
+
await _getUserCollateralForce(
|
|
3169
|
+
this.llamalend.constants.NETWORK_NAME,
|
|
3170
|
+
this.addresses.controller,
|
|
3171
|
+
address,
|
|
3172
|
+
newTx
|
|
3173
|
+
);
|
|
3174
|
+
}
|
|
3163
3175
|
}
|
|
@@ -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
|
|