@berachain/berajs 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{BeraError-D1HS_rbb.d.cts → BeraError-_mQdkanr.d.cts} +35 -10
- package/dist/{BeraError-D1HS_rbb.d.ts → BeraError-_mQdkanr.d.ts} +35 -10
- package/dist/HoneyConfigProvider-CK6mOKFH.d.ts +390 -0
- package/dist/HoneyConfigProvider-Ca3ouozs.d.cts +390 -0
- package/dist/{RequestError-D8AE6xnI.d.cts → RequestError-A8XJ6QR9.d.cts} +1 -1
- package/dist/{RequestError-m4jxyM7D.d.ts → RequestError-Dk97z8rm.d.ts} +1 -1
- package/dist/abi/exports.cjs +2 -0
- package/dist/abi/exports.cjs.map +1 -0
- package/dist/abi/{index.d.cts → exports.d.cts} +12369 -9122
- package/dist/abi/{index.d.ts → exports.d.ts} +12369 -9122
- package/dist/abi/exports.mjs +2 -0
- package/dist/abi/exports.mjs.map +1 -0
- package/dist/actions/exports.cjs +2 -0
- package/dist/actions/exports.cjs.map +1 -0
- package/dist/actions/{index.d.cts → exports.d.cts} +80 -107
- package/dist/actions/{index.d.ts → exports.d.ts} +80 -107
- package/dist/actions/exports.mjs +2 -0
- package/dist/actions/exports.mjs.map +1 -0
- package/dist/chunk-575OK77P.mjs +2 -0
- package/dist/chunk-575OK77P.mjs.map +1 -0
- package/dist/chunk-7GWTHOLO.mjs +2 -0
- package/dist/chunk-7GWTHOLO.mjs.map +1 -0
- package/dist/chunk-7SC4VD3U.cjs +2 -0
- package/dist/chunk-7SC4VD3U.cjs.map +1 -0
- package/dist/chunk-BHNQX4XC.mjs +2 -0
- package/dist/chunk-BHNQX4XC.mjs.map +1 -0
- package/dist/chunk-BOYZVULX.cjs +2 -0
- package/dist/chunk-BOYZVULX.cjs.map +1 -0
- package/dist/chunk-C3FHGFLK.mjs +2 -0
- package/dist/chunk-C3FHGFLK.mjs.map +1 -0
- package/dist/chunk-C3G5KXCH.mjs +2 -0
- package/dist/chunk-C3G5KXCH.mjs.map +1 -0
- package/dist/chunk-CYKCYPFR.cjs +2 -0
- package/dist/chunk-CYKCYPFR.cjs.map +1 -0
- package/dist/chunk-F4BKSBEM.mjs +2 -0
- package/dist/chunk-F4BKSBEM.mjs.map +1 -0
- package/dist/chunk-FL2N3XHK.cjs +2 -0
- package/dist/chunk-FL2N3XHK.cjs.map +1 -0
- package/dist/chunk-G6NA6NSM.mjs +4 -0
- package/dist/chunk-G6NA6NSM.mjs.map +1 -0
- package/dist/chunk-H2QSRMVS.mjs +2 -0
- package/dist/chunk-H2QSRMVS.mjs.map +1 -0
- package/dist/chunk-IJM76AWK.cjs +4 -0
- package/dist/chunk-IJM76AWK.cjs.map +1 -0
- package/dist/chunk-MTS5SZLA.mjs +2 -0
- package/dist/chunk-MTS5SZLA.mjs.map +1 -0
- package/dist/chunk-MUNAP5TM.cjs +2 -0
- package/dist/chunk-MUNAP5TM.cjs.map +1 -0
- package/dist/chunk-NAXAZJJY.mjs +2 -0
- package/dist/chunk-NAXAZJJY.mjs.map +1 -0
- package/dist/chunk-OGJMSGB2.mjs +2 -0
- package/dist/chunk-OGJMSGB2.mjs.map +1 -0
- package/dist/chunk-OIYXOKTT.cjs +2 -0
- package/dist/chunk-OIYXOKTT.cjs.map +1 -0
- package/dist/chunk-OS5AJMYJ.cjs +2 -0
- package/dist/chunk-OS5AJMYJ.cjs.map +1 -0
- package/dist/chunk-Q3SCM6WL.mjs +2 -0
- package/dist/chunk-Q3SCM6WL.mjs.map +1 -0
- package/dist/chunk-SWMJQOH6.cjs +2 -0
- package/dist/chunk-SWMJQOH6.cjs.map +1 -0
- package/dist/chunk-TEBJWAVU.mjs +2 -0
- package/dist/chunk-TEBJWAVU.mjs.map +1 -0
- package/dist/chunk-TJWKS54T.mjs +2 -0
- package/dist/chunk-TJWKS54T.mjs.map +1 -0
- package/dist/chunk-UQUWMHVF.cjs +2 -0
- package/dist/chunk-UQUWMHVF.cjs.map +1 -0
- package/dist/chunk-UXUWSRVV.cjs +2 -0
- package/dist/chunk-UXUWSRVV.cjs.map +1 -0
- package/dist/chunk-VP7XUOSI.cjs +2 -0
- package/dist/chunk-VP7XUOSI.cjs.map +1 -0
- package/dist/chunk-VXL2ZZ4X.cjs +2 -0
- package/dist/chunk-VXL2ZZ4X.cjs.map +1 -0
- package/dist/chunk-WRFDB3QJ.cjs +2 -0
- package/dist/chunk-WRFDB3QJ.cjs.map +1 -0
- package/dist/chunk-WTCBORPB.cjs +2 -0
- package/dist/chunk-WTCBORPB.cjs.map +1 -0
- package/dist/chunk-XNJLSA6P.cjs +2 -0
- package/dist/chunk-XNJLSA6P.cjs.map +1 -0
- package/dist/chunk-YQGZMWDT.mjs +2 -0
- package/dist/chunk-YQGZMWDT.mjs.map +1 -0
- package/dist/chunk-YXLFOEZN.mjs +2 -0
- package/dist/chunk-YXLFOEZN.mjs.map +1 -0
- package/dist/chunk-ZAKA4TGK.cjs +2 -0
- package/dist/chunk-ZAKA4TGK.cjs.map +1 -0
- package/dist/chunk-ZQRACIGR.mjs +2 -0
- package/dist/chunk-ZQRACIGR.mjs.map +1 -0
- package/dist/contexts/exports.cjs +2 -0
- package/dist/contexts/exports.cjs.map +1 -0
- package/dist/contexts/{index.d.ts → exports.d.cts} +19 -28
- package/dist/contexts/{index.d.cts → exports.d.ts} +19 -28
- package/dist/contexts/exports.mjs +2 -0
- package/dist/contexts/exports.mjs.map +1 -0
- package/dist/contracts-CQIPk0Jc.d.cts +74 -0
- package/dist/contracts-CQIPk0Jc.d.ts +74 -0
- package/dist/{defaultFlags-V-tJs2K8.d.cts → defaultFlags-d0kPbT0i.d.cts} +1 -1
- package/dist/{defaultFlags-V-tJs2K8.d.ts → defaultFlags-d0kPbT0i.d.ts} +1 -1
- package/dist/dex-C_BB0b0O.d.cts +37 -0
- package/dist/dex-C_BB0b0O.d.ts +37 -0
- package/dist/enum/exports.cjs +2 -0
- package/dist/enum/exports.cjs.map +1 -0
- package/dist/enum/exports.d.cts +24 -0
- package/dist/enum/exports.d.ts +24 -0
- package/dist/enum/exports.mjs +2 -0
- package/dist/enum/exports.mjs.map +1 -0
- package/dist/errors/exports.cjs +2 -0
- package/dist/errors/exports.cjs.map +1 -0
- package/dist/errors/exports.d.cts +385 -0
- package/dist/errors/exports.d.ts +385 -0
- package/dist/errors/exports.mjs +2 -0
- package/dist/{getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts → getValidatorQueuedOperatorAddress-BX35p2Lv.d.ts} +125 -15
- package/dist/{getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts → getValidatorQueuedOperatorAddress-It0GsdvQ.d.cts} +125 -15
- package/dist/global.d-Ba-NIojH.d.cts +474 -0
- package/dist/global.d-By70bEv2.d.ts +474 -0
- package/dist/honey-CYm0RWf4.d.cts +14 -0
- package/dist/honey-CYm0RWf4.d.ts +14 -0
- package/dist/hooks/exports.cjs +4 -0
- package/dist/hooks/exports.cjs.map +1 -0
- package/dist/hooks/{index.d.cts → exports.d.cts} +223 -173
- package/dist/hooks/{index.d.ts → exports.d.ts} +223 -173
- package/dist/hooks/exports.mjs +4 -0
- package/dist/hooks/exports.mjs.map +1 -0
- package/dist/{BexStatusProvider-nS3NcdxI.d.cts → transactionStore-BvStaXf3.d.ts} +41 -1
- package/dist/{BexStatusProvider-nS3NcdxI.d.ts → transactionStore-CQrGYSY2.d.cts} +41 -1
- package/dist/{txnEnum-BQKDfaeH.d.cts → txnEnum-BYNbCxla.d.cts} +1 -0
- package/dist/{txnEnum-BQKDfaeH.d.ts → txnEnum-BYNbCxla.d.ts} +1 -0
- package/dist/types/exports.cjs +1 -0
- package/dist/types/exports.cjs.map +1 -0
- package/dist/types/exports.d.cts +58 -0
- package/dist/types/exports.d.ts +58 -0
- package/dist/types/exports.mjs +1 -0
- package/dist/{useHoneySwapState-C-9BV4VB.d.cts → useHoneySwapState-B-vmIP1b.d.cts} +1 -1
- package/dist/{useHoneySwapState-CUY5Sm1b.d.ts → useHoneySwapState-D1DKG_Of.d.ts} +1 -1
- package/dist/utils/exports.cjs +2 -0
- package/dist/utils/exports.cjs.map +1 -0
- package/dist/utils/{index.d.cts → exports.d.cts} +83 -20
- package/dist/utils/{index.d.ts → exports.d.ts} +83 -20
- package/dist/utils/exports.mjs +2 -0
- package/dist/utils/exports.mjs.map +1 -0
- package/package.json +16 -17
- package/src/abi/{index.ts → exports.ts} +3 -0
- package/src/abi/pol/LSTStakerVault.ts +2032 -0
- package/src/abi/utils/openChainErrors.ts +71 -30
- package/src/abi/utils/thirdwebMinimalAccount.ts +616 -0
- package/src/actions/clients/BeraApolloClient.ts +8 -6
- package/src/actions/dex/__tests__/aggregators.unit.test.ts +2 -5
- package/src/actions/dex/aggregators/base.ts +74 -16
- package/src/actions/dex/aggregators/bex.ts +54 -74
- package/src/actions/dex/aggregators/bgt.ts +31 -8
- package/src/actions/dex/aggregators/{enso.ts → enso/enso.ts} +18 -14
- package/src/actions/dex/aggregators/enso/ensoErc4626.debug.test.ts +37 -0
- package/src/actions/dex/aggregators/enso/ensoErc4626.ts +176 -0
- package/src/actions/dex/aggregators/erc4626.ts +122 -0
- package/src/actions/dex/aggregators/fly.ts +59 -53
- package/src/actions/dex/aggregators/haiku.ts +52 -54
- package/src/actions/dex/aggregators/honey.ts +54 -45
- package/src/actions/dex/aggregators/kyberswap.ts +41 -39
- package/src/actions/dex/aggregators/oogabooga.ts +47 -46
- package/src/actions/dex/aggregators/openOcean.ts +51 -46
- package/src/actions/dex/aggregators/wbera.ts +54 -42
- package/src/actions/dex/b-sdk.ts +5 -2
- package/src/actions/dex/getIsTokenExploited.ts +2 -2
- package/src/actions/enso/{zap.ts → getEnsoSwapBundle.ts} +4 -5
- package/src/actions/enso/getEnsoUserTokensWithBalances.debug.test.ts +73 -0
- package/src/actions/enso/{getEnsoUserToken.ts → getEnsoUserTokensWithBalances.ts} +42 -30
- package/src/actions/enso/util.ts +1 -1
- package/src/actions/{index.ts → exports.ts} +5 -0
- package/src/actions/governance/__tests__/checkProposalField.unit.test.ts +1 -1
- package/src/actions/governance/__tests__/getQuorum.integration.test.ts +1 -1
- package/src/actions/governance/checkProposalField.ts +1 -1
- package/src/actions/governance/computeActualStatus.ts +1 -1
- package/src/actions/governance/getBodyErrors.ts +1 -1
- package/src/actions/governance/getDecodedFunctionData.ts +1 -4
- package/src/actions/governance/getProposalDetails.ts +2 -2
- package/src/actions/governance/getProposalFromTx.ts +1 -2
- package/src/actions/governance/getProposalParams.ts +7 -8
- package/src/actions/governance/getQuorum.ts +1 -2
- package/src/actions/honey/getCollateralWeights.ts +1 -1
- package/src/actions/honey/getHoneyCollaterals.ts +1 -0
- package/src/actions/honey/getHoneyVaultsBalance.ts +51 -55
- package/src/actions/honey/getSwapPayload.ts +37 -35
- package/src/actions/honey/tests/pyth.integration.test.ts +0 -1
- package/src/actions/pol/__tests__/getAllValidators.integration.test.ts +1 -1
- package/src/actions/pol/getEarnedStakedBeraVault.ts +31 -0
- package/src/actions/pol/getGlobalData.ts +14 -13
- package/src/actions/pol/getLSTStakeConfig.ts +67 -0
- package/src/actions/pol/getMarkets.ts +1 -1
- package/src/actions/pol/getRewardProofsByValidator.ts +1 -1
- package/src/actions/pol/getRewardVaultIncentives.ts +3 -5
- package/src/actions/pol/getRewardVaults.ts +2 -3
- package/src/actions/pol/getSWBeraVaultMetadata.ts +7 -5
- package/src/actions/pol/getSWBeraWithdrawal.ts +41 -27
- package/src/actions/pol/getStakeWithdrawalCooldown.ts +5 -7
- package/src/actions/pol/getStakingDailyAssets.ts +21 -0
- package/src/actions/pol/getStakingTokenInformation.ts +3 -4
- package/src/actions/pol/getTotalStakedAmount.ts +47 -0
- package/src/actions/pol/getUserClaimableIncentives.ts +1 -1
- package/src/actions/pol/getUserVaults.ts +8 -6
- package/src/actions/pol/getUserVaultsBalance.ts +4 -16
- package/src/actions/prices/getTokenCurrentPrices.ts +8 -3
- package/src/actions/tokens/getAllowances.ts +68 -41
- package/src/actions/tokens/getTokenInformation.ts +4 -1
- package/src/actions/tokens/getTokens.ts +1 -1
- package/src/actions/tokens/getUnderlyingToken.ts +53 -0
- package/src/actions/tokens/getWalletBalances.integration.test.ts +53 -14
- package/src/actions/tokens/getWalletBalances.ts +69 -43
- package/src/actions/transactions/beraWriteContract.integration.test.ts +18 -6
- package/src/actions/transactions/beraWriteContract.ts +3 -3
- package/src/actions/validators/getUserActiveValidators.ts +2 -3
- package/src/actions/validators/getUserBoostsOnValidator.ts +2 -3
- package/src/contexts/BeraFlags/defaultFlags.ts +4 -0
- package/src/contexts/SwrFallback.tsx +13 -3
- package/src/contexts/TokensProvider.tsx +35 -8
- package/src/{hooks/transactions → contexts}/TransactionStoreContext.tsx +32 -4
- package/src/contexts/block-time-provider.tsx +1 -1
- package/src/contexts/{index.ts → exports.ts} +1 -1
- package/src/data/contracts.ts +16 -1
- package/src/enum/contracts.ts +13 -0
- package/src/enum/dex.ts +29 -0
- package/src/enum/{index.ts → exports.ts} +3 -0
- package/src/enum/governance.ts +61 -0
- package/src/enum/honey.ts +12 -0
- package/src/enum/txnEnum.ts +1 -0
- package/src/errors/BeraError.ts +50 -11
- package/src/errors/BeraMonitoring.ts +66 -0
- package/src/errors/BeraTracing.ts +79 -0
- package/src/errors/BeraTracing.unit.test.ts +198 -0
- package/src/errors/RequestError.ts +2 -2
- package/src/errors/assert.ts +4 -2
- package/src/errors/assert.unit.test.ts +6 -2
- package/src/errors/errorMap.ts +16 -6
- package/src/errors/{index.ts → exports.ts} +7 -0
- package/src/errors/getErrorMessage.ts +22 -3
- package/src/errors/getRevertReason.integration.test.ts +17 -5
- package/src/errors/getRevertReason.ts +41 -2
- package/src/errors/initBeraError.ts +52 -7
- package/src/errors/parseViemError.ts +114 -27
- package/src/errors/severity.ts +12 -0
- package/src/hooks/bend/useGetConvertToAssets.ts +3 -2
- package/src/hooks/dex/useAggregatorsQuotes.ts +126 -365
- package/src/hooks/dex/useAllUserPools.ts +1 -1
- package/src/hooks/dex/useApiPool.ts +1 -1
- package/src/hooks/dex/useCreatePool.ts +6 -5
- package/src/hooks/dex/useExploitedTokens.ts +1 -1
- package/src/hooks/dex/useLiquidityMismatch.ts +2 -5
- package/src/hooks/dex/useLpPosition.ts +21 -20
- package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +40 -29
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +1 -1
- package/src/hooks/dex/usePoolEvents.ts +1 -1
- package/src/hooks/dex/usePools.ts +1 -1
- package/src/hooks/dex/usePriceImpact.ts +40 -0
- package/src/hooks/dex/useSingleAggregatorQuote.ts +350 -0
- package/src/hooks/enso/useBendZapSupply.ts +216 -0
- package/src/hooks/enso/useEnsoSwapBundle.ts +107 -0
- package/src/hooks/enso/useEnsoUserTokensWithBalances.ts +43 -0
- package/src/hooks/enso/useZapStakeBera.ts +113 -0
- package/src/hooks/{index.ts → exports.ts} +18 -7
- package/src/hooks/governance/useCreateProposal.ts +8 -8
- package/src/hooks/governance/usePollAllProposals.ts +1 -1
- package/src/hooks/governance/usePollProposal.ts +1 -1
- package/src/hooks/governance/usePollProposalThreshold.ts +1 -1
- package/src/hooks/governance/usePollUserDelegates.ts +1 -1
- package/src/hooks/governance/useProposalState.ts +2 -2
- package/src/hooks/honey/useCappedGlobally.ts +2 -1
- package/src/hooks/honey/useCappedRelatively.ts +1 -1
- package/src/hooks/honey/useCollateralWeights.ts +2 -1
- package/src/hooks/honey/useHoneyAlerts.ts +11 -11
- package/src/hooks/honey/useHoneyBalances.ts +7 -3
- package/src/hooks/honey/useHoneyGlobalData.ts +2 -1
- package/src/hooks/honey/useHoneySwapState.ts +2 -1
- package/src/hooks/honey/useHoneyVaultsBalance.ts +1 -1
- package/src/hooks/honey/useIsBadCollateralAsset.ts +2 -1
- package/src/hooks/honey/useIsBasketModeEnabled.ts +1 -1
- package/src/hooks/honey/usePythLatestPrices.ts +1 -1
- package/src/hooks/pol/useOnChainRewardVault.ts +3 -2
- package/src/hooks/pol/usePollGlobalData.ts +1 -1
- package/src/hooks/pol/usePollMarkets.ts +1 -1
- package/src/hooks/pol/useQueuedBeraUnlock.ts +17 -15
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +6 -3
- package/src/hooks/pol/useRewardVault.ts +1 -1
- package/src/hooks/pol/useRewardVaults.ts +1 -1
- package/src/hooks/pol/useSWBeraVaultMetadata.ts +35 -0
- package/src/hooks/pol/useStakedAPR.ts +38 -0
- package/src/hooks/pol/useStakedData.ts +117 -0
- package/src/hooks/pol/useStakedSnapshots.ts +52 -0
- package/src/hooks/pol/useTotalStakedAmount.ts +30 -0
- package/src/hooks/pol/useUserVaultInfo.ts +1 -1
- package/src/hooks/pol/useVaultValidators.ts +1 -1
- package/src/hooks/tokens/useMultipleTokenInformation.ts +15 -6
- package/src/hooks/tokens/usePollAllowances.ts +15 -19
- package/src/hooks/tokens/usePollBalance.ts +8 -4
- package/src/hooks/tokens/usePollWalletBalances.ts +14 -11
- package/src/hooks/tokens/useStakingTokenInformation.ts +2 -1
- package/src/hooks/tokens/useTokenCurrentPrice.ts +4 -2
- package/src/hooks/tokens/useTokenCurrentPrices.ts +92 -13
- package/src/hooks/tokens/useTokenInformation.ts +11 -6
- package/src/hooks/tokens/useTokenPrice.ts +21 -0
- package/src/hooks/tokens/useTokenPrices.ts +133 -0
- package/src/hooks/tokens/useTokens.ts +1 -0
- package/src/hooks/tokens/useUnderlyingAsset.ts +23 -0
- package/src/hooks/transactions/transactionStore.ts +86 -65
- package/src/hooks/transactions/transactionStore.unit.test.ts +54 -1
- package/src/hooks/transactions/useAddRecentTransaction.ts +1 -1
- package/src/hooks/transactions/useRecentTransactions.ts +1 -1
- package/src/hooks/transactions/useSetTransactionStatus.ts +31 -0
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +2 -1
- package/src/hooks/validators/useAllValidators.ts +1 -1
- package/src/hooks/validators/useApiValidator.ts +1 -1
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +1 -1
- package/src/hooks/validators/useManagedValidatorByAccount.ts +1 -1
- package/src/hooks/validators/useManagedValidatorRole.ts +1 -1
- package/src/hooks/validators/useOnChainValidator.ts +1 -1
- package/src/hooks/validators/useStakingPoolBatch.ts +1 -1
- package/src/hooks/validators/useUserActiveValidators.ts +1 -1
- package/src/hooks/validators/useUserBoostsOnValidator.ts +1 -1
- package/src/hooks/validators/useUserClaimableIncentives.ts +8 -8
- package/src/hooks/validators/useValidator.ts +1 -1
- package/src/hooks/validators/useValidatorAnalytics.ts +1 -1
- package/src/hooks/validators/useValidatorCommission.ts +1 -1
- package/src/hooks/validators/useValidatorQueuedCommission.ts +1 -1
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +1 -1
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +1 -1
- package/src/hooks/validators/useValidatorRewardAllocation.ts +1 -1
- package/src/types/{dex.ts → dex.d.ts} +96 -67
- package/src/types/{enso.ts → enso.d.ts} +1 -1
- package/src/types/exports.ts +8 -0
- package/src/types/{global.ts → global.d.ts} +1 -30
- package/src/types/{governance.ts → governance.d.ts} +2 -64
- package/src/types/{honeySwap.ts → honeySwap.d.ts} +1 -13
- package/src/types/{pol.ts → pol.d.ts} +12 -1
- package/src/types/staking.d.ts +22 -0
- package/src/utils/createEmitter.ts +122 -0
- package/src/utils/createEmitter.unit.test.ts +149 -0
- package/src/utils/{index.ts → exports.ts} +3 -2
- package/src/utils/filter.ts +34 -0
- package/src/utils/formatNumber.ts +1 -1
- package/src/utils/formatNumber.unit.test.ts +2 -1
- package/src/utils/formatTokenList.ts +4 -10
- package/src/utils/getHoneySwapMessage.test.ts +1 -2
- package/src/utils/getServerSideClient.ts +4 -5
- package/src/utils/isDifferenceExceedingThreshold.ts +1 -1
- package/src/utils/layerZeroScan.ts +122 -0
- package/src/utils/math.ts +1 -1
- package/src/utils/parseWhiskToken.ts +15 -0
- package/src/utils/poolNamings.ts +1 -1
- package/src/utils/tokens.ts +23 -7
- package/dist/HoneyConfigProvider-6PXZJMSU.d.cts +0 -562
- package/dist/HoneyConfigProvider-CwDFrt02.d.ts +0 -562
- package/dist/abi/index.cjs +0 -2
- package/dist/abi/index.cjs.map +0 -1
- package/dist/abi/index.mjs +0 -2
- package/dist/actions/index.cjs +0 -2
- package/dist/actions/index.cjs.map +0 -1
- package/dist/actions/index.mjs +0 -2
- package/dist/aggregatorsRouter-Cny4B_MB.d.cts +0 -593
- package/dist/aggregatorsRouter-Cny4B_MB.d.ts +0 -593
- package/dist/chunk-22MQVFHP.cjs +0 -2
- package/dist/chunk-22MQVFHP.cjs.map +0 -1
- package/dist/chunk-3TKSVFZ3.mjs +0 -2
- package/dist/chunk-3TKSVFZ3.mjs.map +0 -1
- package/dist/chunk-6VF3RF53.cjs +0 -3
- package/dist/chunk-6VF3RF53.cjs.map +0 -1
- package/dist/chunk-6W22TFYA.mjs +0 -2
- package/dist/chunk-6W22TFYA.mjs.map +0 -1
- package/dist/chunk-AMRJ4B36.mjs +0 -2
- package/dist/chunk-AMRJ4B36.mjs.map +0 -1
- package/dist/chunk-DS2ZDVKU.mjs +0 -2
- package/dist/chunk-DS2ZDVKU.mjs.map +0 -1
- package/dist/chunk-ED43NYSE.cjs +0 -2
- package/dist/chunk-ED43NYSE.cjs.map +0 -1
- package/dist/chunk-EU4WFADK.cjs +0 -2
- package/dist/chunk-EU4WFADK.cjs.map +0 -1
- package/dist/chunk-HCTFDGXL.mjs +0 -2
- package/dist/chunk-HCTFDGXL.mjs.map +0 -1
- package/dist/chunk-IOSYBHKU.mjs +0 -2
- package/dist/chunk-IOSYBHKU.mjs.map +0 -1
- package/dist/chunk-JMKLDDKY.cjs +0 -2
- package/dist/chunk-JMKLDDKY.cjs.map +0 -1
- package/dist/chunk-KMKUXP2S.mjs +0 -3
- package/dist/chunk-KMKUXP2S.mjs.map +0 -1
- package/dist/chunk-OJXJ6CZ4.mjs +0 -4
- package/dist/chunk-OJXJ6CZ4.mjs.map +0 -1
- package/dist/chunk-PHIOKO3A.mjs +0 -2
- package/dist/chunk-PHIOKO3A.mjs.map +0 -1
- package/dist/chunk-QCK474XD.cjs +0 -2
- package/dist/chunk-QCK474XD.cjs.map +0 -1
- package/dist/chunk-REDXXUK7.cjs +0 -2
- package/dist/chunk-REDXXUK7.cjs.map +0 -1
- package/dist/chunk-S74ZMG2G.cjs +0 -2
- package/dist/chunk-S74ZMG2G.cjs.map +0 -1
- package/dist/chunk-TOAXF4YW.cjs +0 -2
- package/dist/chunk-TOAXF4YW.cjs.map +0 -1
- package/dist/chunk-UZ5CB33M.cjs +0 -2
- package/dist/chunk-UZ5CB33M.cjs.map +0 -1
- package/dist/chunk-VYWYJR63.mjs +0 -2
- package/dist/chunk-VYWYJR63.mjs.map +0 -1
- package/dist/chunk-XFPTQMAK.cjs +0 -4
- package/dist/chunk-XFPTQMAK.cjs.map +0 -1
- package/dist/chunk-YK4NINF5.mjs +0 -2
- package/dist/chunk-YK4NINF5.mjs.map +0 -1
- package/dist/contexts/index.cjs +0 -2
- package/dist/contexts/index.cjs.map +0 -1
- package/dist/contexts/index.mjs +0 -2
- package/dist/contexts/index.mjs.map +0 -1
- package/dist/enum/index.cjs +0 -2
- package/dist/enum/index.cjs.map +0 -1
- package/dist/enum/index.d.cts +0 -31
- package/dist/enum/index.d.ts +0 -31
- package/dist/enum/index.mjs +0 -2
- package/dist/enum/index.mjs.map +0 -1
- package/dist/errors/index.cjs +0 -2
- package/dist/errors/index.cjs.map +0 -1
- package/dist/errors/index.d.cts +0 -204
- package/dist/errors/index.d.ts +0 -204
- package/dist/errors/index.mjs +0 -2
- package/dist/errors/index.mjs.map +0 -1
- package/dist/hooks/index.cjs +0 -4
- package/dist/hooks/index.cjs.map +0 -1
- package/dist/hooks/index.mjs +0 -4
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/staking-F9Nx9TKD.d.ts +0 -246
- package/dist/staking-f4BpYH7l.d.cts +0 -246
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -56
- package/dist/types/index.d.ts +0 -56
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/utils/index.cjs +0 -2
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.mjs +0 -2
- package/dist/utils/index.mjs.map +0 -1
- package/src/actions/dex/getTransactionCount.ts +0 -29
- package/src/actions/enso/bend.ts +0 -143
- package/src/actions/enso/getEnsoUserToken.debug.test.ts +0 -57
- package/src/contexts/berajsProvider/context.tsx +0 -49
- package/src/contexts/berajsProvider/index.ts +0 -2
- package/src/contexts/berajsProvider/useBeraJs.ts +0 -18
- package/src/hooks/dex/usePollVaultIsPaused.ts +0 -30
- package/src/hooks/enso/useBendTransactionRequests.ts +0 -247
- package/src/hooks/enso/useEnsoZap.ts +0 -166
- package/src/hooks/enso/useZapTransactionRequests.ts +0 -81
- package/src/hooks/pol/useEarnedStakedBeraVault.ts +0 -59
- package/src/hooks/pol/useStakedBeraSnapshots.ts +0 -27
- package/src/hooks/validators/validatorRoleManager.ts +0 -0
- package/src/types/index.ts +0 -8
- package/src/types/staking.ts +0 -7
- package/src/utils/formatAggregatorsQuotes.ts +0 -57
- package/src/utils/formatAggregatorsQuotes.unit.test.ts +0 -191
- package/src/utils/sentryBeforeSend.ts +0 -52
- /package/dist/{abi/index.mjs.map → errors/exports.mjs.map} +0 -0
- /package/dist/{actions/index.mjs.map → types/exports.mjs.map} +0 -0
- /package/src/actions/dex/{__tests__ → aggregators}/haiku.integration.test.ts +0 -0
- /package/src/types/{bribe-boost.ts → bribe-boost.d.ts} +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
|
|
3
|
+
import { beraFetchJson } from "~/utils/beraFetch";
|
|
4
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
5
|
+
|
|
6
|
+
export async function getStakingDailyAssets({
|
|
7
|
+
address,
|
|
8
|
+
range,
|
|
9
|
+
}: {
|
|
10
|
+
address: Address;
|
|
11
|
+
range: 30 | 60 | 90;
|
|
12
|
+
}): Promise<{ _timestamp: number; total_assets: string }[]> {
|
|
13
|
+
const now = new Date();
|
|
14
|
+
const startDayDate = new Date(
|
|
15
|
+
now.getTime() - Number(range) * 24 * 60 * 60 * 1000,
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const { config } = parseBaseArgs({});
|
|
19
|
+
const url = `${config.bonder}/vaults/${address}/total-assets-by-day?start=${startDayDate.toISOString().split("T")[0]}`;
|
|
20
|
+
return beraFetchJson<{ _timestamp: number; total_assets: string }[]>(url);
|
|
21
|
+
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type Address, erc20Abi, formatUnits } from "viem";
|
|
1
|
+
import { type Address, erc20Abi, formatUnits, type PublicClient } from "viem";
|
|
3
2
|
|
|
4
3
|
import { assertPublicClient } from "~/errors/assert";
|
|
5
|
-
import type { Token } from "~/types";
|
|
4
|
+
import type { Token } from "~/types/dex";
|
|
6
5
|
|
|
7
6
|
export interface GetStakingTokenInformation {
|
|
8
7
|
address: Address;
|
|
9
|
-
publicClient:
|
|
8
|
+
publicClient: PublicClient | undefined;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export type GetStakingTokenInformationResponse = Partial<Token> | undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import type { Address } from "@berachain/config";
|
|
4
|
+
|
|
5
|
+
import { stakeBeraVaultAbi } from "~/abi/pol/stakeBeraVault";
|
|
6
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Get the total staked amount for a given vault address
|
|
10
|
+
* @param vaultAddresses - The addresses of the vaults to get the total staked amount for
|
|
11
|
+
* @param publicClient - The public client to use to get the total staked amount
|
|
12
|
+
* @returns The total staked amount for the given vault addresses
|
|
13
|
+
*/
|
|
14
|
+
export async function getTotalStakedAmount({
|
|
15
|
+
vaultAddresses,
|
|
16
|
+
publicClient,
|
|
17
|
+
}: {
|
|
18
|
+
vaultAddresses: Address[];
|
|
19
|
+
publicClient?: PublicClient;
|
|
20
|
+
} & BeraJS.BaseFunctionArgs): Promise<Record<Address, bigint>> {
|
|
21
|
+
assertPublicClient(publicClient);
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const totalAssets = await Promise.all(
|
|
25
|
+
vaultAddresses.map(async (address) => {
|
|
26
|
+
return await publicClient.readContract({
|
|
27
|
+
address,
|
|
28
|
+
abi: stakeBeraVaultAbi,
|
|
29
|
+
functionName: "totalAssets",
|
|
30
|
+
});
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const stakedAmount = vaultAddresses.reduce(
|
|
35
|
+
(acc, address, index) => {
|
|
36
|
+
acc[address] = totalAssets[index];
|
|
37
|
+
return acc;
|
|
38
|
+
},
|
|
39
|
+
{} as Record<Address, bigint>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return stakedAmount;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error("Failed to get total staked amount", error);
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Address } from "viem";
|
|
2
2
|
|
|
3
3
|
import { BeraError } from "~/errors/BeraError";
|
|
4
|
-
import type { BribeBoostRewardItem } from "~/types";
|
|
4
|
+
import type { BribeBoostRewardItem } from "~/types/bribe-boost";
|
|
5
5
|
import { getErrorResponse } from "~/utils/getErrorResponse";
|
|
6
6
|
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
7
7
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as Sentry from "@sentry/nextjs";
|
|
2
1
|
import { type Address, formatUnits, type PublicClient } from "viem";
|
|
3
2
|
|
|
4
3
|
import {
|
|
@@ -11,6 +10,8 @@ import {
|
|
|
11
10
|
|
|
12
11
|
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
13
12
|
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
13
|
+
import { BeraError } from "~/errors/BeraError";
|
|
14
|
+
import { BeraMonitoring } from "~/errors/BeraMonitoring";
|
|
14
15
|
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
15
16
|
|
|
16
17
|
export interface UserVault {
|
|
@@ -100,13 +101,14 @@ export async function getUserVaults({
|
|
|
100
101
|
if (!deposit.vault) {
|
|
101
102
|
// This is in case the API is missing the vault data
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
new
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
BeraMonitoring.captureException(
|
|
105
|
+
new BeraError({
|
|
106
|
+
message: "Deposit data from API is missing vault",
|
|
107
|
+
level: "error",
|
|
108
|
+
extra: {
|
|
107
109
|
deposit,
|
|
108
110
|
},
|
|
109
|
-
},
|
|
111
|
+
}),
|
|
110
112
|
);
|
|
111
113
|
|
|
112
114
|
console.error("Deposit data from API is missing vault", deposit);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Address, PublicClient } from "viem";
|
|
2
2
|
|
|
3
3
|
import { rewardVaultAbi } from "~/abi/pol/rewardVault";
|
|
4
|
-
import {
|
|
4
|
+
import { assertAddress, assertPublicClient } from "~/errors/assert";
|
|
5
5
|
|
|
6
6
|
export interface GetUserVaultsInfo {
|
|
7
7
|
account: string | undefined;
|
|
@@ -15,20 +15,8 @@ export async function getUserVaultsBalance({
|
|
|
15
15
|
publicClient,
|
|
16
16
|
}: GetUserVaultsInfo): Promise<{ balance: bigint; delegated: bigint }> {
|
|
17
17
|
assertPublicClient(publicClient);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
throw new InvalidArgumentError({
|
|
21
|
-
property: "account",
|
|
22
|
-
value: account,
|
|
23
|
-
expected: "Address",
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
if (!vaultAddress || !isAddress(vaultAddress))
|
|
27
|
-
throw new InvalidArgumentError({
|
|
28
|
-
property: "vaultAddress",
|
|
29
|
-
value: vaultAddress,
|
|
30
|
-
expected: "Address",
|
|
31
|
-
});
|
|
18
|
+
assertAddress(account, "account");
|
|
19
|
+
assertAddress(vaultAddress, "vaultAddress");
|
|
32
20
|
|
|
33
21
|
try {
|
|
34
22
|
const [balance, delegated] = await Promise.all([
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
} from "@berachain/graphql/dex/api";
|
|
9
9
|
|
|
10
10
|
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
11
|
-
import type { TokenCurrentPriceMap } from "~/types";
|
|
12
|
-
import { getSafeNumber } from "~/utils";
|
|
11
|
+
import type { TokenCurrentPriceMap } from "~/types/dex";
|
|
12
|
+
import { getSafeNumber } from "~/utils/formatNumber";
|
|
13
13
|
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
14
14
|
import { isToken } from "~/utils/tokens";
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ export async function getTokenCurrentPrices({
|
|
|
19
19
|
}: {
|
|
20
20
|
addressIn: string[];
|
|
21
21
|
} & BeraJS.BaseFunctionArgs): Promise<TokenCurrentPriceMap> {
|
|
22
|
-
const { config } = parseBaseArgs(args);
|
|
22
|
+
const { config, chainId } = parseBaseArgs(args);
|
|
23
23
|
|
|
24
24
|
const addressIn = _addressIn
|
|
25
25
|
.map((a) => a.toLowerCase())
|
|
@@ -49,26 +49,31 @@ export async function getTokenCurrentPrices({
|
|
|
49
49
|
map[getAddress(formattedAddress)] = {
|
|
50
50
|
price: getSafeNumber(tokenInformation.price.toString()),
|
|
51
51
|
updatedAt: tokenInformation.updatedAt,
|
|
52
|
+
chainId,
|
|
52
53
|
};
|
|
53
54
|
|
|
54
55
|
map[formattedAddress.toLowerCase()] = {
|
|
55
56
|
price: getSafeNumber(tokenInformation.price.toString()),
|
|
56
57
|
updatedAt: tokenInformation.updatedAt,
|
|
58
|
+
chainId,
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
if (isToken(formattedAddress, "WBERA")) {
|
|
60
62
|
map[zeroAddress] = {
|
|
61
63
|
price: getSafeNumber(tokenInformation.price.toString()),
|
|
62
64
|
updatedAt: tokenInformation.updatedAt,
|
|
65
|
+
chainId,
|
|
63
66
|
};
|
|
64
67
|
map[config.tokens.bgt.toLowerCase()] = {
|
|
65
68
|
price: getSafeNumber(tokenInformation.price.toString()),
|
|
66
69
|
updatedAt: tokenInformation.updatedAt,
|
|
70
|
+
chainId,
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
map[config.tokens.bgt] = {
|
|
70
74
|
price: getSafeNumber(tokenInformation.price.toString()),
|
|
71
75
|
updatedAt: tokenInformation.updatedAt,
|
|
76
|
+
chainId,
|
|
72
77
|
};
|
|
73
78
|
}
|
|
74
79
|
|
|
@@ -1,59 +1,86 @@
|
|
|
1
|
+
import { type Config, getPublicClient } from "@wagmi/core";
|
|
1
2
|
import {
|
|
2
3
|
type Address,
|
|
3
4
|
type ContractFunctionParameters,
|
|
4
5
|
erc20Abi,
|
|
5
6
|
formatUnits,
|
|
6
|
-
type PublicClient,
|
|
7
7
|
} from "viem";
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import { assertDefined, assertPublicClient } from "~/errors/assert";
|
|
10
|
+
import type { AllowanceQueryItem, AllowanceToken } from "~/types/dex";
|
|
10
11
|
|
|
11
12
|
export interface GetAllowances {
|
|
12
|
-
|
|
13
|
+
items: AllowanceQueryItem[] | undefined;
|
|
13
14
|
account: `0x${string}` | undefined;
|
|
14
|
-
|
|
15
|
-
publicClient: PublicClient | undefined;
|
|
15
|
+
config: Config | undefined;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export type GetAllowancesResponse = AllowanceToken[] | undefined;
|
|
19
19
|
|
|
20
20
|
export async function getAllowances({
|
|
21
|
-
|
|
21
|
+
items: itemsList,
|
|
22
22
|
account,
|
|
23
|
-
|
|
24
|
-
publicClient,
|
|
23
|
+
config,
|
|
25
24
|
}: GetAllowances): Promise<GetAllowancesResponse> {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
assertDefined(itemsList, "items");
|
|
26
|
+
assertDefined(config, "config");
|
|
27
|
+
assertDefined(account, "account");
|
|
28
|
+
|
|
29
|
+
const tokensByChainId = Object.groupBy(
|
|
30
|
+
itemsList,
|
|
31
|
+
(item) => item.token.chainId,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const res = await Promise.allSettled(
|
|
35
|
+
Object.entries(tokensByChainId).map(async ([chainId, items]) => {
|
|
36
|
+
if (!items) return [];
|
|
37
|
+
|
|
38
|
+
const publicClient = getPublicClient(config, {
|
|
39
|
+
chainId: Number(chainId),
|
|
40
|
+
});
|
|
41
|
+
assertPublicClient(publicClient, `publicClient ${chainId}`);
|
|
42
|
+
|
|
43
|
+
const result = await publicClient.multicall({
|
|
44
|
+
contracts: items.map(
|
|
45
|
+
(item) =>
|
|
46
|
+
({
|
|
47
|
+
address: item.token.address,
|
|
48
|
+
abi: erc20Abi,
|
|
49
|
+
functionName: "allowance",
|
|
50
|
+
args: [account, item.spender as Address],
|
|
51
|
+
}) as const as ContractFunctionParameters<
|
|
52
|
+
typeof erc20Abi,
|
|
53
|
+
"view",
|
|
54
|
+
"allowance"
|
|
55
|
+
>,
|
|
56
|
+
),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const allowances = result.map((item, index: number) => {
|
|
60
|
+
const token = items[index];
|
|
61
|
+
if (item.error) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const resultAllowanceToken: AllowanceToken = {
|
|
66
|
+
token: token.token,
|
|
67
|
+
spender: token.spender,
|
|
68
|
+
amount: token.amount,
|
|
69
|
+
allowance: {
|
|
70
|
+
raw: item.result.toString(),
|
|
71
|
+
formatted: formatUnits(item.result, token.token.decimals),
|
|
72
|
+
},
|
|
73
|
+
needsApproval: item.result < BigInt(token.amount.raw),
|
|
74
|
+
} satisfies AllowanceToken;
|
|
75
|
+
return resultAllowanceToken;
|
|
76
|
+
});
|
|
77
|
+
return allowances.filter((i): i is AllowanceToken => Boolean(i));
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
return res
|
|
82
|
+
.flatMap((result) =>
|
|
83
|
+
result.status === "fulfilled" ? result.value : undefined,
|
|
84
|
+
)
|
|
85
|
+
.filter((i): i is AllowanceToken => Boolean(i));
|
|
59
86
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type Address, erc20Abi, type PublicClient } from "viem";
|
|
2
2
|
|
|
3
3
|
import { initBeraError } from "~/errors/initBeraError";
|
|
4
|
-
import type { MinimalERC20 } from "~/types";
|
|
4
|
+
import type { MinimalERC20 } from "~/types/dex";
|
|
5
5
|
|
|
6
6
|
export interface GetTokenInformation {
|
|
7
7
|
address: Address;
|
|
8
8
|
publicClient: PublicClient;
|
|
9
|
+
chainId: number;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export type GetTokenInformationResponse = MinimalERC20 | undefined;
|
|
@@ -13,6 +14,7 @@ export type GetTokenInformationResponse = MinimalERC20 | undefined;
|
|
|
13
14
|
export async function getTokenInformation({
|
|
14
15
|
address,
|
|
15
16
|
publicClient,
|
|
17
|
+
chainId,
|
|
16
18
|
}: GetTokenInformation): Promise<GetTokenInformationResponse> {
|
|
17
19
|
try {
|
|
18
20
|
if (!publicClient) {
|
|
@@ -42,6 +44,7 @@ export async function getTokenInformation({
|
|
|
42
44
|
decimals,
|
|
43
45
|
name,
|
|
44
46
|
symbol,
|
|
47
|
+
chainId,
|
|
45
48
|
};
|
|
46
49
|
if (
|
|
47
50
|
typeof token.decimals !== "number" ||
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type Config, getPublicClient } from "@wagmi/core";
|
|
2
|
+
import { erc4626Abi } from "viem";
|
|
3
|
+
|
|
4
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
5
|
+
import { initBeraError } from "~/errors/initBeraError";
|
|
6
|
+
import type { MinimalERC20 } from "~/types/dex";
|
|
7
|
+
import { isToken } from "~/utils/tokens";
|
|
8
|
+
import { getTokenInformation } from "./getTokenInformation";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to resolve the underlying asset of an ERC4626 vault by calling `asset()`.
|
|
12
|
+
* Returns the full token info if the token is an ERC4626 vault, or `null` if it isn't
|
|
13
|
+
* (i.e. the `asset()` call reverts). Skips the native gas token (BERA) since it can't be a vault.
|
|
14
|
+
*/
|
|
15
|
+
export async function getUnderlyingToken({
|
|
16
|
+
token,
|
|
17
|
+
wagmiConfig,
|
|
18
|
+
}: {
|
|
19
|
+
token: MinimalERC20;
|
|
20
|
+
wagmiConfig: Config;
|
|
21
|
+
}) {
|
|
22
|
+
try {
|
|
23
|
+
if (isToken(token, "BERA")) {
|
|
24
|
+
// gas token can't have an underlying token
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const publicClient = getPublicClient(wagmiConfig, {
|
|
29
|
+
chainId: token.chainId,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
assertPublicClient(publicClient);
|
|
33
|
+
|
|
34
|
+
const address = await publicClient.readContract({
|
|
35
|
+
address: token.address,
|
|
36
|
+
abi: erc4626Abi,
|
|
37
|
+
functionName: "asset",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
return await getTokenInformation({
|
|
41
|
+
address: address,
|
|
42
|
+
publicClient,
|
|
43
|
+
chainId: token.chainId,
|
|
44
|
+
});
|
|
45
|
+
} catch (e) {
|
|
46
|
+
const err = initBeraError({ cause: e });
|
|
47
|
+
if (err.reason === 'The contract function "asset" reverted.') {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { assert, describe, expect, it
|
|
1
|
+
import { ethAddress } from "viem";
|
|
2
|
+
import { assert, describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { appConfig } from "@berachain/config/internal";
|
|
5
|
+
import {
|
|
6
|
+
defaultChain,
|
|
7
|
+
externalChains,
|
|
8
|
+
transports,
|
|
9
|
+
} from "@berachain/config/internal/wagmi";
|
|
10
|
+
|
|
11
|
+
import { getConfig } from "@berachain/wagmi/config";
|
|
3
12
|
|
|
4
|
-
import { getServerSidePublicClient } from "~/utils/getServerSideClient";
|
|
5
13
|
import { isToken } from "~/utils/tokens";
|
|
6
14
|
import { getTokens } from "./getTokens";
|
|
7
15
|
import { getWalletBalances } from "./getWalletBalances";
|
|
@@ -13,20 +21,28 @@ import { getWalletBalances } from "./getWalletBalances";
|
|
|
13
21
|
*/
|
|
14
22
|
const account = "0x08194D89A52C1410F4bcc46FE11AC2387aC69de8";
|
|
15
23
|
describe("getWalletBalances", async () => {
|
|
24
|
+
const { wagmi: wagmiConfig } = getConfig({
|
|
25
|
+
transports,
|
|
26
|
+
defaultChain,
|
|
27
|
+
chains: externalChains,
|
|
28
|
+
thirdweb: { clientId: appConfig.apiKeys.public.thirdweb },
|
|
29
|
+
});
|
|
30
|
+
|
|
16
31
|
it("should have gas balance", async () => {
|
|
17
32
|
const tokenList = await getTokens();
|
|
18
|
-
const publicClient = getServerSidePublicClient();
|
|
19
|
-
publicClient.chain = berachain;
|
|
20
|
-
publicClient.multicall = vi.fn().mockResolvedValue(
|
|
21
|
-
tokenList.map(() => ({
|
|
22
|
-
result: 123n,
|
|
23
|
-
})),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
33
|
const balances = await getWalletBalances({
|
|
27
34
|
account,
|
|
28
|
-
|
|
29
|
-
tokenList
|
|
35
|
+
wagmiConfig,
|
|
36
|
+
tokenList: [
|
|
37
|
+
...tokenList,
|
|
38
|
+
{
|
|
39
|
+
address: "0x0000000000000000000000000000000000000000",
|
|
40
|
+
decimals: 18,
|
|
41
|
+
symbol: "ETH",
|
|
42
|
+
name: "Ether",
|
|
43
|
+
chainId: 1,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
30
46
|
}).catch((error) => {
|
|
31
47
|
assert.fail(error);
|
|
32
48
|
});
|
|
@@ -35,6 +51,29 @@ describe("getWalletBalances", async () => {
|
|
|
35
51
|
|
|
36
52
|
expect(beraBalance).toBeDefined();
|
|
37
53
|
|
|
38
|
-
expect(beraBalance?.balance).toBeGreaterThan(0n);
|
|
54
|
+
expect(BigInt(beraBalance?.balance.raw)).toBeGreaterThan(0n);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should have balance for multiple chains", async () => {
|
|
58
|
+
const balances = await getWalletBalances({
|
|
59
|
+
account,
|
|
60
|
+
wagmiConfig,
|
|
61
|
+
tokenList: [
|
|
62
|
+
{
|
|
63
|
+
address: ethAddress,
|
|
64
|
+
decimals: 18,
|
|
65
|
+
symbol: "ETH",
|
|
66
|
+
name: "Ether",
|
|
67
|
+
chainId: 1,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
}).catch((error) => {
|
|
71
|
+
assert.fail(error);
|
|
72
|
+
});
|
|
73
|
+
expect(balances).toBeDefined();
|
|
74
|
+
expect(balances?.length).toBeGreaterThan(0);
|
|
75
|
+
expect(balances?.some((b) => isToken(b, "ETH") && b.chainId === 1)).toBe(
|
|
76
|
+
true,
|
|
77
|
+
);
|
|
39
78
|
});
|
|
40
79
|
});
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
+
import { type Config, getChainId, getPublicClient } from "@wagmi/core";
|
|
1
2
|
import {
|
|
2
3
|
type Address,
|
|
3
4
|
type ContractFunctionParameters,
|
|
4
5
|
erc20Abi,
|
|
5
6
|
formatUnits,
|
|
6
7
|
isAddress,
|
|
7
|
-
type PublicClient,
|
|
8
8
|
} from "viem";
|
|
9
9
|
|
|
10
10
|
import { multicall3Abi } from "~/abi/utils/multicall3";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
assertAddress,
|
|
13
|
+
assertDefined,
|
|
14
|
+
assertPublicClient,
|
|
15
|
+
} from "~/errors/assert";
|
|
12
16
|
import type { BalanceToken, Token } from "~/types/dex";
|
|
13
17
|
import { isToken } from "~/utils/tokens";
|
|
14
18
|
|
|
15
19
|
export interface GetWalletBalances {
|
|
16
20
|
account: string | undefined;
|
|
17
21
|
tokenList: Token[] | undefined;
|
|
18
|
-
|
|
22
|
+
wagmiConfig: Config | undefined;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
@@ -63,61 +67,83 @@ export function getBalanceCall({
|
|
|
63
67
|
export async function getWalletBalances({
|
|
64
68
|
account,
|
|
65
69
|
tokenList,
|
|
66
|
-
|
|
70
|
+
wagmiConfig: config,
|
|
67
71
|
}: GetWalletBalances): Promise<BalanceToken[] | undefined> {
|
|
68
|
-
|
|
72
|
+
assertDefined(config, "config");
|
|
69
73
|
if (!account || !tokenList)
|
|
70
74
|
throw new Error("account or tokenList is not defined");
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
assertAddress(account, "account");
|
|
73
77
|
|
|
74
78
|
const filteredTokenList = tokenList.filter((token) =>
|
|
75
79
|
isAddress(token.address),
|
|
76
80
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"publicClient.chain.contracts.multicall3",
|
|
81
|
+
|
|
82
|
+
const tokensByChainId = Object.groupBy(
|
|
83
|
+
filteredTokenList,
|
|
84
|
+
(token) => token.chainId ?? getChainId(config),
|
|
82
85
|
);
|
|
83
86
|
|
|
84
|
-
const
|
|
87
|
+
const res = await Promise.allSettled(
|
|
88
|
+
Object.entries(tokensByChainId).map(async ([chainId, tokens]) => {
|
|
89
|
+
assertDefined(tokens, "tokens");
|
|
90
|
+
const publicClient = getPublicClient(config, {
|
|
91
|
+
chainId: Number(chainId),
|
|
92
|
+
});
|
|
93
|
+
assertPublicClient(publicClient, `publicClient ${chainId}`);
|
|
94
|
+
assertDefined(publicClient.chain, "publicClient.chain");
|
|
95
|
+
assertDefined(
|
|
96
|
+
publicClient.chain.contracts,
|
|
97
|
+
"publicClient.chain.contracts",
|
|
98
|
+
);
|
|
99
|
+
assertDefined(
|
|
100
|
+
publicClient.chain.contracts.multicall3,
|
|
101
|
+
"publicClient.chain.contracts.multicall3",
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const { multicall3 } = publicClient.chain.contracts;
|
|
105
|
+
|
|
106
|
+
const multicall3Address =
|
|
107
|
+
typeof multicall3 === "string" ? multicall3 : multicall3.address;
|
|
85
108
|
|
|
86
|
-
|
|
87
|
-
typeof multicall3 === "string" ? multicall3 : multicall3.address;
|
|
109
|
+
assertAddress(multicall3Address, "multicall3Address");
|
|
88
110
|
|
|
89
|
-
|
|
111
|
+
const call = tokens.map((token: Token) =>
|
|
112
|
+
getBalanceCall({
|
|
113
|
+
token,
|
|
114
|
+
account,
|
|
115
|
+
multicallAddress: multicall3Address,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
90
118
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
119
|
+
const result = await publicClient.multicall({
|
|
120
|
+
contracts: call,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
return result.map((item, index) => {
|
|
124
|
+
const token = tokens[index];
|
|
125
|
+
if (item.error) {
|
|
126
|
+
return { ...token, balance: { raw: "0", formatted: "0" } };
|
|
127
|
+
}
|
|
128
|
+
const formattedBalance = formatUnits(
|
|
129
|
+
item.result,
|
|
130
|
+
token?.decimals || 18,
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const resultBalanceToken: BalanceToken = {
|
|
134
|
+
...token,
|
|
135
|
+
balance: {
|
|
136
|
+
raw: item.result.toString(),
|
|
137
|
+
// TODO: this was done 10 months ago, i'm not sure it's a good solution.
|
|
138
|
+
formatted: formattedBalance.includes("e") ? "0" : formattedBalance,
|
|
139
|
+
},
|
|
140
|
+
} satisfies BalanceToken;
|
|
141
|
+
return resultBalanceToken;
|
|
142
|
+
});
|
|
96
143
|
}),
|
|
97
144
|
);
|
|
98
145
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const balances = await Promise.all(
|
|
104
|
-
result.map(async (item, index) => {
|
|
105
|
-
const token = filteredTokenList[index];
|
|
106
|
-
if (item.error) {
|
|
107
|
-
return { balance: 0n, formattedBalance: "0", ...token };
|
|
108
|
-
}
|
|
109
|
-
const formattedBalance = formatUnits(item.result, token?.decimals || 18);
|
|
110
|
-
|
|
111
|
-
const resultBalanceToken: BalanceToken = {
|
|
112
|
-
balance: item.result,
|
|
113
|
-
// TODO: this was done 10 months ago, i'm not sure it's a good solution.
|
|
114
|
-
formattedBalance: formattedBalance.includes("e")
|
|
115
|
-
? "0"
|
|
116
|
-
: formattedBalance,
|
|
117
|
-
...token,
|
|
118
|
-
} as BalanceToken;
|
|
119
|
-
return resultBalanceToken;
|
|
120
|
-
}),
|
|
146
|
+
return res.flatMap((result) =>
|
|
147
|
+
result.status === "fulfilled" ? result.value : [],
|
|
121
148
|
);
|
|
122
|
-
return balances as BalanceToken[];
|
|
123
149
|
}
|