@defisaver/positions-sdk 0.0.25 → 0.0.26
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 +8 -0
- package/cjs/config/contracts.js +6 -4
- package/cjs/curveUsd/index.js +1 -1
- package/cjs/helpers/curveUsdHelpers/index.d.ts +2 -1
- package/cjs/helpers/curveUsdHelpers/index.js +24 -17
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/services/utils.d.ts +4 -0
- package/cjs/services/utils.js +13 -1
- package/cjs/types/contracts/generated/CrvUSDView.d.ts +30 -4
- package/cjs/types/curveUsd.d.ts +6 -0
- package/esm/config/contracts.d.ts +8 -0
- package/esm/config/contracts.js +6 -4
- package/esm/curveUsd/index.js +1 -1
- package/esm/helpers/curveUsdHelpers/index.d.ts +2 -1
- package/esm/helpers/curveUsdHelpers/index.js +25 -18
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/services/utils.d.ts +4 -0
- package/esm/services/utils.js +11 -0
- package/esm/types/contracts/generated/CrvUSDView.d.ts +30 -4
- package/esm/types/curveUsd.d.ts +6 -0
- 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 +675 -673
- package/src/constants/index.ts +3 -3
- package/src/contracts.ts +100 -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 +40 -32
- 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 +48 -35
- 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 +43 -8
- package/src/types/curveUsd.ts +118 -112
- 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 +64 -0
|
@@ -10,26 +10,33 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import Dec from 'decimal.js';
|
|
13
|
-
import { getAssetsTotal } from '../../moneymarket';
|
|
13
|
+
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
14
|
+
import { mapRange } from '../../services/utils';
|
|
14
15
|
export const getCrvUsdAggregatedData = (_a) => {
|
|
15
|
-
var { loanExists, usedAssets, network, selectedMarket } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket"]);
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
var { loanExists, usedAssets, network, selectedMarket, numOfBands } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket", "numOfBands"]);
|
|
17
|
+
const payload = {};
|
|
18
|
+
payload.supplied = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
|
|
19
|
+
payload.borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
|
|
20
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
21
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
22
|
+
payload.ratio = loanExists
|
|
23
|
+
? new Dec(payload.suppliedUsd)
|
|
24
|
+
.dividedBy(payload.borrowedUsd)
|
|
23
25
|
.times(100)
|
|
24
26
|
.toString()
|
|
25
27
|
: '0';
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
// this is all approximation
|
|
29
|
+
payload.minAllowedRatio = mapRange(numOfBands, 4, 50, 115, 140); // collateral ratio
|
|
30
|
+
payload.collFactor = new Dec(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
|
|
31
|
+
// only take in consideration collAsset
|
|
32
|
+
payload.borrowLimitUsd = usedAssets[selectedMarket.collAsset].isSupplied
|
|
33
|
+
? new Dec(usedAssets[selectedMarket.collAsset].suppliedUsd).mul(payload.collFactor).toString()
|
|
34
|
+
: '0';
|
|
35
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
36
|
+
payload.leveragedType = leveragedType;
|
|
37
|
+
if (leveragedType !== '') {
|
|
38
|
+
payload.leveragedAsset = leveragedAsset;
|
|
39
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
40
|
+
}
|
|
41
|
+
return payload;
|
|
35
42
|
};
|
|
@@ -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', 'crvUSD'];
|
|
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,3 +14,7 @@ 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,3 +19,14 @@ 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,7 +138,9 @@ export declare namespace CurveUsdView {
|
|
|
138
138
|
[
|
|
139
139
|
number | string | BN[],
|
|
140
140
|
number | string | BN[]
|
|
141
|
-
]
|
|
141
|
+
],
|
|
142
|
+
number | string | BN,
|
|
143
|
+
boolean
|
|
142
144
|
] | {
|
|
143
145
|
loanExists: boolean;
|
|
144
146
|
collateralPrice: number | string | BN;
|
|
@@ -152,6 +154,8 @@ export declare namespace CurveUsdView {
|
|
|
152
154
|
health: number | string | BN;
|
|
153
155
|
bandRange: [number | string | BN, number | string | BN];
|
|
154
156
|
usersBands: [number | string | BN[], number | string | BN[]];
|
|
157
|
+
collRatio: number | string | BN;
|
|
158
|
+
isInSoftLiquidation: boolean;
|
|
155
159
|
};
|
|
156
160
|
type UserDataStructOutputArray = [
|
|
157
161
|
boolean,
|
|
@@ -171,7 +175,9 @@ export declare namespace CurveUsdView {
|
|
|
171
175
|
[
|
|
172
176
|
string[],
|
|
173
177
|
string[]
|
|
174
|
-
]
|
|
178
|
+
],
|
|
179
|
+
string,
|
|
180
|
+
boolean
|
|
175
181
|
];
|
|
176
182
|
type UserDataStructOutputStruct = {
|
|
177
183
|
loanExists: boolean;
|
|
@@ -186,6 +192,8 @@ export declare namespace CurveUsdView {
|
|
|
186
192
|
health: string;
|
|
187
193
|
bandRange: [string, string];
|
|
188
194
|
usersBands: [string[], string[]];
|
|
195
|
+
collRatio: string;
|
|
196
|
+
isInSoftLiquidation: boolean;
|
|
189
197
|
};
|
|
190
198
|
type UserDataStructOutput = UserDataStructOutputArray & UserDataStructOutputStruct;
|
|
191
199
|
}
|
|
@@ -193,15 +201,33 @@ export interface CrvUSDView extends BaseContract {
|
|
|
193
201
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): CrvUSDView;
|
|
194
202
|
clone(): CrvUSDView;
|
|
195
203
|
methods: {
|
|
204
|
+
WBTC_HEALTH_ZAP(): NonPayableTransactionObject<string>;
|
|
205
|
+
WBTC_MARKET(): NonPayableTransactionObject<string>;
|
|
196
206
|
createLoanData(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.CreateLoanDataStructOutput>;
|
|
197
207
|
getBandData(market: string, n: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput>;
|
|
198
|
-
|
|
199
|
-
|
|
208
|
+
getBandsData(market: string, from: number | string | BN, to: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
209
|
+
getBandsDataForPosition(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
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
|
+
}>;
|
|
200
224
|
globalData(market: string): NonPayableTransactionObject<CurveUsdView.GlobalDataStructOutput>;
|
|
201
225
|
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>;
|
|
202
227
|
maxBorrow(market: string, collateral: number | string | BN, N: number | string | BN): NonPayableTransactionObject<string>;
|
|
203
228
|
minCollateral(market: string, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<string>;
|
|
204
229
|
userData(market: string, user: string): NonPayableTransactionObject<CurveUsdView.UserDataStructOutput>;
|
|
230
|
+
userMaxWithdraw(_controllerAddress: string, _user: string): NonPayableTransactionObject<string>;
|
|
205
231
|
};
|
|
206
232
|
events: {
|
|
207
233
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
package/esm/types/curveUsd.d.ts
CHANGED
|
@@ -67,6 +67,12 @@ 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;
|
|
70
76
|
}
|
|
71
77
|
export interface CrvUSDUsedAsset {
|
|
72
78
|
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.26",
|
|
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
|
+
}
|