@defisaver/positions-sdk 0.0.6 → 0.0.7
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/aaveV3/index.js +1 -1
- package/cjs/chickenBonds/index.js +2 -1
- package/cjs/helpers/aaveHelpers/index.js +14 -2
- package/cjs/helpers/chickenBondsHelpers/index.d.ts +1 -0
- package/cjs/helpers/chickenBondsHelpers/index.js +14 -1
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/types/chickenBonds.d.ts +1 -0
- package/esm/aaveV3/index.js +1 -1
- package/esm/chickenBonds/index.js +3 -2
- package/esm/helpers/aaveHelpers/index.js +14 -2
- package/esm/helpers/chickenBondsHelpers/index.d.ts +1 -0
- package/esm/helpers/chickenBondsHelpers/index.js +12 -0
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/types/chickenBonds.d.ts +1 -0
- package/package.json +1 -1
- package/src/aaveV3/index.ts +1 -0
- package/src/chickenBonds/index.ts +3 -2
- package/src/helpers/aaveHelpers/index.ts +16 -2
- package/src/helpers/chickenBondsHelpers/index.ts +11 -0
- package/src/helpers/compoundHelpers/index.ts +4 -4
- package/src/types/chickenBonds.ts +1 -0
- package/yarn-error.log +64 -0
package/cjs/aaveV3/index.js
CHANGED
|
@@ -163,7 +163,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
163
163
|
liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationThreshold).div(10000).toString(),
|
|
164
164
|
collateralFactor: new decimal_js_1.default(tokenMarket.ltv).div(10000).toString(),
|
|
165
165
|
priceSource: tokenMarket.priceSource,
|
|
166
|
-
} }));
|
|
166
|
+
}, aTokenAddress: tokenMarket.aTokenAddress }));
|
|
167
167
|
})));
|
|
168
168
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
169
169
|
/* eslint-disable no-param-reassign */
|
|
@@ -90,7 +90,7 @@ const fetchCBondsForUser = (web3, network, address) => __awaiter(void 0, void 0,
|
|
|
90
90
|
return bonds.map(({ bondID, accruedBLUSD, claimedBLUSD, endTime, lusdAmount, maxAmountBLUSD, startTime, status, tokenURI, }) => ({
|
|
91
91
|
bondId: bondID,
|
|
92
92
|
status,
|
|
93
|
-
|
|
93
|
+
tokenURI: (0, chickenBondsHelpers_1.decodeTokenURIToSvg)(tokenURI),
|
|
94
94
|
startTime: new Date(+startTime * 1000),
|
|
95
95
|
endTime: new Date(+endTime * 1000),
|
|
96
96
|
accruedBLUSD: (0, tokens_1.assetAmountInEth)(accruedBLUSD, 'bLUSD'),
|
|
@@ -112,6 +112,7 @@ const fetchCBondForId = (web3, network, bondId) => __awaiter(void 0, void 0, voi
|
|
|
112
112
|
claimedBLUSD: (0, tokens_1.assetAmountInEth)(bond.claimedBLUSD, 'bLUSD'),
|
|
113
113
|
lusdAmount: (0, tokens_1.assetAmountInEth)(bond.lusdAmount, 'LUSD'),
|
|
114
114
|
maxAmountBLUSD: (0, tokens_1.assetAmountInEth)(bond.maxAmountBLUSD, 'bLUSD'),
|
|
115
|
+
tokenURI: (0, chickenBondsHelpers_1.decodeTokenURIToSvg)(bond.tokenURI),
|
|
115
116
|
};
|
|
116
117
|
});
|
|
117
118
|
exports.fetchCBondForId = fetchCBondForId;
|
|
@@ -77,8 +77,20 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
77
77
|
const payload = {};
|
|
78
78
|
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
79
79
|
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
80
|
-
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) =>
|
|
81
|
-
|
|
80
|
+
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
81
|
+
const suppliedUsdAmount = (0, exports.isMorphoAaveV3)(data)
|
|
82
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
83
|
+
? new decimal_js_1.default(suppliedUsd).minus(new decimal_js_1.default(suppliedUsd).div(100).times(0.1)).toString()
|
|
84
|
+
: suppliedUsd;
|
|
85
|
+
return new decimal_js_1.default(suppliedUsdAmount).mul((0, exports.aaveAnyGetEmodeMutableProps)(data, symbol).collateralFactor);
|
|
86
|
+
});
|
|
87
|
+
payload.liquidationLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
88
|
+
const suppliedUsdAmount = (0, exports.isMorphoAaveV3)(data)
|
|
89
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
90
|
+
? new decimal_js_1.default(suppliedUsd).minus(new decimal_js_1.default(suppliedUsd).div(100).times(0.1)).toString()
|
|
91
|
+
: suppliedUsd;
|
|
92
|
+
return new decimal_js_1.default(suppliedUsdAmount).mul((0, exports.aaveAnyGetEmodeMutableProps)(data, symbol).liquidationRatio);
|
|
93
|
+
});
|
|
82
94
|
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
83
95
|
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
84
96
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const calcCBondsBLUSDFloorPrice: (bLUSDSupply: string, totalReserveLUSD: string) => string;
|
|
2
2
|
export declare const calcAverageBondAgeMs: (totalWeightedStartTimes: string, totalPendingLusd: string) => number;
|
|
3
|
+
export declare const decodeTokenURIToSvg: (tokenURI: string) => string;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calcAverageBondAgeMs = exports.calcCBondsBLUSDFloorPrice = void 0;
|
|
6
|
+
exports.decodeTokenURIToSvg = exports.calcAverageBondAgeMs = exports.calcCBondsBLUSDFloorPrice = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const calcCBondsBLUSDFloorPrice = (bLUSDSupply, totalReserveLUSD) => {
|
|
9
9
|
if (new decimal_js_1.default(bLUSDSupply).eq(0))
|
|
@@ -17,3 +17,16 @@ const calcAverageBondAgeMs = (totalWeightedStartTimes, totalPendingLusd) => {
|
|
|
17
17
|
return Date.now() - averageStartTimeMs;
|
|
18
18
|
};
|
|
19
19
|
exports.calcAverageBondAgeMs = calcAverageBondAgeMs;
|
|
20
|
+
const decodeTokenURIToSvg = (tokenURI) => {
|
|
21
|
+
var _a;
|
|
22
|
+
try {
|
|
23
|
+
const dataStartIndex = tokenURI.indexOf('base64,') + 'base64,'.length;
|
|
24
|
+
const json = atob(tokenURI.slice(dataStartIndex));
|
|
25
|
+
return (_a = JSON.parse(json)) === null || _a === void 0 ? void 0 : _a.image;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.error(e);
|
|
29
|
+
return 'Error parsing NFT image';
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.decodeTokenURIToSvg = decodeTokenURIToSvg;
|
|
@@ -26,7 +26,7 @@ const formatMarketData = (data, network, baseAssetPrice) => {
|
|
|
26
26
|
const assetInfo = (0, tokens_1.getAssetInfoByAddress)(data.tokenAddr, network);
|
|
27
27
|
const isWETH = assetInfo.symbol === 'WETH';
|
|
28
28
|
const price = (0, utils_1.getEthAmountForDecimals)(data.price, 8);
|
|
29
|
-
return (Object.assign(Object.assign({}, data), {
|
|
29
|
+
return (Object.assign(Object.assign({}, data), { priceInBaseAsset: (0, utils_1.getEthAmountForDecimals)(data.price, 8), price: new decimal_js_1.default(price).mul(baseAssetPrice).toString(), collateralFactor: (0, utils_1.getEthAmountForDecimals)(data.borrowCollateralFactor, 18), liquidationRatio: (0, utils_1.getEthAmountForDecimals)(data.liquidateCollateralFactor, 18), supplyCap: (0, utils_1.getEthAmountForDecimals)(data.supplyCap, assetInfo.decimals), totalSupply: (0, utils_1.getEthAmountForDecimals)(data.totalSupply, assetInfo.decimals), symbol: isWETH ? 'ETH' : assetInfo.symbol, supplyRate: '0', borrowRate: '0', canBeBorrowed: false, canBeSupplied: true }));
|
|
30
30
|
};
|
|
31
31
|
exports.formatMarketData = formatMarketData;
|
|
32
32
|
// TODO: maybe not hardcode decimals
|
|
@@ -38,7 +38,7 @@ const formatBaseData = (data, network, baseAssetPrice) => {
|
|
|
38
38
|
.toString()), borrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(data.borrowRate).div(1e18).mul(constants_1.SECONDS_PER_YEAR).mul(100)
|
|
39
39
|
.toString()), utilization: (0, utils_1.getEthAmountForDecimals)(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
|
|
40
40
|
totalSupply,
|
|
41
|
-
totalBorrow, marketLiquidity: new decimal_js_1.default(totalSupply).minus(totalBorrow).toString(), symbol: (0, utils_1.wethToEth)(assetInfo.symbol),
|
|
41
|
+
totalBorrow, marketLiquidity: new decimal_js_1.default(totalSupply).minus(totalBorrow).toString(), symbol: (0, utils_1.wethToEth)(assetInfo.symbol), priceInBaseAsset: (0, utils_1.getEthAmountForDecimals)(data.price, 8), price: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: (0, utils_1.getEthAmountForDecimals)(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: (0, utils_1.getEthAmountForDecimals)(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: (0, utils_1.getEthAmountForDecimals)(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
|
|
42
42
|
};
|
|
43
43
|
exports.formatBaseData = formatBaseData;
|
|
44
44
|
const getIncentiveApys = (baseData, compPrice) => {
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -154,7 +154,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
154
154
|
liquidationRatio: new Dec(tokenMarket.liquidationThreshold).div(10000).toString(),
|
|
155
155
|
collateralFactor: new Dec(tokenMarket.ltv).div(10000).toString(),
|
|
156
156
|
priceSource: tokenMarket.priceSource,
|
|
157
|
-
} }));
|
|
157
|
+
}, aTokenAddress: tokenMarket.aTokenAddress }));
|
|
158
158
|
})));
|
|
159
159
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
160
160
|
/* eslint-disable no-param-reassign */
|
|
@@ -11,7 +11,7 @@ import Dec from 'decimal.js';
|
|
|
11
11
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
12
12
|
import { ChickenBondsManagerContract, ChickenBondsViewContract } from '../contracts';
|
|
13
13
|
import { multicall } from '../multicall';
|
|
14
|
-
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice } from '../helpers/chickenBondsHelpers';
|
|
14
|
+
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice, decodeTokenURIToSvg } from '../helpers/chickenBondsHelpers';
|
|
15
15
|
export const getChickenBondsAccountBalances = (web3, network, block, addressMapping, bondId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const viewContract = ChickenBondsViewContract(web3, network, block);
|
|
17
17
|
const fullBondInfo = yield viewContract.methods.getBondFullInfo(bondId).call({}, block);
|
|
@@ -82,7 +82,7 @@ export const fetchCBondsForUser = (web3, network, address) => __awaiter(void 0,
|
|
|
82
82
|
return bonds.map(({ bondID, accruedBLUSD, claimedBLUSD, endTime, lusdAmount, maxAmountBLUSD, startTime, status, tokenURI, }) => ({
|
|
83
83
|
bondId: bondID,
|
|
84
84
|
status,
|
|
85
|
-
|
|
85
|
+
tokenURI: decodeTokenURIToSvg(tokenURI),
|
|
86
86
|
startTime: new Date(+startTime * 1000),
|
|
87
87
|
endTime: new Date(+endTime * 1000),
|
|
88
88
|
accruedBLUSD: assetAmountInEth(accruedBLUSD, 'bLUSD'),
|
|
@@ -103,5 +103,6 @@ export const fetchCBondForId = (web3, network, bondId) => __awaiter(void 0, void
|
|
|
103
103
|
claimedBLUSD: assetAmountInEth(bond.claimedBLUSD, 'bLUSD'),
|
|
104
104
|
lusdAmount: assetAmountInEth(bond.lusdAmount, 'LUSD'),
|
|
105
105
|
maxAmountBLUSD: assetAmountInEth(bond.maxAmountBLUSD, 'bLUSD'),
|
|
106
|
+
tokenURI: decodeTokenURIToSvg(bond.tokenURI),
|
|
106
107
|
};
|
|
107
108
|
});
|
|
@@ -61,8 +61,20 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
61
61
|
const payload = {};
|
|
62
62
|
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
63
63
|
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
64
|
-
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) =>
|
|
65
|
-
|
|
64
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
65
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
66
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
67
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
68
|
+
: suppliedUsd;
|
|
69
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).collateralFactor);
|
|
70
|
+
});
|
|
71
|
+
payload.liquidationLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
72
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
73
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
74
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
75
|
+
: suppliedUsd;
|
|
76
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).liquidationRatio);
|
|
77
|
+
});
|
|
66
78
|
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
67
79
|
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
68
80
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const calcCBondsBLUSDFloorPrice: (bLUSDSupply: string, totalReserveLUSD: string) => string;
|
|
2
2
|
export declare const calcAverageBondAgeMs: (totalWeightedStartTimes: string, totalPendingLusd: string) => number;
|
|
3
|
+
export declare const decodeTokenURIToSvg: (tokenURI: string) => string;
|
|
@@ -9,3 +9,15 @@ export const calcAverageBondAgeMs = (totalWeightedStartTimes, totalPendingLusd)
|
|
|
9
9
|
.toNumber();
|
|
10
10
|
return Date.now() - averageStartTimeMs;
|
|
11
11
|
};
|
|
12
|
+
export const decodeTokenURIToSvg = (tokenURI) => {
|
|
13
|
+
var _a;
|
|
14
|
+
try {
|
|
15
|
+
const dataStartIndex = tokenURI.indexOf('base64,') + 'base64,'.length;
|
|
16
|
+
const json = atob(tokenURI.slice(dataStartIndex));
|
|
17
|
+
return (_a = JSON.parse(json)) === null || _a === void 0 ? void 0 : _a.image;
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.error(e);
|
|
21
|
+
return 'Error parsing NFT image';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -20,7 +20,7 @@ export const formatMarketData = (data, network, baseAssetPrice) => {
|
|
|
20
20
|
const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
|
|
21
21
|
const isWETH = assetInfo.symbol === 'WETH';
|
|
22
22
|
const price = getEthAmountForDecimals(data.price, 8);
|
|
23
|
-
return (Object.assign(Object.assign({}, data), {
|
|
23
|
+
return (Object.assign(Object.assign({}, data), { priceInBaseAsset: getEthAmountForDecimals(data.price, 8), price: new Dec(price).mul(baseAssetPrice).toString(), collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18), liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18), supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals), totalSupply: getEthAmountForDecimals(data.totalSupply, assetInfo.decimals), symbol: isWETH ? 'ETH' : assetInfo.symbol, supplyRate: '0', borrowRate: '0', canBeBorrowed: false, canBeSupplied: true }));
|
|
24
24
|
};
|
|
25
25
|
// TODO: maybe not hardcode decimals
|
|
26
26
|
export const formatBaseData = (data, network, baseAssetPrice) => {
|
|
@@ -31,7 +31,7 @@ export const formatBaseData = (data, network, baseAssetPrice) => {
|
|
|
31
31
|
.toString()), borrowRate: aprToApy(new Dec(data.borrowRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
|
|
32
32
|
.toString()), utilization: getEthAmountForDecimals(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
|
|
33
33
|
totalSupply,
|
|
34
|
-
totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol),
|
|
34
|
+
totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol), priceInBaseAsset: getEthAmountForDecimals(data.price, 8), price: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
|
|
35
35
|
};
|
|
36
36
|
export const getIncentiveApys = (baseData, compPrice) => {
|
|
37
37
|
const incentiveSupplyApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString();
|
package/package.json
CHANGED
package/src/aaveV3/index.ts
CHANGED
|
@@ -237,6 +237,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
237
237
|
collateralFactor: new Dec(tokenMarket.ltv).div(10000).toString(),
|
|
238
238
|
priceSource: tokenMarket.priceSource,
|
|
239
239
|
},
|
|
240
|
+
aTokenAddress: tokenMarket.aTokenAddress,
|
|
240
241
|
});
|
|
241
242
|
}));
|
|
242
243
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { ChickenBondsManagerContract, ChickenBondsViewContract } from '../contracts';
|
|
10
10
|
import { BondInfoBasic, ChickenBondsSystemInfoBasic } from '../types';
|
|
11
11
|
import { multicall } from '../multicall';
|
|
12
|
-
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice } from '../helpers/chickenBondsHelpers';
|
|
12
|
+
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice, decodeTokenURIToSvg } from '../helpers/chickenBondsHelpers';
|
|
13
13
|
|
|
14
14
|
export const getChickenBondsAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, bondId: string): Promise<PositionBalances> => {
|
|
15
15
|
const viewContract = ChickenBondsViewContract(web3, network, block);
|
|
@@ -94,7 +94,7 @@ export const fetchCBondsForUser = async (web3: Web3, network: NetworkNumber, add
|
|
|
94
94
|
}) => ({
|
|
95
95
|
bondId: bondID,
|
|
96
96
|
status,
|
|
97
|
-
|
|
97
|
+
tokenURI: decodeTokenURIToSvg(tokenURI),
|
|
98
98
|
startTime: new Date(+startTime * 1000),
|
|
99
99
|
endTime: new Date(+endTime * 1000),
|
|
100
100
|
accruedBLUSD: assetAmountInEth(accruedBLUSD, 'bLUSD'),
|
|
@@ -118,5 +118,6 @@ export const fetchCBondForId = async (web3: Web3, network: NetworkNumber, bondId
|
|
|
118
118
|
claimedBLUSD: assetAmountInEth(bond.claimedBLUSD, 'bLUSD'),
|
|
119
119
|
lusdAmount: assetAmountInEth(bond.lusdAmount, 'LUSD'),
|
|
120
120
|
maxAmountBLUSD: assetAmountInEth(bond.maxAmountBLUSD, 'bLUSD'),
|
|
121
|
+
tokenURI: decodeTokenURIToSvg(bond.tokenURI),
|
|
121
122
|
};
|
|
122
123
|
};
|
|
@@ -87,12 +87,26 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
87
87
|
payload.borrowLimitUsd = getAssetsTotal(
|
|
88
88
|
usedAssets,
|
|
89
89
|
({ isSupplied, collateral }: { isSupplied: boolean, collateral: string }) => isSupplied && collateral,
|
|
90
|
-
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) =>
|
|
90
|
+
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => {
|
|
91
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
92
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
93
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
94
|
+
: suppliedUsd;
|
|
95
|
+
|
|
96
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).collateralFactor);
|
|
97
|
+
},
|
|
91
98
|
);
|
|
92
99
|
payload.liquidationLimitUsd = getAssetsTotal(
|
|
93
100
|
usedAssets,
|
|
94
101
|
({ isSupplied, collateral }: { isSupplied: boolean, collateral: string }) => isSupplied && collateral,
|
|
95
|
-
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) =>
|
|
102
|
+
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => {
|
|
103
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
104
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
105
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
106
|
+
: suppliedUsd;
|
|
107
|
+
|
|
108
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).liquidationRatio);
|
|
109
|
+
},
|
|
96
110
|
);
|
|
97
111
|
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
98
112
|
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
@@ -10,4 +10,15 @@ export const calcAverageBondAgeMs = (totalWeightedStartTimes: string, totalPendi
|
|
|
10
10
|
.toNumber();
|
|
11
11
|
|
|
12
12
|
return Date.now() - averageStartTimeMs;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const decodeTokenURIToSvg = (tokenURI: string): string => {
|
|
16
|
+
try {
|
|
17
|
+
const dataStartIndex = tokenURI.indexOf('base64,') + 'base64,'.length;
|
|
18
|
+
const json = atob(tokenURI.slice(dataStartIndex));
|
|
19
|
+
return JSON.parse(json)?.image;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error(e);
|
|
22
|
+
return 'Error parsing NFT image';
|
|
23
|
+
}
|
|
13
24
|
};
|
|
@@ -17,8 +17,8 @@ export const formatMarketData = (data: any, network: NetworkNumber, baseAssetPri
|
|
|
17
17
|
const price = getEthAmountForDecimals(data.price, 8);
|
|
18
18
|
return ({
|
|
19
19
|
...data,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
21
|
+
price: new Dec(price).mul(baseAssetPrice).toString(),
|
|
22
22
|
collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18),
|
|
23
23
|
liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18),
|
|
24
24
|
supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals),
|
|
@@ -47,8 +47,8 @@ export const formatBaseData = (data: any, network: NetworkNumber, baseAssetPrice
|
|
|
47
47
|
totalBorrow,
|
|
48
48
|
marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(),
|
|
49
49
|
symbol: wethToEth(assetInfo.symbol),
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
51
|
+
price: baseAssetPrice,
|
|
52
52
|
collateralFactor: '0',
|
|
53
53
|
liquidationRatio: '0',
|
|
54
54
|
canBeBorrowed: true,
|
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
|