@ichidao/ichi-vaults-sdk 0.1.42 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -208
- package/dist/abis/types/AlgebraIntegralPool.d.ts +702 -793
- package/dist/abis/types/AlgebraPool.d.ts +693 -730
- package/dist/abis/types/ClPool.d.ts +789 -871
- package/dist/abis/types/DepositGuard.d.ts +193 -178
- package/dist/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
- package/dist/abis/types/ERC20.d.ts +120 -147
- package/dist/abis/types/ERC20Wrapper.d.ts +147 -155
- package/dist/abis/types/IchiVault.d.ts +598 -728
- package/dist/abis/types/MultiFeeDistributer.d.ts +314 -423
- package/dist/abis/types/Multicall.d.ts +58 -73
- package/dist/abis/types/UniswapV3Pool.d.ts +654 -693
- package/dist/abis/types/common.d.ts +40 -12
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.js +10 -13
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.js.map +1 -1
- package/dist/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/AlgebraPool__factory.js +10 -13
- package/dist/abis/types/factories/AlgebraPool__factory.js.map +1 -1
- package/dist/abis/types/factories/ClPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/ClPool__factory.js +10 -13
- package/dist/abis/types/factories/ClPool__factory.js.map +1 -1
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js +10 -13
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js.map +1 -1
- package/dist/abis/types/factories/DepositGuard__factory.d.ts +2 -3
- package/dist/abis/types/factories/DepositGuard__factory.js +10 -13
- package/dist/abis/types/factories/DepositGuard__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
- package/dist/abis/types/factories/ERC20Wrapper__factory.js +10 -13
- package/dist/abis/types/factories/ERC20Wrapper__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20__factory.d.ts +2 -3
- package/dist/abis/types/factories/ERC20__factory.js +10 -13
- package/dist/abis/types/factories/ERC20__factory.js.map +1 -1
- package/dist/abis/types/factories/IchiVault__factory.d.ts +2 -3
- package/dist/abis/types/factories/IchiVault__factory.js +10 -13
- package/dist/abis/types/factories/IchiVault__factory.js.map +1 -1
- package/dist/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
- package/dist/abis/types/factories/MultiFeeDistributer__factory.js +10 -13
- package/dist/abis/types/factories/MultiFeeDistributer__factory.js.map +1 -1
- package/dist/abis/types/factories/Multicall__factory.d.ts +2 -3
- package/dist/abis/types/factories/Multicall__factory.js +10 -13
- package/dist/abis/types/factories/Multicall__factory.js.map +1 -1
- package/dist/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
- package/dist/abis/types/factories/UniswapV3Pool__factory.js +10 -13
- package/dist/abis/types/factories/UniswapV3Pool__factory.js.map +1 -1
- package/dist/src/__tests__/index.test.js +376 -700
- package/dist/src/__tests__/index.test.js.map +1 -1
- package/dist/src/abis/types/AlgebraIntegralPool.d.ts +702 -793
- package/dist/src/abis/types/AlgebraPool.d.ts +693 -730
- package/dist/src/abis/types/ClPool.d.ts +789 -871
- package/dist/src/abis/types/DepositGuard.d.ts +193 -178
- package/dist/src/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
- package/dist/src/abis/types/ERC20.d.ts +120 -147
- package/dist/src/abis/types/ERC20Wrapper.d.ts +147 -155
- package/dist/src/abis/types/IchiVault.d.ts +598 -728
- package/dist/src/abis/types/MultiFeeDistributer.d.ts +314 -423
- package/dist/src/abis/types/Multicall.d.ts +58 -73
- package/dist/src/abis/types/UniswapV3Pool.d.ts +654 -693
- package/dist/src/abis/types/common.d.ts +40 -12
- package/dist/src/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ClPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/DepositGuard__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ERC20__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/IchiVault__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/Multicall__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
- package/dist/src/contracts/index.d.ts +1 -1
- package/dist/src/contracts/index.js +12 -12
- package/dist/src/contracts/index.js.map +1 -1
- package/dist/src/functions/_totalBalances.d.ts +2 -3
- package/dist/src/functions/_totalBalances.js +46 -117
- package/dist/src/functions/_totalBalances.js.map +1 -1
- package/dist/src/functions/_vaultEvents.js +347 -488
- package/dist/src/functions/_vaultEvents.js.map +1 -1
- package/dist/src/functions/_withdrawHelpers.d.ts +2 -3
- package/dist/src/functions/_withdrawHelpers.js +13 -62
- package/dist/src/functions/_withdrawHelpers.js.map +1 -1
- package/dist/src/functions/calculateApr.d.ts +1 -1
- package/dist/src/functions/calculateApr.js +77 -150
- package/dist/src/functions/calculateApr.js.map +1 -1
- package/dist/src/functions/calculateDtr.d.ts +1 -1
- package/dist/src/functions/calculateDtr.js +84 -169
- package/dist/src/functions/calculateDtr.js.map +1 -1
- package/dist/src/functions/calculateFees.d.ts +1 -1
- package/dist/src/functions/calculateFees.js +97 -172
- package/dist/src/functions/calculateFees.js.map +1 -1
- package/dist/src/functions/chains.js +6 -6
- package/dist/src/functions/chains.js.map +1 -1
- package/dist/src/functions/claimRewards.d.ts +3 -4
- package/dist/src/functions/claimRewards.js +29 -92
- package/dist/src/functions/claimRewards.js.map +1 -1
- package/dist/src/functions/deposit.d.ts +7 -9
- package/dist/src/functions/deposit.js +199 -364
- package/dist/src/functions/deposit.js.map +1 -1
- package/dist/src/functions/depositWithHtsWrapping.d.ts +4 -6
- package/dist/src/functions/depositWithHtsWrapping.js +109 -226
- package/dist/src/functions/depositWithHtsWrapping.js.map +1 -1
- package/dist/src/functions/getFeeAprs.d.ts +1 -1
- package/dist/src/functions/getFeeAprs.js +55 -111
- package/dist/src/functions/getFeeAprs.js.map +1 -1
- package/dist/src/functions/priceFromPool.d.ts +3 -4
- package/dist/src/functions/priceFromPool.js +99 -208
- package/dist/src/functions/priceFromPool.js.map +1 -1
- package/dist/src/functions/rewardInfo.js +79 -159
- package/dist/src/functions/rewardInfo.js.map +1 -1
- package/dist/src/functions/totalBalances.d.ts +2 -3
- package/dist/src/functions/totalBalances.js +14 -67
- package/dist/src/functions/totalBalances.js.map +1 -1
- package/dist/src/functions/userBalances.d.ts +2 -3
- package/dist/src/functions/userBalances.js +244 -368
- package/dist/src/functions/userBalances.js.map +1 -1
- package/dist/src/functions/userRewards.d.ts +1 -1
- package/dist/src/functions/userRewards.js +87 -145
- package/dist/src/functions/userRewards.js.map +1 -1
- package/dist/src/functions/vault.d.ts +1 -1
- package/dist/src/functions/vault.js +203 -383
- package/dist/src/functions/vault.js.map +1 -1
- package/dist/src/functions/vaultBasics.js +6 -7
- package/dist/src/functions/vaultBasics.js.map +1 -1
- package/dist/src/functions/vaultMetrics.d.ts +1 -1
- package/dist/src/functions/vaultMetrics.js +111 -189
- package/dist/src/functions/vaultMetrics.js.map +1 -1
- package/dist/src/functions/vaultPositions.d.ts +1 -1
- package/dist/src/functions/vaultPositions.js +69 -134
- package/dist/src/functions/vaultPositions.js.map +1 -1
- package/dist/src/functions/vaultTvl.d.ts +1 -1
- package/dist/src/functions/vaultTvl.js +80 -165
- package/dist/src/functions/vaultTvl.js.map +1 -1
- package/dist/src/functions/withdraw.d.ts +6 -8
- package/dist/src/functions/withdraw.js +165 -295
- package/dist/src/functions/withdraw.js.map +1 -1
- package/dist/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
- package/dist/src/functions/withdrawWithErc20Wrapping.js +59 -126
- package/dist/src/functions/withdrawWithErc20Wrapping.js.map +1 -1
- package/dist/src/graphql/constants.js +211 -212
- package/dist/src/graphql/constants.js.map +1 -1
- package/dist/src/graphql/functions.js +30 -102
- package/dist/src/graphql/functions.js.map +1 -1
- package/dist/src/graphql/queries.js +407 -42
- package/dist/src/graphql/queries.js.map +1 -1
- package/dist/src/index.cjs.js +3 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.esm.js +3 -2
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/src/contracts/index.d.ts +1 -1
- package/dist/src/src/functions/_totalBalances.d.ts +2 -3
- package/dist/src/src/functions/_withdrawHelpers.d.ts +2 -3
- package/dist/src/src/functions/calculateApr.d.ts +1 -1
- package/dist/src/src/functions/calculateDtr.d.ts +1 -1
- package/dist/src/src/functions/calculateFees.d.ts +1 -1
- package/dist/src/src/functions/claimRewards.d.ts +3 -4
- package/dist/src/src/functions/deposit.d.ts +7 -9
- package/dist/src/src/functions/depositWithHtsWrapping.d.ts +4 -6
- package/dist/src/src/functions/getFeeAprs.d.ts +1 -1
- package/dist/src/src/functions/priceFromPool.d.ts +3 -4
- package/dist/src/src/functions/totalBalances.d.ts +2 -3
- package/dist/src/src/functions/userBalances.d.ts +2 -3
- package/dist/src/src/functions/userRewards.d.ts +1 -1
- package/dist/src/src/functions/vault.d.ts +1 -1
- package/dist/src/src/functions/vaultMetrics.d.ts +1 -1
- package/dist/src/src/functions/vaultPositions.d.ts +1 -1
- package/dist/src/src/functions/vaultTvl.d.ts +1 -1
- package/dist/src/src/functions/withdraw.d.ts +6 -8
- package/dist/src/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
- package/dist/src/src/index.d.ts +1 -0
- package/dist/src/src/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/src/types/index.d.ts +11 -13
- package/dist/src/src/utils/amountWithSlippage.d.ts +1 -2
- package/dist/src/src/utils/config/addresses.d.ts +1 -1
- package/dist/src/src/utils/formatBigInt.d.ts +1 -2
- package/dist/src/src/utils/getConfigByFactory.d.ts +33 -0
- package/dist/src/src/utils/getPrice.d.ts +1 -2
- package/dist/src/src/utils/multicallUtils.d.ts +9 -10
- package/dist/src/src/utils/parseBigInt.d.ts +1 -2
- package/dist/src/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/types/calculateGasMargin.js +4 -5
- package/dist/src/types/calculateGasMargin.js.map +1 -1
- package/dist/src/types/index.d.ts +11 -13
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/utils/amountWithSlippage.d.ts +1 -2
- package/dist/src/utils/amountWithSlippage.js +1 -1
- package/dist/src/utils/amountWithSlippage.js.map +1 -1
- package/dist/src/utils/cache.js +2 -2
- package/dist/src/utils/cache.js.map +1 -1
- package/dist/src/utils/config/addresses.d.ts +1 -1
- package/dist/src/utils/config/addresses.js +267 -268
- package/dist/src/utils/config/addresses.js.map +1 -1
- package/dist/src/utils/formatBigInt.d.ts +1 -2
- package/dist/src/utils/formatBigInt.js +4 -5
- package/dist/src/utils/formatBigInt.js.map +1 -1
- package/dist/src/utils/getConfigByFactory.d.ts +33 -0
- package/dist/src/utils/getConfigByFactory.js +79 -0
- package/dist/src/utils/getConfigByFactory.js.map +1 -0
- package/dist/src/utils/getGraphUrls.js +8 -12
- package/dist/src/utils/getGraphUrls.js.map +1 -1
- package/dist/src/utils/getPrice.d.ts +1 -2
- package/dist/src/utils/getPrice.js +5 -6
- package/dist/src/utils/getPrice.js.map +1 -1
- package/dist/src/utils/isVelodrome.js +2 -3
- package/dist/src/utils/isVelodrome.js.map +1 -1
- package/dist/src/utils/multicallUtils.d.ts +9 -10
- package/dist/src/utils/multicallUtils.js +38 -93
- package/dist/src/utils/multicallUtils.js.map +1 -1
- package/dist/src/utils/parseBigInt.d.ts +1 -2
- package/dist/src/utils/parseBigInt.js +5 -7
- package/dist/src/utils/parseBigInt.js.map +1 -1
- package/dist/src/utils/positionKey.js +2 -4
- package/dist/src/utils/positionKey.js.map +1 -1
- package/package.json +5 -17
|
@@ -1,51 +1,15 @@
|
|
|
1
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 __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.getFeeAprs = void 0;
|
|
43
7
|
// eslint-disable-next-line import/no-cycle
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
8
|
+
const vault_1 = require("./vault");
|
|
9
|
+
const constants_1 = require("../graphql/constants");
|
|
10
|
+
const getGraphUrls_1 = require("../utils/getGraphUrls");
|
|
11
|
+
const cache_1 = __importDefault(require("../utils/cache"));
|
|
12
|
+
const functions_1 = require("../graphql/functions");
|
|
49
13
|
/**
|
|
50
14
|
* Get fee APR values for a vault from a V2 subgraph
|
|
51
15
|
* @param vaultAddress The address of the vault
|
|
@@ -53,77 +17,57 @@ var functions_1 = require("../graphql/functions");
|
|
|
53
17
|
* @param dex The DEX identifier
|
|
54
18
|
* @returns Fee APR data for different time periods or null if data not available
|
|
55
19
|
*/
|
|
56
|
-
function getFeeAprs(vaultAddress, jsonProvider, dex) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_b = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true), publishedUrl = _b.publishedUrl, url = _b.url;
|
|
78
|
-
_c.label = 2;
|
|
79
|
-
case 2:
|
|
80
|
-
_c.trys.push([2, 11, , 12]);
|
|
81
|
-
result = null;
|
|
82
|
-
if (!publishedUrl) return [3 /*break*/, 6];
|
|
83
|
-
_c.label = 3;
|
|
84
|
-
case 3:
|
|
85
|
-
_c.trys.push([3, 5, , 6]);
|
|
86
|
-
return [4 /*yield*/, (0, functions_1.sendFeeAprQueryRequest)(publishedUrl, vaultAddress)];
|
|
87
|
-
case 4:
|
|
88
|
-
result = _c.sent();
|
|
89
|
-
return [3 /*break*/, 6];
|
|
90
|
-
case 5:
|
|
91
|
-
error_1 = _c.sent();
|
|
92
|
-
console.error('Request to published graph URL failed:', error_1);
|
|
93
|
-
return [3 /*break*/, 6];
|
|
94
|
-
case 6:
|
|
95
|
-
if (!!result) return [3 /*break*/, 10];
|
|
96
|
-
_c.label = 7;
|
|
97
|
-
case 7:
|
|
98
|
-
_c.trys.push([7, 9, , 10]);
|
|
99
|
-
return [4 /*yield*/, (0, functions_1.sendFeeAprQueryRequest)(url, vaultAddress)];
|
|
100
|
-
case 8:
|
|
101
|
-
result = _c.sent();
|
|
102
|
-
return [3 /*break*/, 10];
|
|
103
|
-
case 9:
|
|
104
|
-
error_2 = _c.sent();
|
|
105
|
-
console.error('Request to public graph URL failed:', error_2);
|
|
106
|
-
return [2 /*return*/, null];
|
|
107
|
-
case 10:
|
|
108
|
-
if (!(result === null || result === void 0 ? void 0 : result.ichiVault)) {
|
|
109
|
-
return [2 /*return*/, null];
|
|
110
|
-
}
|
|
111
|
-
feeAprData = {
|
|
112
|
-
feeApr_1d: result.ichiVault.feeApr_1d ? result.ichiVault.feeApr_1d : null,
|
|
113
|
-
feeApr_3d: result.ichiVault.feeApr_3d ? result.ichiVault.feeApr_3d : null,
|
|
114
|
-
feeApr_7d: result.ichiVault.feeApr_7d ? result.ichiVault.feeApr_7d : null,
|
|
115
|
-
feeApr_30d: result.ichiVault.feeApr_30d ? result.ichiVault.feeApr_30d : null,
|
|
116
|
-
};
|
|
117
|
-
cache_1.default.set(key, feeAprData, ttl);
|
|
118
|
-
return [2 /*return*/, feeAprData];
|
|
119
|
-
case 11:
|
|
120
|
-
error_3 = _c.sent();
|
|
121
|
-
console.error("Could not get fee APRs for vault ".concat(vaultAddress, " on chain ").concat(chainId, " and dex ").concat(dex, ":"), error_3);
|
|
122
|
-
return [2 /*return*/, null];
|
|
123
|
-
case 12: return [2 /*return*/];
|
|
20
|
+
async function getFeeAprs(vaultAddress, jsonProvider, dex) {
|
|
21
|
+
const key = `feeAprs-${dex}-${vaultAddress}`;
|
|
22
|
+
const cachedData = cache_1.default.get(key);
|
|
23
|
+
if (cachedData) {
|
|
24
|
+
return cachedData;
|
|
25
|
+
}
|
|
26
|
+
// Cache for 30 minutes
|
|
27
|
+
const ttl = 30 * 60 * 1000;
|
|
28
|
+
const { chainId } = await (0, vault_1.validateVaultData)(vaultAddress, jsonProvider, dex);
|
|
29
|
+
// Check if the subgraph is version 2
|
|
30
|
+
const dexConfig = constants_1.graphUrls[chainId]?.[dex];
|
|
31
|
+
if (!dexConfig || dexConfig.version !== 2) {
|
|
32
|
+
console.error(`This function is not supported on chain ${chainId} and dex ${dex}:`);
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const { publishedUrl, url } = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
36
|
+
try {
|
|
37
|
+
let result = null;
|
|
38
|
+
if (publishedUrl) {
|
|
39
|
+
try {
|
|
40
|
+
result = await (0, functions_1.sendFeeAprQueryRequest)(publishedUrl, vaultAddress);
|
|
124
41
|
}
|
|
125
|
-
|
|
126
|
-
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('Request to published graph URL failed:', error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!result) {
|
|
47
|
+
try {
|
|
48
|
+
result = await (0, functions_1.sendFeeAprQueryRequest)(url, vaultAddress);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
console.error('Request to public graph URL failed:', error);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (!result?.ichiVault) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const feeAprData = {
|
|
59
|
+
feeApr_1d: result.ichiVault.feeApr_1d ? result.ichiVault.feeApr_1d : null,
|
|
60
|
+
feeApr_3d: result.ichiVault.feeApr_3d ? result.ichiVault.feeApr_3d : null,
|
|
61
|
+
feeApr_7d: result.ichiVault.feeApr_7d ? result.ichiVault.feeApr_7d : null,
|
|
62
|
+
feeApr_30d: result.ichiVault.feeApr_30d ? result.ichiVault.feeApr_30d : null,
|
|
63
|
+
};
|
|
64
|
+
cache_1.default.set(key, feeAprData, ttl);
|
|
65
|
+
return feeAprData;
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error(`Could not get fee APRs for vault ${vaultAddress} on chain ${chainId} and dex ${dex}:`, error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
127
71
|
}
|
|
128
72
|
exports.getFeeAprs = getFeeAprs;
|
|
129
73
|
//# sourceMappingURL=getFeeAprs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFeeAprs.js","sourceRoot":"","sources":["../../../src/functions/getFeeAprs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"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ber';
|
|
1
|
+
import { JsonRpcProvider } from 'ethers';
|
|
3
2
|
import { IchiVault, SupportedChainId, SupportedDex } from '../types';
|
|
4
|
-
export declare function getSqrtPriceFromPool(poolAddress: string, jsonProvider: JsonRpcProvider, chainId: SupportedChainId, dex: SupportedDex): Promise<
|
|
5
|
-
export declare function getSqrtPriceFromVault(vault: IchiVault, jsonProvider: JsonRpcProvider, chainId: SupportedChainId, dex: SupportedDex): Promise<
|
|
3
|
+
export declare function getSqrtPriceFromPool(poolAddress: string, jsonProvider: JsonRpcProvider, chainId: SupportedChainId, dex: SupportedDex): Promise<bigint>;
|
|
4
|
+
export declare function getSqrtPriceFromVault(vault: IchiVault, jsonProvider: JsonRpcProvider, chainId: SupportedChainId, dex: SupportedDex): Promise<bigint>;
|
|
6
5
|
export declare function getCurrPrice(vault: IchiVault, jsonProvider: JsonRpcProvider, chainId: SupportedChainId, dex: SupportedDex, isVaultInverted: boolean, token0decimals: number, token1decimals: number): Promise<number>;
|
|
7
6
|
export declare function getVaultTvl(vault: IchiVault, jsonProvider: JsonRpcProvider, chainId: SupportedChainId, dex: SupportedDex, isVaultInverted: boolean, token0decimals: number, token1decimals: number): Promise<number>;
|
|
8
7
|
export declare function getCurrLpPrice(vault: IchiVault, jsonProvider: JsonRpcProvider, dex: SupportedDex, chainId: SupportedChainId, isVaultInverted: boolean, token0decimals: number, token1decimals: number): Promise<number>;
|
|
@@ -1,234 +1,125 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable no-redeclare */
|
|
3
3
|
/* eslint-disable import/prefer-default-export */
|
|
4
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
14
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
15
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
16
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
17
|
-
function step(op) {
|
|
18
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
19
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
20
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
21
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
22
|
-
switch (op[0]) {
|
|
23
|
-
case 0: case 1: t = op; break;
|
|
24
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
25
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
26
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
27
|
-
default:
|
|
28
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
29
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
30
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
31
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
32
|
-
if (t[2]) _.ops.pop();
|
|
33
|
-
_.trys.pop(); continue;
|
|
34
|
-
}
|
|
35
|
-
op = body.call(thisArg, _);
|
|
36
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
37
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
4
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
5
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
6
|
};
|
|
43
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
8
|
exports.getCurrentDtr = exports.getCurrLpPrice = exports.getVaultTvl = exports.getCurrPrice = exports.getSqrtPriceFromVault = exports.getSqrtPriceFromPool = void 0;
|
|
45
|
-
|
|
9
|
+
const types_1 = require("../types");
|
|
46
10
|
// eslint-disable-next-line import/no-cycle
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function getSqrtPriceFromPool(poolAddress, jsonProvider, chainId, dex) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case 1:
|
|
70
|
-
globalState = _b.sent();
|
|
71
|
-
return [2 /*return*/, globalState[0]];
|
|
72
|
-
case 2:
|
|
73
|
-
poolContract = (0, contracts_1.getAlgebraPoolContract)(poolAddress, jsonProvider);
|
|
74
|
-
return [4 /*yield*/, poolContract.globalState()];
|
|
75
|
-
case 3:
|
|
76
|
-
globalState = _b.sent();
|
|
77
|
-
return [2 /*return*/, globalState.price];
|
|
78
|
-
case 4: return [3 /*break*/, 9];
|
|
79
|
-
case 5:
|
|
80
|
-
if (!(dexConfig.ammVersion === addresses_1.AMM_VERSIONS.VELODROME)) return [3 /*break*/, 7];
|
|
81
|
-
poolContract = (0, contracts_1.getClPoolContract)(poolAddress, jsonProvider);
|
|
82
|
-
return [4 /*yield*/, poolContract.slot0()];
|
|
83
|
-
case 6:
|
|
84
|
-
slot0 = _b.sent();
|
|
85
|
-
return [2 /*return*/, slot0[0]];
|
|
86
|
-
case 7:
|
|
87
|
-
poolContract = (0, contracts_1.getUniswapV3PoolContract)(poolAddress, jsonProvider);
|
|
88
|
-
return [4 /*yield*/, poolContract.slot0()];
|
|
89
|
-
case 8:
|
|
90
|
-
slot0 = _b.sent();
|
|
91
|
-
return [2 /*return*/, slot0[0]];
|
|
92
|
-
case 9: return [3 /*break*/, 11];
|
|
93
|
-
case 10:
|
|
94
|
-
e_1 = _b.sent();
|
|
95
|
-
console.error("Could not get price from pool ".concat(poolAddress));
|
|
96
|
-
throw e_1;
|
|
97
|
-
case 11: return [2 /*return*/];
|
|
11
|
+
const vault_1 = require("./vault");
|
|
12
|
+
const totalBalances_1 = require("./totalBalances");
|
|
13
|
+
const getPrice_1 = __importDefault(require("../utils/getPrice"));
|
|
14
|
+
const contracts_1 = require("../contracts");
|
|
15
|
+
const addresses_1 = require("../utils/config/addresses");
|
|
16
|
+
const _totalBalances_1 = require("./_totalBalances");
|
|
17
|
+
async function getSqrtPriceFromPool(poolAddress, jsonProvider, chainId, dex) {
|
|
18
|
+
try {
|
|
19
|
+
const dexConfig = addresses_1.addressConfig[chainId]?.[dex];
|
|
20
|
+
if (!dexConfig) {
|
|
21
|
+
throw new Error(`Config not found for dex ${dex} on chain ${chainId}`);
|
|
22
|
+
}
|
|
23
|
+
if (dexConfig.isAlgebra) {
|
|
24
|
+
if (dexConfig.ammVersion === addresses_1.AMM_VERSIONS.ALGEBRA_INTEGRAL) {
|
|
25
|
+
const poolContract = (0, contracts_1.getAlgebraIntegralPoolContract)(poolAddress, jsonProvider);
|
|
26
|
+
const globalState = await poolContract.globalState();
|
|
27
|
+
return globalState[0];
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
const poolContract = (0, contracts_1.getAlgebraPoolContract)(poolAddress, jsonProvider);
|
|
31
|
+
const globalState = await poolContract.globalState();
|
|
32
|
+
return globalState.price;
|
|
98
33
|
}
|
|
99
|
-
}
|
|
100
|
-
|
|
34
|
+
}
|
|
35
|
+
else if (dexConfig.ammVersion === addresses_1.AMM_VERSIONS.VELODROME) {
|
|
36
|
+
const poolContract = (0, contracts_1.getClPoolContract)(poolAddress, jsonProvider);
|
|
37
|
+
const slot0 = await poolContract.slot0();
|
|
38
|
+
return slot0[0];
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const poolContract = (0, contracts_1.getUniswapV3PoolContract)(poolAddress, jsonProvider);
|
|
42
|
+
const slot0 = await poolContract.slot0();
|
|
43
|
+
return slot0[0];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
console.error(`Could not get price from pool ${poolAddress}`);
|
|
48
|
+
throw e;
|
|
49
|
+
}
|
|
101
50
|
}
|
|
102
51
|
exports.getSqrtPriceFromPool = getSqrtPriceFromPool;
|
|
103
|
-
function getSqrtPriceFromVault(vault, jsonProvider, chainId, dex) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
poolAddress = _a.sent();
|
|
114
|
-
return [4 /*yield*/, getSqrtPriceFromPool(poolAddress, jsonProvider, chainId, dex)];
|
|
115
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
116
|
-
case 3:
|
|
117
|
-
e_2 = _a.sent();
|
|
118
|
-
console.error("Could not get price from vault ".concat(vault.id, " "));
|
|
119
|
-
throw e_2;
|
|
120
|
-
case 4: return [2 /*return*/];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
});
|
|
52
|
+
async function getSqrtPriceFromVault(vault, jsonProvider, chainId, dex) {
|
|
53
|
+
try {
|
|
54
|
+
const vaultContract = (0, contracts_1.getIchiVaultContract)(vault.id, jsonProvider);
|
|
55
|
+
const poolAddress = await vaultContract.pool();
|
|
56
|
+
return await getSqrtPriceFromPool(poolAddress, jsonProvider, chainId, dex);
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.error(`Could not get price from vault ${vault.id} `);
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
124
62
|
}
|
|
125
63
|
exports.getSqrtPriceFromVault = getSqrtPriceFromVault;
|
|
126
64
|
// current price in pool of scarse token in deposit tokens
|
|
127
|
-
function getCurrPrice(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
price = (0, getPrice_1.default)(isVaultInverted, sqrtPrice, depositTokenDecimals, scarceTokenDecimals, 15);
|
|
140
|
-
return [2 /*return*/, price];
|
|
141
|
-
case 2:
|
|
142
|
-
e_3 = _a.sent();
|
|
143
|
-
console.error("Could not get price from vault ".concat(vault.id, " "));
|
|
144
|
-
throw e_3;
|
|
145
|
-
case 3: return [2 /*return*/];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
65
|
+
async function getCurrPrice(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals) {
|
|
66
|
+
try {
|
|
67
|
+
const sqrtPrice = await getSqrtPriceFromVault(vault, jsonProvider, chainId, dex);
|
|
68
|
+
const depositTokenDecimals = isVaultInverted ? token1decimals : token0decimals;
|
|
69
|
+
const scarceTokenDecimals = isVaultInverted ? token0decimals : token1decimals;
|
|
70
|
+
const price = (0, getPrice_1.default)(isVaultInverted, sqrtPrice, depositTokenDecimals, scarceTokenDecimals, 15);
|
|
71
|
+
return price;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
console.error(`Could not get price from vault ${vault.id} `);
|
|
75
|
+
throw e;
|
|
76
|
+
}
|
|
149
77
|
}
|
|
150
78
|
exports.getCurrPrice = getCurrPrice;
|
|
151
|
-
function getVaultTvl(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
totalAmounts = _a.sent();
|
|
159
|
-
return [4 /*yield*/, getCurrPrice(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals)];
|
|
160
|
-
case 2:
|
|
161
|
-
price = _a.sent();
|
|
162
|
-
tvl = !isVaultInverted
|
|
163
|
-
? Number(totalAmounts.total0) + Number(totalAmounts.total1) * price
|
|
164
|
-
: Number(totalAmounts.total1) + Number(totalAmounts.total0) * price;
|
|
165
|
-
return [2 /*return*/, tvl];
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
});
|
|
79
|
+
async function getVaultTvl(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals) {
|
|
80
|
+
const totalAmounts = await (0, _totalBalances_1._getTotalAmounts)(vault, jsonProvider, chainId);
|
|
81
|
+
const price = await getCurrPrice(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals);
|
|
82
|
+
const tvl = !isVaultInverted
|
|
83
|
+
? Number(totalAmounts.total0) + Number(totalAmounts.total1) * price
|
|
84
|
+
: Number(totalAmounts.total1) + Number(totalAmounts.total0) * price;
|
|
85
|
+
return tvl;
|
|
169
86
|
}
|
|
170
87
|
exports.getVaultTvl = getVaultTvl;
|
|
171
88
|
// current LP price in pool in deposit tokens
|
|
172
|
-
function getCurrLpPrice(vault, jsonProvider, dex, chainId, isVaultInverted, token0decimals, token1decimals) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
throw new Error("Could not get LP price. Vault total supply is 0 for vault ".concat(vault.id, " on chain ").concat(chainId));
|
|
187
|
-
}
|
|
188
|
-
result = currTvl / Number(totalSupply);
|
|
189
|
-
return [2 /*return*/, result];
|
|
190
|
-
case 3:
|
|
191
|
-
e_4 = _a.sent();
|
|
192
|
-
console.error("Could not get LP price from vault ".concat(vault.id, " "));
|
|
193
|
-
throw e_4;
|
|
194
|
-
case 4: return [2 /*return*/];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
});
|
|
89
|
+
async function getCurrLpPrice(vault, jsonProvider, dex, chainId, isVaultInverted, token0decimals, token1decimals) {
|
|
90
|
+
try {
|
|
91
|
+
const currTvl = await getVaultTvl(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals);
|
|
92
|
+
const totalSupply = await (0, _totalBalances_1._getTotalSupply)(vault.id, jsonProvider);
|
|
93
|
+
if (Number(totalSupply) === 0) {
|
|
94
|
+
throw new Error(`Could not get LP price. Vault total supply is 0 for vault ${vault.id} on chain ${chainId}`);
|
|
95
|
+
}
|
|
96
|
+
const result = currTvl / Number(totalSupply);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
console.error(`Could not get LP price from vault ${vault.id} `);
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
198
103
|
}
|
|
199
104
|
exports.getCurrLpPrice = getCurrLpPrice;
|
|
200
105
|
// total amounts at deposit or withdrawal in deposit tokens
|
|
201
|
-
function getCurrentDtr(vaultAddress, jsonProvider, dex, isVaultInverted, token0decimals, token1decimals) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
case 3:
|
|
219
|
-
totalAmounts = _a.sent();
|
|
220
|
-
return [4 /*yield*/, getCurrPrice(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals)];
|
|
221
|
-
case 4:
|
|
222
|
-
price = _a.sent();
|
|
223
|
-
if (Number(totalAmounts.total0) + Number(totalAmounts.total1) * price === 0)
|
|
224
|
-
return [2 /*return*/, 0];
|
|
225
|
-
dtr = !isVaultInverted
|
|
226
|
-
? (Number(totalAmounts.total0) / (Number(totalAmounts.total0) + Number(totalAmounts.total1) * price)) * 100
|
|
227
|
-
: (Number(totalAmounts.total1) / (Number(totalAmounts.total1) + Number(totalAmounts.total0) * price)) * 100;
|
|
228
|
-
return [2 /*return*/, dtr];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
106
|
+
async function getCurrentDtr(vaultAddress, jsonProvider, dex, isVaultInverted, token0decimals, token1decimals) {
|
|
107
|
+
const network = await jsonProvider.getNetwork();
|
|
108
|
+
const chainId = Number(network.chainId);
|
|
109
|
+
if (!Object.values(types_1.SupportedChainId).includes(chainId)) {
|
|
110
|
+
throw new Error(`Unsupported chainId: ${chainId ?? 'undefined'}`);
|
|
111
|
+
}
|
|
112
|
+
const vault = await (0, vault_1.getIchiVaultInfo)(chainId, dex, vaultAddress, jsonProvider);
|
|
113
|
+
if (!vault)
|
|
114
|
+
throw new Error(`Vault ${vaultAddress} not found on chain ${chainId} and dex ${dex}`);
|
|
115
|
+
const totalAmounts = await (0, totalBalances_1.getTotalAmounts)(vaultAddress, jsonProvider, dex);
|
|
116
|
+
const price = await getCurrPrice(vault, jsonProvider, chainId, dex, isVaultInverted, token0decimals, token1decimals);
|
|
117
|
+
if (Number(totalAmounts.total0) + Number(totalAmounts.total1) * price === 0)
|
|
118
|
+
return 0;
|
|
119
|
+
const dtr = !isVaultInverted
|
|
120
|
+
? (Number(totalAmounts.total0) / (Number(totalAmounts.total0) + Number(totalAmounts.total1) * price)) * 100
|
|
121
|
+
: (Number(totalAmounts.total1) / (Number(totalAmounts.total1) + Number(totalAmounts.total0) * price)) * 100;
|
|
122
|
+
return dtr;
|
|
232
123
|
}
|
|
233
124
|
exports.getCurrentDtr = getCurrentDtr;
|
|
234
125
|
//# sourceMappingURL=priceFromPool.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"priceFromPool.js","sourceRoot":"","sources":["../../../src/functions/priceFromPool.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,iDAAiD
|
|
1
|
+
{"version":3,"file":"priceFromPool.js","sourceRoot":"","sources":["../../../src/functions/priceFromPool.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,iDAAiD;;;;;;AAGjD,oCAAqE;AACrE,2CAA2C;AAC3C,mCAA2C;AAC3C,mDAAkD;AAClD,iEAAyC;AACzC,4CAMsB;AACtB,yDAAwE;AACxE,qDAAqE;AAE9D,KAAK,UAAU,oBAAoB,CACxC,WAAmB,EACnB,YAA6B,EAC7B,OAAyB,EACzB,GAAiB;IAEjB,IAAI;QACF,MAAM,SAAS,GAAG,yBAAa,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QAEhD,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,GAAG,aAAa,OAAO,EAAE,CAAC,CAAC;SACxE;QAED,IAAI,SAAS,CAAC,SAAS,EAAE;YACvB,IAAI,SAAS,CAAC,UAAU,KAAK,wBAAY,CAAC,gBAAgB,EAAE;gBAC1D,MAAM,YAAY,GAAG,IAAA,0CAA8B,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;gBAC/E,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,WAAW,EAAE,CAAC;gBACrD,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC;aACvB;iBAAM;gBACL,MAAM,YAAY,GAAG,IAAA,kCAAsB,EAAC,WAAW,EAAE,YAAY,CAAC,CAAC;gBACvE,MAAM,WAAW,GAAG,MAAM,YAAY,CAAC,WAAW,EAAE,CAAC;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