@tokemak/queries 0.0.16 → 0.0.17
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/dist/index.cjs +239 -137
- package/dist/index.d.ts +43 -1
- package/dist/index.js +189 -92
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -48,7 +48,7 @@ var require_bn = __commonJS({
|
|
|
48
48
|
ctor.prototype = new TempCtor();
|
|
49
49
|
ctor.prototype.constructor = ctor;
|
|
50
50
|
}
|
|
51
|
-
function BN2(number,
|
|
51
|
+
function BN2(number, base4, endian) {
|
|
52
52
|
if (BN2.isBN(number)) {
|
|
53
53
|
return number;
|
|
54
54
|
}
|
|
@@ -57,11 +57,11 @@ var require_bn = __commonJS({
|
|
|
57
57
|
this.length = 0;
|
|
58
58
|
this.red = null;
|
|
59
59
|
if (number !== null) {
|
|
60
|
-
if (
|
|
61
|
-
endian =
|
|
62
|
-
|
|
60
|
+
if (base4 === "le" || base4 === "be") {
|
|
61
|
+
endian = base4;
|
|
62
|
+
base4 = 10;
|
|
63
63
|
}
|
|
64
|
-
this._init(number || 0,
|
|
64
|
+
this._init(number || 0, base4 || 10, endian || "be");
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
if (typeof module2 === "object") {
|
|
@@ -96,17 +96,17 @@ var require_bn = __commonJS({
|
|
|
96
96
|
return left;
|
|
97
97
|
return right;
|
|
98
98
|
};
|
|
99
|
-
BN2.prototype._init = function init(number,
|
|
99
|
+
BN2.prototype._init = function init(number, base4, endian) {
|
|
100
100
|
if (typeof number === "number") {
|
|
101
|
-
return this._initNumber(number,
|
|
101
|
+
return this._initNumber(number, base4, endian);
|
|
102
102
|
}
|
|
103
103
|
if (typeof number === "object") {
|
|
104
|
-
return this._initArray(number,
|
|
104
|
+
return this._initArray(number, base4, endian);
|
|
105
105
|
}
|
|
106
|
-
if (
|
|
107
|
-
|
|
106
|
+
if (base4 === "hex") {
|
|
107
|
+
base4 = 16;
|
|
108
108
|
}
|
|
109
|
-
assert(
|
|
109
|
+
assert(base4 === (base4 | 0) && base4 >= 2 && base4 <= 36);
|
|
110
110
|
number = number.toString().replace(/\s+/g, "");
|
|
111
111
|
var start = 0;
|
|
112
112
|
if (number[0] === "-") {
|
|
@@ -114,17 +114,17 @@ var require_bn = __commonJS({
|
|
|
114
114
|
this.negative = 1;
|
|
115
115
|
}
|
|
116
116
|
if (start < number.length) {
|
|
117
|
-
if (
|
|
117
|
+
if (base4 === 16) {
|
|
118
118
|
this._parseHex(number, start, endian);
|
|
119
119
|
} else {
|
|
120
|
-
this._parseBase(number,
|
|
120
|
+
this._parseBase(number, base4, start);
|
|
121
121
|
if (endian === "le") {
|
|
122
|
-
this._initArray(this.toArray(),
|
|
122
|
+
this._initArray(this.toArray(), base4, endian);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
|
-
BN2.prototype._initNumber = function _initNumber(number,
|
|
127
|
+
BN2.prototype._initNumber = function _initNumber(number, base4, endian) {
|
|
128
128
|
if (number < 0) {
|
|
129
129
|
this.negative = 1;
|
|
130
130
|
number = -number;
|
|
@@ -149,9 +149,9 @@ var require_bn = __commonJS({
|
|
|
149
149
|
}
|
|
150
150
|
if (endian !== "le")
|
|
151
151
|
return;
|
|
152
|
-
this._initArray(this.toArray(),
|
|
152
|
+
this._initArray(this.toArray(), base4, endian);
|
|
153
153
|
};
|
|
154
|
-
BN2.prototype._initArray = function _initArray(number,
|
|
154
|
+
BN2.prototype._initArray = function _initArray(number, base4, endian) {
|
|
155
155
|
assert(typeof number.length === "number");
|
|
156
156
|
if (number.length <= 0) {
|
|
157
157
|
this.words = [0];
|
|
@@ -265,20 +265,20 @@ var require_bn = __commonJS({
|
|
|
265
265
|
}
|
|
266
266
|
return r;
|
|
267
267
|
}
|
|
268
|
-
BN2.prototype._parseBase = function _parseBase(number,
|
|
268
|
+
BN2.prototype._parseBase = function _parseBase(number, base4, start) {
|
|
269
269
|
this.words = [0];
|
|
270
270
|
this.length = 1;
|
|
271
|
-
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *=
|
|
271
|
+
for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base4) {
|
|
272
272
|
limbLen++;
|
|
273
273
|
}
|
|
274
274
|
limbLen--;
|
|
275
|
-
limbPow = limbPow /
|
|
275
|
+
limbPow = limbPow / base4 | 0;
|
|
276
276
|
var total = number.length - start;
|
|
277
277
|
var mod = total % limbLen;
|
|
278
278
|
var end = Math.min(total, total - mod) + start;
|
|
279
279
|
var word = 0;
|
|
280
280
|
for (var i = start; i < end; i += limbLen) {
|
|
281
|
-
word = parseBase(number, i, i + limbLen,
|
|
281
|
+
word = parseBase(number, i, i + limbLen, base4);
|
|
282
282
|
this.imuln(limbPow);
|
|
283
283
|
if (this.words[0] + word < 67108864) {
|
|
284
284
|
this.words[0] += word;
|
|
@@ -288,9 +288,9 @@ var require_bn = __commonJS({
|
|
|
288
288
|
}
|
|
289
289
|
if (mod !== 0) {
|
|
290
290
|
var pow = 1;
|
|
291
|
-
word = parseBase(number, i, number.length,
|
|
291
|
+
word = parseBase(number, i, number.length, base4);
|
|
292
292
|
for (i = 0; i < mod; i++) {
|
|
293
|
-
pow *=
|
|
293
|
+
pow *= base4;
|
|
294
294
|
}
|
|
295
295
|
this.imuln(pow);
|
|
296
296
|
if (this.words[0] + word < 67108864) {
|
|
@@ -460,11 +460,11 @@ var require_bn = __commonJS({
|
|
|
460
460
|
52521875,
|
|
461
461
|
60466176
|
|
462
462
|
];
|
|
463
|
-
BN2.prototype.toString = function toString(
|
|
464
|
-
|
|
463
|
+
BN2.prototype.toString = function toString(base4, padding) {
|
|
464
|
+
base4 = base4 || 10;
|
|
465
465
|
padding = padding | 0 || 1;
|
|
466
466
|
var out;
|
|
467
|
-
if (
|
|
467
|
+
if (base4 === 16 || base4 === "hex") {
|
|
468
468
|
out = "";
|
|
469
469
|
var off = 0;
|
|
470
470
|
var carry = 0;
|
|
@@ -494,14 +494,14 @@ var require_bn = __commonJS({
|
|
|
494
494
|
}
|
|
495
495
|
return out;
|
|
496
496
|
}
|
|
497
|
-
if (
|
|
498
|
-
var groupSize = groupSizes[
|
|
499
|
-
var groupBase = groupBases[
|
|
497
|
+
if (base4 === (base4 | 0) && base4 >= 2 && base4 <= 36) {
|
|
498
|
+
var groupSize = groupSizes[base4];
|
|
499
|
+
var groupBase = groupBases[base4];
|
|
500
500
|
out = "";
|
|
501
501
|
var c = this.clone();
|
|
502
502
|
c.negative = 0;
|
|
503
503
|
while (!c.isZero()) {
|
|
504
|
-
var r = c.modrn(groupBase).toString(
|
|
504
|
+
var r = c.modrn(groupBase).toString(base4);
|
|
505
505
|
c = c.idivn(groupBase);
|
|
506
506
|
if (!c.isZero()) {
|
|
507
507
|
out = zeros[groupSize - r.length] + r + out;
|
|
@@ -2972,7 +2972,7 @@ var require_bn = __commonJS({
|
|
|
2972
2972
|
var require_src = __commonJS({
|
|
2973
2973
|
"../../node_modules/@layerzerolabs/lz-v2-utilities/node_modules/base-x/src/index.js"(exports, module) {
|
|
2974
2974
|
"use strict";
|
|
2975
|
-
function
|
|
2975
|
+
function base4(ALPHABET) {
|
|
2976
2976
|
if (ALPHABET.length >= 255) {
|
|
2977
2977
|
throw new TypeError("Alphabet too long");
|
|
2978
2978
|
}
|
|
@@ -3100,7 +3100,7 @@ var require_src = __commonJS({
|
|
|
3100
3100
|
decode
|
|
3101
3101
|
};
|
|
3102
3102
|
}
|
|
3103
|
-
module.exports =
|
|
3103
|
+
module.exports = base4;
|
|
3104
3104
|
}
|
|
3105
3105
|
});
|
|
3106
3106
|
|
|
@@ -4750,11 +4750,8 @@ var getChainUserAutopoolsHistory = async ({
|
|
|
4750
4750
|
}
|
|
4751
4751
|
};
|
|
4752
4752
|
|
|
4753
|
-
// functions/
|
|
4754
|
-
import {
|
|
4755
|
-
formatDateToReadable as formatDateToReadable2,
|
|
4756
|
-
formatUnitsNum as formatUnitsNum2
|
|
4757
|
-
} from "@tokemak/utils";
|
|
4753
|
+
// functions/processUserHistory.ts
|
|
4754
|
+
import { formatDateToReadable as formatDateToReadable2, formatUnitsNum as formatUnitsNum2 } from "@tokemak/utils";
|
|
4758
4755
|
|
|
4759
4756
|
// functions/getTokenValueDayDatas.ts
|
|
4760
4757
|
import { mainnet as mainnet3 } from "viem/chains";
|
|
@@ -4989,27 +4986,22 @@ var getHistoricalTokenPrices = async () => {
|
|
|
4989
4986
|
return historicalTokenPrices;
|
|
4990
4987
|
};
|
|
4991
4988
|
|
|
4992
|
-
// functions/
|
|
4993
|
-
var ONE_DAY_IN_MS = 24 * 60 * 60 * 1e3;
|
|
4989
|
+
// functions/processUserHistory.ts
|
|
4994
4990
|
function validateEnhancedUserHistoryEntry(entry) {
|
|
4995
4991
|
return entry && typeof entry === "object" && entry.date instanceof Date && typeof entry.timestamp === "string" && Array.isArray(entry.autopools) && entry.nav && typeof entry.nav.ETH === "number" && typeof entry.nav.USD === "number" && typeof entry.nav.PXETH === "number" && typeof entry.nav.USDC === "number" && typeof entry.nav.EURC === "number" && typeof entry.nav.USDT === "number" && Array.isArray(entry.events) && typeof entry.differential === "number";
|
|
4996
4992
|
}
|
|
4997
|
-
var
|
|
4993
|
+
var processUserHistory = async ({
|
|
4994
|
+
address,
|
|
4995
|
+
autopoolsHistory,
|
|
4996
|
+
events,
|
|
4997
|
+
userHistory
|
|
4998
|
+
}) => {
|
|
4998
4999
|
if (!autopoolsHistory) {
|
|
4999
5000
|
throw new Error("No autopools history found");
|
|
5000
5001
|
}
|
|
5001
5002
|
if (!events) {
|
|
5002
5003
|
throw new Error("No events found");
|
|
5003
5004
|
}
|
|
5004
|
-
const chains = getChainsForEnv({ includeTestnet });
|
|
5005
|
-
const userHistory = (await Promise.all(
|
|
5006
|
-
chains.map(
|
|
5007
|
-
(chain) => getChainUserAutopoolsHistory({
|
|
5008
|
-
address,
|
|
5009
|
-
chainId: chain.chainId
|
|
5010
|
-
})
|
|
5011
|
-
)
|
|
5012
|
-
)).flat();
|
|
5013
5005
|
const groupedByVault = userHistory.reduce((acc, data) => {
|
|
5014
5006
|
const vaultId = data.vaultAddress.toLowerCase();
|
|
5015
5007
|
if (!acc[vaultId]) {
|
|
@@ -5191,6 +5183,32 @@ var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeT
|
|
|
5191
5183
|
return result;
|
|
5192
5184
|
};
|
|
5193
5185
|
|
|
5186
|
+
// functions/getUserAutopoolsHistory.ts
|
|
5187
|
+
var getUserAutopoolsHistory = async (address, autopoolsHistory, events, includeTestnet = false) => {
|
|
5188
|
+
if (!autopoolsHistory) {
|
|
5189
|
+
throw new Error("No autopools history found");
|
|
5190
|
+
}
|
|
5191
|
+
if (!events) {
|
|
5192
|
+
throw new Error("No events found");
|
|
5193
|
+
}
|
|
5194
|
+
const chains = getChainsForEnv({ includeTestnet });
|
|
5195
|
+
const userHistory = (await Promise.all(
|
|
5196
|
+
chains.map(
|
|
5197
|
+
(chain) => getChainUserAutopoolsHistory({
|
|
5198
|
+
address,
|
|
5199
|
+
chainId: chain.chainId
|
|
5200
|
+
})
|
|
5201
|
+
)
|
|
5202
|
+
)).flat();
|
|
5203
|
+
const processedHistory = await processUserHistory({
|
|
5204
|
+
address,
|
|
5205
|
+
autopoolsHistory,
|
|
5206
|
+
events,
|
|
5207
|
+
userHistory
|
|
5208
|
+
});
|
|
5209
|
+
return processedHistory;
|
|
5210
|
+
};
|
|
5211
|
+
|
|
5194
5212
|
// functions/getUserSushiLP.ts
|
|
5195
5213
|
import { readContracts as readContracts2 } from "@wagmi/core";
|
|
5196
5214
|
import { poolV1Abi, sushiPoolAbi as sushiPoolAbi2 } from "@tokemak/abis";
|
|
@@ -5351,7 +5369,7 @@ var getMutlipleAutopoolRebalances = async (ids, chainId = 1) => {
|
|
|
5351
5369
|
|
|
5352
5370
|
// functions/getAutopoolDayData.ts
|
|
5353
5371
|
import { formatUnits as formatUnits4 } from "viem";
|
|
5354
|
-
import { formatEtherNum as
|
|
5372
|
+
import { formatEtherNum as formatEtherNum3 } from "@tokemak/utils";
|
|
5355
5373
|
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP2 } from "@tokemak/constants";
|
|
5356
5374
|
import { getSdkByChainId as getSdkByChainId9 } from "@tokemak/graph-cli";
|
|
5357
5375
|
var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_LAUNCH_TIMESTAMP2) => {
|
|
@@ -5365,10 +5383,10 @@ var getAutopoolDayData = async (address, chainId = 1, startTimestamp = TOKEMAK_L
|
|
|
5365
5383
|
const navPerShare = autoPoolDayData.nav / autoPoolDayData.totalSupply;
|
|
5366
5384
|
let baseApy = autoPoolDayData.autopoolApy;
|
|
5367
5385
|
let rewarderApy = 0;
|
|
5368
|
-
const formattedRewarder7DayMAApy =
|
|
5386
|
+
const formattedRewarder7DayMAApy = formatEtherNum3(
|
|
5369
5387
|
BigInt(Number(autoPoolDayData.rewarderDay7MAApy) || 0)
|
|
5370
5388
|
);
|
|
5371
|
-
const formattedRewarder30DayMAApy =
|
|
5389
|
+
const formattedRewarder30DayMAApy = formatEtherNum3(
|
|
5372
5390
|
BigInt(Number(autoPoolDayData.rewarderDay30MAApy) || 0)
|
|
5373
5391
|
);
|
|
5374
5392
|
if (formattedRewarder7DayMAApy) {
|
|
@@ -5470,7 +5488,7 @@ var getChainUserAutopools = async ({
|
|
|
5470
5488
|
// functions/getUserAutopools.ts
|
|
5471
5489
|
import {
|
|
5472
5490
|
convertTimestampToDate as convertTimestampToDate3,
|
|
5473
|
-
formatEtherNum as
|
|
5491
|
+
formatEtherNum as formatEtherNum5,
|
|
5474
5492
|
formatUnitsNum as formatUnitsNum3
|
|
5475
5493
|
} from "@tokemak/utils";
|
|
5476
5494
|
import { ETH_TOKEN as ETH_TOKEN4 } from "@tokemak/tokenlist";
|
|
@@ -5478,7 +5496,7 @@ import { ETH_TOKEN as ETH_TOKEN4 } from "@tokemak/tokenlist";
|
|
|
5478
5496
|
// functions/getUserAutopool.tsx
|
|
5479
5497
|
import { erc20Abi } from "viem";
|
|
5480
5498
|
import { readContract as readContract5, readContracts as readContracts5 } from "@wagmi/core";
|
|
5481
|
-
import { formatEtherNum as
|
|
5499
|
+
import { formatEtherNum as formatEtherNum4 } from "@tokemak/utils";
|
|
5482
5500
|
import { autopoolEthAbi } from "@tokemak/abis";
|
|
5483
5501
|
var getUserAutopool = async (wagmiConfig, {
|
|
5484
5502
|
address,
|
|
@@ -5527,10 +5545,10 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
5527
5545
|
args: [address],
|
|
5528
5546
|
chainId: autopool?.chain?.chainId
|
|
5529
5547
|
});
|
|
5530
|
-
const stakedShares =
|
|
5548
|
+
const stakedShares = formatEtherNum4(stakedPoolShares);
|
|
5531
5549
|
const stakedNav = stakedShares * (autopool?.navPerShare.baseAsset || 0);
|
|
5532
5550
|
const stakedNavUsd = stakedShares * (autopool?.navPerShare.USD || 0);
|
|
5533
|
-
const unstakedShares =
|
|
5551
|
+
const unstakedShares = formatEtherNum4(unstakedPoolShares || 0n);
|
|
5534
5552
|
const unstakedNav = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
5535
5553
|
const unstakedNavUsd = unstakedShares * (autopool?.navPerShare.USD || 0);
|
|
5536
5554
|
const totalShares = unstakedShares + stakedShares;
|
|
@@ -5551,7 +5569,7 @@ var getUserAutopool = async (wagmiConfig, {
|
|
|
5551
5569
|
});
|
|
5552
5570
|
pastRewarderBalances = pastRewards.map(({ result }, index) => {
|
|
5553
5571
|
const balance = result;
|
|
5554
|
-
const shares =
|
|
5572
|
+
const shares = formatEtherNum4(result);
|
|
5555
5573
|
const nav = shares * (autopool?.navPerShare.baseAsset || 0);
|
|
5556
5574
|
const navUsd = shares * (autopool?.navPerShare.USD || 0);
|
|
5557
5575
|
return {
|
|
@@ -5669,8 +5687,8 @@ var getUserAutopools = async ({
|
|
|
5669
5687
|
);
|
|
5670
5688
|
if (autopoolData) {
|
|
5671
5689
|
const isDOLA = autopoolData.symbol === "autoDOLA" && userAutoDOLA;
|
|
5672
|
-
const userShares = isDOLA ? userAutoDOLA?.totalShares :
|
|
5673
|
-
const totalVaultShares =
|
|
5690
|
+
const userShares = isDOLA ? userAutoDOLA?.totalShares : formatEtherNum5(userAutopool?.totalShares);
|
|
5691
|
+
const totalVaultShares = formatEtherNum5(autopoolData?.totalSupply);
|
|
5674
5692
|
const userShareOfVault = userShares / totalVaultShares;
|
|
5675
5693
|
const totalDeposits = formatUnitsNum3(
|
|
5676
5694
|
userActivity?.totals[userAutopool.vaultAddress]?.totalDeposits || 0n,
|
|
@@ -5730,6 +5748,7 @@ var getUserAutopools = async ({
|
|
|
5730
5748
|
};
|
|
5731
5749
|
}
|
|
5732
5750
|
});
|
|
5751
|
+
console.log(totalWithdrawals, totalDeposits);
|
|
5733
5752
|
const userNav = userShares * autopoolData?.navPerShare.baseAsset;
|
|
5734
5753
|
const userReturns = userNav + totalWithdrawals - totalDeposits;
|
|
5735
5754
|
const userSupplied = totalDeposits - totalWithdrawals;
|
|
@@ -5785,7 +5804,7 @@ var getUserAutopools = async ({
|
|
|
5785
5804
|
totalWithdrawals: prev.totalWithdrawals + totalWithdrawals
|
|
5786
5805
|
};
|
|
5787
5806
|
const stakedBalance = isDOLA ? userAutoDOLA?.staked.balance : BigInt(userAutopool?.stakedShares);
|
|
5788
|
-
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares :
|
|
5807
|
+
const stakedShares = isDOLA ? userAutoDOLA?.staked.shares : formatEtherNum5(stakedBalance);
|
|
5789
5808
|
const stakedNav = stakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
5790
5809
|
const staked = convertBaseAssetToTokenPrices(
|
|
5791
5810
|
stakedNav,
|
|
@@ -5793,7 +5812,7 @@ var getUserAutopools = async ({
|
|
|
5793
5812
|
prices
|
|
5794
5813
|
);
|
|
5795
5814
|
const unstakedBalance = isDOLA ? userAutoDOLA?.unstaked.balance : BigInt(userAutopool?.walletShares);
|
|
5796
|
-
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares :
|
|
5815
|
+
const unstakedShares = isDOLA ? userAutoDOLA?.unstaked.shares : formatEtherNum5(unstakedBalance);
|
|
5797
5816
|
const unstakedNav = unstakedShares * (autopoolData?.navPerShare.baseAsset || 0);
|
|
5798
5817
|
const unstaked = convertBaseAssetToTokenPrices(
|
|
5799
5818
|
unstakedNav,
|
|
@@ -6104,6 +6123,7 @@ var getUserActivity = async ({
|
|
|
6104
6123
|
(chain) => getChainUserActivity(address, chain.chainId)
|
|
6105
6124
|
)
|
|
6106
6125
|
);
|
|
6126
|
+
console.log(userActivities);
|
|
6107
6127
|
const mergedActivity = userActivities.reduce(
|
|
6108
6128
|
(acc, chainActivity) => {
|
|
6109
6129
|
if (chainActivity?.events) {
|
|
@@ -6591,7 +6611,7 @@ var getAmountWithdrawn = async ({
|
|
|
6591
6611
|
// functions/getAmountDeposited.ts
|
|
6592
6612
|
import { readContract as readContract11 } from "@wagmi/core";
|
|
6593
6613
|
import { autopoolEthAbi as autopoolEthAbi4 } from "@tokemak/abis";
|
|
6594
|
-
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as
|
|
6614
|
+
import { calculateMinAmountWithSlippage as calculateMinAmountWithSlippage2, formatEtherNum as formatEtherNum6 } from "@tokemak/utils";
|
|
6595
6615
|
var getAmountDeposited = async ({
|
|
6596
6616
|
address,
|
|
6597
6617
|
chainId,
|
|
@@ -6616,9 +6636,9 @@ var getAmountDeposited = async ({
|
|
|
6616
6636
|
previewDeposit,
|
|
6617
6637
|
slippage
|
|
6618
6638
|
);
|
|
6619
|
-
return
|
|
6639
|
+
return formatEtherNum6(minAmountWithSlippage);
|
|
6620
6640
|
} else {
|
|
6621
|
-
return
|
|
6641
|
+
return formatEtherNum6(previewDeposit);
|
|
6622
6642
|
}
|
|
6623
6643
|
} catch (e) {
|
|
6624
6644
|
console.error(e);
|
|
@@ -7484,7 +7504,7 @@ import {
|
|
|
7484
7504
|
convertChainCycleToUnix as convertChainCycleToUnix2,
|
|
7485
7505
|
convertSecondsToRemainingTime,
|
|
7486
7506
|
formatCurrency as formatCurrency2,
|
|
7487
|
-
formatEtherNum as
|
|
7507
|
+
formatEtherNum as formatEtherNum7
|
|
7488
7508
|
} from "@tokemak/utils";
|
|
7489
7509
|
import { readContracts as readContracts6 } from "@wagmi/core";
|
|
7490
7510
|
import { formatEther as formatEther2 } from "viem";
|
|
@@ -7562,7 +7582,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
7562
7582
|
balanceExcludingWithdrawal = balanceExcludingWithdrawal - withdrawalAmount;
|
|
7563
7583
|
}
|
|
7564
7584
|
const withdrawalAmountUsd = formatCurrency2(
|
|
7565
|
-
|
|
7585
|
+
formatEtherNum7(withdrawalAmount) * tokePrice
|
|
7566
7586
|
);
|
|
7567
7587
|
const lockDuration = Number(depositLockDuration);
|
|
7568
7588
|
const lockCycle = Number(depositLockCycle);
|
|
@@ -7587,7 +7607,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
7587
7607
|
Number(formatEther2(balanceExcludingWithdrawal)) * tokePrice
|
|
7588
7608
|
);
|
|
7589
7609
|
const balanceExcludingWithdrawalUsd = formatCurrency2(
|
|
7590
|
-
|
|
7610
|
+
formatEtherNum7(balanceExcludingWithdrawal) * tokePrice
|
|
7591
7611
|
);
|
|
7592
7612
|
const isUnlockRequestAvailable = currentCycle === withdrawAvailable;
|
|
7593
7613
|
const hasRequestedUnlock = withdrawalAmount > 0n;
|
|
@@ -7615,8 +7635,8 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
7615
7635
|
unlockPeriodDateRangeArray,
|
|
7616
7636
|
chainId === sepolia2.id ? "time" : "date"
|
|
7617
7637
|
);
|
|
7618
|
-
const totalActiveUserCredits =
|
|
7619
|
-
const totalUserCredits =
|
|
7638
|
+
const totalActiveUserCredits = formatEtherNum7(balanceExcludingWithdrawal) * lockDurationInMonths;
|
|
7639
|
+
const totalUserCredits = formatEtherNum7(balance) * lockDurationInMonths;
|
|
7620
7640
|
return {
|
|
7621
7641
|
balance,
|
|
7622
7642
|
balanceUSD,
|
|
@@ -7643,7 +7663,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
7643
7663
|
unlockRenewalDate,
|
|
7644
7664
|
lockDurationInMonths,
|
|
7645
7665
|
boost: lockDuration,
|
|
7646
|
-
points:
|
|
7666
|
+
points: formatEtherNum7(balanceExcludingWithdrawal) * lockDuration,
|
|
7647
7667
|
totalActiveCredits: totalActiveUserCredits,
|
|
7648
7668
|
totalCredits: totalUserCredits
|
|
7649
7669
|
};
|
|
@@ -7655,7 +7675,7 @@ var getChainUserSToke = async (wagmiConfig, {
|
|
|
7655
7675
|
};
|
|
7656
7676
|
|
|
7657
7677
|
// functions/getUserSToke.ts
|
|
7658
|
-
import { formatCurrency as formatCurrency3, formatEtherNum as
|
|
7678
|
+
import { formatCurrency as formatCurrency3, formatEtherNum as formatEtherNum8 } from "@tokemak/utils";
|
|
7659
7679
|
var getUserSToke = async (wagmiConfig, {
|
|
7660
7680
|
address,
|
|
7661
7681
|
tokePrice,
|
|
@@ -7682,7 +7702,7 @@ var getUserSToke = async (wagmiConfig, {
|
|
|
7682
7702
|
}
|
|
7683
7703
|
return acc;
|
|
7684
7704
|
}, 0n);
|
|
7685
|
-
const totalBalance =
|
|
7705
|
+
const totalBalance = formatEtherNum8(totalBalanceRaw || 0n);
|
|
7686
7706
|
const totalBalanceUsd = formatCurrency3(totalBalance * tokePrice);
|
|
7687
7707
|
const hasBalance = totalBalance > 0;
|
|
7688
7708
|
return {
|
|
@@ -7835,7 +7855,7 @@ var getChainCycleRolloverBlockNumber = async (wagmiConfig, {
|
|
|
7835
7855
|
};
|
|
7836
7856
|
|
|
7837
7857
|
// functions/getChainUserSTokeVotes.ts
|
|
7838
|
-
import { formatEtherNum as
|
|
7858
|
+
import { formatEtherNum as formatEtherNum9 } from "@tokemak/utils";
|
|
7839
7859
|
import { getSdkByChainId as getSdkByChainId13 } from "@tokemak/graph-cli";
|
|
7840
7860
|
var getChainUserSTokeVotes = async ({
|
|
7841
7861
|
address,
|
|
@@ -7858,10 +7878,10 @@ var getChainUserSTokeVotes = async ({
|
|
|
7858
7878
|
subgraphUserVotesData?.pools || [],
|
|
7859
7879
|
subgraphUserVotesData?.weights || []
|
|
7860
7880
|
);
|
|
7861
|
-
const stakedToke =
|
|
7881
|
+
const stakedToke = formatEtherNum9(
|
|
7862
7882
|
BigInt(subgraphAccountVotesBalance?.amount || 0n)
|
|
7863
7883
|
);
|
|
7864
|
-
const totalUserVotes =
|
|
7884
|
+
const totalUserVotes = formatEtherNum9(
|
|
7865
7885
|
BigInt(subgraphAccountVotesBalance?.points || 0n)
|
|
7866
7886
|
);
|
|
7867
7887
|
const autopools = {};
|
|
@@ -7949,7 +7969,7 @@ var getUserSTokeVotes = async ({
|
|
|
7949
7969
|
|
|
7950
7970
|
// functions/getChainSTokeVotes.ts
|
|
7951
7971
|
import { AUTOPOOLS_WHITELIST_PROD as AUTOPOOLS_WHITELIST_PROD2 } from "@tokemak/config";
|
|
7952
|
-
import { formatEtherNum as
|
|
7972
|
+
import { formatEtherNum as formatEtherNum10, formatLargeNumber as formatLargeNumber3 } from "@tokemak/utils";
|
|
7953
7973
|
import { getAddress as getAddress5 } from "viem";
|
|
7954
7974
|
import { getSdkByChainId as getSdkByChainId14 } from "@tokemak/graph-cli";
|
|
7955
7975
|
var getChainSTokeVotes = async ({
|
|
@@ -7980,13 +8000,13 @@ var getChainSTokeVotes = async ({
|
|
|
7980
8000
|
updatedPoints
|
|
7981
8001
|
);
|
|
7982
8002
|
const globalSystemVotes = globalVoted + globalNotVoted;
|
|
7983
|
-
const totalSystemVotesNum =
|
|
8003
|
+
const totalSystemVotesNum = formatEtherNum10(globalSystemVotes);
|
|
7984
8004
|
const formattedAutopoolVotes = Object.fromEntries(
|
|
7985
8005
|
Object.entries(autopoolVotes).filter(
|
|
7986
8006
|
([poolAddress]) => includeTestnet ? true : whitelistedPools.includes(poolAddress)
|
|
7987
8007
|
).map(([poolAddress, rawVote]) => {
|
|
7988
8008
|
const formattedVote = formatLargeNumber3(
|
|
7989
|
-
|
|
8009
|
+
formatEtherNum10(BigInt(rawVote))
|
|
7990
8010
|
);
|
|
7991
8011
|
return [
|
|
7992
8012
|
poolAddress,
|
|
@@ -8027,7 +8047,7 @@ var getSTokeVotes = async ({
|
|
|
8027
8047
|
// functions/getChainSTokeRewards.ts
|
|
8028
8048
|
import { AUTOPOOLS_WHITELIST_PROD as AUTOPOOLS_WHITELIST_PROD3 } from "@tokemak/config";
|
|
8029
8049
|
import { formatUnits as formatUnits6 } from "viem";
|
|
8030
|
-
import { formatEtherNum as
|
|
8050
|
+
import { formatEtherNum as formatEtherNum11 } from "@tokemak/utils";
|
|
8031
8051
|
import { getSdkByChainId as getSdkByChainId15 } from "@tokemak/graph-cli";
|
|
8032
8052
|
var getChainSTokeRewards = async ({
|
|
8033
8053
|
chainId
|
|
@@ -8051,9 +8071,9 @@ var getChainSTokeRewards = async ({
|
|
|
8051
8071
|
if (!whitelistedPools.includes(pool.id.toLowerCase())) {
|
|
8052
8072
|
continue;
|
|
8053
8073
|
}
|
|
8054
|
-
const convertedBalance =
|
|
8074
|
+
const convertedBalance = formatEtherNum11(pool.balance);
|
|
8055
8075
|
const convertedBalanceUSD = Number(formatUnits6(pool.balanceUSD, 8));
|
|
8056
|
-
const convertedApr =
|
|
8076
|
+
const convertedApr = formatEtherNum11(pool.currentAprPerCredit);
|
|
8057
8077
|
if (minApr === null || convertedApr < minApr) {
|
|
8058
8078
|
minApr = convertedApr;
|
|
8059
8079
|
}
|
|
@@ -8129,7 +8149,7 @@ import {
|
|
|
8129
8149
|
getCoreConfig as getCoreConfig9,
|
|
8130
8150
|
getMainnetConfig as getMainnetConfig6
|
|
8131
8151
|
} from "@tokemak/config";
|
|
8132
|
-
import { formatEtherNum as
|
|
8152
|
+
import { formatEtherNum as formatEtherNum12 } from "@tokemak/utils";
|
|
8133
8153
|
var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
8134
8154
|
address,
|
|
8135
8155
|
chainId,
|
|
@@ -8180,14 +8200,14 @@ var getChainUserSTokeRewards = async (wagmiConfig, {
|
|
|
8180
8200
|
throw fallbackError;
|
|
8181
8201
|
}
|
|
8182
8202
|
}
|
|
8183
|
-
const claimableNum =
|
|
8203
|
+
const claimableNum = formatEtherNum12(tokeRewards?.claimable || 0n);
|
|
8184
8204
|
const claimableUsd = tokePrice * claimableNum;
|
|
8185
8205
|
const hasClaimable = claimableNum > 0n;
|
|
8186
|
-
const pendingRewards =
|
|
8206
|
+
const pendingRewards = formatEtherNum12(
|
|
8187
8207
|
tokeRewards?.rewardsPayload.breakdown?.totalRewardAmount || 0n
|
|
8188
8208
|
);
|
|
8189
8209
|
const pendingRewardsUsd = tokePrice * pendingRewards;
|
|
8190
|
-
const totalRewardsReceived =
|
|
8210
|
+
const totalRewardsReceived = formatEtherNum12(
|
|
8191
8211
|
tokeRewards.rewardsPayload.payload.amount || 0n
|
|
8192
8212
|
);
|
|
8193
8213
|
const totalRewardsReceivedUsd = tokePrice * totalRewardsReceived;
|
|
@@ -8404,7 +8424,7 @@ var getEthPriceAtBlock = async (wagmiConfig, blockNumber, chainId) => {
|
|
|
8404
8424
|
};
|
|
8405
8425
|
|
|
8406
8426
|
// functions/getRebalanceStats.ts
|
|
8407
|
-
import { formatEtherNum as
|
|
8427
|
+
import { formatEtherNum as formatEtherNum13, formatUnitsNum as formatUnitsNum5 } from "@tokemak/utils";
|
|
8408
8428
|
import { USDC_TOKEN as USDC_TOKEN3 } from "@tokemak/tokenlist";
|
|
8409
8429
|
import { sonic as sonic4 } from "viem/chains";
|
|
8410
8430
|
var BATCH_SIZE = 500;
|
|
@@ -8439,7 +8459,7 @@ var getRebalanceValueUsd = async (rebalance, chainId, wagmiConfig) => {
|
|
|
8439
8459
|
chainId
|
|
8440
8460
|
);
|
|
8441
8461
|
const ethUsd = Number(formatUnitsNum5(price, USDC_TOKEN3.decimals));
|
|
8442
|
-
const ethAmt = Number(
|
|
8462
|
+
const ethAmt = Number(formatEtherNum13(ethWei));
|
|
8443
8463
|
const usd = ethAmt * ethUsd;
|
|
8444
8464
|
return usd;
|
|
8445
8465
|
} catch (e) {
|
|
@@ -8563,10 +8583,10 @@ var getAutopoolUserActivity = async ({
|
|
|
8563
8583
|
userAddress,
|
|
8564
8584
|
chainId = 1
|
|
8565
8585
|
}) => {
|
|
8566
|
-
const {
|
|
8586
|
+
const { GetUserAutopoolBalanceChangeHistory } = getSdkByChainId18(chainId);
|
|
8567
8587
|
try {
|
|
8568
8588
|
const userAutopoolBalanceChanges = await paginateQuery(
|
|
8569
|
-
(vars) =>
|
|
8589
|
+
(vars) => GetUserAutopoolBalanceChangeHistory({
|
|
8570
8590
|
userAddress,
|
|
8571
8591
|
vaultAddress: autopoolAddress,
|
|
8572
8592
|
first: vars?.first || 1e3,
|
|
@@ -8640,7 +8660,7 @@ import { readContract as readContract17, readContracts as readContracts8 } from
|
|
|
8640
8660
|
import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
8641
8661
|
import {
|
|
8642
8662
|
convertTimestampToDate as convertTimestampToDate4,
|
|
8643
|
-
formatEtherNum as
|
|
8663
|
+
formatEtherNum as formatEtherNum14,
|
|
8644
8664
|
formatUnitsNum as formatUnitsNum6
|
|
8645
8665
|
} from "@tokemak/utils";
|
|
8646
8666
|
var getAutopoolUser = async (config, {
|
|
@@ -8684,14 +8704,14 @@ var getAutopoolUser = async (config, {
|
|
|
8684
8704
|
args: [address],
|
|
8685
8705
|
chainId: autopool?.chain?.chainId
|
|
8686
8706
|
});
|
|
8687
|
-
const stakedShares =
|
|
8707
|
+
const stakedShares = formatEtherNum14(stakedPoolShares);
|
|
8688
8708
|
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
8689
8709
|
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8690
8710
|
autopool?.baseAsset.price,
|
|
8691
8711
|
autopool?.denomination.price,
|
|
8692
8712
|
prices
|
|
8693
8713
|
);
|
|
8694
|
-
const unstakedShares =
|
|
8714
|
+
const unstakedShares = formatEtherNum14(unstakedPoolShares || 0n);
|
|
8695
8715
|
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
8696
8716
|
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8697
8717
|
autopool?.baseAsset.price,
|
|
@@ -8771,6 +8791,81 @@ var getAutopoolUser = async (config, {
|
|
|
8771
8791
|
}
|
|
8772
8792
|
};
|
|
8773
8793
|
};
|
|
8794
|
+
|
|
8795
|
+
// functions/getAutopoolUserHistory.ts
|
|
8796
|
+
import { getSdkByChainId as getSdkByChainId20 } from "@tokemak/graph-cli";
|
|
8797
|
+
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP4 } from "@tokemak/constants";
|
|
8798
|
+
import { base as base3 } from "viem/chains";
|
|
8799
|
+
|
|
8800
|
+
// functions/getAutopoolHistory.ts
|
|
8801
|
+
import { getSdkByChainId as getSdkByChainId19 } from "@tokemak/graph-cli";
|
|
8802
|
+
import { base as base2 } from "viem/chains";
|
|
8803
|
+
import { TOKEMAK_LAUNCH_TIMESTAMP as TOKEMAK_LAUNCH_TIMESTAMP3 } from "@tokemak/constants";
|
|
8804
|
+
var getAutopoolHistory = async (autopool) => {
|
|
8805
|
+
try {
|
|
8806
|
+
if (!autopool) {
|
|
8807
|
+
throw new Error("No autopools found");
|
|
8808
|
+
}
|
|
8809
|
+
const { GetAutopoolDayNav } = getSdkByChainId19(
|
|
8810
|
+
autopool?.chain?.chainId || base2.id
|
|
8811
|
+
);
|
|
8812
|
+
const { autopoolDayDatas } = await GetAutopoolDayNav({
|
|
8813
|
+
address: autopool?.poolAddress,
|
|
8814
|
+
timestamp: TOKEMAK_LAUNCH_TIMESTAMP3
|
|
8815
|
+
});
|
|
8816
|
+
const vaultId = autopool?.poolAddress.toLowerCase();
|
|
8817
|
+
const formattedData = autopoolDayDatas.map((dayData) => {
|
|
8818
|
+
return {
|
|
8819
|
+
...dayData,
|
|
8820
|
+
vaultId,
|
|
8821
|
+
vault: {
|
|
8822
|
+
id: vaultId
|
|
8823
|
+
},
|
|
8824
|
+
date: new Date(dayData.timestamp * 1e3),
|
|
8825
|
+
baseAsset: autopool?.baseAsset
|
|
8826
|
+
};
|
|
8827
|
+
});
|
|
8828
|
+
const filledData = fillMissingDates(formattedData);
|
|
8829
|
+
return { [vaultId]: filledData };
|
|
8830
|
+
} catch (e) {
|
|
8831
|
+
console.log(e);
|
|
8832
|
+
}
|
|
8833
|
+
};
|
|
8834
|
+
|
|
8835
|
+
// functions/getAutopoolUserHistory.ts
|
|
8836
|
+
var getAutopoolUserHistory = async ({
|
|
8837
|
+
userAddress,
|
|
8838
|
+
autopool,
|
|
8839
|
+
userActivity
|
|
8840
|
+
}) => {
|
|
8841
|
+
const { GetUserVaultDayData } = getSdkByChainId20(
|
|
8842
|
+
autopool?.chain?.chainId || base3.id
|
|
8843
|
+
);
|
|
8844
|
+
try {
|
|
8845
|
+
if (userAddress) {
|
|
8846
|
+
const { userVaultDayDatas } = await GetUserVaultDayData({
|
|
8847
|
+
address: userAddress,
|
|
8848
|
+
timestamp: TOKEMAK_LAUNCH_TIMESTAMP4,
|
|
8849
|
+
vaultAddress: autopool?.poolAddress
|
|
8850
|
+
});
|
|
8851
|
+
const autopoolHistory = await getAutopoolHistory(autopool);
|
|
8852
|
+
if (!autopoolHistory) {
|
|
8853
|
+
throw new Error("No autopool history found");
|
|
8854
|
+
}
|
|
8855
|
+
const processedHistory = processUserHistory({
|
|
8856
|
+
address: userAddress,
|
|
8857
|
+
autopoolsHistory: autopoolHistory,
|
|
8858
|
+
events: userActivity.events,
|
|
8859
|
+
userHistory: userVaultDayDatas
|
|
8860
|
+
});
|
|
8861
|
+
return processedHistory;
|
|
8862
|
+
}
|
|
8863
|
+
return [];
|
|
8864
|
+
} catch (e) {
|
|
8865
|
+
console.error(e);
|
|
8866
|
+
return [];
|
|
8867
|
+
}
|
|
8868
|
+
};
|
|
8774
8869
|
export {
|
|
8775
8870
|
AutopoolCategory,
|
|
8776
8871
|
BASE_ASSETS,
|
|
@@ -8799,10 +8894,12 @@ export {
|
|
|
8799
8894
|
getAutopilotRouter,
|
|
8800
8895
|
getAutopoolCategory,
|
|
8801
8896
|
getAutopoolDayData,
|
|
8897
|
+
getAutopoolHistory,
|
|
8802
8898
|
getAutopoolInfo,
|
|
8803
8899
|
getAutopoolRebalances,
|
|
8804
8900
|
getAutopoolUser,
|
|
8805
8901
|
getAutopoolUserActivity,
|
|
8902
|
+
getAutopoolUserHistory,
|
|
8806
8903
|
getAutopools,
|
|
8807
8904
|
getAutopoolsHistory,
|
|
8808
8905
|
getAutopoolsRebalances,
|