@defisaver/positions-sdk 0.0.24 → 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/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/spark/index.js +1 -0
- 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/spark/index.js +1 -0
- package/esm/types/contracts/generated/CrvUSDView.d.ts +30 -4
- package/esm/types/curveUsd.d.ts +6 -0
- package/package.json +1 -1
- package/src/config/contracts.js +6 -4
- package/src/curveUsd/index.ts +1 -1
- package/src/helpers/curveUsdHelpers/index.ts +28 -20
- package/src/moneymarket/moneymarketCommonService.ts +1 -1
- package/src/services/utils.ts +14 -1
- package/src/spark/index.ts +1 -0
- package/src/types/contracts/generated/CrvUSDView.ts +43 -8
- package/src/types/curveUsd.ts +6 -0
- package/yarn-error.log +64 -0
- package/.yarn/releases/yarn-1.22.1.cjs +0 -147386
- package/.yarn/releases/yarn-1.22.1.js +0 -147386
- package/.yarnrc.yml +0 -1
- package/package-lock.json +0 -12896
|
@@ -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
package/src/config/contracts.js
CHANGED
|
@@ -527,13 +527,15 @@ module.exports = {
|
|
|
527
527
|
}
|
|
528
528
|
},
|
|
529
529
|
"crvUSDView": {
|
|
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":"
|
|
530
|
+
"abi": [{"inputs":[],"name":"CurveUsdInvalidController","type":"error"},{"inputs":[],"name":"WBTC_HEALTH_ZAP","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WBTC_MARKET","outputs":[{"internalType":"address","name":"","type":"address"}],"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":"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":"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"},{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"uint256","name":"debt","type":"uint256"},{"internalType":"uint256","name":"N","type":"uint256"}],"name":"getBandsDataForPosition","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":"_controllerAddress","type":"address"},{"internalType":"address","name":"_user","type":"address"}],"name":"getCollAmountsFromAMM","outputs":[{"internalType":"uint256","name":"crvUsdAmount","type":"uint256"},{"internalType":"uint256","name":"collAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address","name":"_controllerAddr","type":"address"}],"name":"getCollateralRatio","outputs":[{"internalType":"uint256","name":"collRatio","type":"uint256"},{"internalType":"bool","name":"isInSoftLiquidation","type":"bool"}],"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":"health","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_controllerAddr","type":"address"}],"name":"isControllerValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":"uint256","name":"collRatio","type":"uint256"},{"internalType":"bool","name":"isInSoftLiquidation","type":"bool"}],"internalType":"struct CurveUsdView.UserData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_controllerAddress","type":"address"},{"internalType":"address","name":"_user","type":"address"}],"name":"userMaxWithdraw","outputs":[{"internalType":"uint256","name":"maxWithdraw","type":"uint256"}],"stateMutability":"view","type":"function"}],
|
|
531
531
|
"networks": {
|
|
532
532
|
"1": {
|
|
533
|
-
"address": "
|
|
534
|
-
"createdBlock":
|
|
533
|
+
"address": "0x4BbCf0e587853aAEdFC3E60f74C10E07D8deA701",
|
|
534
|
+
"createdBlock": 18823384,
|
|
535
535
|
"oldVersions": {
|
|
536
|
-
"17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95"
|
|
536
|
+
"17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95",
|
|
537
|
+
"17683243": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
|
|
538
|
+
"18419795": "0x4df1281f9d2303be453e0085881702a4b1358692",
|
|
537
539
|
}
|
|
538
540
|
}
|
|
539
541
|
}
|
package/src/curveUsd/index.ts
CHANGED
|
@@ -216,7 +216,7 @@ export const getCurveUsdUserData = async (web3: Web3, network: NetworkNumber, ad
|
|
|
216
216
|
usedAssets,
|
|
217
217
|
status,
|
|
218
218
|
...getCrvUsdAggregatedData({
|
|
219
|
-
loanExists: data.loanExists, usedAssets, network: NetworkNumber.Eth, selectedMarket,
|
|
219
|
+
loanExists: data.loanExists, usedAssets, network: NetworkNumber.Eth, selectedMarket, numOfBands: data.N,
|
|
220
220
|
}),
|
|
221
221
|
userBands,
|
|
222
222
|
};
|
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { CrvUSDAggregatedPositionData, CrvUSDMarketData, CrvUSDUsedAssets } from '../../types';
|
|
3
|
-
import { NetworkNumber } from '../../types/common';
|
|
4
|
-
import { getAssetsTotal } from '../../moneymarket';
|
|
3
|
+
import { MMUsedAssets, NetworkNumber } from '../../types/common';
|
|
4
|
+
import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
|
|
5
|
+
import { mapRange } from '../../services/utils';
|
|
5
6
|
|
|
6
7
|
export const getCrvUsdAggregatedData = ({
|
|
7
|
-
loanExists, usedAssets, network, selectedMarket, ...rest
|
|
8
|
+
loanExists, usedAssets, network, selectedMarket, numOfBands, ...rest
|
|
8
9
|
}:{
|
|
9
|
-
loanExists: boolean, usedAssets: CrvUSDUsedAssets, network: NetworkNumber, selectedMarket: CrvUSDMarketData,
|
|
10
|
+
loanExists: boolean, usedAssets: CrvUSDUsedAssets, network: NetworkNumber, selectedMarket: CrvUSDMarketData, numOfBands: number | string
|
|
10
11
|
}): CrvUSDAggregatedPositionData => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const payload = {} as CrvUSDAggregatedPositionData;
|
|
13
|
+
payload.supplied = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ supplied }: { supplied: string }) => supplied); // this is wrong if we are in soft-liquidations
|
|
14
|
+
payload.borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowed }: { borrowed: string }) => borrowed);
|
|
15
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
16
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
? new Dec(
|
|
18
|
-
.dividedBy(
|
|
18
|
+
payload.ratio = loanExists
|
|
19
|
+
? new Dec(payload.suppliedUsd)
|
|
20
|
+
.dividedBy(payload.borrowedUsd)
|
|
19
21
|
.times(100)
|
|
20
22
|
.toString()
|
|
21
23
|
: '0';
|
|
22
24
|
|
|
23
|
-
//
|
|
25
|
+
// this is all approximation
|
|
26
|
+
payload.minAllowedRatio = mapRange(numOfBands, 4, 50, 115, 140); // collateral ratio
|
|
27
|
+
payload.collFactor = new Dec(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
|
|
28
|
+
// only take in consideration collAsset
|
|
29
|
+
payload.borrowLimitUsd = usedAssets[selectedMarket.collAsset].isSupplied
|
|
30
|
+
? new Dec(usedAssets[selectedMarket.collAsset].suppliedUsd).mul(payload.collFactor).toString()
|
|
31
|
+
: '0';
|
|
32
|
+
|
|
33
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets as unknown as MMUsedAssets);
|
|
34
|
+
payload.leveragedType = leveragedType;
|
|
35
|
+
if (leveragedType !== '') {
|
|
36
|
+
payload.leveragedAsset = leveragedAsset;
|
|
37
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
38
|
+
}
|
|
24
39
|
|
|
25
|
-
return
|
|
26
|
-
ratio,
|
|
27
|
-
supplied: _supplied,
|
|
28
|
-
suppliedUsd: _suppliedUsd,
|
|
29
|
-
borrowedUsd: _borrowedUsd,
|
|
30
|
-
borrowed: _borrowed,
|
|
31
|
-
safetyRatio: ratio,
|
|
32
|
-
};
|
|
40
|
+
return payload;
|
|
33
41
|
};
|
|
@@ -20,7 +20,7 @@ export const calcLeverageLiqPrice = (leverageType: string, assetPrice: string, b
|
|
|
20
20
|
|
|
21
21
|
export const calculateBorrowingAssetLimit = (assetBorrowedUsd: string, borrowLimitUsd: string) => new Dec(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
|
|
22
22
|
|
|
23
|
-
export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI'];
|
|
23
|
+
export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'];
|
|
24
24
|
|
|
25
25
|
export const isLeveragedPos = (usedAssets: MMUsedAssets, dustLimit = 5) => {
|
|
26
26
|
let borrowUnstable = 0;
|
package/src/services/utils.ts
CHANGED
|
@@ -32,4 +32,17 @@ export const ethToWethByAddress = (maybeEthAddr: string, chainId = NetworkNumber
|
|
|
32
32
|
export const bytesToString = (hex: string) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
33
33
|
.toString()
|
|
34
34
|
// eslint-disable-next-line no-control-regex
|
|
35
|
-
.replace(/\x00/g, '');
|
|
35
|
+
.replace(/\x00/g, '');
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
39
|
+
*/
|
|
40
|
+
export const mapRange = (input: number | string, minInput: number | string, maxInput: number | string, minOutput:number | string, maxOutput: number | string) => {
|
|
41
|
+
// slope = 1.0 * (output_end - output_start) / (input_end - input_start)
|
|
42
|
+
const inputDiff = new Dec(maxInput).minus(minInput);
|
|
43
|
+
const outputDiff = new Dec(maxOutput).minus(minOutput);
|
|
44
|
+
const slope = new Dec(outputDiff).div(inputDiff);
|
|
45
|
+
|
|
46
|
+
// output = output_start + slope * (input - input_start)
|
|
47
|
+
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
48
|
+
};
|
package/src/spark/index.ts
CHANGED
|
@@ -124,6 +124,7 @@ export const getSparkMarketsData = async (web3: Web3, network: NetworkNumber, se
|
|
|
124
124
|
price: new Dec(market.price.toString()).div(1e8).toString(), // is actually price in USD
|
|
125
125
|
isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
|
|
126
126
|
isFlashLoanEnabled: market.isFlashLoanEnabled,
|
|
127
|
+
aTokenAddress: market.aTokenAddress,
|
|
127
128
|
eModeCategoryData: {
|
|
128
129
|
label: market.label,
|
|
129
130
|
liquidationBonus: new Dec(market.liquidationBonus).div(10000).toString(),
|
|
@@ -159,7 +159,9 @@ export declare namespace CurveUsdView {
|
|
|
159
159
|
number | string | BN,
|
|
160
160
|
number | string | BN,
|
|
161
161
|
[number | string | BN, number | string | BN],
|
|
162
|
-
[number | string | BN[], number | string | BN[]]
|
|
162
|
+
[number | string | BN[], number | string | BN[]],
|
|
163
|
+
number | string | BN,
|
|
164
|
+
boolean
|
|
163
165
|
]
|
|
164
166
|
| {
|
|
165
167
|
loanExists: boolean;
|
|
@@ -174,6 +176,8 @@ export declare namespace CurveUsdView {
|
|
|
174
176
|
health: number | string | BN;
|
|
175
177
|
bandRange: [number | string | BN, number | string | BN];
|
|
176
178
|
usersBands: [number | string | BN[], number | string | BN[]];
|
|
179
|
+
collRatio: number | string | BN;
|
|
180
|
+
isInSoftLiquidation: boolean;
|
|
177
181
|
};
|
|
178
182
|
|
|
179
183
|
export type UserDataStructOutputArray = [
|
|
@@ -188,7 +192,9 @@ export declare namespace CurveUsdView {
|
|
|
188
192
|
string,
|
|
189
193
|
string,
|
|
190
194
|
[string, string],
|
|
191
|
-
[string[], string[]]
|
|
195
|
+
[string[], string[]],
|
|
196
|
+
string,
|
|
197
|
+
boolean
|
|
192
198
|
];
|
|
193
199
|
export type UserDataStructOutputStruct = {
|
|
194
200
|
loanExists: boolean;
|
|
@@ -203,6 +209,8 @@ export declare namespace CurveUsdView {
|
|
|
203
209
|
health: string;
|
|
204
210
|
bandRange: [string, string];
|
|
205
211
|
usersBands: [string[], string[]];
|
|
212
|
+
collRatio: string;
|
|
213
|
+
isInSoftLiquidation: boolean;
|
|
206
214
|
};
|
|
207
215
|
export type UserDataStructOutput = UserDataStructOutputArray &
|
|
208
216
|
UserDataStructOutputStruct;
|
|
@@ -216,6 +224,10 @@ export interface CrvUSDView extends BaseContract {
|
|
|
216
224
|
): CrvUSDView;
|
|
217
225
|
clone(): CrvUSDView;
|
|
218
226
|
methods: {
|
|
227
|
+
WBTC_HEALTH_ZAP(): NonPayableTransactionObject<string>;
|
|
228
|
+
|
|
229
|
+
WBTC_MARKET(): NonPayableTransactionObject<string>;
|
|
230
|
+
|
|
219
231
|
createLoanData(
|
|
220
232
|
market: string,
|
|
221
233
|
collateral: number | string | BN,
|
|
@@ -228,18 +240,32 @@ export interface CrvUSDView extends BaseContract {
|
|
|
228
240
|
n: number | string | BN
|
|
229
241
|
): NonPayableTransactionObject<CurveUsdView.BandStructOutput>;
|
|
230
242
|
|
|
231
|
-
|
|
243
|
+
getBandsData(
|
|
244
|
+
market: string,
|
|
245
|
+
from: number | string | BN,
|
|
246
|
+
to: number | string | BN
|
|
247
|
+
): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
248
|
+
|
|
249
|
+
getBandsDataForPosition(
|
|
232
250
|
market: string,
|
|
233
251
|
collateral: number | string | BN,
|
|
234
252
|
debt: number | string | BN,
|
|
235
253
|
N: number | string | BN
|
|
236
254
|
): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
237
255
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
256
|
+
getCollAmountsFromAMM(
|
|
257
|
+
_controllerAddress: string,
|
|
258
|
+
_user: string
|
|
259
|
+
): NonPayableTransactionObject<
|
|
260
|
+
[string, string] & { crvUsdAmount: string; collAmount: string }
|
|
261
|
+
>;
|
|
262
|
+
|
|
263
|
+
getCollateralRatio(
|
|
264
|
+
_user: string,
|
|
265
|
+
_controllerAddr: string
|
|
266
|
+
): NonPayableTransactionObject<
|
|
267
|
+
[string, boolean] & { collRatio: string; isInSoftLiquidation: boolean }
|
|
268
|
+
>;
|
|
243
269
|
|
|
244
270
|
globalData(
|
|
245
271
|
market: string
|
|
@@ -254,6 +280,10 @@ export interface CrvUSDView extends BaseContract {
|
|
|
254
280
|
numBands: number | string | BN
|
|
255
281
|
): NonPayableTransactionObject<string>;
|
|
256
282
|
|
|
283
|
+
isControllerValid(
|
|
284
|
+
_controllerAddr: string
|
|
285
|
+
): NonPayableTransactionObject<boolean>;
|
|
286
|
+
|
|
257
287
|
maxBorrow(
|
|
258
288
|
market: string,
|
|
259
289
|
collateral: number | string | BN,
|
|
@@ -270,6 +300,11 @@ export interface CrvUSDView extends BaseContract {
|
|
|
270
300
|
market: string,
|
|
271
301
|
user: string
|
|
272
302
|
): NonPayableTransactionObject<CurveUsdView.UserDataStructOutput>;
|
|
303
|
+
|
|
304
|
+
userMaxWithdraw(
|
|
305
|
+
_controllerAddress: string,
|
|
306
|
+
_user: string
|
|
307
|
+
): NonPayableTransactionObject<string>;
|
|
273
308
|
};
|
|
274
309
|
events: {
|
|
275
310
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|
package/src/types/curveUsd.ts
CHANGED
|
@@ -74,6 +74,12 @@ export interface CrvUSDAggregatedPositionData {
|
|
|
74
74
|
borrowedUsd: string,
|
|
75
75
|
borrowed: string,
|
|
76
76
|
safetyRatio: string,
|
|
77
|
+
borrowLimitUsd: string,
|
|
78
|
+
minAllowedRatio: number,
|
|
79
|
+
collFactor: string,
|
|
80
|
+
leveragedType: string,
|
|
81
|
+
leveragedAsset?: string,
|
|
82
|
+
liquidationPrice?: string,
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
export interface CrvUSDUsedAsset {
|
package/yarn-error.log
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
Arguments:
|
|
2
|
+
/Users/stefan/.nvm/versions/node/v14.19.0/bin/node /usr/local/Cellar/yarn/1.22.19/libexec/bin/yarn.js
|
|
3
|
+
|
|
4
|
+
PATH:
|
|
5
|
+
/Users/stefan/.nvm/versions/node/v14.19.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/go/bin:/Users/stefan/WebstormProjects/defisaver-positions-sdk/node_modules/.bin:/usr/local/go
|
|
6
|
+
|
|
7
|
+
Yarn version:
|
|
8
|
+
1.22.19
|
|
9
|
+
|
|
10
|
+
Node version:
|
|
11
|
+
14.19.0
|
|
12
|
+
|
|
13
|
+
Platform:
|
|
14
|
+
darwin x64
|
|
15
|
+
|
|
16
|
+
Trace:
|
|
17
|
+
Error: incorrect data check
|
|
18
|
+
at Zlib.zlibOnError [as onerror] (zlib.js:187:17)
|
|
19
|
+
|
|
20
|
+
npm manifest:
|
|
21
|
+
{
|
|
22
|
+
"name": "defisaver-positions-sdk",
|
|
23
|
+
"version": "0.0.1",
|
|
24
|
+
"description": "",
|
|
25
|
+
"main": "./cjs/index.js",
|
|
26
|
+
"module": "./esm/src/index.js",
|
|
27
|
+
"types": "./esm/src/index.d.ts",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
30
|
+
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
31
|
+
"build": "npm run build:cjs && npm run build:esm",
|
|
32
|
+
"dev": "tsc -p tsconfig.cjs.json --watch",
|
|
33
|
+
"lint": "eslint src/ --fix",
|
|
34
|
+
"generate-contracts": "node scripts/generateContracts.js",
|
|
35
|
+
"test": "mocha tests/*",
|
|
36
|
+
"build-test": "npm run build && mocha tests/*"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [],
|
|
39
|
+
"author": "",
|
|
40
|
+
"license": "ISC",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@defisaver/tokens": "^1.4.56",
|
|
43
|
+
"decimal.js": "^10.4.3"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@defisaver/eslint-config": "^1.0.1",
|
|
47
|
+
"chai": "^4.3.8",
|
|
48
|
+
"dotenv": "^16.3.1",
|
|
49
|
+
"eslint": "^8.49.0",
|
|
50
|
+
"mocha": "^10.2.0",
|
|
51
|
+
"typechain": "^8.3.1",
|
|
52
|
+
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
53
|
+
"typescript": "^5.2.2"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"web3": "^1.10.2"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
yarn manifest:
|
|
61
|
+
No manifest
|
|
62
|
+
|
|
63
|
+
Lockfile:
|
|
64
|
+
No lockfile
|