@defisaver/positions-sdk 0.0.27 → 0.0.29
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 +63 -63
- package/cjs/config/contracts.d.ts +18 -9
- package/cjs/config/contracts.js +8 -7
- package/cjs/contracts.d.ts +1 -1
- package/cjs/contracts.js +27 -4
- package/cjs/curveUsd/index.js +1 -1
- package/cjs/helpers/curveUsdHelpers/index.d.ts +1 -2
- package/cjs/helpers/curveUsdHelpers/index.js +17 -25
- package/cjs/markets/aave/marketAssets.d.ts +1 -1
- package/cjs/markets/aave/marketAssets.js +1 -1
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/services/utils.d.ts +0 -4
- package/cjs/services/utils.js +1 -13
- package/cjs/types/contracts/generated/CrvUSDView.d.ts +4 -30
- package/cjs/types/curveUsd.d.ts +0 -6
- package/esm/config/contracts.d.ts +18 -9
- package/esm/config/contracts.js +8 -7
- package/esm/contracts.d.ts +1 -1
- package/esm/contracts.js +27 -4
- package/esm/curveUsd/index.js +1 -1
- package/esm/helpers/curveUsdHelpers/index.d.ts +1 -2
- package/esm/helpers/curveUsdHelpers/index.js +18 -26
- package/esm/markets/aave/marketAssets.d.ts +1 -1
- package/esm/markets/aave/marketAssets.js +1 -1
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/services/utils.d.ts +0 -4
- package/esm/services/utils.js +0 -11
- package/esm/types/contracts/generated/CrvUSDView.d.ts +4 -30
- package/esm/types/curveUsd.d.ts +0 -6
- package/package.json +40 -40
- package/src/aaveV2/index.ts +226 -226
- package/src/aaveV3/index.ts +561 -561
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +275 -275
- package/src/config/contracts.js +676 -675
- package/src/constants/index.ts +3 -3
- package/src/contracts.ts +126 -100
- package/src/curveUsd/index.ts +228 -228
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +134 -134
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +181 -181
- package/src/helpers/curveUsdHelpers/index.ts +32 -40
- package/src/helpers/index.ts +5 -5
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +40 -40
- package/src/liquity/index.ts +116 -116
- package/src/maker/index.ts +101 -101
- package/src/markets/aave/index.ts +80 -80
- package/src/markets/aave/marketAssets.ts +32 -32
- package/src/markets/compound/index.ts +141 -141
- package/src/markets/compound/marketsAssets.ts +46 -46
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +3 -3
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +9 -9
- package/src/moneymarket/moneymarketCommonService.ts +75 -75
- package/src/morpho/markets.ts +39 -39
- package/src/morphoAaveV2/index.ts +255 -255
- package/src/morphoAaveV3/index.ts +619 -619
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +35 -48
- package/src/spark/index.ts +422 -422
- package/src/staking/staking.ts +167 -167
- package/src/types/aave.ts +256 -256
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +83 -83
- package/src/types/compound.ts +128 -128
- package/src/types/contracts/generated/CrvUSDView.ts +8 -43
- package/src/types/curveUsd.ts +112 -118
- package/src/types/index.ts +6 -6
- package/src/types/liquity.ts +30 -30
- package/src/types/maker.ts +50 -50
- package/src/types/spark.ts +106 -106
- package/yarn-error.log +0 -64
package/esm/config/contracts.js
CHANGED
|
@@ -527,15 +527,13 @@ module.exports = {
|
|
|
527
527
|
}
|
|
528
528
|
},
|
|
529
529
|
"crvUSDView": {
|
|
530
|
-
"abi": [{ "inputs": [
|
|
530
|
+
"abi": [{ "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "createLoanData", "outputs": [{ "components": [{ "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "uint256", "name": "minColl", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrow", "type": "uint256" }, { "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct CurveUsdView.CreateLoanData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "n", "type": "int256" }], "name": "getBandData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "from", "type": "int256" }, { "internalType": "int256", "name": "to", "type": "int256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }], "name": "globalData", "outputs": [{ "components": [{ "internalType": "address", "name": "collateral", "type": "address" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "int256", "name": "activeBand", "type": "int256" }, { "internalType": "uint256", "name": "A", "type": "uint256" }, { "internalType": "uint256", "name": "totalDebt", "type": "uint256" }, { "internalType": "uint256", "name": "ammPrice", "type": "uint256" }, { "internalType": "uint256", "name": "basePrice", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePrice", "type": "uint256" }, { "internalType": "uint256", "name": "minted", "type": "uint256" }, { "internalType": "uint256", "name": "redeemed", "type": "uint256" }, { "internalType": "uint256", "name": "monetaryPolicyRate", "type": "uint256" }, { "internalType": "uint256", "name": "ammRate", "type": "uint256" }, { "internalType": "int256", "name": "minBand", "type": "int256" }, { "internalType": "int256", "name": "maxBand", "type": "int256" }], "internalType": "struct CurveUsdView.GlobalData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }, { "internalType": "int256", "name": "collChange", "type": "int256" }, { "internalType": "int256", "name": "debtChange", "type": "int256" }, { "internalType": "bool", "name": "isFull", "type": "bool" }, { "internalType": "uint256", "name": "numBands", "type": "uint256" }], "name": "healthCalculator", "outputs": [{ "internalType": "int256", "name": "", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "maxBorrow", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "minCollateral", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "userData", "outputs": [{ "components": [{ "internalType": "bool", "name": "loanExists", "type": "bool" }, { "internalType": "uint256", "name": "collateralPrice", "type": "uint256" }, { "internalType": "uint256", "name": "marketCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "curveUsdCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }, { "internalType": "uint256", "name": "priceLow", "type": "uint256" }, { "internalType": "uint256", "name": "priceHigh", "type": "uint256" }, { "internalType": "uint256", "name": "liquidationDiscount", "type": "uint256" }, { "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "int256[2]", "name": "bandRange", "type": "int256[2]" }, { "internalType": "uint256[][2]", "name": "usersBands", "type": "uint256[][2]" }], "internalType": "struct CurveUsdView.UserData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }],
|
|
531
531
|
"networks": {
|
|
532
532
|
"1": {
|
|
533
|
-
"address": "
|
|
534
|
-
"createdBlock":
|
|
533
|
+
"address": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
|
|
534
|
+
"createdBlock": 17683243,
|
|
535
535
|
"oldVersions": {
|
|
536
|
-
"17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95"
|
|
537
|
-
"17683243": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
|
|
538
|
-
"18419795": "0x4df1281f9d2303be453e0085881702a4b1358692",
|
|
536
|
+
"17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95"
|
|
539
537
|
}
|
|
540
538
|
}
|
|
541
539
|
}
|
|
@@ -558,7 +556,10 @@ module.exports = {
|
|
|
558
556
|
"12549073": "0xFCDd12C6317adbd033B93486d176f99441344A0f",
|
|
559
557
|
"12567960": "0x0bE59e4804d957026a0E31B5d0BEA0fbaE262ba7",
|
|
560
558
|
"12638758": "0x30EFEF27A6919d927E4c684E373198F671c686Dc",
|
|
561
|
-
"12746821":
|
|
559
|
+
"12746821": {
|
|
560
|
+
"abi": [{ "inputs": [{ "internalType": "address", "name": "_troveOwner", "type": "address" }], "name": "getTroveInfo", "outputs": [{ "internalType": "uint256", "name": "troveStatus", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "bool", "name": "recoveryMode", "type": "bool" }], "stateMutability": "view", "type": "function" }],
|
|
561
|
+
"address": "0xD1913B977737c9505B8EcFEDB8121546096d3393"
|
|
562
|
+
},
|
|
562
563
|
}
|
|
563
564
|
}
|
|
564
565
|
}
|
package/esm/contracts.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as ContractTypes from './types/contracts/generated';
|
|
|
5
5
|
import { Blockish, NetworkNumber } from './types/common';
|
|
6
6
|
export type ConfigKey = keyof typeof configRaw;
|
|
7
7
|
export declare const getConfigContractAddress: (name: ConfigKey, network: NetworkNumber, block?: Blockish) => string;
|
|
8
|
-
export declare const getConfigContractAbi: (name: ConfigKey) => any[];
|
|
8
|
+
export declare const getConfigContractAbi: (name: ConfigKey, network?: NetworkNumber, block?: Blockish) => any[];
|
|
9
9
|
export declare const getErc20Contract: (address: string, web3: Web3) => import("web3-eth-contract").Contract;
|
|
10
10
|
export declare const createContractWrapper: (web3: Web3, network: NetworkNumber, name: ConfigKey, _address?: string, block?: Blockish) => BaseContract;
|
|
11
11
|
export declare const UniMulticallContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.UniMulticall;
|
package/esm/contracts.js
CHANGED
|
@@ -8,18 +8,41 @@ export const getConfigContractAddress = (name, network, block) => {
|
|
|
8
8
|
return latestAddress;
|
|
9
9
|
}
|
|
10
10
|
const oldVersions = (networkData === null || networkData === void 0 ? void 0 : networkData.oldVersions) || {};
|
|
11
|
-
|
|
11
|
+
// Versions are ordered from oldest to the newest
|
|
12
|
+
for (const [createdBlock, addressOrObject] of Object.entries(oldVersions).reverse()) {
|
|
12
13
|
if (block >= Number(createdBlock)) {
|
|
13
|
-
|
|
14
|
+
if (typeof addressOrObject !== 'string') {
|
|
15
|
+
return addressOrObject.address;
|
|
16
|
+
}
|
|
17
|
+
return addressOrObject;
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
return latestAddress;
|
|
18
22
|
};
|
|
19
|
-
export const getConfigContractAbi = (name) =>
|
|
23
|
+
export const getConfigContractAbi = (name, network, block) => {
|
|
24
|
+
const networkData = network ? contractConfig[name].networks[network] : null;
|
|
25
|
+
const latestAbi = contractConfig[name].abi;
|
|
26
|
+
if (block && block !== 'latest' && networkData) {
|
|
27
|
+
if (block >= ((networkData === null || networkData === void 0 ? void 0 : networkData.createdBlock) || 0)) {
|
|
28
|
+
return latestAbi;
|
|
29
|
+
}
|
|
30
|
+
const oldVersions = (networkData === null || networkData === void 0 ? void 0 : networkData.oldVersions) || {};
|
|
31
|
+
// Versions are ordered from oldest to the newest
|
|
32
|
+
for (const [createdBlock, addressOrObject] of Object.entries(oldVersions).reverse()) {
|
|
33
|
+
if (block >= Number(createdBlock)) {
|
|
34
|
+
if (typeof addressOrObject !== 'string') {
|
|
35
|
+
return addressOrObject.abi;
|
|
36
|
+
}
|
|
37
|
+
return latestAbi;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return latestAbi;
|
|
42
|
+
};
|
|
20
43
|
const createContractFromConfigFunc = (name, _address) => (web3, network, block) => {
|
|
21
44
|
const address = _address || getConfigContractAddress(name, network, block);
|
|
22
|
-
return new web3.eth.Contract(
|
|
45
|
+
return new web3.eth.Contract(getConfigContractAbi(name, network, block), address);
|
|
23
46
|
};
|
|
24
47
|
export const getErc20Contract = (address, web3) => (new web3.eth.Contract(getConfigContractAbi('Erc20'), address));
|
|
25
48
|
export const createContractWrapper = (web3, network, name, _address, block) => (createContractFromConfigFunc(name, _address)(web3, network, block));
|
package/esm/curveUsd/index.js
CHANGED
|
@@ -179,7 +179,7 @@ export const getCurveUsdUserData = (web3, network, address, selectedMarket, acti
|
|
|
179
179
|
priceHigh,
|
|
180
180
|
priceLow, liquidationDiscount: assetAmountInEth(data.liquidationDiscount), numOfBands: data.N, usedAssets,
|
|
181
181
|
status }), getCrvUsdAggregatedData({
|
|
182
|
-
loanExists: data.loanExists, usedAssets, network: NetworkNumber.Eth, selectedMarket,
|
|
182
|
+
loanExists: data.loanExists, usedAssets, network: NetworkNumber.Eth, selectedMarket,
|
|
183
183
|
})), { userBands });
|
|
184
184
|
});
|
|
185
185
|
export const getCurveUsdFullPositionData = (web3, network, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CrvUSDAggregatedPositionData, CrvUSDMarketData, CrvUSDUsedAssets } from '../../types';
|
|
2
2
|
import { NetworkNumber } from '../../types/common';
|
|
3
|
-
export declare const getCrvUsdAggregatedData: ({ loanExists, usedAssets, network, selectedMarket,
|
|
3
|
+
export declare const getCrvUsdAggregatedData: ({ loanExists, usedAssets, network, selectedMarket, ...rest }: {
|
|
4
4
|
loanExists: boolean;
|
|
5
5
|
usedAssets: CrvUSDUsedAssets;
|
|
6
6
|
network: NetworkNumber;
|
|
7
7
|
selectedMarket: CrvUSDMarketData;
|
|
8
|
-
numOfBands: number | string;
|
|
9
8
|
}) => CrvUSDAggregatedPositionData;
|
|
@@ -10,34 +10,26 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import Dec from 'decimal.js';
|
|
13
|
-
import {
|
|
14
|
-
import { mapRange } from '../../services/utils';
|
|
13
|
+
import { getAssetsTotal } from '../../moneymarket';
|
|
15
14
|
export const getCrvUsdAggregatedData = (_a) => {
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
? new Dec(payload.suppliedUsd)
|
|
25
|
-
.dividedBy(payload.borrowedUsd)
|
|
15
|
+
var { loanExists, usedAssets, network, selectedMarket } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket"]);
|
|
16
|
+
const _supplied = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
|
|
17
|
+
const _borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
|
|
18
|
+
const _suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
19
|
+
const _borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
20
|
+
const ratio = loanExists
|
|
21
|
+
? new Dec(_suppliedUsd)
|
|
22
|
+
.dividedBy(_borrowedUsd)
|
|
26
23
|
.times(100)
|
|
27
24
|
.toString()
|
|
28
25
|
: '0';
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (leveragedType !== '') {
|
|
39
|
-
payload.leveragedAsset = leveragedAsset;
|
|
40
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
41
|
-
}
|
|
42
|
-
return payload;
|
|
26
|
+
// we don't have borrowLimitUsd here
|
|
27
|
+
return {
|
|
28
|
+
ratio,
|
|
29
|
+
supplied: _supplied,
|
|
30
|
+
suppliedUsd: _suppliedUsd,
|
|
31
|
+
borrowedUsd: _borrowedUsd,
|
|
32
|
+
borrowed: _borrowed,
|
|
33
|
+
safetyRatio: ratio,
|
|
34
|
+
};
|
|
43
35
|
};
|
|
@@ -5,5 +5,5 @@ export declare const aaveV3AssetsDefaultMarket: {
|
|
|
5
5
|
readonly 1: readonly ["WBTC", "ETH", "wstETH", "USDC", "DAI", "LINK", "AAVE", "cbETH", "USDT", "rETH", "LUSD", "UNI", "MKR", "SNX", "BAL", "LDO", "CRV", "ENS", "1INCH", "GHO", "FRAX", "RPL", "sDAI"];
|
|
6
6
|
readonly 10: readonly ["DAI", "USDC.e", "USDT", "SUSD", "AAVE", "LINK", "WBTC", "ETH", "OP", "wstETH", "LUSD", "MAI", "rETH"];
|
|
7
7
|
readonly 42161: readonly ["ETH", "DAI", "EURS", "USDC", "USDT", "AAVE", "LINK", "WBTC", "wstETH", "MAI", "rETH", "LUSD", "USDC.e", "FRAX", "ARB"];
|
|
8
|
-
readonly 8453: readonly ["ETH", "USDbC", "cbETH"];
|
|
8
|
+
readonly 8453: readonly ["ETH", "USDbC", "cbETH", "wstETH"];
|
|
9
9
|
};
|
|
@@ -23,6 +23,6 @@ export const aaveV3AssetsDefaultMarket = {
|
|
|
23
23
|
'ETH', 'DAI', 'EURS', 'USDC', 'USDT', 'AAVE', 'LINK', 'WBTC', 'wstETH', 'MAI', 'rETH', 'LUSD', 'USDC.e', 'FRAX', 'ARB',
|
|
24
24
|
],
|
|
25
25
|
[NetworkNumber.Base]: [
|
|
26
|
-
'ETH', 'USDbC', 'cbETH',
|
|
26
|
+
'ETH', 'USDbC', 'cbETH', 'wstETH',
|
|
27
27
|
],
|
|
28
28
|
};
|
|
@@ -16,7 +16,7 @@ export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borr
|
|
|
16
16
|
return '0';
|
|
17
17
|
};
|
|
18
18
|
export const calculateBorrowingAssetLimit = (assetBorrowedUsd, borrowLimitUsd) => new Dec(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
|
|
19
|
-
export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI'
|
|
19
|
+
export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI'];
|
|
20
20
|
export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
21
21
|
let borrowUnstable = 0;
|
|
22
22
|
let supplyStable = 0;
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -14,7 +14,3 @@ export declare const handleWbtcLegacy: (asset: string) => string;
|
|
|
14
14
|
export declare const wethToEthByAddress: (maybeWethAddr: string, chainId?: NetworkNumber) => string;
|
|
15
15
|
export declare const ethToWethByAddress: (maybeEthAddr: string, chainId?: NetworkNumber) => string;
|
|
16
16
|
export declare const bytesToString: (hex: string) => string;
|
|
17
|
-
/**
|
|
18
|
-
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
19
|
-
*/
|
|
20
|
-
export declare const mapRange: (input: number | string, minInput: number | string, maxInput: number | string, minOutput: number | string, maxOutput: number | string) => number;
|
package/esm/services/utils.js
CHANGED
|
@@ -19,14 +19,3 @@ export const bytesToString = (hex) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
|
19
19
|
.toString()
|
|
20
20
|
// eslint-disable-next-line no-control-regex
|
|
21
21
|
.replace(/\x00/g, '');
|
|
22
|
-
/**
|
|
23
|
-
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
24
|
-
*/
|
|
25
|
-
export const mapRange = (input, minInput, maxInput, minOutput, maxOutput) => {
|
|
26
|
-
// slope = 1.0 * (output_end - output_start) / (input_end - input_start)
|
|
27
|
-
const inputDiff = new Dec(maxInput).minus(minInput);
|
|
28
|
-
const outputDiff = new Dec(maxOutput).minus(minOutput);
|
|
29
|
-
const slope = new Dec(outputDiff).div(inputDiff);
|
|
30
|
-
// output = output_start + slope * (input - input_start)
|
|
31
|
-
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
32
|
-
};
|
|
@@ -138,9 +138,7 @@ export declare namespace CurveUsdView {
|
|
|
138
138
|
[
|
|
139
139
|
number | string | BN[],
|
|
140
140
|
number | string | BN[]
|
|
141
|
-
]
|
|
142
|
-
number | string | BN,
|
|
143
|
-
boolean
|
|
141
|
+
]
|
|
144
142
|
] | {
|
|
145
143
|
loanExists: boolean;
|
|
146
144
|
collateralPrice: number | string | BN;
|
|
@@ -154,8 +152,6 @@ export declare namespace CurveUsdView {
|
|
|
154
152
|
health: number | string | BN;
|
|
155
153
|
bandRange: [number | string | BN, number | string | BN];
|
|
156
154
|
usersBands: [number | string | BN[], number | string | BN[]];
|
|
157
|
-
collRatio: number | string | BN;
|
|
158
|
-
isInSoftLiquidation: boolean;
|
|
159
155
|
};
|
|
160
156
|
type UserDataStructOutputArray = [
|
|
161
157
|
boolean,
|
|
@@ -175,9 +171,7 @@ export declare namespace CurveUsdView {
|
|
|
175
171
|
[
|
|
176
172
|
string[],
|
|
177
173
|
string[]
|
|
178
|
-
]
|
|
179
|
-
string,
|
|
180
|
-
boolean
|
|
174
|
+
]
|
|
181
175
|
];
|
|
182
176
|
type UserDataStructOutputStruct = {
|
|
183
177
|
loanExists: boolean;
|
|
@@ -192,8 +186,6 @@ export declare namespace CurveUsdView {
|
|
|
192
186
|
health: string;
|
|
193
187
|
bandRange: [string, string];
|
|
194
188
|
usersBands: [string[], string[]];
|
|
195
|
-
collRatio: string;
|
|
196
|
-
isInSoftLiquidation: boolean;
|
|
197
189
|
};
|
|
198
190
|
type UserDataStructOutput = UserDataStructOutputArray & UserDataStructOutputStruct;
|
|
199
191
|
}
|
|
@@ -201,33 +193,15 @@ export interface CrvUSDView extends BaseContract {
|
|
|
201
193
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): CrvUSDView;
|
|
202
194
|
clone(): CrvUSDView;
|
|
203
195
|
methods: {
|
|
204
|
-
WBTC_HEALTH_ZAP(): NonPayableTransactionObject<string>;
|
|
205
|
-
WBTC_MARKET(): NonPayableTransactionObject<string>;
|
|
206
196
|
createLoanData(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.CreateLoanDataStructOutput>;
|
|
207
197
|
getBandData(market: string, n: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput>;
|
|
208
|
-
getBandsData(market: string,
|
|
209
|
-
|
|
210
|
-
getCollAmountsFromAMM(_controllerAddress: string, _user: string): NonPayableTransactionObject<[
|
|
211
|
-
string,
|
|
212
|
-
string
|
|
213
|
-
] & {
|
|
214
|
-
crvUsdAmount: string;
|
|
215
|
-
collAmount: string;
|
|
216
|
-
}>;
|
|
217
|
-
getCollateralRatio(_user: string, _controllerAddr: string): NonPayableTransactionObject<[
|
|
218
|
-
string,
|
|
219
|
-
boolean
|
|
220
|
-
] & {
|
|
221
|
-
collRatio: string;
|
|
222
|
-
isInSoftLiquidation: boolean;
|
|
223
|
-
}>;
|
|
198
|
+
"getBandsData(address,uint256,uint256,uint256)"(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
199
|
+
"getBandsData(address,int256,int256)"(market: string, from: number | string | BN, to: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
224
200
|
globalData(market: string): NonPayableTransactionObject<CurveUsdView.GlobalDataStructOutput>;
|
|
225
201
|
healthCalculator(market: string, user: string, collChange: number | string | BN, debtChange: number | string | BN, isFull: boolean, numBands: number | string | BN): NonPayableTransactionObject<string>;
|
|
226
|
-
isControllerValid(_controllerAddr: string): NonPayableTransactionObject<boolean>;
|
|
227
202
|
maxBorrow(market: string, collateral: number | string | BN, N: number | string | BN): NonPayableTransactionObject<string>;
|
|
228
203
|
minCollateral(market: string, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<string>;
|
|
229
204
|
userData(market: string, user: string): NonPayableTransactionObject<CurveUsdView.UserDataStructOutput>;
|
|
230
|
-
userMaxWithdraw(_controllerAddress: string, _user: string): NonPayableTransactionObject<string>;
|
|
231
205
|
};
|
|
232
206
|
events: {
|
|
233
207
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
package/esm/types/curveUsd.d.ts
CHANGED
|
@@ -67,12 +67,6 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
67
67
|
borrowedUsd: string;
|
|
68
68
|
borrowed: string;
|
|
69
69
|
safetyRatio: string;
|
|
70
|
-
borrowLimitUsd: string;
|
|
71
|
-
minAllowedRatio: number;
|
|
72
|
-
collFactor: string;
|
|
73
|
-
leveragedType: string;
|
|
74
|
-
leveragedAsset?: string;
|
|
75
|
-
liquidationPrice?: string;
|
|
76
70
|
}
|
|
77
71
|
export interface CrvUSDUsedAsset {
|
|
78
72
|
isSupplied: boolean;
|
package/package.json
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./cjs/index.js",
|
|
6
|
-
"module": "./esm/index.js",
|
|
7
|
-
"types": "./esm/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
10
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
-
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
-
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
|
-
"lint": "eslint src/ --fix",
|
|
14
|
-
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
-
"test": "mocha tests/*",
|
|
16
|
-
"build-test": "npm run build && mocha tests/*"
|
|
17
|
-
},
|
|
18
|
-
"keywords": [],
|
|
19
|
-
"author": "",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@defisaver/tokens": "^1.5.5",
|
|
23
|
-
"@ethersproject/bignumber": "^5.7.0",
|
|
24
|
-
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
|
-
"decimal.js": "^10.4.3"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
29
|
-
"chai": "^4.3.8",
|
|
30
|
-
"dotenv": "^16.3.1",
|
|
31
|
-
"eslint": "^8.49.0",
|
|
32
|
-
"mocha": "^10.2.0",
|
|
33
|
-
"typechain": "^8.3.1",
|
|
34
|
-
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
35
|
-
"typescript": "^5.2.2"
|
|
36
|
-
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"web3": "^1.10.2"
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@defisaver/positions-sdk",
|
|
3
|
+
"version": "0.0.29",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./cjs/index.js",
|
|
6
|
+
"module": "./esm/index.js",
|
|
7
|
+
"types": "./esm/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
10
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
11
|
+
"build": "npm run generate-contracts && npm run build:cjs && npm run build:esm",
|
|
12
|
+
"dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
|
|
13
|
+
"lint": "eslint src/ --fix",
|
|
14
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
15
|
+
"test": "mocha tests/*",
|
|
16
|
+
"build-test": "npm run build && mocha tests/*"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@defisaver/tokens": "^1.5.5",
|
|
23
|
+
"@ethersproject/bignumber": "^5.7.0",
|
|
24
|
+
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
|
+
"decimal.js": "^10.4.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
29
|
+
"chai": "^4.3.8",
|
|
30
|
+
"dotenv": "^16.3.1",
|
|
31
|
+
"eslint": "^8.49.0",
|
|
32
|
+
"mocha": "^10.2.0",
|
|
33
|
+
"typechain": "^8.3.1",
|
|
34
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
35
|
+
"typescript": "^5.2.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"web3": "^1.10.2"
|
|
39
|
+
}
|
|
40
|
+
}
|