@defisaver/positions-sdk 0.0.18 → 0.0.19
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/helpers/aaveHelpers/index.js +5 -0
- package/cjs/liquity/index.d.ts +1 -0
- package/cjs/liquity/index.js +15 -2
- package/cjs/types/aave.d.ts +5 -0
- package/cjs/types/liquity.d.ts +1 -0
- package/esm/helpers/aaveHelpers/index.js +5 -0
- package/esm/liquity/index.d.ts +1 -0
- package/esm/liquity/index.js +13 -1
- package/esm/types/aave.d.ts +5 -0
- package/esm/types/liquity.d.ts +1 -0
- package/package.json +1 -1
- package/src/helpers/aaveHelpers/index.ts +7 -0
- package/src/liquity/index.ts +14 -1
- package/src/types/aave.ts +5 -0
- package/src/types/liquity.ts +1 -0
|
@@ -114,6 +114,11 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
114
114
|
}
|
|
115
115
|
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
116
116
|
}
|
|
117
|
+
payload.suppliedEth = new decimal_js_1.default(payload.suppliedUsd).div(assetsData.ETH.price).toString();
|
|
118
|
+
payload.borrowedEth = new decimal_js_1.default(payload.borrowedUsd).div(assetsData.ETH.price).toString();
|
|
119
|
+
payload.leftToBorrowEth = new decimal_js_1.default(payload.leftToBorrowUsd).div(assetsData.ETH.price).toString();
|
|
120
|
+
payload.borrowLimitEth = new decimal_js_1.default(payload.borrowLimitUsd).div(assetsData.ETH.price).toString();
|
|
121
|
+
payload.liquidationLimitEth = new decimal_js_1.default(payload.liquidationLimitUsd).div(assetsData.ETH.price).toString();
|
|
117
122
|
return payload;
|
|
118
123
|
};
|
|
119
124
|
exports.aaveAnyGetAggregatedPositionData = aaveAnyGetAggregatedPositionData;
|
package/cjs/liquity/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import { LiquityTroveInfo } from '../types';
|
|
|
4
4
|
export declare const LIQUITY_NORMAL_MODE_RATIO = 110;
|
|
5
5
|
export declare const LIQUITY_RECOVERY_MODE_RATIO = 150;
|
|
6
6
|
export declare const getLiquityAccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
7
|
+
export declare const getDebtInFront: (viewContract: any, address: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
7
8
|
export declare const getLiquityTroveInfo: (web3: Web3, network: NetworkNumber, address: string) => Promise<LiquityTroveInfo>;
|
package/cjs/liquity/index.js
CHANGED
|
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getLiquityTroveInfo = exports.getLiquityAccountBalances = exports.LIQUITY_RECOVERY_MODE_RATIO = exports.LIQUITY_NORMAL_MODE_RATIO = void 0;
|
|
15
|
+
exports.getLiquityTroveInfo = exports.getDebtInFront = exports.getLiquityAccountBalances = exports.LIQUITY_RECOVERY_MODE_RATIO = exports.LIQUITY_NORMAL_MODE_RATIO = void 0;
|
|
16
16
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
17
|
const tokens_1 = require("@defisaver/tokens");
|
|
18
18
|
const contracts_1 = require("../contracts");
|
|
19
19
|
const multicall_1 = require("../multicall");
|
|
20
20
|
const types_1 = require("../types");
|
|
21
|
+
const constants_1 = require("../constants");
|
|
21
22
|
exports.LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
|
|
22
23
|
exports.LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
|
|
23
24
|
const getLiquityAccountBalances = (web3, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -41,6 +42,14 @@ const getLiquityAccountBalances = (web3, network, block, addressMapping, address
|
|
|
41
42
|
return balances;
|
|
42
43
|
});
|
|
43
44
|
exports.getLiquityAccountBalances = getLiquityAccountBalances;
|
|
45
|
+
const _getDebtInFront = (viewContract, address, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getDebtInFront(address, accumulatedSum, iterations).call(); });
|
|
46
|
+
const getDebtInFront = (viewContract, address, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const { debt, next } = yield _getDebtInFront(viewContract, address, accumulatedSum, iterations);
|
|
48
|
+
if (next === constants_1.ZERO_ADDRESS)
|
|
49
|
+
return (0, tokens_1.assetAmountInEth)(debt, 'LUSD');
|
|
50
|
+
return (0, exports.getDebtInFront)(viewContract, next, debt, iterations);
|
|
51
|
+
});
|
|
52
|
+
exports.getDebtInFront = getDebtInFront;
|
|
44
53
|
const getLiquityTroveInfo = (web3, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
54
|
const viewContract = (0, contracts_1.LiquityViewContract)(web3, network);
|
|
46
55
|
const collSurplusPoolContract = (0, contracts_1.LiquityCollSurplusPoolContract)(web3, network);
|
|
@@ -79,7 +88,10 @@ const getLiquityTroveInfo = (web3, network, address) => __awaiter(void 0, void 0
|
|
|
79
88
|
params: [],
|
|
80
89
|
},
|
|
81
90
|
];
|
|
82
|
-
const multiRes = yield
|
|
91
|
+
const [multiRes, debtInFront] = yield Promise.all([
|
|
92
|
+
(0, multicall_1.multicall)(multicallData, web3, network),
|
|
93
|
+
(0, exports.getDebtInFront)(viewContract, address),
|
|
94
|
+
]);
|
|
83
95
|
const recoveryMode = multiRes[0][6];
|
|
84
96
|
const totalETH = multiRes[4][0];
|
|
85
97
|
const totalLUSD = multiRes[5][0];
|
|
@@ -94,6 +106,7 @@ const getLiquityTroveInfo = (web3, network, address) => __awaiter(void 0, void 0
|
|
|
94
106
|
assetPrice: (0, tokens_1.assetAmountInEth)(multiRes[3][0]),
|
|
95
107
|
totalETH,
|
|
96
108
|
totalLUSD,
|
|
109
|
+
debtInFront,
|
|
97
110
|
minCollateralRatio: recoveryMode ? exports.LIQUITY_RECOVERY_MODE_RATIO : exports.LIQUITY_NORMAL_MODE_RATIO,
|
|
98
111
|
priceForRecovery: new decimal_js_1.default(recoveryMode ? exports.LIQUITY_RECOVERY_MODE_RATIO : exports.LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
|
|
99
112
|
.toString(),
|
package/cjs/types/aave.d.ts
CHANGED
|
@@ -199,11 +199,16 @@ export interface AaveV3IncentiveData {
|
|
|
199
199
|
}
|
|
200
200
|
export interface AaveV3AggregatedPositionData {
|
|
201
201
|
suppliedUsd: string;
|
|
202
|
+
suppliedEth: string;
|
|
202
203
|
suppliedCollateralUsd: string;
|
|
203
204
|
borrowedUsd: string;
|
|
205
|
+
borrowedEth: string;
|
|
204
206
|
borrowLimitUsd: string;
|
|
207
|
+
borrowLimitEth: string;
|
|
205
208
|
liquidationLimitUsd: string;
|
|
209
|
+
liquidationLimitEth: string;
|
|
206
210
|
leftToBorrowUsd: string;
|
|
211
|
+
leftToBorrowEth: string;
|
|
207
212
|
ratio: string;
|
|
208
213
|
collRatio: string;
|
|
209
214
|
netApy: string;
|
package/cjs/types/liquity.d.ts
CHANGED
|
@@ -98,5 +98,10 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
98
98
|
}
|
|
99
99
|
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
100
100
|
}
|
|
101
|
+
payload.suppliedEth = new Dec(payload.suppliedUsd).div(assetsData.ETH.price).toString();
|
|
102
|
+
payload.borrowedEth = new Dec(payload.borrowedUsd).div(assetsData.ETH.price).toString();
|
|
103
|
+
payload.leftToBorrowEth = new Dec(payload.leftToBorrowUsd).div(assetsData.ETH.price).toString();
|
|
104
|
+
payload.borrowLimitEth = new Dec(payload.borrowLimitUsd).div(assetsData.ETH.price).toString();
|
|
105
|
+
payload.liquidationLimitEth = new Dec(payload.liquidationLimitUsd).div(assetsData.ETH.price).toString();
|
|
101
106
|
return payload;
|
|
102
107
|
};
|
package/esm/liquity/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import { LiquityTroveInfo } from '../types';
|
|
|
4
4
|
export declare const LIQUITY_NORMAL_MODE_RATIO = 110;
|
|
5
5
|
export declare const LIQUITY_RECOVERY_MODE_RATIO = 150;
|
|
6
6
|
export declare const getLiquityAccountBalances: (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, address: EthAddress) => Promise<PositionBalances>;
|
|
7
|
+
export declare const getDebtInFront: (viewContract: any, address: string, accumulatedSum?: string, iterations?: number) => Promise<string>;
|
|
7
8
|
export declare const getLiquityTroveInfo: (web3: Web3, network: NetworkNumber, address: string) => Promise<LiquityTroveInfo>;
|
package/esm/liquity/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
|
12
12
|
import { LiquityActivePoolContract, LiquityCollSurplusPoolContract, LiquityPriceFeedContract, LiquityTroveManagerContract, LiquityViewContract, } from '../contracts';
|
|
13
13
|
import { multicall } from '../multicall';
|
|
14
14
|
import { LIQUITY_TROVE_STATUS_ENUM } from '../types';
|
|
15
|
+
import { ZERO_ADDRESS } from '../constants';
|
|
15
16
|
export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
|
|
16
17
|
export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
|
|
17
18
|
export const getLiquityAccountBalances = (web3, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -34,6 +35,13 @@ export const getLiquityAccountBalances = (web3, network, block, addressMapping,
|
|
|
34
35
|
};
|
|
35
36
|
return balances;
|
|
36
37
|
});
|
|
38
|
+
const _getDebtInFront = (viewContract, address, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () { return viewContract.methods.getDebtInFront(address, accumulatedSum, iterations).call(); });
|
|
39
|
+
export const getDebtInFront = (viewContract, address, accumulatedSum = '0', iterations = 2000) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const { debt, next } = yield _getDebtInFront(viewContract, address, accumulatedSum, iterations);
|
|
41
|
+
if (next === ZERO_ADDRESS)
|
|
42
|
+
return assetAmountInEth(debt, 'LUSD');
|
|
43
|
+
return getDebtInFront(viewContract, next, debt, iterations);
|
|
44
|
+
});
|
|
37
45
|
export const getLiquityTroveInfo = (web3, network, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
46
|
const viewContract = LiquityViewContract(web3, network);
|
|
39
47
|
const collSurplusPoolContract = LiquityCollSurplusPoolContract(web3, network);
|
|
@@ -72,7 +80,10 @@ export const getLiquityTroveInfo = (web3, network, address) => __awaiter(void 0,
|
|
|
72
80
|
params: [],
|
|
73
81
|
},
|
|
74
82
|
];
|
|
75
|
-
const multiRes = yield
|
|
83
|
+
const [multiRes, debtInFront] = yield Promise.all([
|
|
84
|
+
multicall(multicallData, web3, network),
|
|
85
|
+
getDebtInFront(viewContract, address),
|
|
86
|
+
]);
|
|
76
87
|
const recoveryMode = multiRes[0][6];
|
|
77
88
|
const totalETH = multiRes[4][0];
|
|
78
89
|
const totalLUSD = multiRes[5][0];
|
|
@@ -87,6 +98,7 @@ export const getLiquityTroveInfo = (web3, network, address) => __awaiter(void 0,
|
|
|
87
98
|
assetPrice: assetAmountInEth(multiRes[3][0]),
|
|
88
99
|
totalETH,
|
|
89
100
|
totalLUSD,
|
|
101
|
+
debtInFront,
|
|
90
102
|
minCollateralRatio: recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO,
|
|
91
103
|
priceForRecovery: new Dec(recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
|
|
92
104
|
.toString(),
|
package/esm/types/aave.d.ts
CHANGED
|
@@ -199,11 +199,16 @@ export interface AaveV3IncentiveData {
|
|
|
199
199
|
}
|
|
200
200
|
export interface AaveV3AggregatedPositionData {
|
|
201
201
|
suppliedUsd: string;
|
|
202
|
+
suppliedEth: string;
|
|
202
203
|
suppliedCollateralUsd: string;
|
|
203
204
|
borrowedUsd: string;
|
|
205
|
+
borrowedEth: string;
|
|
204
206
|
borrowLimitUsd: string;
|
|
207
|
+
borrowLimitEth: string;
|
|
205
208
|
liquidationLimitUsd: string;
|
|
209
|
+
liquidationLimitEth: string;
|
|
206
210
|
leftToBorrowUsd: string;
|
|
211
|
+
leftToBorrowEth: string;
|
|
207
212
|
ratio: string;
|
|
208
213
|
collRatio: string;
|
|
209
214
|
netApy: string;
|
package/esm/types/liquity.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -131,5 +131,12 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
131
131
|
}
|
|
132
132
|
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
payload.suppliedEth = new Dec(payload.suppliedUsd).div(assetsData.ETH.price).toString();
|
|
136
|
+
payload.borrowedEth = new Dec(payload.borrowedUsd).div(assetsData.ETH.price).toString();
|
|
137
|
+
payload.leftToBorrowEth = new Dec(payload.leftToBorrowUsd).div(assetsData.ETH.price).toString();
|
|
138
|
+
payload.borrowLimitEth = new Dec(payload.borrowLimitUsd).div(assetsData.ETH.price).toString();
|
|
139
|
+
payload.liquidationLimitEth = new Dec(payload.liquidationLimitUsd).div(assetsData.ETH.price).toString();
|
|
140
|
+
|
|
134
141
|
return payload;
|
|
135
142
|
};
|
package/src/liquity/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '../contracts';
|
|
10
10
|
import { multicall } from '../multicall';
|
|
11
11
|
import { LIQUITY_TROVE_STATUS_ENUM, LiquityTroveInfo } from '../types';
|
|
12
|
+
import { ZERO_ADDRESS } from '../constants';
|
|
12
13
|
|
|
13
14
|
export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
|
|
14
15
|
export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
|
|
@@ -38,6 +39,14 @@ export const getLiquityAccountBalances = async (web3: Web3, network: NetworkNumb
|
|
|
38
39
|
return balances;
|
|
39
40
|
};
|
|
40
41
|
|
|
42
|
+
const _getDebtInFront = async (viewContract: any, address: string, accumulatedSum = '0', iterations = 2000) => viewContract.methods.getDebtInFront(address, accumulatedSum, iterations).call();
|
|
43
|
+
|
|
44
|
+
export const getDebtInFront = async (viewContract: any, address: string, accumulatedSum = '0', iterations = 2000): Promise<string> => {
|
|
45
|
+
const { debt, next } = await _getDebtInFront(viewContract, address, accumulatedSum, iterations);
|
|
46
|
+
if (next === ZERO_ADDRESS) return assetAmountInEth(debt, 'LUSD');
|
|
47
|
+
return getDebtInFront(viewContract, next, debt, iterations);
|
|
48
|
+
};
|
|
49
|
+
|
|
41
50
|
export const getLiquityTroveInfo = async (web3: Web3, network: NetworkNumber, address: string): Promise<LiquityTroveInfo> => {
|
|
42
51
|
const viewContract = LiquityViewContract(web3, network);
|
|
43
52
|
const collSurplusPoolContract = LiquityCollSurplusPoolContract(web3, network);
|
|
@@ -78,7 +87,10 @@ export const getLiquityTroveInfo = async (web3: Web3, network: NetworkNumber, ad
|
|
|
78
87
|
},
|
|
79
88
|
];
|
|
80
89
|
|
|
81
|
-
const multiRes = await
|
|
90
|
+
const [multiRes, debtInFront] = await Promise.all([
|
|
91
|
+
multicall(multicallData, web3, network),
|
|
92
|
+
getDebtInFront(viewContract, address),
|
|
93
|
+
]);
|
|
82
94
|
|
|
83
95
|
const recoveryMode = multiRes[0][6];
|
|
84
96
|
const totalETH = multiRes[4][0];
|
|
@@ -95,6 +107,7 @@ export const getLiquityTroveInfo = async (web3: Web3, network: NetworkNumber, ad
|
|
|
95
107
|
assetPrice: assetAmountInEth(multiRes[3][0]),
|
|
96
108
|
totalETH,
|
|
97
109
|
totalLUSD,
|
|
110
|
+
debtInFront,
|
|
98
111
|
minCollateralRatio: recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO,
|
|
99
112
|
priceForRecovery: new Dec(recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
|
|
100
113
|
.toString(),
|
package/src/types/aave.ts
CHANGED
|
@@ -222,11 +222,16 @@ export interface AaveV3IncentiveData {
|
|
|
222
222
|
|
|
223
223
|
export interface AaveV3AggregatedPositionData {
|
|
224
224
|
suppliedUsd: string,
|
|
225
|
+
suppliedEth: string,
|
|
225
226
|
suppliedCollateralUsd: string,
|
|
226
227
|
borrowedUsd: string,
|
|
228
|
+
borrowedEth: string,
|
|
227
229
|
borrowLimitUsd: string,
|
|
230
|
+
borrowLimitEth: string,
|
|
228
231
|
liquidationLimitUsd: string,
|
|
232
|
+
liquidationLimitEth: string,
|
|
229
233
|
leftToBorrowUsd: string,
|
|
234
|
+
leftToBorrowEth: string,
|
|
230
235
|
ratio: string,
|
|
231
236
|
collRatio: string,
|
|
232
237
|
netApy: string,
|