@tokemak/queries 0.0.13 → 0.0.14
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 +216 -0
- package/dist/index.d.ts +170 -1
- package/dist/index.js +218 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -3144,6 +3144,8 @@ __export(queries_exports, {
|
|
|
3144
3144
|
getAutopoolDayData: () => getAutopoolDayData,
|
|
3145
3145
|
getAutopoolInfo: () => getAutopoolInfo,
|
|
3146
3146
|
getAutopoolRebalances: () => getAutopoolRebalances,
|
|
3147
|
+
getAutopoolUser: () => getAutopoolUser,
|
|
3148
|
+
getAutopoolUserActivity: () => getAutopoolUserActivity,
|
|
3147
3149
|
getAutopools: () => getAutopools,
|
|
3148
3150
|
getAutopoolsHistory: () => getAutopoolsHistory,
|
|
3149
3151
|
getAutopoolsRebalances: () => getAutopoolsRebalances,
|
|
@@ -8589,6 +8591,218 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
8589
8591
|
const allRebalances = [...currentRebalances, ...allNewRebalances];
|
|
8590
8592
|
return calculateRebalanceStats(allRebalances);
|
|
8591
8593
|
};
|
|
8594
|
+
|
|
8595
|
+
// functions/getAutopoolUserActivity.ts
|
|
8596
|
+
var import_graph_cli18 = require("@tokemak/graph-cli");
|
|
8597
|
+
var getAutopoolUserActivity = async ({
|
|
8598
|
+
autopoolAddress,
|
|
8599
|
+
userAddress,
|
|
8600
|
+
chainId = 1
|
|
8601
|
+
}) => {
|
|
8602
|
+
const { GetUserBalanceChangeHistory } = (0, import_graph_cli18.getSdkByChainId)(chainId);
|
|
8603
|
+
try {
|
|
8604
|
+
const userAutopoolBalanceChanges = await paginateQuery(
|
|
8605
|
+
(vars) => GetUserBalanceChangeHistory({
|
|
8606
|
+
userAddress,
|
|
8607
|
+
vaultAddress: autopoolAddress,
|
|
8608
|
+
first: vars?.first || 1e3,
|
|
8609
|
+
skip: vars?.skip || 0
|
|
8610
|
+
}),
|
|
8611
|
+
"userAutopoolBalanceChanges",
|
|
8612
|
+
{
|
|
8613
|
+
first: 1e3,
|
|
8614
|
+
maxPages: 100
|
|
8615
|
+
}
|
|
8616
|
+
);
|
|
8617
|
+
let userActivityTotals = {};
|
|
8618
|
+
let events = [];
|
|
8619
|
+
userAutopoolBalanceChanges.forEach((activity) => {
|
|
8620
|
+
if (!userActivityTotals[activity.vaultAddress]) {
|
|
8621
|
+
userActivityTotals[activity.vaultAddress] = {
|
|
8622
|
+
totalDeposits: 0n,
|
|
8623
|
+
totalWithdrawals: 0n,
|
|
8624
|
+
totalStakes: 0n,
|
|
8625
|
+
totalUnstakes: 0n,
|
|
8626
|
+
chainId
|
|
8627
|
+
};
|
|
8628
|
+
}
|
|
8629
|
+
activity.items.forEach((item) => {
|
|
8630
|
+
let eventType;
|
|
8631
|
+
if (item.staked && item.assetChange > 0n) {
|
|
8632
|
+
userActivityTotals[activity.vaultAddress].totalStakes += BigInt(
|
|
8633
|
+
item.assetChange
|
|
8634
|
+
);
|
|
8635
|
+
eventType = "Stake";
|
|
8636
|
+
} else if (item.staked && item.assetChange < 0n) {
|
|
8637
|
+
userActivityTotals[activity.vaultAddress].totalUnstakes += BigInt(
|
|
8638
|
+
BigInt(item.assetChange) * -1n
|
|
8639
|
+
);
|
|
8640
|
+
eventType = "Unstake";
|
|
8641
|
+
} else if (!item.staked && item.assetChange > 0n) {
|
|
8642
|
+
userActivityTotals[activity.vaultAddress].totalDeposits += BigInt(
|
|
8643
|
+
item.assetChange
|
|
8644
|
+
);
|
|
8645
|
+
eventType = "Deposit";
|
|
8646
|
+
} else if (!item.staked && item.assetChange < 0n) {
|
|
8647
|
+
userActivityTotals[activity.vaultAddress].totalWithdrawals += BigInt(
|
|
8648
|
+
BigInt(item.assetChange) * -1n
|
|
8649
|
+
);
|
|
8650
|
+
eventType = "Withdrawal";
|
|
8651
|
+
} else {
|
|
8652
|
+
eventType = "Unknown";
|
|
8653
|
+
}
|
|
8654
|
+
if (!item.staked) {
|
|
8655
|
+
events.push({
|
|
8656
|
+
timestamp: activity.timestamp,
|
|
8657
|
+
shareChange: item.shareChange,
|
|
8658
|
+
assetChange: item.assetChange,
|
|
8659
|
+
vaultAddress: activity.vaultAddress,
|
|
8660
|
+
eventType
|
|
8661
|
+
// staked: item.staked,
|
|
8662
|
+
});
|
|
8663
|
+
}
|
|
8664
|
+
});
|
|
8665
|
+
});
|
|
8666
|
+
return { events, totals: userActivityTotals };
|
|
8667
|
+
} catch (error) {
|
|
8668
|
+
console.error(error);
|
|
8669
|
+
return [];
|
|
8670
|
+
}
|
|
8671
|
+
};
|
|
8672
|
+
|
|
8673
|
+
// functions/getAutopoolUser.ts
|
|
8674
|
+
var import_viem21 = require("viem");
|
|
8675
|
+
var import_core23 = require("@wagmi/core");
|
|
8676
|
+
var import_abis22 = require("@tokemak/abis");
|
|
8677
|
+
var import_utils52 = require("@tokemak/utils");
|
|
8678
|
+
var getAutopoolUser = async (config, {
|
|
8679
|
+
autopool,
|
|
8680
|
+
address,
|
|
8681
|
+
userActivity,
|
|
8682
|
+
prices
|
|
8683
|
+
}) => {
|
|
8684
|
+
const autopoolContract = {
|
|
8685
|
+
address: autopool?.poolAddress,
|
|
8686
|
+
abi: import_abis22.autopoolEthAbi,
|
|
8687
|
+
chainId: autopool?.chain?.chainId
|
|
8688
|
+
};
|
|
8689
|
+
const [
|
|
8690
|
+
{ result: autopoolRewarderContract },
|
|
8691
|
+
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
8692
|
+
] = await (0, import_core23.readContracts)(config, {
|
|
8693
|
+
contracts: [
|
|
8694
|
+
{
|
|
8695
|
+
...autopoolContract,
|
|
8696
|
+
functionName: "rewarder",
|
|
8697
|
+
args: []
|
|
8698
|
+
},
|
|
8699
|
+
{
|
|
8700
|
+
...autopoolContract,
|
|
8701
|
+
functionName: "balanceOf",
|
|
8702
|
+
args: [address]
|
|
8703
|
+
}
|
|
8704
|
+
]
|
|
8705
|
+
});
|
|
8706
|
+
if (!autopoolRewarderContract) {
|
|
8707
|
+
throw new Error("No rewarder contract found");
|
|
8708
|
+
}
|
|
8709
|
+
if (unstakedPoolSharesError) {
|
|
8710
|
+
throw new Error("Error fetching unstaked pool shares");
|
|
8711
|
+
}
|
|
8712
|
+
const stakedPoolShares = await (0, import_core23.readContract)(config, {
|
|
8713
|
+
address: autopoolRewarderContract,
|
|
8714
|
+
abi: import_viem21.erc20Abi,
|
|
8715
|
+
functionName: "balanceOf",
|
|
8716
|
+
args: [address],
|
|
8717
|
+
chainId: autopool?.chain?.chainId
|
|
8718
|
+
});
|
|
8719
|
+
const stakedShares = (0, import_utils52.formatEtherNum)(stakedPoolShares);
|
|
8720
|
+
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
8721
|
+
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8722
|
+
autopool?.baseAsset.price,
|
|
8723
|
+
autopool?.denomination.price,
|
|
8724
|
+
prices
|
|
8725
|
+
);
|
|
8726
|
+
const unstakedShares = (0, import_utils52.formatEtherNum)(unstakedPoolShares || 0n);
|
|
8727
|
+
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
8728
|
+
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8729
|
+
autopool?.baseAsset.price,
|
|
8730
|
+
autopool?.denomination.price,
|
|
8731
|
+
prices
|
|
8732
|
+
);
|
|
8733
|
+
const shares = unstakedShares + stakedShares;
|
|
8734
|
+
const nav = convertBaseAssetToTokenPricesAndDenom(
|
|
8735
|
+
shares * (autopool?.navPerShare.baseAsset || 0),
|
|
8736
|
+
autopool?.baseAsset.price,
|
|
8737
|
+
autopool?.denomination.price,
|
|
8738
|
+
prices
|
|
8739
|
+
);
|
|
8740
|
+
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
8741
|
+
(0, import_utils52.formatUnitsNum)(
|
|
8742
|
+
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
8743
|
+
autopool?.baseAsset.decimals
|
|
8744
|
+
),
|
|
8745
|
+
autopool?.baseAsset.price,
|
|
8746
|
+
autopool?.denomination.price,
|
|
8747
|
+
prices
|
|
8748
|
+
);
|
|
8749
|
+
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
8750
|
+
(0, import_utils52.formatUnitsNum)(
|
|
8751
|
+
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
8752
|
+
autopool?.baseAsset.decimals
|
|
8753
|
+
),
|
|
8754
|
+
autopool?.baseAsset.price,
|
|
8755
|
+
autopool?.denomination.price,
|
|
8756
|
+
prices
|
|
8757
|
+
);
|
|
8758
|
+
const returns = convertBaseAssetToTokenPricesAndDenom(
|
|
8759
|
+
nav.baseAsset + totalWithdrawals.baseAsset - totalDeposits.baseAsset,
|
|
8760
|
+
autopool?.baseAsset.price,
|
|
8761
|
+
autopool?.denomination.price,
|
|
8762
|
+
prices
|
|
8763
|
+
);
|
|
8764
|
+
const supplied = convertBaseAssetToTokenPricesAndDenom(
|
|
8765
|
+
totalDeposits.baseAsset - totalWithdrawals.baseAsset,
|
|
8766
|
+
autopool?.baseAsset.price,
|
|
8767
|
+
autopool?.denomination.price,
|
|
8768
|
+
prices
|
|
8769
|
+
);
|
|
8770
|
+
const poolEvents = userActivity?.events.filter(
|
|
8771
|
+
(event) => event.vaultAddress === autopool?.poolAddress
|
|
8772
|
+
);
|
|
8773
|
+
let lastDeposit;
|
|
8774
|
+
if (poolEvents && poolEvents?.length > 0) {
|
|
8775
|
+
lastDeposit = (0, import_utils52.convertTimestampToDate)(
|
|
8776
|
+
poolEvents[poolEvents.length - 1].timestamp
|
|
8777
|
+
).toLocaleDateString("en-US", {
|
|
8778
|
+
day: "2-digit",
|
|
8779
|
+
month: "short",
|
|
8780
|
+
year: "numeric"
|
|
8781
|
+
});
|
|
8782
|
+
}
|
|
8783
|
+
return {
|
|
8784
|
+
symbol: autopool?.symbol,
|
|
8785
|
+
poolAddress: autopool?.poolAddress,
|
|
8786
|
+
userAddress: address,
|
|
8787
|
+
shares: {
|
|
8788
|
+
unstaked: unstakedShares,
|
|
8789
|
+
staked: stakedShares,
|
|
8790
|
+
total: shares
|
|
8791
|
+
},
|
|
8792
|
+
balance: {
|
|
8793
|
+
unstaked,
|
|
8794
|
+
staked,
|
|
8795
|
+
total: nav
|
|
8796
|
+
},
|
|
8797
|
+
returns,
|
|
8798
|
+
activity: {
|
|
8799
|
+
totalDeposits,
|
|
8800
|
+
totalWithdrawals,
|
|
8801
|
+
lastDeposit,
|
|
8802
|
+
supplied
|
|
8803
|
+
}
|
|
8804
|
+
};
|
|
8805
|
+
};
|
|
8592
8806
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8593
8807
|
0 && (module.exports = {
|
|
8594
8808
|
AutopoolCategory,
|
|
@@ -8620,6 +8834,8 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
8620
8834
|
getAutopoolDayData,
|
|
8621
8835
|
getAutopoolInfo,
|
|
8622
8836
|
getAutopoolRebalances,
|
|
8837
|
+
getAutopoolUser,
|
|
8838
|
+
getAutopoolUserActivity,
|
|
8623
8839
|
getAutopools,
|
|
8624
8840
|
getAutopoolsHistory,
|
|
8625
8841
|
getAutopoolsRebalances,
|
package/dist/index.d.ts
CHANGED
|
@@ -3146,4 +3146,173 @@ declare const getChainAutopoolsApr: (chainId: number) => Promise<ChainAutopoolsA
|
|
|
3146
3146
|
|
|
3147
3147
|
declare const getBlobData: (blobName: string) => Promise<any>;
|
|
3148
3148
|
|
|
3149
|
-
|
|
3149
|
+
declare const getAutopoolUserActivity: ({ autopoolAddress, userAddress, chainId, }: {
|
|
3150
|
+
autopoolAddress: Address;
|
|
3151
|
+
userAddress: Address;
|
|
3152
|
+
chainId?: SupportedChainIds;
|
|
3153
|
+
}) => Promise<never[] | {
|
|
3154
|
+
events: {
|
|
3155
|
+
timestamp: number;
|
|
3156
|
+
shareChange: string;
|
|
3157
|
+
assetChange: string;
|
|
3158
|
+
vaultAddress: string;
|
|
3159
|
+
eventType: EventType;
|
|
3160
|
+
}[];
|
|
3161
|
+
totals: UserActivityTotalsType;
|
|
3162
|
+
}>;
|
|
3163
|
+
|
|
3164
|
+
declare const getAutopoolUser: (config: Config, { autopool, address, userActivity, prices, }: {
|
|
3165
|
+
autopool: IAutopool;
|
|
3166
|
+
address: Address;
|
|
3167
|
+
userActivity: IUserActivity;
|
|
3168
|
+
prices: TokenPrices;
|
|
3169
|
+
}) => Promise<{
|
|
3170
|
+
symbol: string;
|
|
3171
|
+
poolAddress: `0x${string}`;
|
|
3172
|
+
userAddress: `0x${string}`;
|
|
3173
|
+
shares: {
|
|
3174
|
+
unstaked: number;
|
|
3175
|
+
staked: number;
|
|
3176
|
+
total: number;
|
|
3177
|
+
};
|
|
3178
|
+
balance: {
|
|
3179
|
+
unstaked: {
|
|
3180
|
+
denom: number;
|
|
3181
|
+
ETH: number;
|
|
3182
|
+
WETH: number;
|
|
3183
|
+
USDC: number;
|
|
3184
|
+
DOLA: number;
|
|
3185
|
+
USDT0: number;
|
|
3186
|
+
EURC: number;
|
|
3187
|
+
PXETH: number;
|
|
3188
|
+
S: number;
|
|
3189
|
+
USDT: number;
|
|
3190
|
+
TOKE: number;
|
|
3191
|
+
SILO: number;
|
|
3192
|
+
XPL: number;
|
|
3193
|
+
WS: number;
|
|
3194
|
+
WXPL: number;
|
|
3195
|
+
baseAsset: number;
|
|
3196
|
+
USD: number;
|
|
3197
|
+
};
|
|
3198
|
+
staked: {
|
|
3199
|
+
denom: number;
|
|
3200
|
+
ETH: number;
|
|
3201
|
+
WETH: number;
|
|
3202
|
+
USDC: number;
|
|
3203
|
+
DOLA: number;
|
|
3204
|
+
USDT0: number;
|
|
3205
|
+
EURC: number;
|
|
3206
|
+
PXETH: number;
|
|
3207
|
+
S: number;
|
|
3208
|
+
USDT: number;
|
|
3209
|
+
TOKE: number;
|
|
3210
|
+
SILO: number;
|
|
3211
|
+
XPL: number;
|
|
3212
|
+
WS: number;
|
|
3213
|
+
WXPL: number;
|
|
3214
|
+
baseAsset: number;
|
|
3215
|
+
USD: number;
|
|
3216
|
+
};
|
|
3217
|
+
total: {
|
|
3218
|
+
denom: number;
|
|
3219
|
+
ETH: number;
|
|
3220
|
+
WETH: number;
|
|
3221
|
+
USDC: number;
|
|
3222
|
+
DOLA: number;
|
|
3223
|
+
USDT0: number;
|
|
3224
|
+
EURC: number;
|
|
3225
|
+
PXETH: number;
|
|
3226
|
+
S: number;
|
|
3227
|
+
USDT: number;
|
|
3228
|
+
TOKE: number;
|
|
3229
|
+
SILO: number;
|
|
3230
|
+
XPL: number;
|
|
3231
|
+
WS: number;
|
|
3232
|
+
WXPL: number;
|
|
3233
|
+
baseAsset: number;
|
|
3234
|
+
USD: number;
|
|
3235
|
+
};
|
|
3236
|
+
};
|
|
3237
|
+
returns: {
|
|
3238
|
+
denom: number;
|
|
3239
|
+
ETH: number;
|
|
3240
|
+
WETH: number;
|
|
3241
|
+
USDC: number;
|
|
3242
|
+
DOLA: number;
|
|
3243
|
+
USDT0: number;
|
|
3244
|
+
EURC: number;
|
|
3245
|
+
PXETH: number;
|
|
3246
|
+
S: number;
|
|
3247
|
+
USDT: number;
|
|
3248
|
+
TOKE: number;
|
|
3249
|
+
SILO: number;
|
|
3250
|
+
XPL: number;
|
|
3251
|
+
WS: number;
|
|
3252
|
+
WXPL: number;
|
|
3253
|
+
baseAsset: number;
|
|
3254
|
+
USD: number;
|
|
3255
|
+
};
|
|
3256
|
+
activity: {
|
|
3257
|
+
totalDeposits: {
|
|
3258
|
+
denom: number;
|
|
3259
|
+
ETH: number;
|
|
3260
|
+
WETH: number;
|
|
3261
|
+
USDC: number;
|
|
3262
|
+
DOLA: number;
|
|
3263
|
+
USDT0: number;
|
|
3264
|
+
EURC: number;
|
|
3265
|
+
PXETH: number;
|
|
3266
|
+
S: number;
|
|
3267
|
+
USDT: number;
|
|
3268
|
+
TOKE: number;
|
|
3269
|
+
SILO: number;
|
|
3270
|
+
XPL: number;
|
|
3271
|
+
WS: number;
|
|
3272
|
+
WXPL: number;
|
|
3273
|
+
baseAsset: number;
|
|
3274
|
+
USD: number;
|
|
3275
|
+
};
|
|
3276
|
+
totalWithdrawals: {
|
|
3277
|
+
denom: number;
|
|
3278
|
+
ETH: number;
|
|
3279
|
+
WETH: number;
|
|
3280
|
+
USDC: number;
|
|
3281
|
+
DOLA: number;
|
|
3282
|
+
USDT0: number;
|
|
3283
|
+
EURC: number;
|
|
3284
|
+
PXETH: number;
|
|
3285
|
+
S: number;
|
|
3286
|
+
USDT: number;
|
|
3287
|
+
TOKE: number;
|
|
3288
|
+
SILO: number;
|
|
3289
|
+
XPL: number;
|
|
3290
|
+
WS: number;
|
|
3291
|
+
WXPL: number;
|
|
3292
|
+
baseAsset: number;
|
|
3293
|
+
USD: number;
|
|
3294
|
+
};
|
|
3295
|
+
lastDeposit: string | undefined;
|
|
3296
|
+
supplied: {
|
|
3297
|
+
denom: number;
|
|
3298
|
+
ETH: number;
|
|
3299
|
+
WETH: number;
|
|
3300
|
+
USDC: number;
|
|
3301
|
+
DOLA: number;
|
|
3302
|
+
USDT0: number;
|
|
3303
|
+
EURC: number;
|
|
3304
|
+
PXETH: number;
|
|
3305
|
+
S: number;
|
|
3306
|
+
USDT: number;
|
|
3307
|
+
TOKE: number;
|
|
3308
|
+
SILO: number;
|
|
3309
|
+
XPL: number;
|
|
3310
|
+
WS: number;
|
|
3311
|
+
WXPL: number;
|
|
3312
|
+
baseAsset: number;
|
|
3313
|
+
USD: number;
|
|
3314
|
+
};
|
|
3315
|
+
};
|
|
3316
|
+
}>;
|
|
3317
|
+
|
|
3318
|
+
export { AggregatedDayData, AutopoolCategory, AutopoolsApr, BASE_ASSETS, BATCH_SIZE, BaseAsset, BaseAssetWithUsd, BaseDataEntry, ChainAutopoolsAprResponse, ChainSTokeRewardsType, ChainSTokeType, ChainSTokeVotes, Currencies, CurveLP, ETH_BASE_ASSETS, EUR_BASE_ASSETS, EnhancedUserHistoryEntry, EventType, ExtraReward, FillData, GetLayerzeroStatusConfig, HistoricalTokenPrices, IAutopool, IAutopools, IAutopoolsHistory, IRebalance, IStoke, IStokeRewards, ISushiLP, ITopAutopoolHolder, ITopAutopoolHolders, IUserActivity, IUserAutopool, IUserAutopools, IUserAutopoolsRewards, IUserExtraRewards, IUserReward, LayerzeroStatus, MessageStatus, Order, PRICED_TOKENS, PoolRewardsBalanceDayData, QuoteAndPriceBaseConfig, QuoteAndPriceBaseResult, QuoteResult, RawRebalance, Reward, RewardDetails, STokeVotes, SendParam, SwapQuoteParams, SwapQuoteResponse, TokenPrices, USD_BASE_ASSETS, UserActivity, UserActivityTotalsType, UserAutopoolsVotes, UserDayDataEntry, UserSTokeVotes, VaultAddedMapping, aggregateSTokeRewardsDayData, arraysToObject, calculateRebalanceStats, convertBaseAssetToTokenPrices, convertBaseAssetToTokenPricesAndDenom, fetchChainDataMap, fetchChainRebalances, fillMissingDates, findClosestDateEntry, findClosestEntry, findClosestTimestampEntry, formatDateRange, getAddressFromSystemRegistry, getAllowance, getAmountDeposited, getAmountWithdrawn, getAutopilotRouter, getAutopoolCategory, getAutopoolDayData, getAutopoolInfo, getAutopoolRebalances, getAutopoolUser, getAutopoolUserActivity, getAutopools, getAutopoolsHistory, getAutopoolsRebalances, getBlobData, getBlobHistoricalTokenPrices, getBridgeFee, getChainAutopools, getChainAutopoolsApr, getChainCycleRolloverBlockNumber, getChainSToke, getChainSTokeRewards, getChainSubgraphStatus, getChainUserActivity, getChainUserAutopools, getChainUserSToke, getChainUserSTokeRewards, getChainUserSTokeVotes, getChainsForEnv, getCurrentCycleId, getCurveLP, getCycleV1, getDefillamaPrice, getDynamicSwap, getEthPrice, getEthPriceAtBlock, getExchangeNames, getGenStratAprs, getHistoricalTokenPrices, getLayerzeroStatus, getMutlipleAutopoolRebalances, getPoolStats, getPoolsAndDestinations, getPoolsAndDestinationsReturnType, getProtocolStats, getRebalanceStats, getRebalanceValueUsd, getRewardsPayloadV1, getSToke, getSTokeChainsForEnv, getSTokeRewards, getSTokeVotes, getSubgraphStatus, getSushiLP, getSwapQuote, getSystemConfig, getTimestampDaysFromStart, getTokePrice, getTokenList, getTokenPrice, getTokenPrices, getTopAutopoolHolders, getUserActivity, getUserAutoEthRewards, getUserAutopool, getUserAutopools, getUserAutopoolsHistory, getUserAutopoolsRewards, getUserCurveLP, getUserRewardsV1, getUserSToke, getUserSTokeVotes, getUserSushiLP, getUserTokenBalances, getUserV1, mergeArrays, mergeArraysWithKey, mergeStringArrays, minAmountDepositedBaseConfig, minAmountDepositedFunctionConfig, minAmountWithdrawnBaseConfig, minAmountWithdrawnFunctionConfig, modifyAutopoolName, nestedArrayToObject, paginateQuery, processRebalance, processRebalancesInBatches, rewardsData, systemRegistryFunctionNames, updateRebalanceStats, waitForMessageReceived };
|
package/dist/index.js
CHANGED
|
@@ -8555,6 +8555,222 @@ var updateRebalanceStats = async (wagmiConfig, {
|
|
|
8555
8555
|
const allRebalances = [...currentRebalances, ...allNewRebalances];
|
|
8556
8556
|
return calculateRebalanceStats(allRebalances);
|
|
8557
8557
|
};
|
|
8558
|
+
|
|
8559
|
+
// functions/getAutopoolUserActivity.ts
|
|
8560
|
+
import { getSdkByChainId as getSdkByChainId18 } from "@tokemak/graph-cli";
|
|
8561
|
+
var getAutopoolUserActivity = async ({
|
|
8562
|
+
autopoolAddress,
|
|
8563
|
+
userAddress,
|
|
8564
|
+
chainId = 1
|
|
8565
|
+
}) => {
|
|
8566
|
+
const { GetUserBalanceChangeHistory } = getSdkByChainId18(chainId);
|
|
8567
|
+
try {
|
|
8568
|
+
const userAutopoolBalanceChanges = await paginateQuery(
|
|
8569
|
+
(vars) => GetUserBalanceChangeHistory({
|
|
8570
|
+
userAddress,
|
|
8571
|
+
vaultAddress: autopoolAddress,
|
|
8572
|
+
first: vars?.first || 1e3,
|
|
8573
|
+
skip: vars?.skip || 0
|
|
8574
|
+
}),
|
|
8575
|
+
"userAutopoolBalanceChanges",
|
|
8576
|
+
{
|
|
8577
|
+
first: 1e3,
|
|
8578
|
+
maxPages: 100
|
|
8579
|
+
}
|
|
8580
|
+
);
|
|
8581
|
+
let userActivityTotals = {};
|
|
8582
|
+
let events = [];
|
|
8583
|
+
userAutopoolBalanceChanges.forEach((activity) => {
|
|
8584
|
+
if (!userActivityTotals[activity.vaultAddress]) {
|
|
8585
|
+
userActivityTotals[activity.vaultAddress] = {
|
|
8586
|
+
totalDeposits: 0n,
|
|
8587
|
+
totalWithdrawals: 0n,
|
|
8588
|
+
totalStakes: 0n,
|
|
8589
|
+
totalUnstakes: 0n,
|
|
8590
|
+
chainId
|
|
8591
|
+
};
|
|
8592
|
+
}
|
|
8593
|
+
activity.items.forEach((item) => {
|
|
8594
|
+
let eventType;
|
|
8595
|
+
if (item.staked && item.assetChange > 0n) {
|
|
8596
|
+
userActivityTotals[activity.vaultAddress].totalStakes += BigInt(
|
|
8597
|
+
item.assetChange
|
|
8598
|
+
);
|
|
8599
|
+
eventType = "Stake";
|
|
8600
|
+
} else if (item.staked && item.assetChange < 0n) {
|
|
8601
|
+
userActivityTotals[activity.vaultAddress].totalUnstakes += BigInt(
|
|
8602
|
+
BigInt(item.assetChange) * -1n
|
|
8603
|
+
);
|
|
8604
|
+
eventType = "Unstake";
|
|
8605
|
+
} else if (!item.staked && item.assetChange > 0n) {
|
|
8606
|
+
userActivityTotals[activity.vaultAddress].totalDeposits += BigInt(
|
|
8607
|
+
item.assetChange
|
|
8608
|
+
);
|
|
8609
|
+
eventType = "Deposit";
|
|
8610
|
+
} else if (!item.staked && item.assetChange < 0n) {
|
|
8611
|
+
userActivityTotals[activity.vaultAddress].totalWithdrawals += BigInt(
|
|
8612
|
+
BigInt(item.assetChange) * -1n
|
|
8613
|
+
);
|
|
8614
|
+
eventType = "Withdrawal";
|
|
8615
|
+
} else {
|
|
8616
|
+
eventType = "Unknown";
|
|
8617
|
+
}
|
|
8618
|
+
if (!item.staked) {
|
|
8619
|
+
events.push({
|
|
8620
|
+
timestamp: activity.timestamp,
|
|
8621
|
+
shareChange: item.shareChange,
|
|
8622
|
+
assetChange: item.assetChange,
|
|
8623
|
+
vaultAddress: activity.vaultAddress,
|
|
8624
|
+
eventType
|
|
8625
|
+
// staked: item.staked,
|
|
8626
|
+
});
|
|
8627
|
+
}
|
|
8628
|
+
});
|
|
8629
|
+
});
|
|
8630
|
+
return { events, totals: userActivityTotals };
|
|
8631
|
+
} catch (error) {
|
|
8632
|
+
console.error(error);
|
|
8633
|
+
return [];
|
|
8634
|
+
}
|
|
8635
|
+
};
|
|
8636
|
+
|
|
8637
|
+
// functions/getAutopoolUser.ts
|
|
8638
|
+
import { erc20Abi as erc20Abi3 } from "viem";
|
|
8639
|
+
import { readContract as readContract17, readContracts as readContracts8 } from "@wagmi/core";
|
|
8640
|
+
import { autopoolEthAbi as autopoolEthAbi5 } from "@tokemak/abis";
|
|
8641
|
+
import {
|
|
8642
|
+
convertTimestampToDate as convertTimestampToDate4,
|
|
8643
|
+
formatEtherNum as formatEtherNum15,
|
|
8644
|
+
formatUnitsNum as formatUnitsNum6
|
|
8645
|
+
} from "@tokemak/utils";
|
|
8646
|
+
var getAutopoolUser = async (config, {
|
|
8647
|
+
autopool,
|
|
8648
|
+
address,
|
|
8649
|
+
userActivity,
|
|
8650
|
+
prices
|
|
8651
|
+
}) => {
|
|
8652
|
+
const autopoolContract = {
|
|
8653
|
+
address: autopool?.poolAddress,
|
|
8654
|
+
abi: autopoolEthAbi5,
|
|
8655
|
+
chainId: autopool?.chain?.chainId
|
|
8656
|
+
};
|
|
8657
|
+
const [
|
|
8658
|
+
{ result: autopoolRewarderContract },
|
|
8659
|
+
{ result: unstakedPoolShares, error: unstakedPoolSharesError }
|
|
8660
|
+
] = await readContracts8(config, {
|
|
8661
|
+
contracts: [
|
|
8662
|
+
{
|
|
8663
|
+
...autopoolContract,
|
|
8664
|
+
functionName: "rewarder",
|
|
8665
|
+
args: []
|
|
8666
|
+
},
|
|
8667
|
+
{
|
|
8668
|
+
...autopoolContract,
|
|
8669
|
+
functionName: "balanceOf",
|
|
8670
|
+
args: [address]
|
|
8671
|
+
}
|
|
8672
|
+
]
|
|
8673
|
+
});
|
|
8674
|
+
if (!autopoolRewarderContract) {
|
|
8675
|
+
throw new Error("No rewarder contract found");
|
|
8676
|
+
}
|
|
8677
|
+
if (unstakedPoolSharesError) {
|
|
8678
|
+
throw new Error("Error fetching unstaked pool shares");
|
|
8679
|
+
}
|
|
8680
|
+
const stakedPoolShares = await readContract17(config, {
|
|
8681
|
+
address: autopoolRewarderContract,
|
|
8682
|
+
abi: erc20Abi3,
|
|
8683
|
+
functionName: "balanceOf",
|
|
8684
|
+
args: [address],
|
|
8685
|
+
chainId: autopool?.chain?.chainId
|
|
8686
|
+
});
|
|
8687
|
+
const stakedShares = formatEtherNum15(stakedPoolShares);
|
|
8688
|
+
const staked = convertBaseAssetToTokenPricesAndDenom(
|
|
8689
|
+
stakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8690
|
+
autopool?.baseAsset.price,
|
|
8691
|
+
autopool?.denomination.price,
|
|
8692
|
+
prices
|
|
8693
|
+
);
|
|
8694
|
+
const unstakedShares = formatEtherNum15(unstakedPoolShares || 0n);
|
|
8695
|
+
const unstaked = convertBaseAssetToTokenPricesAndDenom(
|
|
8696
|
+
unstakedShares * (autopool?.navPerShare.baseAsset || 0),
|
|
8697
|
+
autopool?.baseAsset.price,
|
|
8698
|
+
autopool?.denomination.price,
|
|
8699
|
+
prices
|
|
8700
|
+
);
|
|
8701
|
+
const shares = unstakedShares + stakedShares;
|
|
8702
|
+
const nav = convertBaseAssetToTokenPricesAndDenom(
|
|
8703
|
+
shares * (autopool?.navPerShare.baseAsset || 0),
|
|
8704
|
+
autopool?.baseAsset.price,
|
|
8705
|
+
autopool?.denomination.price,
|
|
8706
|
+
prices
|
|
8707
|
+
);
|
|
8708
|
+
const totalDeposits = convertBaseAssetToTokenPricesAndDenom(
|
|
8709
|
+
formatUnitsNum6(
|
|
8710
|
+
userActivity?.totals[autopool?.poolAddress]?.totalDeposits || 0n,
|
|
8711
|
+
autopool?.baseAsset.decimals
|
|
8712
|
+
),
|
|
8713
|
+
autopool?.baseAsset.price,
|
|
8714
|
+
autopool?.denomination.price,
|
|
8715
|
+
prices
|
|
8716
|
+
);
|
|
8717
|
+
const totalWithdrawals = convertBaseAssetToTokenPricesAndDenom(
|
|
8718
|
+
formatUnitsNum6(
|
|
8719
|
+
userActivity?.totals[autopool?.poolAddress]?.totalWithdrawals || 0n,
|
|
8720
|
+
autopool?.baseAsset.decimals
|
|
8721
|
+
),
|
|
8722
|
+
autopool?.baseAsset.price,
|
|
8723
|
+
autopool?.denomination.price,
|
|
8724
|
+
prices
|
|
8725
|
+
);
|
|
8726
|
+
const returns = convertBaseAssetToTokenPricesAndDenom(
|
|
8727
|
+
nav.baseAsset + totalWithdrawals.baseAsset - totalDeposits.baseAsset,
|
|
8728
|
+
autopool?.baseAsset.price,
|
|
8729
|
+
autopool?.denomination.price,
|
|
8730
|
+
prices
|
|
8731
|
+
);
|
|
8732
|
+
const supplied = convertBaseAssetToTokenPricesAndDenom(
|
|
8733
|
+
totalDeposits.baseAsset - totalWithdrawals.baseAsset,
|
|
8734
|
+
autopool?.baseAsset.price,
|
|
8735
|
+
autopool?.denomination.price,
|
|
8736
|
+
prices
|
|
8737
|
+
);
|
|
8738
|
+
const poolEvents = userActivity?.events.filter(
|
|
8739
|
+
(event) => event.vaultAddress === autopool?.poolAddress
|
|
8740
|
+
);
|
|
8741
|
+
let lastDeposit;
|
|
8742
|
+
if (poolEvents && poolEvents?.length > 0) {
|
|
8743
|
+
lastDeposit = convertTimestampToDate4(
|
|
8744
|
+
poolEvents[poolEvents.length - 1].timestamp
|
|
8745
|
+
).toLocaleDateString("en-US", {
|
|
8746
|
+
day: "2-digit",
|
|
8747
|
+
month: "short",
|
|
8748
|
+
year: "numeric"
|
|
8749
|
+
});
|
|
8750
|
+
}
|
|
8751
|
+
return {
|
|
8752
|
+
symbol: autopool?.symbol,
|
|
8753
|
+
poolAddress: autopool?.poolAddress,
|
|
8754
|
+
userAddress: address,
|
|
8755
|
+
shares: {
|
|
8756
|
+
unstaked: unstakedShares,
|
|
8757
|
+
staked: stakedShares,
|
|
8758
|
+
total: shares
|
|
8759
|
+
},
|
|
8760
|
+
balance: {
|
|
8761
|
+
unstaked,
|
|
8762
|
+
staked,
|
|
8763
|
+
total: nav
|
|
8764
|
+
},
|
|
8765
|
+
returns,
|
|
8766
|
+
activity: {
|
|
8767
|
+
totalDeposits,
|
|
8768
|
+
totalWithdrawals,
|
|
8769
|
+
lastDeposit,
|
|
8770
|
+
supplied
|
|
8771
|
+
}
|
|
8772
|
+
};
|
|
8773
|
+
};
|
|
8558
8774
|
export {
|
|
8559
8775
|
AutopoolCategory,
|
|
8560
8776
|
BASE_ASSETS,
|
|
@@ -8585,6 +8801,8 @@ export {
|
|
|
8585
8801
|
getAutopoolDayData,
|
|
8586
8802
|
getAutopoolInfo,
|
|
8587
8803
|
getAutopoolRebalances,
|
|
8804
|
+
getAutopoolUser,
|
|
8805
|
+
getAutopoolUserActivity,
|
|
8588
8806
|
getAutopools,
|
|
8589
8807
|
getAutopoolsHistory,
|
|
8590
8808
|
getAutopoolsRebalances,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tokemak/queries",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"main": "./dist/index.cjs",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"@wagmi/core": "2.x",
|
|
27
27
|
"wagmi": "2.x",
|
|
28
28
|
"@tokemak/abis": "0.0.3",
|
|
29
|
-
"@tokemak/constants": "0.0.4",
|
|
30
|
-
"@tokemak/graph-cli": "0.0.5",
|
|
31
29
|
"@tokemak/config": "0.0.4",
|
|
30
|
+
"@tokemak/constants": "0.0.4",
|
|
31
|
+
"@tokemak/graph-cli": "0.0.6",
|
|
32
32
|
"@tokemak/tokenlist": "0.0.3",
|
|
33
33
|
"@tokemak/utils": "0.0.5"
|
|
34
34
|
},
|