@sonarwatch/portfolio-plugins 0.14.14 → 0.14.16
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/plugins/aftermath/helpers.d.ts +4 -0
- package/src/plugins/aftermath/helpers.js +81 -0
- package/src/plugins/aftermath/helpers.js.map +1 -0
- package/src/plugins/aftermath/poolsJob.js +1 -1
- package/src/plugins/aftermath/poolsJob.js.map +1 -1
- package/src/plugins/aftermath/stakingFetcher.js +42 -9
- package/src/plugins/aftermath/stakingFetcher.js.map +1 -1
- package/src/plugins/aftermath/types.d.ts +12 -0
- package/src/plugins/navi/collateralFetcher.js +46 -37
- package/src/plugins/navi/collateralFetcher.js.map +1 -1
- package/src/plugins/suilend/helpers.d.ts +4 -1
- package/src/plugins/suilend/helpers.js +25 -12
- package/src/plugins/suilend/helpers.js.map +1 -1
- package/src/plugins/suilend/obligationsFetcher.js +24 -5
- package/src/plugins/suilend/obligationsFetcher.js.map +1 -1
- package/src/plugins/suilend/types.d.ts +1 -1
- package/src/utils/misc/getLendingMarketAprs.d.ts +18 -0
- package/src/utils/misc/getLendingMarketAprs.js +58 -0
- package/src/utils/misc/getLendingMarketAprs.js.map +1 -0
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
4
4
|
|
5
|
+
## [0.14.16](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.15...plugins-0.14.16) (2024-10-25)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
## [0.14.15](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.14...plugins-0.14.15) (2024-10-25)
|
10
|
+
|
11
|
+
|
12
|
+
|
5
13
|
## [0.14.14](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.13...plugins-0.14.14) (2024-10-24)
|
6
14
|
|
7
15
|
|
package/package.json
CHANGED
@@ -0,0 +1,4 @@
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
2
|
+
import { BurnerVault, StakingPosition } from './types';
|
3
|
+
import { SuiClient } from '../../utils/clients/types';
|
4
|
+
export declare const getHarvestRewards: (client: SuiClient, sender: string, stakedPosition: StakingPosition, stakeCoinType: string, vault: BurnerVault) => Promise<Map<string, BigNumber>>;
|
@@ -0,0 +1,81 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.getHarvestRewards = void 0;
|
16
|
+
const portfolio_core_1 = require("@sonarwatch/portfolio-core");
|
17
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
18
|
+
const transactions_1 = require("@mysten/sui/transactions");
|
19
|
+
const getHarvestRewards = (client, sender, stakedPosition, stakeCoinType, vault) => __awaiter(void 0, void 0, void 0, function* () {
|
20
|
+
const rewards = new Map();
|
21
|
+
const rewardCoinTypes = vault.type_names.filter((coinType, i) => vault.rewards[i] !== '0' && i > 0);
|
22
|
+
if (rewardCoinTypes.length === 0)
|
23
|
+
return rewards;
|
24
|
+
const transactionBlock = new transactions_1.Transaction();
|
25
|
+
const harvestedRewardsEventMetadataId = transactionBlock.moveCall({
|
26
|
+
target: `0xcd41fbc59af65b7c58fd2590d5e35efbf756d50e6da2bd0413917102be6e1fdf::staked_position::begin_harvest`,
|
27
|
+
typeArguments: [stakeCoinType],
|
28
|
+
arguments: [transactionBlock.object(vault.id.id)],
|
29
|
+
});
|
30
|
+
const harvestedCoins = {};
|
31
|
+
for (const rewardCoinType of rewardCoinTypes) {
|
32
|
+
const harvestedCoin = transactionBlock.moveCall({
|
33
|
+
target: `0xcd41fbc59af65b7c58fd2590d5e35efbf756d50e6da2bd0413917102be6e1fdf::staked_position::harvest_rewards`,
|
34
|
+
typeArguments: [stakeCoinType, rewardCoinType],
|
35
|
+
arguments: [
|
36
|
+
transactionBlock.object(stakedPosition.id.id),
|
37
|
+
transactionBlock.object(vault.id.id),
|
38
|
+
harvestedRewardsEventMetadataId,
|
39
|
+
transactionBlock.object(portfolio_core_1.suiClockAddress),
|
40
|
+
],
|
41
|
+
});
|
42
|
+
if (rewardCoinType in harvestedCoins) {
|
43
|
+
harvestedCoins[rewardCoinType].push(harvestedCoin);
|
44
|
+
}
|
45
|
+
else {
|
46
|
+
harvestedCoins[rewardCoinType] = [harvestedCoin];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
transactionBlock.moveCall({
|
50
|
+
target: `0xcd41fbc59af65b7c58fd2590d5e35efbf756d50e6da2bd0413917102be6e1fdf::staked_position::end_harvest`,
|
51
|
+
typeArguments: [],
|
52
|
+
arguments: [harvestedRewardsEventMetadataId],
|
53
|
+
});
|
54
|
+
for (const [, harvestedCoinIds] of Object.entries(harvestedCoins)) {
|
55
|
+
const coinToTransfer = harvestedCoinIds[0];
|
56
|
+
if (harvestedCoinIds.length > 1)
|
57
|
+
transactionBlock.mergeCoins(coinToTransfer, harvestedCoinIds.slice(1));
|
58
|
+
transactionBlock.transferObjects([coinToTransfer], sender);
|
59
|
+
}
|
60
|
+
const dir = yield client.devInspectTransactionBlock({
|
61
|
+
sender,
|
62
|
+
transactionBlock,
|
63
|
+
});
|
64
|
+
const event = dir.events.find((e) => e.type ===
|
65
|
+
'0x4f0a1a923dd063757fd37e04a9c2cee8980008e94433c9075c390065f98e9e4b::events::HarvestedRewardsEvent');
|
66
|
+
if (!event || !event.parsedJson)
|
67
|
+
return rewards;
|
68
|
+
const parsedEvent = event;
|
69
|
+
if (!parsedEvent.parsedJson)
|
70
|
+
return rewards;
|
71
|
+
parsedEvent.parsedJson.reward_types.forEach((coinType, i) => {
|
72
|
+
if (parsedEvent.parsedJson) {
|
73
|
+
const balance = new bignumber_js_1.default(parsedEvent.parsedJson.reward_amounts[i]);
|
74
|
+
if (balance.isGreaterThan(0))
|
75
|
+
rewards.set(coinType, balance);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return rewards;
|
79
|
+
});
|
80
|
+
exports.getHarvestRewards = getHarvestRewards;
|
81
|
+
//# sourceMappingURL=helpers.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/aftermath/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAA6D;AAC7D,gEAAqC;AACrC,2DAGkC;AAU3B,MAAM,iBAAiB,GAAG,CAC/B,MAAiB,EACjB,MAAc,EACd,cAA+B,EAC/B,aAAqB,EACrB,KAAkB,EAClB,EAAE;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAC;IAE7C,MAAM,eAAe,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,CAC7C,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CACnD,CAAC;IACF,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAEjD,MAAM,gBAAgB,GAAG,IAAI,0BAAW,EAAE,CAAC;IAE3C,MAAM,+BAA+B,GAAG,gBAAgB,CAAC,QAAQ,CAAC;QAChE,MAAM,EAAE,oGAAoG;QAC5G,aAAa,EAAE,CA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AC,CAAC;QAEzE,gBAAgB,CAAC,eAAe,CAAC,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,0BAA0B,CAAC;QAClD,MAAM;QACN,gBAAgB;KACjB,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAC3B,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI;QACN,mGAAmG,CACtG,CAAC;IAEF,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC;IAEhD,MAAM,WAAW,GAAG,KAAgC,CAAC;IACrD,IAAI,CAAC,WAAW,CAAC,UAAU;QAAE,OAAO,OAAO,CAAC;IAE5C,WAAW,CAAC,UAAU,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE;QAC1D,IAAI,WAAW,CAAC,UAAU,EAAE,CAAC;YAC3B,MAAM,OAAO,GAAG,IAAI,sBAAS,CAAC,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;YACxE,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA,CAAC;AAjFW,QAAA,iBAAiB,qBAiF5B"}
|
@@ -74,7 +74,7 @@ const executor = (cache) => __awaiter(void 0, void 0, void 0, function* () {
|
|
74
74
|
return;
|
75
75
|
}
|
76
76
|
const tokenPrice = tokenPriceById.get(cAddress);
|
77
|
-
if (!
|
77
|
+
if (!poolInfo.coin_decimals)
|
78
78
|
return;
|
79
79
|
poolUnderlyingsRaw.push({
|
80
80
|
address: cAddress,
|
@@ -1 +1 @@
|
|
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,SAAS;gBAClB,QAAQ,EAAE,QAAQ,CAAC,WAAW;gBAC9B,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK;aAC3C;YACD,QAAQ,EAAE,SAAS;YACnB,kBAAkB;YAClB,gBAAgB,EAAE,IAAI;SACvB,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC,CAAA,CAAC;AAEF,MAAM,GAAG,GAAQ;IACf,EAAE,EAAE,GAAG,sBAAU,QAAQ;IACzB,QAAQ;IACR,KAAK,EAAE,QAAQ;CAChB,CAAC;AACF,kBAAe,GAAG,CAAC"}
|
@@ -19,6 +19,8 @@ const clients_1 = require("../../utils/clients");
|
|
19
19
|
const getOwnedObjects_1 = require("../../utils/sui/getOwnedObjects");
|
20
20
|
const multiGetObjects_1 = require("../../utils/sui/multiGetObjects");
|
21
21
|
const tokenPriceToAssetTokens_1 = __importDefault(require("../../utils/misc/tokenPriceToAssetTokens"));
|
22
|
+
const helpers_1 = require("./helpers");
|
23
|
+
const tokenPriceToAssetToken_1 = __importDefault(require("../../utils/misc/tokenPriceToAssetToken"));
|
22
24
|
const farmFactor = new bignumber_js_1.default(Math.pow(10, 9));
|
23
25
|
const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* () {
|
24
26
|
var _a;
|
@@ -41,6 +43,7 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
41
43
|
});
|
42
44
|
const burnerVaultsObjects = yield (0, multiGetObjects_1.multiGetObjects)(client, burnerVaults);
|
43
45
|
const burnerVaultsTypes = burnerVaultsObjects.map((vault) => { var _a; return (_a = vault.data) === null || _a === void 0 ? void 0 : _a.type; });
|
46
|
+
const tokenAddresses = [];
|
44
47
|
const lpMints = burnerVaultsTypes
|
45
48
|
.map((type) => {
|
46
49
|
var _a, _b;
|
@@ -49,10 +52,31 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
49
52
|
const lp = (_b = (_a = (0, portfolio_core_1.parseTypeString)(type).keys) === null || _a === void 0 ? void 0 : _a.at(0)) === null || _b === void 0 ? void 0 : _b.type;
|
50
53
|
if (!lp || !lp.includes('af_lp'))
|
51
54
|
return undefined;
|
52
|
-
|
55
|
+
tokenAddresses.push((0, portfolio_core_1.formatTokenAddress)(lp, portfolio_core_1.NetworkId.sui));
|
56
|
+
return lp;
|
53
57
|
})
|
54
58
|
.flat();
|
55
|
-
|
59
|
+
burnerVaultsObjects.forEach((vault) => {
|
60
|
+
var _a, _b;
|
61
|
+
(_b = (_a = vault.data) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.fields.type_names.forEach((ct) => tokenAddresses.push(ct));
|
62
|
+
});
|
63
|
+
const [tokenPriceById, rewards] = yield Promise.all([
|
64
|
+
cache.getTokenPricesAsMap(tokenAddresses, portfolio_core_1.NetworkId.sui),
|
65
|
+
Promise.all(stakedPositions.map((object, i) => {
|
66
|
+
var _a, _b, _c, _d, _e;
|
67
|
+
const lp = lpMints[i];
|
68
|
+
const burnerVault = burnerVaultsObjects.find((bv) => { var _a, _b; return (_b = (_a = bv.data) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.fields.id.id; });
|
69
|
+
if (!lp)
|
70
|
+
return null;
|
71
|
+
if (!((_a = object.data) === null || _a === void 0 ? void 0 : _a.content))
|
72
|
+
return null;
|
73
|
+
if (!burnerVault || !((_c = (_b = burnerVault.data) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c.fields))
|
74
|
+
return null;
|
75
|
+
return (0, helpers_1.getHarvestRewards)(client, owner, object.data.content.fields, lp, (_e = (_d = burnerVault.data) === null || _d === void 0 ? void 0 : _d.content) === null || _e === void 0 ? void 0 : _e.fields);
|
76
|
+
})),
|
77
|
+
]);
|
78
|
+
if (!tokenPriceById)
|
79
|
+
return [];
|
56
80
|
const liquidities = [];
|
57
81
|
for (let i = 0; i < stakedPositions.length; i++) {
|
58
82
|
const object = stakedPositions[i];
|
@@ -61,20 +85,29 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
61
85
|
const lp = lpMints[i];
|
62
86
|
if (!lp)
|
63
87
|
continue;
|
64
|
-
const
|
65
|
-
if (!
|
88
|
+
const lpTokenPrice = tokenPriceById.get((0, portfolio_core_1.formatTokenAddress)(lp, portfolio_core_1.NetworkId.sui));
|
89
|
+
if (!lpTokenPrice)
|
66
90
|
continue;
|
67
91
|
const position = object.data.content.fields;
|
68
92
|
const amount = new bignumber_js_1.default(position.balance)
|
69
93
|
.dividedBy(farmFactor)
|
70
94
|
.toNumber();
|
71
|
-
const assets = (0, tokenPriceToAssetTokens_1.default)(
|
72
|
-
const
|
95
|
+
const assets = (0, tokenPriceToAssetTokens_1.default)(lpTokenPrice.address, amount, portfolio_core_1.NetworkId.sui, lpTokenPrice);
|
96
|
+
const rewardAssets = [];
|
97
|
+
const rewardsForPosition = rewards[i];
|
98
|
+
if (rewardsForPosition) {
|
99
|
+
rewardsForPosition.forEach((rewardAmount, coinType) => {
|
100
|
+
const tokenPrice = tokenPriceById.get((0, portfolio_core_1.formatTokenAddress)(coinType, portfolio_core_1.NetworkId.sui));
|
101
|
+
if (tokenPrice)
|
102
|
+
rewardAssets.push((0, tokenPriceToAssetToken_1.default)((0, portfolio_core_1.formatTokenAddress)(coinType, portfolio_core_1.NetworkId.sui), rewardAmount.dividedBy(Math.pow(10, tokenPrice.decimals)).toNumber(), portfolio_core_1.NetworkId.sui, tokenPrice));
|
103
|
+
});
|
104
|
+
}
|
105
|
+
const value = (0, portfolio_core_1.getUsdValueSum)([...assets, ...rewardAssets].map((asset) => asset.value));
|
73
106
|
liquidities.push({
|
74
107
|
assets,
|
75
|
-
assetsValue: value,
|
76
|
-
rewardAssets
|
77
|
-
rewardAssetsValue:
|
108
|
+
assetsValue: (0, portfolio_core_1.getUsdValueSum)(assets.map((asset) => asset.value)),
|
109
|
+
rewardAssets,
|
110
|
+
rewardAssetsValue: (0, portfolio_core_1.getUsdValueSum)(rewardAssets.map((asset) => asset.value)),
|
78
111
|
value,
|
79
112
|
yields: [],
|
80
113
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"stakingFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/aftermath/stakingFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+
|
1
|
+
{"version":3,"file":"stakingFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/aftermath/stakingFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAOoC;AACpC,gEAAqC;AAGrC,2CAAsD;AACtD,iDAAmD;AACnD,qEAAkE;AAElE,qEAAkE;AAClE,uGAA+E;AAC/E,uCAA8C;AAC9C,qGAA6E;AAE7E,MAAM,UAAU,GAAG,IAAI,sBAAS,CAAC,SAAA,EAAE,EAAI,CAAC,CAAA,CAAC,CAAC;AAE1C,MAAM,QAAQ,GAAoB,CAAO,KAAa,EAAE,KAAY,EAAE,EAAE;;IACtE,MAAM,MAAM,GAAG,IAAA,sBAAY,GAAE,CAAC;IAE9B,MAAM,eAAe,GAAG,MAAM,IAAA,iCAAe,EAC3C,MAAM,EACN,KAAK,EACL;QACE,MAAM,EAAE;YACN,UAAU,EAAE,uBAAW;SACxB;QACD,OAAO,EAAE;YACP,WAAW,EAAE,IAAI;SAClB;KACF,CACF,CAAC;IACF,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAE5C,MAAM,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;;QAClD,IAAI,MAAA,MAAA,MAAM,CAAC,IAAI,0CAAE,OAAO,0CAAE,MAAM,CAAC,oBAAoB;YACnD,OAAO,MAAM,CAAC,IAAI,CA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M,EAAE,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CACzD,CAAC;QAEF,WAAW,CAAC,IAAI,CAAC;YACf,MAAM;YACN,WAAW,EAAE,IAAA,+BAAc,EAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC/D,YAAY;YACZ,iBAAiB,EAAE,IAAA,+BAAc,EAC/B,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CACzC;YACD,KAAK;YACL,MAAM,EAAE,EAAE;SACX,CAAC,CAAC;IACL,CAAC;IAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAExC,OAAO;QACL;YACE,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,EAAE,WAAW,EAAE;YACrB,KAAK,EAAE,SAAS;YAChB,SAAS,EAAE,0BAAS,CAAC,GAAG;YACxB,UAAU,EAAV,sBAAU;YACV,KAAK,EAAE,IAAA,+BAAc,EAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC3D;KACF,CAAC;AACJ,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,UAAU;IAC3B,SAAS,EAAE,0BAAS,CAAC,GAAG;IACxB,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
@@ -51,3 +51,15 @@ export type PoolFactory = {
|
|
51
51
|
name: string;
|
52
52
|
value: string;
|
53
53
|
};
|
54
|
+
export type BurnerVault = {
|
55
|
+
id: ID;
|
56
|
+
emission_rates: string[];
|
57
|
+
type_names: string[];
|
58
|
+
rewards: string[];
|
59
|
+
};
|
60
|
+
export type CoinType = string;
|
61
|
+
export type HarvestedRewards = {
|
62
|
+
afterburner_vault_id: string;
|
63
|
+
reward_amounts: string[];
|
64
|
+
reward_types: string[];
|
65
|
+
};
|
@@ -46,22 +46,27 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
46
46
|
if (!borrowBalance.error && ((_a = borrowBalance.data) === null || _a === void 0 ? void 0 : _a.content)) {
|
47
47
|
const borrowInfo = (_b = borrowBalance.data.content) === null || _b === void 0 ? void 0 : _b.fields;
|
48
48
|
if (borrowInfo.value) {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
49
|
+
const amount = new bignumber_js_1.default(borrowInfo.value)
|
50
|
+
.times(rData.value.fields.current_borrow_index)
|
51
|
+
.dividedBy(amountFactor);
|
52
|
+
if (amount.isGreaterThan(0.002)) {
|
53
|
+
element.addBorrowedAsset({
|
54
|
+
address: rData.value.fields.coin_type,
|
55
|
+
amount: new bignumber_js_1.default(borrowInfo.value)
|
56
|
+
.times(rData.value.fields.current_borrow_index)
|
57
|
+
.dividedBy(amountFactor),
|
58
|
+
alreadyShifted: true,
|
59
|
+
});
|
60
|
+
const apy = new bignumber_js_1.default(rData.value.fields.current_borrow_rate)
|
61
|
+
.dividedBy(Math.pow(10, constants_1.rateFactor))
|
62
|
+
.toNumber();
|
63
|
+
element.addBorrowedYield([
|
64
|
+
{
|
65
|
+
apr: -(0, portfolio_core_1.apyToApr)(apy),
|
66
|
+
apy: -apy,
|
67
|
+
},
|
68
|
+
]);
|
69
|
+
}
|
65
70
|
}
|
66
71
|
}
|
67
72
|
if (!supplyBalance.error && ((_d = (_c = supplyBalance.data) === null || _c === void 0 ? void 0 : _c.content) === null || _d === void 0 ? void 0 : _d.fields)) {
|
@@ -70,32 +75,36 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
70
75
|
const amount = new bignumber_js_1.default(supplyInfo.value)
|
71
76
|
.times(rData.value.fields.current_supply_index)
|
72
77
|
.dividedBy(amountFactor);
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
.
|
89
|
-
|
78
|
+
if (amount.isGreaterThan(0.002)) {
|
79
|
+
element.addSuppliedAsset({
|
80
|
+
address: rData.value.fields.coin_type,
|
81
|
+
amount,
|
82
|
+
alreadyShifted: true,
|
83
|
+
});
|
84
|
+
const apy = new bignumber_js_1.default(rData.value.fields.current_supply_rate)
|
85
|
+
.dividedBy(Math.pow(10, constants_1.rateFactor))
|
86
|
+
.toNumber();
|
87
|
+
element.addSuppliedYield([
|
88
|
+
{
|
89
|
+
apr: (0, portfolio_core_1.apyToApr)(apy),
|
90
|
+
apy,
|
91
|
+
},
|
92
|
+
]);
|
93
|
+
element.addSuppliedLtv(new bignumber_js_1.default(rData.value.fields.liquidation_factors.fields.threshold)
|
94
|
+
.div(Math.pow(10, 27))
|
95
|
+
.toNumber());
|
96
|
+
}
|
90
97
|
}
|
91
98
|
}
|
92
99
|
}
|
93
100
|
if (rewards.size > 0) {
|
94
101
|
rewards.forEach((amount, coinType) => {
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
102
|
+
if (amount > 0.002) {
|
103
|
+
element.addRewardAsset({
|
104
|
+
address: coinType,
|
105
|
+
amount,
|
106
|
+
});
|
107
|
+
}
|
99
108
|
});
|
100
109
|
}
|
101
110
|
return elementRegistry.getElements(cache);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"collateralFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/navi/collateralFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAiE;AACjE,gEAAqC;AAGrC,2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CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;gBAClE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE;aACxC,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,CAAC,KAAK,KAAI,MAAA,aAAa,CAAC,IAAI,0CAAE,OAAO,CAAA,EAAE,CAAC;YACxD,MAAM,UAAU,GAAG,MAAA,aAAa,CAAC,IAAI,CAAC,OAAO,0CAAE,MAAM,CAAC;YACtD,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;gBACrB,OAAO,CAAC,gBAAgB,CAAC;
|
1
|
+
{"version":3,"file":"collateralFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/navi/collateralFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAAiE;AACjE,gEAAqC;AAGrC,2CAKqB;AACrB,iDAAmD;AAEnD,iFAA8E;AAC9E,+DAA4D;AAC5D,gFAA6E;AAE7E,MAAM,YAAY,GAAG,IAAI,sBAAS,CAAC,SAAA,EAAE,EAAI,EAAE,CAAA,CAAC,CAAC;AAE7C,MAAM,QAAQ,GAAoB,CAAO,KAAa,EAAE,KAAY,EAAE,EAAE;;IACtE,MAAM,MAAM,GAAG,IAAA,sBAAY,GAAE,CAAC;IAE9B,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,OAAO,CAAgB,uBAAW,EAAE;QACnE,MAAM,EAAE,0BAAc;QACtB,SAAS,EAAE,0BAAS,CAAC,GAAG;KACzB,CAAC,CAAC;IACH,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IAE7B,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,IAAA,yCAAmB,EAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAE1E,MAAM,eAAe,GAAG,IAAI,i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endRate } from '@sonarwatch/portfolio-core';
|
3
3
|
import { LendingMarket, PoolReward, Reserve } from './types';
|
4
|
-
export declare function
|
4
|
+
export declare function getPoolsRewardsMaps(lendingMarkets: LendingMarket[] | undefined): [PoolRewardById, PoolsRewardByManagerId];
|
5
|
+
type PoolRewardById = Map<string, PoolReward>;
|
6
|
+
type PoolsRewardByManagerId = Map<string, PoolReward[]>;
|
5
7
|
export declare function getRatesAsMap(borrowLendRates: BorrowLendRate[] | undefined): Map<string, BorrowLendRate>;
|
6
8
|
export declare function getBorrowApr(utilization: BigNumber, borrowedAmount: BigNumber, availableAmount: BigNumber, reserveFields: Reserve): number;
|
7
9
|
export declare function getDepositApr(utilization: BigNumber, borrowApr: number, reserveFields: Reserve): number;
|
10
|
+
export {};
|
@@ -3,26 +3,35 @@ 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.getDepositApr = exports.getBorrowApr = exports.getRatesAsMap = exports.
|
6
|
+
exports.getDepositApr = exports.getBorrowApr = exports.getRatesAsMap = exports.getPoolsRewardsMaps = void 0;
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
8
|
-
function
|
9
|
-
const
|
8
|
+
function getPoolsRewardsMaps(lendingMarkets) {
|
9
|
+
const poolRewardById = new Map();
|
10
|
+
const poolsRewardByManagerId = new Map();
|
10
11
|
if (!lendingMarkets)
|
11
|
-
return
|
12
|
+
return [poolRewardById, poolsRewardByManagerId];
|
12
13
|
for (const lendingMarket of lendingMarkets) {
|
13
14
|
const { reserves } = lendingMarket;
|
14
15
|
for (const reserve of reserves) {
|
15
|
-
const
|
16
|
-
for (const poolReward of
|
17
|
-
if (!poolReward)
|
16
|
+
const depositdPoolsRewards = reserve.fields.deposits_pool_reward_manager.fields.pool_rewards;
|
17
|
+
for (const poolReward of depositdPoolsRewards) {
|
18
|
+
if (!poolReward || !poolReward.fields)
|
18
19
|
continue;
|
19
|
-
|
20
|
+
poolRewardById.set(poolReward.fields.id.id, poolReward.fields);
|
20
21
|
}
|
22
|
+
poolsRewardByManagerId.set(reserve.fields.deposits_pool_reward_manager.fields.id.id, depositdPoolsRewards.map((data) => (data ? data.fields : null)));
|
23
|
+
const borrowPoolsRewards = reserve.fields.borrows_pool_reward_manager.fields.pool_rewards;
|
24
|
+
for (const poolReward of borrowPoolsRewards) {
|
25
|
+
if (!poolReward || !poolReward.fields)
|
26
|
+
continue;
|
27
|
+
poolRewardById.set(poolReward.fields.id.id, poolReward.fields);
|
28
|
+
}
|
29
|
+
poolsRewardByManagerId.set(reserve.fields.borrows_pool_reward_manager.fields.id.id, borrowPoolsRewards.map((data) => (data ? data.fields : null)));
|
21
30
|
}
|
22
31
|
}
|
23
|
-
return
|
32
|
+
return [poolRewardById, poolsRewardByManagerId];
|
24
33
|
}
|
25
|
-
exports.
|
34
|
+
exports.getPoolsRewardsMaps = getPoolsRewardsMaps;
|
26
35
|
function getRatesAsMap(borrowLendRates) {
|
27
36
|
const ratesByReserveId = new Map();
|
28
37
|
if (!borrowLendRates)
|
@@ -37,9 +46,13 @@ exports.getRatesAsMap = getRatesAsMap;
|
|
37
46
|
function getBorrowApr(utilization, borrowedAmount, availableAmount, reserveFields) {
|
38
47
|
const { interest_rate_aprs: rateAprs, interest_rate_utils: rateUtils } = reserveFields.config.fields.element.fields;
|
39
48
|
if (borrowedAmount.isZero())
|
40
|
-
return (0, bignumber_js_1.default)(rateAprs[0])
|
49
|
+
return (0, bignumber_js_1.default)(rateAprs[0])
|
50
|
+
.dividedBy(Math.pow(10, 4))
|
51
|
+
.toNumber();
|
41
52
|
if (availableAmount.isZero())
|
42
|
-
return (0, bignumber_js_1.default)(rateAprs[rateAprs.length])
|
53
|
+
return (0, bignumber_js_1.default)(rateAprs[rateAprs.length])
|
54
|
+
.dividedBy(Math.pow(10, 4))
|
55
|
+
.toNumber();
|
43
56
|
for (let i = 0; i < rateUtils.length; i++) {
|
44
57
|
const currentUtil = rateUtils[i] / 100;
|
45
58
|
const nextUtil = rateUtils[i + 1] / 100;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/suilend/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAIrC,SAAgB,
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/suilend/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAIrC,SAAgB,mBAAmB,CACjC,cAA2C;IAE3C,MAAM,cAAc,GAAmB,IAAI,GAAG,EAAE,CAAC;IACjD,MAAM,sBAAsB,GAA2B,IAAI,GAAG,EAAE,CAAC;IACjE,IAAI,CAAC,cAAc;QAAE,OAAO,CAAC,cAAc,EAAE,sBAAsB,CAAC,CAAC;IAErE,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE,CAAC;QAC3C,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;QACnC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,MAAM,oBAAoB,GACxB,OAAO,CAAC,MAAM,CAAC,4BAA4B,CAAC,MAAM,CAAC,YAAY,CAAC;YAClE,KAAK,MAAM,UAAU,IAAI,oBAAoB,EAAE,CAAC;gBAC9C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU,CAAC,MAAM;oBAAE,SAAS;gBAChD,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;YACjE,CAAC;YACD,sBAAsB,CAAC,GAAG,CACxB,OAAO,CAAC,MAAM,CAAC,4BAA4B,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EACxD,oBAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,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AC,KAAK,CAAC,WAAW,CAAC,CAAC;YACxD,MAAM,cAAc,GAAG,QAAQ,GAAG,WAAW,CAAC;YAC9C,OAAO,gBAAgB;iBACpB,SAAS,CAAC,cAAc,CAAC;iBACzB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;iBAChC,IAAI,CAAC,UAAU,CAAC;iBAChB,QAAQ,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAtCD,oCAsCC;AAED,SAAgB,aAAa,CAC3B,WAAsB,EACtB,SAAiB,EACjB,aAAsB;IAEtB,OAAO,IAAA,sBAAS,EAAC,SAAS,CAAC;SACxB,KAAK,CACJ,CAAC;QACC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC;YAC/D,SAAA,EAAE,EAAI,CAAC,CAAA,CACZ;SACA,KAAK,CAAC,WAAW,CAAC;SAClB,QAAQ,EAAE,CAAC;AAChB,CAAC;AAbD,sCAaC"}
|
@@ -54,8 +54,8 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
54
54
|
marketsInfo.lendingMarkets.forEach((market) => {
|
55
55
|
marketsByIndex.set(market.id.id, market);
|
56
56
|
});
|
57
|
-
const poolRewardById = (0, helpers_1.
|
58
|
-
poolRewardById.forEach((pool) => mints.add(pool.coin_type.fields.name));
|
57
|
+
const [poolRewardById, poolsRewardByManagerId] = (0, helpers_1.getPoolsRewardsMaps)(lendingMarkets);
|
58
|
+
poolRewardById.forEach((pool) => pool ? mints.add(pool.coin_type.fields.name) : undefined);
|
59
59
|
const borrowedAssets = [];
|
60
60
|
const borrowedYields = [];
|
61
61
|
const suppliedAssets = [];
|
@@ -152,14 +152,33 @@ const executor = (owner, cache) => __awaiter(void 0, void 0, void 0, function* (
|
|
152
152
|
.dividedBy(Math.pow(10, constants_2.wadsDecimal));
|
153
153
|
if (cumulativeAmount.isLessThanOrEqualTo(0))
|
154
154
|
continue;
|
155
|
-
const
|
156
|
-
if (
|
157
|
-
rewardAmountByMint.set(rewardMint,
|
155
|
+
const previousAmount = rewardAmountByMint.get(rewardMint);
|
156
|
+
if (previousAmount) {
|
157
|
+
rewardAmountByMint.set(rewardMint, previousAmount.plus(cumulativeAmount));
|
158
158
|
}
|
159
159
|
else {
|
160
160
|
rewardAmountByMint.set(rewardMint, cumulativeAmount);
|
161
161
|
}
|
162
162
|
}
|
163
|
+
if (userRewardManager.fields.rewards.length === 0) {
|
164
|
+
const poolsRewards = poolsRewardByManagerId.get(userRewardManager.fields.pool_reward_manager_id);
|
165
|
+
if (poolsRewards) {
|
166
|
+
for (const poolReward of poolsRewards) {
|
167
|
+
if (!poolReward)
|
168
|
+
continue;
|
169
|
+
const amount = new bignumber_js_1.default(poolReward.cumulative_rewards_per_share.fields.value)
|
170
|
+
.times(share)
|
171
|
+
.dividedBy(Math.pow(10, constants_2.wadsDecimal));
|
172
|
+
const previousAmount = rewardAmountByMint.get(poolReward.coin_type.fields.name);
|
173
|
+
if (previousAmount) {
|
174
|
+
rewardAmountByMint.set(poolReward.coin_type.fields.name, previousAmount.plus(amount));
|
175
|
+
}
|
176
|
+
else {
|
177
|
+
rewardAmountByMint.set(poolReward.coin_type.fields.name, amount);
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
163
182
|
}
|
164
183
|
rewardAmountByMint.forEach((amount, mint) => {
|
165
184
|
const tokenPrice = tokenPriceById.get((0, portfolio_core_1.formatTokenAddress)(mint, portfolio_core_1.NetworkId.sui));
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"obligationsFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/suilend/obligationsFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAQoC;AACpC,gEAAqC;AAGrC,2CAKqB;AACrB,iDAAmD;AACnD,qEAAkE;AAOlE,qEAAkE;AAClE,qGAA6E;AAC7E,
|
1
|
+
{"version":3,"file":"obligationsFetcher.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/plugins/suilend/obligationsFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAQoC;AACpC,gEAAqC;AAGrC,2CAKqB;AACrB,iDAAmD;AACnD,qEAAkE;AAOlE,qEAAkE;AAClE,qGAA6E;AAC7E,uCAA+D;AAC/D,iDAAgD;AAEhD,MAAM,QAAQ,GAAoB,CAAO,KAAa,EAAE,KAAY,EAAE,EAAE;;IACtE,MAAM,MAAM,GAAG,IAAA,sBAAY,GAAE,CAAC;IAE9B,MAAM,oBAAoB,GAAG,MAAM,IAAA,iCAAe,EAChD,MAAM,EACN,KAAK,EACL;QACE,MAAM,EAAE,EAAE,OAAO,EAAE,qBAAS,EAAE;KAC/B,CACF,CAAC;IACF,IAAI,oBAAoB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjD,MAAM,aAAa,GAAa,EAAE,CAAC;IACnC,KAAK,MAAM,kBAAkB,IAAI,oBAAoB,EAAE,CAAC;QACtD,MAAM,IAAI,GAAG,MAAA,MAAA,kBAAkB,CAAC,IAAI,0CAAE,OAAO,0CAAE,IAAI,CAAC;QACpD,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,UAAU,CAAC,kCAAsB,CAAC,CAAA;YAAE,SAAS;QAExD,MAAM,YAAY,GAAG,MAAA,MAAA,kBAAkB,CAAC,IAAI,0CAAE,OAAO,0CAAE,MAAM,CAAC,aAAa,CAAC;QAC5E,IAAI,YAAY;YAAE,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,IAAA,iCAAe,EAAa,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7E,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAExC,MAAM,KAAK,G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,MAAM,KAAK,CAAC;QAC3B,cAAc,CAAC,MAAM,KAAK,CAAC;QAC3B,YAAY,CAAC,MAAM,KAAK,CAAC;QAEzB,OAAO,EAAE,CAAC;IAEZ,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,GACrE,IAAA,wCAAuB,EAAC;QACtB,cAAc;QACd,cAAc;QACd,YAAY;QACZ,YAAY;QACZ,eAAe;KAChB,CAAC,CAAC;IAEL,MAAM,OAAO,GAAqB;QAChC,IAAI,EAAE,qCAAoB,CAAC,UAAU;QACrC,SAAS,EAAE,0BAAS,CAAC,GAAG;QACxB,UAAU,EAAV,sBAAU;QACV,KAAK,EAAE,SAAS;QAChB,KAAK;QACL,IAAI,EAAE;YACJ,cAAc;YACd,aAAa;YACb,cAAc;YACd,cAAc;YACd,aAAa;YACb,cAAc;YACd,WAAW;YACX,YAAY;YACZ,WAAW;YACX,KAAK;SACN;KACF,CAAC;IACF,OAAO,CAAC,OAAO,CAAC,CAAC;AACnB,CAAC,CAAA,CAAC;AAEF,MAAM,OAAO,GAAY;IACvB,EAAE,EAAE,GAAG,sBAAU,cAAc;IAC/B,SAAS,EAAE,0BAAS,CAAC,GAAG;IACxB,QAAQ;CACT,CAAC;AAEF,kBAAe,OAAO,CAAC"}
|
@@ -85,7 +85,7 @@ export type PoolRewardManager = {
|
|
85
85
|
pool_rewards: ParsedData<PoolReward>[];
|
86
86
|
total_shares: string;
|
87
87
|
};
|
88
|
-
export type PoolReward = {
|
88
|
+
export type PoolReward = null | {
|
89
89
|
id: ID;
|
90
90
|
additional_fields: ParsedData<AdditionalFields>;
|
91
91
|
allocated_rewards: ParsedData<Value>;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import BigNumber from 'bignumber.js';
|
2
|
+
/**
|
3
|
+
* Get both Lending and Borrowing APRs of a market
|
4
|
+
*
|
5
|
+
* @param {BigNumber} borrowedAmount Borrow Amount of the market (decimals applied)
|
6
|
+
* @param {BigNumber} availableAmount Available Amount of the market (decimals applied)
|
7
|
+
* @param {number[]} interestRateAprs The differents raw level of APRs (i.e 2 = 2%, expecting 2 here)
|
8
|
+
* @param {number[]} interestRateSteps The steps of each level of APRs (i.e 80 = 80%, expecting 80 here)
|
9
|
+
* @param {number} spreadFeeBps The spread fee (fee of the protocol) (i.e 2 = 2%, expecting 2 here)
|
10
|
+
*
|
11
|
+
* @returns {Aprs} BorrowApr and DepositApr of the market in raw value (i.e 0.02 = 2%)
|
12
|
+
*/
|
13
|
+
export default function getLendingMarketAprs(borrowedAmount: BigNumber, availableAmount: BigNumber, interestRateAprs: number[], interestRateSteps: number[], spreadFeeBps: number): Aprs;
|
14
|
+
type Aprs = {
|
15
|
+
borrowApr: number;
|
16
|
+
depositApr: number;
|
17
|
+
};
|
18
|
+
export {};
|
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
7
|
+
/**
|
8
|
+
* Get both Lending and Borrowing APRs of a market
|
9
|
+
*
|
10
|
+
* @param {BigNumber} borrowedAmount Borrow Amount of the market (decimals applied)
|
11
|
+
* @param {BigNumber} availableAmount Available Amount of the market (decimals applied)
|
12
|
+
* @param {number[]} interestRateAprs The differents raw level of APRs (i.e 2 = 2%, expecting 2 here)
|
13
|
+
* @param {number[]} interestRateSteps The steps of each level of APRs (i.e 80 = 80%, expecting 80 here)
|
14
|
+
* @param {number} spreadFeeBps The spread fee (fee of the protocol) (i.e 2 = 2%, expecting 2 here)
|
15
|
+
*
|
16
|
+
* @returns {Aprs} BorrowApr and DepositApr of the market in raw value (i.e 0.02 = 2%)
|
17
|
+
*/
|
18
|
+
function getLendingMarketAprs(borrowedAmount, availableAmount, interestRateAprs, interestRateSteps, spreadFeeBps) {
|
19
|
+
if (interestRateAprs.length !== interestRateSteps.length)
|
20
|
+
throw new Error("Interest Rate Aprs and Steps length don't match");
|
21
|
+
const utilization = borrowedAmount.dividedBy(availableAmount.plus(borrowedAmount));
|
22
|
+
let borrowApr = 0;
|
23
|
+
if (borrowedAmount.isZero())
|
24
|
+
borrowApr = (0, bignumber_js_1.default)(interestRateAprs[0]).dividedBy(100).toNumber();
|
25
|
+
if (availableAmount.isZero())
|
26
|
+
borrowApr = (0, bignumber_js_1.default)(interestRateAprs[interestRateAprs.length])
|
27
|
+
.dividedBy(100)
|
28
|
+
.toNumber();
|
29
|
+
for (let i = 0; i < interestRateSteps.length; i++) {
|
30
|
+
const currentUtil = interestRateSteps[i] / 100;
|
31
|
+
const nextUtil = interestRateSteps[i + 1] / 100;
|
32
|
+
const currentApr = new bignumber_js_1.default(interestRateAprs[i]).dividedBy(100);
|
33
|
+
const nextApr = new bignumber_js_1.default(interestRateAprs[i + 1]).dividedBy(100);
|
34
|
+
if (utilization.isEqualTo(currentUtil)) {
|
35
|
+
borrowApr = currentApr.toNumber();
|
36
|
+
}
|
37
|
+
if (utilization.isLessThan(nextUtil)) {
|
38
|
+
const utilizationDelta = utilization.minus(currentUtil);
|
39
|
+
const utilStepsDelta = nextUtil - currentUtil;
|
40
|
+
borrowApr = utilizationDelta
|
41
|
+
.dividedBy(utilStepsDelta)
|
42
|
+
.times(nextApr.minus(currentApr))
|
43
|
+
.plus(currentApr)
|
44
|
+
.toNumber();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
borrowApr = 0;
|
48
|
+
const depositApr = (0, bignumber_js_1.default)(borrowApr)
|
49
|
+
.times(1 - Number(spreadFeeBps) / 100)
|
50
|
+
.times(utilization)
|
51
|
+
.toNumber();
|
52
|
+
return {
|
53
|
+
borrowApr,
|
54
|
+
depositApr,
|
55
|
+
};
|
56
|
+
}
|
57
|
+
exports.default = getLendingMarketAprs;
|
58
|
+
//# sourceMappingURL=getLendingMarketAprs.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getLendingMarketAprs.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/misc/getLendingMarketAprs.ts"],"names":[],"mappings":";;;;;AAAA,gEAAqC;AAErC;;;;;;;;;;GAUG;AACH,SAAwB,oBAAoB,CAC1C,cAAyB,EACzB,eAA0B,EAC1B,gBAA0B,EAC1B,iBAA2B,EAC3B,YAAoB;IAEpB,IAAI,gBAAgB,CAAC,MAAM,KAAK,iBAAiB,CAAC,MAAM;QACtD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAErE,MAAM,WAAW,GAAG,cAAc,CAAC,SAAS,CAC1C,eAAe,CAAC,IAAI,CAAC,cAAc,CAAC,CACrC,CAAC;IACF,IAAI,SAAS,GAAG,CAAC,CAAC;IAClB,IAAI,cAAc,CAAC,MAAM,EAAE;QACzB,SAAS,GAAG,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvE,IAAI,eAAe,CAAC,MAAM,EAAE;QAC1B,SAAS,GAAG,IAAA,sBAAS,EAAC,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAC;aAC7D,SAAS,CAAC,GAAG,CAAC;aACd,QAAQ,EAAE,CAAC;IAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClD,MAAM,WAAW,GAAG,iBAAiB,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QAC/C,MAAM,QAAQ,GAAG,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;QAChD,MAAM,UAAU,GAAG,IAAI,sBAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACrE,MAAM,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