@curvefi/llamalend-api 1.0.40 → 1.0.42
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/.github/workflows/publish.yml +7 -14
- package/lib/lendMarkets/LendMarketTemplate.d.ts +2 -0
- package/lib/lendMarkets/LendMarketTemplate.js +23 -1
- package/lib/mintMarkets/MintMarketTemplate.d.ts +2 -0
- package/lib/mintMarkets/MintMarketTemplate.js +27 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +11 -0
- package/package.json +1 -1
- package/src/lendMarkets/LendMarketTemplate.ts +25 -0
- package/src/mintMarkets/MintMarketTemplate.ts +27 -0
- package/src/utils.ts +18 -1
|
@@ -4,7 +4,6 @@ on:
|
|
|
4
4
|
push:
|
|
5
5
|
branches:
|
|
6
6
|
- main
|
|
7
|
-
- feat/init
|
|
8
7
|
|
|
9
8
|
jobs:
|
|
10
9
|
release:
|
|
@@ -12,7 +11,7 @@ jobs:
|
|
|
12
11
|
runs-on: ubuntu-latest
|
|
13
12
|
steps:
|
|
14
13
|
- name: Checkout code
|
|
15
|
-
uses: actions/checkout@
|
|
14
|
+
uses: actions/checkout@v5
|
|
16
15
|
- name: get-npm-version
|
|
17
16
|
id: package-version
|
|
18
17
|
uses: martinbeentjes/npm-get-version-action@main
|
|
@@ -42,19 +41,13 @@ jobs:
|
|
|
42
41
|
permissions:
|
|
43
42
|
contents: read
|
|
44
43
|
id-token: write
|
|
44
|
+
environment: production
|
|
45
45
|
steps:
|
|
46
|
-
- uses: actions/checkout@
|
|
47
|
-
-
|
|
48
|
-
uses: actions/setup-node@v4
|
|
46
|
+
- uses: actions/checkout@v5
|
|
47
|
+
- uses: actions/setup-node@v5
|
|
49
48
|
with:
|
|
50
49
|
node-version: 24
|
|
51
50
|
cache: npm
|
|
52
|
-
|
|
53
|
-
-
|
|
54
|
-
|
|
55
|
-
- name: Build
|
|
56
|
-
run: npm run build
|
|
57
|
-
- name: Publish to npm
|
|
58
|
-
run: npm publish --access public
|
|
59
|
-
env:
|
|
60
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
51
|
+
- run: npm ci
|
|
52
|
+
- run: npm run build
|
|
53
|
+
- run: npm publish
|
|
@@ -407,6 +407,7 @@ export declare class LendMarketTemplate {
|
|
|
407
407
|
private _addCollateral;
|
|
408
408
|
addCollateralEstimateGas(collateral: number | string, address?: string): Promise<TGas>;
|
|
409
409
|
addCollateral(collateral: number | string, address?: string): Promise<string>;
|
|
410
|
+
addCollateralFutureLeverage(collateral: number | string, userAddress?: string): Promise<string>;
|
|
410
411
|
maxRemovable(): Promise<string>;
|
|
411
412
|
private _removeCollateralBands;
|
|
412
413
|
removeCollateralBands(collateral: number | string): Promise<[number, number]>;
|
|
@@ -415,6 +416,7 @@ export declare class LendMarketTemplate {
|
|
|
415
416
|
private _removeCollateral;
|
|
416
417
|
removeCollateralEstimateGas(collateral: number | string): Promise<TGas>;
|
|
417
418
|
removeCollateral(collateral: number | string): Promise<string>;
|
|
419
|
+
removeCollateralFutureLeverage(collateral: number | string, userAddress?: string): Promise<string>;
|
|
418
420
|
private _repayBands;
|
|
419
421
|
repayBands(debt: number | string, address?: string): Promise<[number, number]>;
|
|
420
422
|
repayPrices(debt: number | string, address?: string): Promise<string[]>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
import BigNumber from "bignumber.js";
|
|
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";
|
|
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, calculateFutureLeverage, } from "../utils.js";
|
|
13
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";
|
|
@@ -1683,6 +1683,17 @@ export class LendMarketTemplate {
|
|
|
1683
1683
|
return yield this._addCollateral(collateral, address, false);
|
|
1684
1684
|
});
|
|
1685
1685
|
}
|
|
1686
|
+
addCollateralFutureLeverage(collateral_1) {
|
|
1687
|
+
return __awaiter(this, arguments, void 0, function* (collateral, userAddress = '') {
|
|
1688
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1689
|
+
const [userCollateral, { collateral: currentCollateral }] = yield Promise.all([
|
|
1690
|
+
_getUserCollateral(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, userAddress),
|
|
1691
|
+
this.userState(userAddress),
|
|
1692
|
+
]);
|
|
1693
|
+
const total_deposit_from_user = userCollateral.total_deposit_from_user_precise;
|
|
1694
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'add');
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1686
1697
|
// ---------------- REMOVE COLLATERAL ----------------
|
|
1687
1698
|
maxRemovable() {
|
|
1688
1699
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1751,6 +1762,17 @@ export class LendMarketTemplate {
|
|
|
1751
1762
|
return yield this._removeCollateral(collateral, false);
|
|
1752
1763
|
});
|
|
1753
1764
|
}
|
|
1765
|
+
removeCollateralFutureLeverage(collateral_1) {
|
|
1766
|
+
return __awaiter(this, arguments, void 0, function* (collateral, userAddress = '') {
|
|
1767
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1768
|
+
const [userCollateral, { collateral: currentCollateral }] = yield Promise.all([
|
|
1769
|
+
_getUserCollateral(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, userAddress),
|
|
1770
|
+
this.userState(userAddress),
|
|
1771
|
+
]);
|
|
1772
|
+
const total_deposit_from_user = userCollateral.total_deposit_from_user_precise;
|
|
1773
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'remove');
|
|
1774
|
+
});
|
|
1775
|
+
}
|
|
1754
1776
|
// ---------------- REPAY ----------------
|
|
1755
1777
|
_repayBands(debt, address) {
|
|
1756
1778
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -244,6 +244,7 @@ export declare class MintMarketTemplate {
|
|
|
244
244
|
private _addCollateral;
|
|
245
245
|
addCollateralEstimateGas(collateral: number | string, address?: string): Promise<number>;
|
|
246
246
|
addCollateral(collateral: number | string, address?: string): Promise<string>;
|
|
247
|
+
addCollateralFutureLeverage(collateral: number | string, userAddress?: string): Promise<string>;
|
|
247
248
|
maxRemovable(): Promise<string>;
|
|
248
249
|
private _removeCollateralBands;
|
|
249
250
|
removeCollateralBands(collateral: number | string): Promise<[number, number]>;
|
|
@@ -252,6 +253,7 @@ export declare class MintMarketTemplate {
|
|
|
252
253
|
private _removeCollateral;
|
|
253
254
|
removeCollateralEstimateGas(collateral: number | string): Promise<number>;
|
|
254
255
|
removeCollateral(collateral: number | string): Promise<string>;
|
|
256
|
+
removeCollateralFutureLeverage(collateral: number | string, userAddress?: string): Promise<string>;
|
|
255
257
|
private _repayBands;
|
|
256
258
|
repayBands(debt: number | string, address?: string): Promise<[number, number]>;
|
|
257
259
|
repayPrices(debt: number | string, address?: string): Promise<string[]>;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
import BigNumber from "bignumber.js";
|
|
12
|
-
import { _getAddress, parseUnits, BN, toBN, fromBN, getBalances, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, isEth, _cutZeros, formatUnits, smartNumber, MAX_ALLOWANCE, MAX_ACTIVE_BAND, _mulBy1_3, DIGas, } from "../utils.js";
|
|
12
|
+
import { _getAddress, parseUnits, BN, toBN, fromBN, getBalances, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, isEth, _cutZeros, formatUnits, smartNumber, MAX_ALLOWANCE, MAX_ACTIVE_BAND, _mulBy1_3, DIGas, calculateFutureLeverage, } from "../utils.js";
|
|
13
13
|
import { _getUserCollateralCrvUsd, _getUserCollateralCrvUsdFull } from "../external-api.js";
|
|
14
14
|
import { LeverageV2Module } from "./modules/index.js";
|
|
15
15
|
export class MintMarketTemplate {
|
|
@@ -960,6 +960,19 @@ export class MintMarketTemplate {
|
|
|
960
960
|
return yield this._addCollateral(collateral, address, false);
|
|
961
961
|
});
|
|
962
962
|
}
|
|
963
|
+
addCollateralFutureLeverage(collateral_1) {
|
|
964
|
+
return __awaiter(this, arguments, void 0, function* (collateral, userAddress = '') {
|
|
965
|
+
var _a;
|
|
966
|
+
this._checkLeverageForStats();
|
|
967
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
968
|
+
const [userCollateral, { collateral: currentCollateral }] = yield Promise.all([
|
|
969
|
+
_getUserCollateralCrvUsdFull(this.llamalend.constants.NETWORK_NAME, this.controller, userAddress),
|
|
970
|
+
this.userState(userAddress),
|
|
971
|
+
]);
|
|
972
|
+
const total_deposit_from_user = (_a = userCollateral.total_deposit_from_user_precise) !== null && _a !== void 0 ? _a : userCollateral.total_deposit_precise;
|
|
973
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'add');
|
|
974
|
+
});
|
|
975
|
+
}
|
|
963
976
|
// ---------------- REMOVE COLLATERAL ----------------
|
|
964
977
|
maxRemovable() {
|
|
965
978
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1031,6 +1044,19 @@ export class MintMarketTemplate {
|
|
|
1031
1044
|
return yield this._removeCollateral(collateral, false);
|
|
1032
1045
|
});
|
|
1033
1046
|
}
|
|
1047
|
+
removeCollateralFutureLeverage(collateral_1) {
|
|
1048
|
+
return __awaiter(this, arguments, void 0, function* (collateral, userAddress = '') {
|
|
1049
|
+
var _a;
|
|
1050
|
+
this._checkLeverageForStats();
|
|
1051
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1052
|
+
const [userCollateral, { collateral: currentCollateral }] = yield Promise.all([
|
|
1053
|
+
_getUserCollateralCrvUsdFull(this.llamalend.constants.NETWORK_NAME, this.controller, userAddress),
|
|
1054
|
+
this.userState(userAddress),
|
|
1055
|
+
]);
|
|
1056
|
+
const total_deposit_from_user = (_a = userCollateral.total_deposit_from_user_precise) !== null && _a !== void 0 ? _a : userCollateral.total_deposit_precise;
|
|
1057
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'remove');
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1034
1060
|
// ---------------- REPAY ----------------
|
|
1035
1061
|
_repayBands(debt, address) {
|
|
1036
1062
|
return __awaiter(this, void 0, void 0, function* () {
|
package/lib/utils.d.ts
CHANGED
|
@@ -57,3 +57,4 @@ export declare const getLsdApy: ((name: "wstETH" | "sfrxETH") => Promise<{
|
|
|
57
57
|
baseApy: number;
|
|
58
58
|
apyMean30d: number;
|
|
59
59
|
}>>;
|
|
60
|
+
export declare const calculateFutureLeverage: (currentCollateral: number | string, totalDepositFromUser: number | string, collateral: number | string, operation: "add" | "remove") => string;
|
package/lib/utils.js
CHANGED
|
@@ -463,3 +463,14 @@ export const getLsdApy = memoize((name) => __awaiter(void 0, void 0, void 0, fun
|
|
|
463
463
|
promise: true,
|
|
464
464
|
maxAge: 60 * 1000, // 1m
|
|
465
465
|
});
|
|
466
|
+
export const calculateFutureLeverage = (currentCollateral, totalDepositFromUser, collateral, operation) => {
|
|
467
|
+
const collateralBN = BN(collateral);
|
|
468
|
+
const currentCollateralBN = BN(currentCollateral);
|
|
469
|
+
const totalDepositBN = BN(totalDepositFromUser);
|
|
470
|
+
if (operation === 'add') {
|
|
471
|
+
return currentCollateralBN.plus(collateralBN).div(totalDepositBN.plus(collateralBN)).toString();
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
return currentCollateralBN.minus(collateralBN).div(totalDepositBN.minus(collateralBN)).toString();
|
|
475
|
+
}
|
|
476
|
+
};
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
_getUsdRate,
|
|
22
22
|
DIGas,
|
|
23
23
|
smartNumber,
|
|
24
|
+
calculateFutureLeverage,
|
|
24
25
|
} from "../utils.js";
|
|
25
26
|
import {IDict, TGas, TAmount, IReward, IQuoteOdos, IOneWayMarket, IPartialFrac} from "../interfaces.js";
|
|
26
27
|
import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getUserCollateralForce, _getMarketsData } from "../external-api.js";
|
|
@@ -1747,6 +1748,18 @@ export class LendMarketTemplate {
|
|
|
1747
1748
|
return await this._addCollateral(collateral, address, false) as string;
|
|
1748
1749
|
}
|
|
1749
1750
|
|
|
1751
|
+
public async addCollateralFutureLeverage(collateral: number | string, userAddress = ''): Promise<string> {
|
|
1752
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1753
|
+
const [userCollateral, {collateral: currentCollateral}] = await Promise.all([
|
|
1754
|
+
_getUserCollateral(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, userAddress),
|
|
1755
|
+
this.userState(userAddress),
|
|
1756
|
+
]);
|
|
1757
|
+
|
|
1758
|
+
const total_deposit_from_user = userCollateral.total_deposit_from_user_precise;
|
|
1759
|
+
|
|
1760
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'add');
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1750
1763
|
// ---------------- REMOVE COLLATERAL ----------------
|
|
1751
1764
|
|
|
1752
1765
|
public async maxRemovable(): Promise<string> {
|
|
@@ -1813,6 +1826,18 @@ export class LendMarketTemplate {
|
|
|
1813
1826
|
return await this._removeCollateral(collateral, false) as string;
|
|
1814
1827
|
}
|
|
1815
1828
|
|
|
1829
|
+
public async removeCollateralFutureLeverage(collateral: number | string, userAddress = ''): Promise<string> {
|
|
1830
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1831
|
+
const [userCollateral, {collateral: currentCollateral}] = await Promise.all([
|
|
1832
|
+
_getUserCollateral(this.llamalend.constants.NETWORK_NAME, this.addresses.controller, userAddress),
|
|
1833
|
+
this.userState(userAddress),
|
|
1834
|
+
]);
|
|
1835
|
+
|
|
1836
|
+
const total_deposit_from_user = userCollateral.total_deposit_from_user_precise;
|
|
1837
|
+
|
|
1838
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'remove');
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1816
1841
|
// ---------------- REPAY ----------------
|
|
1817
1842
|
|
|
1818
1843
|
private async _repayBands(debt: number | string, address: string): Promise<[bigint, bigint]> {
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
MAX_ACTIVE_BAND,
|
|
20
20
|
_mulBy1_3,
|
|
21
21
|
DIGas,
|
|
22
|
+
calculateFutureLeverage,
|
|
22
23
|
} from "../utils.js";
|
|
23
24
|
import {IDict, ILlamma, TGas} from "../interfaces.js";
|
|
24
25
|
import {_getUserCollateralCrvUsd, _getUserCollateralCrvUsdFull} from "../external-api.js";
|
|
@@ -1001,6 +1002,19 @@ export class MintMarketTemplate {
|
|
|
1001
1002
|
return await this._addCollateral(collateral, address, false) as string;
|
|
1002
1003
|
}
|
|
1003
1004
|
|
|
1005
|
+
public async addCollateralFutureLeverage(collateral: number | string, userAddress = ''): Promise<string> {
|
|
1006
|
+
this._checkLeverageForStats();
|
|
1007
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1008
|
+
const [userCollateral, {collateral: currentCollateral}] = await Promise.all([
|
|
1009
|
+
_getUserCollateralCrvUsdFull(this.llamalend.constants.NETWORK_NAME, this.controller, userAddress),
|
|
1010
|
+
this.userState(userAddress),
|
|
1011
|
+
]);
|
|
1012
|
+
|
|
1013
|
+
const total_deposit_from_user = userCollateral.total_deposit_from_user_precise ?? userCollateral.total_deposit_precise;
|
|
1014
|
+
|
|
1015
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'add');
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1004
1018
|
// ---------------- REMOVE COLLATERAL ----------------
|
|
1005
1019
|
|
|
1006
1020
|
public async maxRemovable(): Promise<string> {
|
|
@@ -1069,6 +1083,19 @@ export class MintMarketTemplate {
|
|
|
1069
1083
|
return await this._removeCollateral(collateral, false) as string;
|
|
1070
1084
|
}
|
|
1071
1085
|
|
|
1086
|
+
public async removeCollateralFutureLeverage(collateral: number | string, userAddress = ''): Promise<string> {
|
|
1087
|
+
this._checkLeverageForStats();
|
|
1088
|
+
userAddress = _getAddress.call(this.llamalend, userAddress);
|
|
1089
|
+
const [userCollateral, {collateral: currentCollateral}] = await Promise.all([
|
|
1090
|
+
_getUserCollateralCrvUsdFull(this.llamalend.constants.NETWORK_NAME, this.controller, userAddress),
|
|
1091
|
+
this.userState(userAddress),
|
|
1092
|
+
]);
|
|
1093
|
+
|
|
1094
|
+
const total_deposit_from_user = userCollateral.total_deposit_from_user_precise ?? userCollateral.total_deposit_precise;
|
|
1095
|
+
|
|
1096
|
+
return calculateFutureLeverage(currentCollateral, total_deposit_from_user, collateral, 'remove');
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1072
1099
|
// ---------------- REPAY ----------------
|
|
1073
1100
|
|
|
1074
1101
|
private async _repayBands(debt: number | string, address: string): Promise<[bigint, bigint]> {
|
package/src/utils.ts
CHANGED
|
@@ -498,4 +498,21 @@ export const getLsdApy = memoize(async(name: 'wstETH' | 'sfrxETH'): Promise<{
|
|
|
498
498
|
{
|
|
499
499
|
promise: true,
|
|
500
500
|
maxAge: 60 * 1000, // 1m
|
|
501
|
-
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
export const calculateFutureLeverage = (
|
|
504
|
+
currentCollateral: number | string,
|
|
505
|
+
totalDepositFromUser: number | string,
|
|
506
|
+
collateral: number | string,
|
|
507
|
+
operation: 'add' | 'remove'
|
|
508
|
+
): string => {
|
|
509
|
+
const collateralBN = BN(collateral);
|
|
510
|
+
const currentCollateralBN = BN(currentCollateral);
|
|
511
|
+
const totalDepositBN = BN(totalDepositFromUser);
|
|
512
|
+
|
|
513
|
+
if (operation === 'add') {
|
|
514
|
+
return currentCollateralBN.plus(collateralBN).div(totalDepositBN.plus(collateralBN)).toString();
|
|
515
|
+
} else {
|
|
516
|
+
return currentCollateralBN.minus(collateralBN).div(totalDepositBN.minus(collateralBN)).toString();
|
|
517
|
+
}
|
|
518
|
+
};
|