@ichidao/ichi-vaults-sdk 0.1.43 → 2.0.1
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 +62 -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 +356 -738
- 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 +217 -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 +2 -2
- package/dist/src/index.esm.js +2 -2
- 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/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/src/types/index.d.ts +12 -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/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 +12 -13
- package/dist/src/types/index.js +1 -0
- 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 +276 -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.js +24 -28
- package/dist/src/utils/getConfigByFactory.js.map +1 -1
- 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,519 +1,378 @@
|
|
|
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.getVaultStateAt = exports._getAllVaultEvents = exports._getWithdraws = exports._getDeposits = exports._getFeesCollectedEvents = exports._getRebalances = exports._getAllEvents = void 0;
|
|
43
7
|
// eslint-disable import/no-cycle
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
function _getAllEvents(vaultAddress, chainId, dex, days) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
hasMoreData.withdraws = false;
|
|
165
|
-
}
|
|
166
|
-
// Check if we've reached the end for all entity types
|
|
167
|
-
endOfData = !Object.values(hasMoreData).some(function (hasMore) { return hasMore; });
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
endOfData = true;
|
|
171
|
-
}
|
|
172
|
-
return [3 /*break*/, 1];
|
|
173
|
-
case 12:
|
|
174
|
-
cache_1.default.set(key, allEvents, ttl);
|
|
175
|
-
return [2 /*return*/, allEvents];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
8
|
+
const constants_1 = require("../graphql/constants");
|
|
9
|
+
const queries_1 = require("../graphql/queries");
|
|
10
|
+
const timestamps_1 = require("../utils/timestamps");
|
|
11
|
+
const getGraphUrls_1 = require("../utils/getGraphUrls");
|
|
12
|
+
const cache_1 = __importDefault(require("../utils/cache"));
|
|
13
|
+
const functions_1 = require("../graphql/functions");
|
|
14
|
+
async function _getAllEvents(vaultAddress, chainId, dex, days) {
|
|
15
|
+
const key = `allevents-${chainId}-${vaultAddress}-${days}`;
|
|
16
|
+
const cachedData = cache_1.default.get(key);
|
|
17
|
+
if (cachedData) {
|
|
18
|
+
return cachedData;
|
|
19
|
+
}
|
|
20
|
+
const ttl = 120000;
|
|
21
|
+
const { publishedUrl, url } = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
22
|
+
const currTimestamp = Date.now();
|
|
23
|
+
const startTimestamp = days
|
|
24
|
+
? parseInt(((currTimestamp - (0, timestamps_1.daysToMilliseconds)(days)) / 1000).toString()).toString()
|
|
25
|
+
: '0';
|
|
26
|
+
const supportsCollectFees = constants_1.graphUrls[chainId][dex]?.supportsCollectFees;
|
|
27
|
+
const query = supportsCollectFees ? queries_1.allEventsQuery : queries_1.allEventsNoCollectFeesQuery;
|
|
28
|
+
const allEvents = [];
|
|
29
|
+
let endOfData = false;
|
|
30
|
+
// Track last timestamp for each entity type
|
|
31
|
+
const lastTimestamps = {
|
|
32
|
+
rebalances: startTimestamp,
|
|
33
|
+
collectFees: startTimestamp,
|
|
34
|
+
deposits: startTimestamp,
|
|
35
|
+
withdraws: startTimestamp,
|
|
36
|
+
};
|
|
37
|
+
// Track whether each entity type has more data
|
|
38
|
+
const hasMoreData = {
|
|
39
|
+
rebalances: true,
|
|
40
|
+
collectFees: supportsCollectFees,
|
|
41
|
+
deposits: true,
|
|
42
|
+
withdraws: true,
|
|
43
|
+
};
|
|
44
|
+
while (!endOfData) {
|
|
45
|
+
let result;
|
|
46
|
+
try {
|
|
47
|
+
if (publishedUrl) {
|
|
48
|
+
result = await (0, functions_1.sendAllEventsQueryRequest)(publishedUrl, vaultAddress, startTimestamp, query(lastTimestamps));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
throw new Error(`Published URL is invalid for dex ${dex} on chain ${chainId}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (publishedUrl) {
|
|
56
|
+
console.error('Request to published graph URL failed:', error);
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
result = await (0, functions_1.sendAllEventsQueryRequest)(url, vaultAddress, startTimestamp, query(lastTimestamps));
|
|
60
|
+
}
|
|
61
|
+
catch (error2) {
|
|
62
|
+
console.error('Request to public graph URL failed:', error2);
|
|
63
|
+
throw new Error(`Could not get events for vault ${vaultAddress} on chain ${chainId}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (result) {
|
|
67
|
+
// Add the results to our collection
|
|
68
|
+
if (result.vaultRebalances && result.vaultRebalances.length > 0) {
|
|
69
|
+
allEvents.push(...result.vaultRebalances);
|
|
70
|
+
// Update cursor for next query
|
|
71
|
+
lastTimestamps.rebalances = result.vaultRebalances[result.vaultRebalances.length - 1].createdAtTimestamp;
|
|
72
|
+
// Check if we've reached the end for this entity
|
|
73
|
+
if (result.vaultRebalances.length < 1000) {
|
|
74
|
+
hasMoreData.rebalances = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
hasMoreData.rebalances = false;
|
|
79
|
+
}
|
|
80
|
+
if (supportsCollectFees && result.vaultCollectFees && result.vaultCollectFees.length > 0) {
|
|
81
|
+
allEvents.push(...result.vaultCollectFees);
|
|
82
|
+
// Update cursor for next query
|
|
83
|
+
lastTimestamps.collectFees = result.vaultCollectFees[result.vaultCollectFees.length - 1].createdAtTimestamp;
|
|
84
|
+
// Check if we've reached the end for this entity
|
|
85
|
+
if (result.vaultCollectFees.length < 1000) {
|
|
86
|
+
hasMoreData.collectFees = false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
hasMoreData.collectFees = false;
|
|
91
|
+
}
|
|
92
|
+
if (result.vaultDeposits && result.vaultDeposits.length > 0) {
|
|
93
|
+
allEvents.push(...result.vaultDeposits);
|
|
94
|
+
// Update cursor for next query
|
|
95
|
+
lastTimestamps.deposits = result.vaultDeposits[result.vaultDeposits.length - 1].createdAtTimestamp;
|
|
96
|
+
// Check if we've reached the end for this entity
|
|
97
|
+
if (result.vaultDeposits.length < 1000) {
|
|
98
|
+
hasMoreData.deposits = false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
hasMoreData.deposits = false;
|
|
103
|
+
}
|
|
104
|
+
if (result.vaultWithdraws && result.vaultWithdraws.length > 0) {
|
|
105
|
+
allEvents.push(...result.vaultWithdraws);
|
|
106
|
+
// Update cursor for next query
|
|
107
|
+
lastTimestamps.withdraws = result.vaultWithdraws[result.vaultWithdraws.length - 1].createdAtTimestamp;
|
|
108
|
+
// Check if we've reached the end for this entity
|
|
109
|
+
if (result.vaultWithdraws.length < 1000) {
|
|
110
|
+
hasMoreData.withdraws = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
hasMoreData.withdraws = false;
|
|
115
|
+
}
|
|
116
|
+
// Check if we've reached the end for all entity types
|
|
117
|
+
endOfData = !Object.values(hasMoreData).some((hasMore) => hasMore);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
endOfData = true;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
cache_1.default.set(key, allEvents, ttl);
|
|
124
|
+
return allEvents;
|
|
179
125
|
}
|
|
180
126
|
exports._getAllEvents = _getAllEvents;
|
|
181
127
|
// eslint-disable-next-line no-underscore-dangle
|
|
182
|
-
function _getRebalances(vaultAddress, chainId, dex, days) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
rebalances.push.apply(rebalances, result);
|
|
236
|
-
if (result.length < 1000) {
|
|
237
|
-
endOfData = true;
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// Update the cursor to the timestamp of the last item
|
|
241
|
-
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
endOfData = true;
|
|
246
|
-
}
|
|
247
|
-
return [3 /*break*/, 1];
|
|
248
|
-
case 12:
|
|
249
|
-
cache_1.default.set(key, rebalances, ttl);
|
|
250
|
-
return [2 /*return*/, rebalances];
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
});
|
|
128
|
+
async function _getRebalances(vaultAddress, chainId, dex, days) {
|
|
129
|
+
const key = `rebalances-${chainId}-${vaultAddress}-${days}`;
|
|
130
|
+
const cachedData = cache_1.default.get(key);
|
|
131
|
+
if (cachedData) {
|
|
132
|
+
return cachedData;
|
|
133
|
+
}
|
|
134
|
+
const ttl = 120000;
|
|
135
|
+
const { publishedUrl, url } = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
136
|
+
const currTimestamp = Date.now();
|
|
137
|
+
const startTimestamp = days
|
|
138
|
+
? parseInt(((currTimestamp - (0, timestamps_1.daysToMilliseconds)(days)) / 1000).toString()).toString()
|
|
139
|
+
: '0';
|
|
140
|
+
const rebalances = [];
|
|
141
|
+
let endOfData = false;
|
|
142
|
+
let lastTimestamp = startTimestamp;
|
|
143
|
+
while (!endOfData) {
|
|
144
|
+
let result;
|
|
145
|
+
try {
|
|
146
|
+
if (publishedUrl) {
|
|
147
|
+
result = await (0, functions_1.sendRebalancesQueryRequest)(publishedUrl, vaultAddress, startTimestamp, (0, queries_1.rebalancesQuery)(lastTimestamp));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
throw new Error(`Published URL is invalid for dex ${dex} on chain ${chainId}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (publishedUrl) {
|
|
155
|
+
console.error('Request to published graph URL failed:', error);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
result = await (0, functions_1.sendRebalancesQueryRequest)(url, vaultAddress, startTimestamp, (0, queries_1.rebalancesQuery)(lastTimestamp));
|
|
159
|
+
}
|
|
160
|
+
catch (error2) {
|
|
161
|
+
console.error('Request to public graph URL failed:', error2);
|
|
162
|
+
throw new Error(`Could not get rebalances for vault ${vaultAddress} on chain ${chainId}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (result && result.length > 0) {
|
|
166
|
+
rebalances.push(...result);
|
|
167
|
+
if (result.length < 1000) {
|
|
168
|
+
endOfData = true;
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// Update the cursor to the timestamp of the last item
|
|
172
|
+
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
endOfData = true;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
cache_1.default.set(key, rebalances, ttl);
|
|
180
|
+
return rebalances;
|
|
254
181
|
}
|
|
255
182
|
exports._getRebalances = _getRebalances;
|
|
256
183
|
// eslint-disable-next-line no-underscore-dangle
|
|
257
|
-
function _getFeesCollectedEvents(vaultAddress, chainId, dex, days) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
return
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
if (result && result.length > 0) {
|
|
317
|
-
otherFees.push.apply(otherFees, result);
|
|
318
|
-
if (result.length < 1000) {
|
|
319
|
-
endOfData = true;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
// Update the cursor to the timestamp of the last item
|
|
323
|
-
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
endOfData = true;
|
|
328
|
-
}
|
|
329
|
-
return [3 /*break*/, 1];
|
|
330
|
-
case 12:
|
|
331
|
-
cache_1.default.set(key, otherFees, ttl);
|
|
332
|
-
return [2 /*return*/, otherFees];
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
});
|
|
184
|
+
async function _getFeesCollectedEvents(vaultAddress, chainId, dex, days) {
|
|
185
|
+
const key = `fees-${chainId}-${vaultAddress}-${days}`;
|
|
186
|
+
const cachedData = cache_1.default.get(key);
|
|
187
|
+
if (cachedData) {
|
|
188
|
+
return cachedData;
|
|
189
|
+
}
|
|
190
|
+
const ttl = 120000;
|
|
191
|
+
const { publishedUrl, url } = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
192
|
+
const supportsCollectFees = constants_1.graphUrls[chainId][dex]?.supportsCollectFees;
|
|
193
|
+
if (!supportsCollectFees) {
|
|
194
|
+
const result = [];
|
|
195
|
+
cache_1.default.set(key, result, 24 * 60 * 60 * 1000);
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
const currTimestamp = Date.now();
|
|
199
|
+
const startTimestamp = days
|
|
200
|
+
? parseInt(((currTimestamp - (0, timestamps_1.daysToMilliseconds)(days)) / 1000).toString()).toString()
|
|
201
|
+
: '0';
|
|
202
|
+
const otherFees = [];
|
|
203
|
+
let endOfData = false;
|
|
204
|
+
let lastTimestamp = startTimestamp;
|
|
205
|
+
while (!endOfData) {
|
|
206
|
+
let result;
|
|
207
|
+
try {
|
|
208
|
+
if (publishedUrl) {
|
|
209
|
+
result = await (0, functions_1.sendCollectFeesQueryRequest)(publishedUrl, vaultAddress, startTimestamp, (0, queries_1.vaultCollectFeesQuery)(lastTimestamp));
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
throw new Error(`Published URL is invalid for dex ${dex} on chain ${chainId}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (publishedUrl) {
|
|
217
|
+
console.error('Request to published graph URL failed:', error);
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
result = await (0, functions_1.sendCollectFeesQueryRequest)(url, vaultAddress, startTimestamp, (0, queries_1.vaultCollectFeesQuery)(lastTimestamp));
|
|
221
|
+
}
|
|
222
|
+
catch (error2) {
|
|
223
|
+
console.error('Request to public graph URL failed:', error2);
|
|
224
|
+
throw new Error(`Could not get collected fees for vault ${vaultAddress} on chain ${chainId}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (result && result.length > 0) {
|
|
228
|
+
otherFees.push(...result);
|
|
229
|
+
if (result.length < 1000) {
|
|
230
|
+
endOfData = true;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
// Update the cursor to the timestamp of the last item
|
|
234
|
+
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
endOfData = true;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
cache_1.default.set(key, otherFees, ttl);
|
|
242
|
+
return otherFees;
|
|
336
243
|
}
|
|
337
244
|
exports._getFeesCollectedEvents = _getFeesCollectedEvents;
|
|
338
245
|
// eslint-disable-next-line no-underscore-dangle
|
|
339
|
-
function _getDeposits(vaultAddress, chainId, dex, days) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
depositEvents.push.apply(depositEvents, result);
|
|
393
|
-
if (result.length < 1000) {
|
|
394
|
-
endOfData = true;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
// Update the cursor to the timestamp of the last item
|
|
398
|
-
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
else {
|
|
402
|
-
endOfData = true;
|
|
403
|
-
}
|
|
404
|
-
return [3 /*break*/, 1];
|
|
405
|
-
case 12:
|
|
406
|
-
cache_1.default.set(key, depositEvents, ttl);
|
|
407
|
-
return [2 /*return*/, depositEvents];
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
});
|
|
246
|
+
async function _getDeposits(vaultAddress, chainId, dex, days) {
|
|
247
|
+
const key = `deposits-${chainId}-${vaultAddress}-${days}`;
|
|
248
|
+
const cachedData = cache_1.default.get(key);
|
|
249
|
+
if (cachedData) {
|
|
250
|
+
return cachedData;
|
|
251
|
+
}
|
|
252
|
+
const ttl = 120000;
|
|
253
|
+
const { publishedUrl, url } = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
254
|
+
const currTimestamp = Date.now();
|
|
255
|
+
const startTimestamp = days
|
|
256
|
+
? parseInt(((currTimestamp - (0, timestamps_1.daysToMilliseconds)(days)) / 1000).toString()).toString()
|
|
257
|
+
: '0';
|
|
258
|
+
const depositEvents = [];
|
|
259
|
+
let endOfData = false;
|
|
260
|
+
let lastTimestamp = startTimestamp;
|
|
261
|
+
while (!endOfData) {
|
|
262
|
+
let result;
|
|
263
|
+
try {
|
|
264
|
+
if (publishedUrl) {
|
|
265
|
+
result = await (0, functions_1.sendDepositsQueryRequest)(publishedUrl, vaultAddress, startTimestamp, (0, queries_1.vaultDepositsQuery)(lastTimestamp));
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
throw new Error(`Published URL is invalid for dex ${dex} on chain ${chainId}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
if (publishedUrl) {
|
|
273
|
+
console.error('Request to published graph URL failed:', error);
|
|
274
|
+
}
|
|
275
|
+
try {
|
|
276
|
+
result = await (0, functions_1.sendDepositsQueryRequest)(url, vaultAddress, startTimestamp, (0, queries_1.vaultDepositsQuery)(lastTimestamp));
|
|
277
|
+
}
|
|
278
|
+
catch (error2) {
|
|
279
|
+
console.error('Request to public graph URL failed:', error2);
|
|
280
|
+
throw new Error(`Could not get deposits for vault ${vaultAddress} on chain ${chainId}`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (result && result.length > 0) {
|
|
284
|
+
depositEvents.push(...result);
|
|
285
|
+
if (result.length < 1000) {
|
|
286
|
+
endOfData = true;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
// Update the cursor to the timestamp of the last item
|
|
290
|
+
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
endOfData = true;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
cache_1.default.set(key, depositEvents, ttl);
|
|
298
|
+
return depositEvents;
|
|
411
299
|
}
|
|
412
300
|
exports._getDeposits = _getDeposits;
|
|
413
301
|
// eslint-disable-next-line no-underscore-dangle
|
|
414
|
-
function _getWithdraws(vaultAddress, chainId, dex, days) {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
withdrawEvents.push.apply(withdrawEvents, result);
|
|
468
|
-
if (result.length < 1000) {
|
|
469
|
-
endOfData = true;
|
|
470
|
-
}
|
|
471
|
-
else {
|
|
472
|
-
// Update the cursor to the timestamp of the last item
|
|
473
|
-
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
else {
|
|
477
|
-
endOfData = true;
|
|
478
|
-
}
|
|
479
|
-
return [3 /*break*/, 1];
|
|
480
|
-
case 12:
|
|
481
|
-
cache_1.default.set(key, withdrawEvents, ttl);
|
|
482
|
-
return [2 /*return*/, withdrawEvents];
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
});
|
|
302
|
+
async function _getWithdraws(vaultAddress, chainId, dex, days) {
|
|
303
|
+
const key = `withdraws-${chainId}-${vaultAddress}-${days}`;
|
|
304
|
+
const cachedData = cache_1.default.get(key);
|
|
305
|
+
if (cachedData) {
|
|
306
|
+
return cachedData;
|
|
307
|
+
}
|
|
308
|
+
const ttl = 120000;
|
|
309
|
+
const { publishedUrl, url } = (0, getGraphUrls_1.getGraphUrls)(chainId, dex, true);
|
|
310
|
+
const currTimestamp = Date.now();
|
|
311
|
+
const startTimestamp = days
|
|
312
|
+
? parseInt(((currTimestamp - (0, timestamps_1.daysToMilliseconds)(days)) / 1000).toString()).toString()
|
|
313
|
+
: '0';
|
|
314
|
+
const withdrawEvents = [];
|
|
315
|
+
let endOfData = false;
|
|
316
|
+
let lastTimestamp = startTimestamp;
|
|
317
|
+
while (!endOfData) {
|
|
318
|
+
let result;
|
|
319
|
+
try {
|
|
320
|
+
if (publishedUrl) {
|
|
321
|
+
result = await (0, functions_1.sendWithdrawsQueryRequest)(publishedUrl, vaultAddress, startTimestamp, (0, queries_1.vaultWithdrawsQuery)(lastTimestamp));
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
throw new Error(`Published URL is invalid for dex ${dex} on chain ${chainId}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
if (publishedUrl) {
|
|
329
|
+
console.error('Request to published graph URL failed:', error);
|
|
330
|
+
}
|
|
331
|
+
try {
|
|
332
|
+
result = await (0, functions_1.sendWithdrawsQueryRequest)(url, vaultAddress, startTimestamp, (0, queries_1.vaultWithdrawsQuery)(lastTimestamp));
|
|
333
|
+
}
|
|
334
|
+
catch (error2) {
|
|
335
|
+
console.error('Request to public graph URL failed:', error2);
|
|
336
|
+
throw new Error(`Could not get withdraws for vault ${vaultAddress} on chain ${chainId}`);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (result && result.length > 0) {
|
|
340
|
+
withdrawEvents.push(...result);
|
|
341
|
+
if (result.length < 1000) {
|
|
342
|
+
endOfData = true;
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
// Update the cursor to the timestamp of the last item
|
|
346
|
+
lastTimestamp = result[result.length - 1].createdAtTimestamp;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
endOfData = true;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
cache_1.default.set(key, withdrawEvents, ttl);
|
|
354
|
+
return withdrawEvents;
|
|
486
355
|
}
|
|
487
356
|
exports._getWithdraws = _getWithdraws;
|
|
488
357
|
// eslint-disable-next-line no-underscore-dangle
|
|
489
|
-
function _getAllVaultEvents(vaultAddress, chainId, dex, days) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
ttl = 120000;
|
|
501
|
-
return [4 /*yield*/, _getAllEvents(vaultAddress, chainId, dex, days)];
|
|
502
|
-
case 1:
|
|
503
|
-
allEvents = _a.sent();
|
|
504
|
-
result = allEvents.sort(function (a, b) { return Number(b.createdAtTimestamp) - Number(a.createdAtTimestamp); });
|
|
505
|
-
cache_1.default.set(key, result, ttl);
|
|
506
|
-
return [2 /*return*/, result];
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
});
|
|
358
|
+
async function _getAllVaultEvents(vaultAddress, chainId, dex, days) {
|
|
359
|
+
const key = `allEvents-${chainId}-${vaultAddress}`;
|
|
360
|
+
const cachedData = cache_1.default.get(key);
|
|
361
|
+
if (cachedData) {
|
|
362
|
+
return cachedData;
|
|
363
|
+
}
|
|
364
|
+
const ttl = 120000;
|
|
365
|
+
const allEvents = await _getAllEvents(vaultAddress, chainId, dex, days);
|
|
366
|
+
const result = allEvents.sort((a, b) => Number(b.createdAtTimestamp) - Number(a.createdAtTimestamp));
|
|
367
|
+
cache_1.default.set(key, result, ttl);
|
|
368
|
+
return result;
|
|
510
369
|
}
|
|
511
370
|
exports._getAllVaultEvents = _getAllVaultEvents;
|
|
512
371
|
function getVaultStateAt(vaultEvents, daysAgo) {
|
|
513
372
|
if (vaultEvents.length === 0) {
|
|
514
373
|
return null;
|
|
515
374
|
}
|
|
516
|
-
|
|
375
|
+
const eventsBefore = vaultEvents.filter((e) => Number(e.createdAtTimestamp) * 1000 <= Date.now() - (0, timestamps_1.daysToMilliseconds)(daysAgo));
|
|
517
376
|
if (eventsBefore.length > 0) {
|
|
518
377
|
return eventsBefore[0];
|
|
519
378
|
}
|