@berachain/berajs 0.1.0 → 0.1.2
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/{dex-jD95agMv.d.cts → HoneyConfigProvider-6PXZJMSU.d.cts} +172 -172
- package/dist/{dex-CxzGqVLe.d.ts → HoneyConfigProvider-CwDFrt02.d.ts} +172 -172
- package/dist/abi/index.cjs +2 -1
- package/dist/abi/index.cjs.map +1 -0
- package/dist/abi/index.mjs +2 -1
- package/dist/abi/index.mjs.map +1 -0
- package/dist/actions/index.cjs +2 -1
- package/dist/actions/index.cjs.map +1 -0
- package/dist/actions/index.d.cts +8 -8
- package/dist/actions/index.d.ts +8 -8
- package/dist/actions/index.mjs +2 -1
- package/dist/actions/index.mjs.map +1 -0
- package/dist/chunk-22MQVFHP.cjs +2 -0
- package/dist/chunk-22MQVFHP.cjs.map +1 -0
- package/dist/chunk-3TKSVFZ3.mjs +2 -0
- package/dist/chunk-3TKSVFZ3.mjs.map +1 -0
- package/dist/chunk-6VF3RF53.cjs +3 -0
- package/dist/chunk-6VF3RF53.cjs.map +1 -0
- package/dist/{chunk-2422CKAT.mjs → chunk-6W22TFYA.mjs} +2 -1
- package/dist/chunk-6W22TFYA.mjs.map +1 -0
- package/dist/chunk-AMRJ4B36.mjs +2 -0
- package/dist/chunk-AMRJ4B36.mjs.map +1 -0
- package/dist/{chunk-4IBBLGNS.mjs → chunk-DS2ZDVKU.mjs} +1 -0
- package/dist/chunk-DS2ZDVKU.mjs.map +1 -0
- package/dist/{chunk-B47PDJZM.cjs → chunk-ED43NYSE.cjs} +2 -1
- package/dist/chunk-ED43NYSE.cjs.map +1 -0
- package/dist/chunk-EU4WFADK.cjs +2 -0
- package/dist/chunk-EU4WFADK.cjs.map +1 -0
- package/dist/{chunk-ASRHUDAH.mjs → chunk-HCTFDGXL.mjs} +1 -0
- package/dist/chunk-HCTFDGXL.mjs.map +1 -0
- package/dist/{chunk-K4NZIO2Z.mjs → chunk-IOSYBHKU.mjs} +1 -0
- package/dist/chunk-IOSYBHKU.mjs.map +1 -0
- package/dist/{chunk-4GY57XKG.cjs → chunk-JMKLDDKY.cjs} +1 -0
- package/dist/chunk-JMKLDDKY.cjs.map +1 -0
- package/dist/chunk-KMKUXP2S.mjs +3 -0
- package/dist/chunk-KMKUXP2S.mjs.map +1 -0
- package/dist/chunk-OJXJ6CZ4.mjs +4 -0
- package/dist/chunk-OJXJ6CZ4.mjs.map +1 -0
- package/dist/{chunk-VA37UBED.mjs → chunk-PHIOKO3A.mjs} +2 -1
- package/dist/chunk-PHIOKO3A.mjs.map +1 -0
- package/dist/{chunk-IKAE7CQU.cjs → chunk-QCK474XD.cjs} +1 -0
- package/dist/chunk-QCK474XD.cjs.map +1 -0
- package/dist/chunk-REDXXUK7.cjs +2 -0
- package/dist/chunk-REDXXUK7.cjs.map +1 -0
- package/dist/{chunk-K2FCHQHA.cjs → chunk-S74ZMG2G.cjs} +2 -1
- package/dist/chunk-S74ZMG2G.cjs.map +1 -0
- package/dist/{chunk-NOV7UCGA.cjs → chunk-TOAXF4YW.cjs} +1 -0
- package/dist/chunk-TOAXF4YW.cjs.map +1 -0
- package/dist/chunk-UZ5CB33M.cjs +2 -0
- package/dist/chunk-UZ5CB33M.cjs.map +1 -0
- package/dist/chunk-VYWYJR63.mjs +2 -0
- package/dist/chunk-VYWYJR63.mjs.map +1 -0
- package/dist/{chunk-WZLPSG5R.cjs → chunk-XFPTQMAK.cjs} +3 -2
- package/dist/chunk-XFPTQMAK.cjs.map +1 -0
- package/dist/chunk-YK4NINF5.mjs +2 -0
- package/dist/chunk-YK4NINF5.mjs.map +1 -0
- package/dist/contexts/index.cjs +2 -1
- package/dist/contexts/index.cjs.map +1 -0
- package/dist/contexts/index.d.cts +7 -5
- package/dist/contexts/index.d.ts +7 -5
- package/dist/contexts/index.mjs +2 -1
- package/dist/contexts/index.mjs.map +1 -0
- package/dist/enum/index.cjs +2 -1
- package/dist/enum/index.cjs.map +1 -0
- package/dist/enum/index.d.cts +1 -1
- package/dist/enum/index.d.ts +1 -1
- package/dist/enum/index.mjs +2 -1
- package/dist/enum/index.mjs.map +1 -0
- package/dist/errors/index.cjs +2 -1
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.d.cts +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.mjs +2 -1
- package/dist/errors/index.mjs.map +1 -0
- package/dist/{getValidatorQueuedOperatorAddress-9jSXlAse.d.ts → getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts} +2 -2
- package/dist/{getValidatorQueuedOperatorAddress-BCYlvah3.d.cts → getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts} +2 -2
- package/dist/hooks/index.cjs +3 -2
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +9 -9
- package/dist/hooks/index.d.ts +9 -9
- package/dist/hooks/index.mjs +3 -2
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/{staking-Bw46L2PT.d.ts → staking-F9Nx9TKD.d.ts} +1 -1
- package/dist/{staking-BxYDlMtj.d.cts → staking-f4BpYH7l.d.cts} +1 -1
- package/dist/{txnEnum-Diichv9Z.d.cts → txnEnum-BQKDfaeH.d.cts} +1 -0
- package/dist/{txnEnum-Diichv9Z.d.ts → txnEnum-BQKDfaeH.d.ts} +1 -0
- package/dist/types/index.cjs +2 -1
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +5 -5
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.mjs +2 -1
- package/dist/types/index.mjs.map +1 -0
- package/dist/{useHoneySwapState-YfMSTWY3.d.cts → useHoneySwapState-C-9BV4VB.d.cts} +1 -1
- package/dist/{useHoneySwapState-CD8v6y1k.d.ts → useHoneySwapState-CUY5Sm1b.d.ts} +1 -1
- package/dist/utils/index.cjs +2 -1
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +5 -5
- package/dist/utils/index.d.ts +5 -5
- package/dist/utils/index.mjs +2 -1
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +4 -3
- package/src/abi/bend/bundler.ts +60 -0
- package/src/abi/bend/generalAdapter.ts +362 -0
- package/src/abi/bend/metaMorpho.ts +2584 -0
- package/src/abi/bend/morpho.ts +444 -0
- package/src/abi/bend/morphoVault.ts +1456 -0
- package/src/abi/bend/publicAllocator.ts +355 -0
- package/src/abi/bex/aggregatorsRouter.ts +492 -0
- package/src/abi/bex/balancerComposableStablePoolFactoryV6.ts +283 -0
- package/src/abi/bex/balancerPoolCreationHelper.ts +267 -0
- package/src/abi/bex/balancerVault.ts +757 -0
- package/src/abi/enso/ensoRouterAbi.ts +140 -0
- package/src/abi/governance/governance.ts +1016 -0
- package/src/abi/governance/governanceTimelock.ts +589 -0
- package/src/abi/honey/collateralVault.ts +1144 -0
- package/src/abi/honey/honey.ts +563 -0
- package/src/abi/honey/honeyFactory.ts +1270 -0
- package/src/abi/honey/honeyFactoryReader.ts +894 -0
- package/src/abi/honey/honeyRootOracle.ts +492 -0
- package/src/abi/honey/pythPriceOracle.ts +619 -0
- package/src/abi/honey/pythWrapper.ts +446 -0
- package/src/abi/index.ts +35 -0
- package/src/abi/pol/beaconDeposit.ts +595 -0
- package/src/abi/pol/beraChef.ts +1019 -0
- package/src/abi/pol/bgt.ts +1008 -0
- package/src/abi/pol/bgtIncentiveDistributor.ts +640 -0
- package/src/abi/pol/bgtStaker.ts +1034 -0
- package/src/abi/pol/rewardAllocationFactory.ts +408 -0
- package/src/abi/pol/rewardVault.ts +1928 -0
- package/src/abi/pol/rewardVaultFactory.ts +586 -0
- package/src/abi/pol/rewardVaultHelper.ts +882 -0
- package/src/abi/pol/stakeBeraVault.ts +1116 -0
- package/src/abi/pol/stakeBeraVaultWithdrawalRequest.ts +618 -0
- package/src/abi/pol/wbera.ts +366 -0
- package/src/abi/pyth/pyth.ts +566 -0
- package/src/abi/pyth/pythErrors.ts +72 -0
- package/src/abi/utils/EIP7702StatelessDelegator.ts +523 -0
- package/src/abi/utils/bundler3errors.ts +6 -0
- package/src/abi/utils/commonAbiErrors.ts +9 -0
- package/src/abi/utils/erc20errors.ts +74 -0
- package/src/abi/utils/merkleDistributor.ts +838 -0
- package/src/abi/utils/multicall3.ts +242 -0
- package/src/abi/utils/openChainErrors.ts +139 -0
- package/src/abi/utils/upgradableBeacon.ts +86 -0
- package/src/actions/bend/getConvertToAssets.ts +23 -0
- package/src/actions/bend/getMaxDeposit.ts +21 -0
- package/src/actions/clients/BeraApolloClient.ts +125 -0
- package/src/actions/clients/getApolloClient.ts +109 -0
- package/src/actions/clients/getEnsoClient.ts +24 -0
- package/src/actions/dex/__tests__/aggregators.unit.test.ts +112 -0
- package/src/actions/dex/__tests__/allPools.integration.test.ts +13 -0
- package/src/actions/dex/__tests__/getOnChainPool.unit.test.ts +15 -0
- package/src/actions/dex/__tests__/haiku.integration.test.ts +40 -0
- package/src/actions/dex/aggregators/base.ts +174 -0
- package/src/actions/dex/aggregators/bex.ts +255 -0
- package/src/actions/dex/aggregators/bgt.ts +50 -0
- package/src/actions/dex/aggregators/enso.ts +113 -0
- package/src/actions/dex/aggregators/fly.ts +136 -0
- package/src/actions/dex/aggregators/haiku.ts +171 -0
- package/src/actions/dex/aggregators/honey.ts +245 -0
- package/src/actions/dex/aggregators/kyberswap.ts +142 -0
- package/src/actions/dex/aggregators/oogabooga.ts +110 -0
- package/src/actions/dex/aggregators/openOcean.ts +142 -0
- package/src/actions/dex/aggregators/wbera.ts +72 -0
- package/src/actions/dex/b-sdk.ts +48 -0
- package/src/actions/dex/getAllPools.ts +60 -0
- package/src/actions/dex/getApiPool.ts +47 -0
- package/src/actions/dex/getGlobalLiquidityAndSwapVolume.ts +29 -0
- package/src/actions/dex/getIsTokenExploited.ts +63 -0
- package/src/actions/dex/getOnChainPool.ts +216 -0
- package/src/actions/dex/getPoolEvents.ts +35 -0
- package/src/actions/dex/getPoolHistoricalData.ts +51 -0
- package/src/actions/dex/getPoolPausedState.ts +40 -0
- package/src/actions/dex/getPoolWithState.ts +24 -0
- package/src/actions/dex/getSubgraphPool.ts +30 -0
- package/src/actions/dex/getTransactionCount.ts +29 -0
- package/src/actions/dex/getVaultPausedState.ts +21 -0
- package/src/actions/enso/bend.ts +143 -0
- package/src/actions/enso/getEnsoUserToken.debug.test.ts +57 -0
- package/src/actions/enso/getEnsoUserToken.ts +133 -0
- package/src/actions/enso/util.ts +60 -0
- package/src/actions/enso/zap.ts +78 -0
- package/src/actions/governance/__tests__/checkProposalField.unit.test.ts +108 -0
- package/src/actions/governance/__tests__/getDecodedFunctionData.integration.test.ts +127 -0
- package/src/actions/governance/__tests__/getQuorum.integration.test.ts +39 -0
- package/src/actions/governance/checkProposalField.ts +211 -0
- package/src/actions/governance/computeActualStatus.ts +154 -0
- package/src/actions/governance/constants.ts +7 -0
- package/src/actions/governance/getAllProposals.ts +75 -0
- package/src/actions/governance/getBodyErrors.ts +28 -0
- package/src/actions/governance/getDecodedFunctionData.ts +170 -0
- package/src/actions/governance/getProposalDetails.ts +40 -0
- package/src/actions/governance/getProposalFromTx.ts +101 -0
- package/src/actions/governance/getProposalParams.ts +247 -0
- package/src/actions/governance/getProposalVotes.ts +20 -0
- package/src/actions/governance/getQuorum.ts +38 -0
- package/src/actions/governance/parseProposalBody.ts +73 -0
- package/src/actions/honey/getChartData.ts +27 -0
- package/src/actions/honey/getCollateralWeights.ts +50 -0
- package/src/actions/honey/getGlobalCapLimit.ts +148 -0
- package/src/actions/honey/getHoneyCollaterals.ts +139 -0
- package/src/actions/honey/getHoneyFees.ts +100 -0
- package/src/actions/honey/getHoneyGlobalData.ts +21 -0
- package/src/actions/honey/getHoneyPausedState.ts +25 -0
- package/src/actions/honey/getHoneyPreview.ts +152 -0
- package/src/actions/honey/getHoneyPythPriceOracle.ts +21 -0
- package/src/actions/honey/getHoneyRootPriceOracle.ts +23 -0
- package/src/actions/honey/getHoneyVaultsBalance.ts +86 -0
- package/src/actions/honey/getPythLatestPrices.ts +54 -0
- package/src/actions/honey/getRelativeCapLimit.ts +83 -0
- package/src/actions/honey/getSharesWithoutFees.ts +65 -0
- package/src/actions/honey/getSwapPayload.ts +128 -0
- package/src/actions/honey/isBadCollateralAsset.ts +77 -0
- package/src/actions/honey/isBasketModeEnabled.ts +47 -0
- package/src/actions/honey/tests/pyth.integration.test.ts +63 -0
- package/src/actions/index.ts +105 -0
- package/src/actions/misc/getBlockTimestamp.ts +41 -0
- package/src/actions/pol/__tests__/getAllValidators.integration.test.ts +55 -0
- package/src/actions/pol/__tests__/getValidator.integration.test.ts +32 -0
- package/src/actions/pol/__tests__/rewardVaults.integration.test.ts +34 -0
- package/src/actions/pol/getBGTGlobalInfo.ts +43 -0
- package/src/actions/pol/getBgtAprSimulation.ts +207 -0
- package/src/actions/pol/getBgtAprSimultaion.unit.test.ts +297 -0
- package/src/actions/pol/getBgtTokenTotalBoosts.ts +30 -0
- package/src/actions/pol/getBgtTokenTotalSupply.ts +29 -0
- package/src/actions/pol/getBlockTime.ts +43 -0
- package/src/actions/pol/getGlobalCuttingBoard.ts +25 -0
- package/src/actions/pol/getGlobalData.ts +74 -0
- package/src/actions/pol/getIncentiveFeeClaimStats.ts +43 -0
- package/src/actions/pol/getMarkets.ts +36 -0
- package/src/actions/pol/getRewardProofsByValidator.ts +49 -0
- package/src/actions/pol/getRewardTokenToBeraRate.ts +30 -0
- package/src/actions/pol/getRewardVault.ts +54 -0
- package/src/actions/pol/getRewardVaultBeaconImplementation.integration.test.ts +18 -0
- package/src/actions/pol/getRewardVaultBeaconImplementation.ts +35 -0
- package/src/actions/pol/getRewardVaultDurationConstants.integration.test.ts +24 -0
- package/src/actions/pol/getRewardVaultDurationConstants.ts +45 -0
- package/src/actions/pol/getRewardVaultFromToken.ts +30 -0
- package/src/actions/pol/getRewardVaultIncentives.ts +122 -0
- package/src/actions/pol/getRewardVaultRewards.ts +109 -0
- package/src/actions/pol/getRewardVaultStakingToken.ts +19 -0
- package/src/actions/pol/getRewardVaults.ts +106 -0
- package/src/actions/pol/getSWBeraVaultMetadata.ts +166 -0
- package/src/actions/pol/getSWBeraWithdrawal.ts +165 -0
- package/src/actions/pol/getStakeWithdrawalCooldown.ts +21 -0
- package/src/actions/pol/getStakedBeraAPR.ts +56 -0
- package/src/actions/pol/getStakedBeraSnapshots.ts +48 -0
- package/src/actions/pol/getStakingTokenInformation.ts +60 -0
- package/src/actions/pol/getUserClaimableIncentives.ts +40 -0
- package/src/actions/pol/getUserVaultInfo.ts +52 -0
- package/src/actions/pol/getUserVaults.ts +185 -0
- package/src/actions/pol/getUserVaultsBalance.ts +54 -0
- package/src/actions/pol/getUserVaultsReward.ts +32 -0
- package/src/actions/pol/getVaultHistory.ts +43 -0
- package/src/actions/pol/getVaultValidators.ts +31 -0
- package/src/actions/pol/getVaultsSupply.ts +28 -0
- package/src/actions/prices/__tests__/prices.integration.test.ts +29 -0
- package/src/actions/prices/getTokenCurrentPrices.ts +79 -0
- package/src/actions/pyth/getHoneyPythFeeds.ts +46 -0
- package/src/actions/pyth/getUpdateFee.ts +27 -0
- package/src/actions/tokens/getAllowances.ts +59 -0
- package/src/actions/tokens/getTokenInformation.ts +57 -0
- package/src/actions/tokens/getTokens.ts +19 -0
- package/src/actions/tokens/getWalletBalances.integration.test.ts +40 -0
- package/src/actions/tokens/getWalletBalances.ts +123 -0
- package/src/actions/transactions/beraWriteContract.integration.test.ts +251 -0
- package/src/actions/transactions/beraWriteContract.ts +722 -0
- package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.integration.test.ts +40 -0
- package/src/actions/validators/getActiveBoostAndCommissionChangeDelay.ts +109 -0
- package/src/actions/validators/getAllValidators.ts +33 -0
- package/src/actions/validators/getApiEnrichedAllocation.ts +33 -0
- package/src/actions/validators/getApiValidator.ts +38 -0
- package/src/actions/validators/getBaselineRewardAllocation.ts +26 -0
- package/src/actions/validators/getDailyValidatorBlockStats.ts +37 -0
- package/src/actions/validators/getDefaultRewardAllocation.ts +39 -0
- package/src/actions/validators/getManagedValidatorByAccount.ts +32 -0
- package/src/actions/validators/getStakingPoolBatch.ts +20 -0
- package/src/actions/validators/getUserActiveValidators.ts +101 -0
- package/src/actions/validators/getUserBoosts.ts +28 -0
- package/src/actions/validators/getUserBoostsOnValidator.ts +70 -0
- package/src/actions/validators/getUserStakingPositions.ts +225 -0
- package/src/actions/validators/getValidatorAnalytics.ts +34 -0
- package/src/actions/validators/getValidatorCommission.ts +24 -0
- package/src/actions/validators/getValidatorEstimatedBgtPerYear.ts +25 -0
- package/src/actions/validators/getValidatorOperatorAddress.ts +27 -0
- package/src/actions/validators/getValidatorQueuedCommission.ts +30 -0
- package/src/actions/validators/getValidatorQueuedOperatorAddress.ts +32 -0
- package/src/actions/validators/getValidatorQueuedRewardAllocation.ts +31 -0
- package/src/actions/validators/getValidatorRewardAllocation.ts +158 -0
- package/src/actions/validators/getValidatorRewardAllocatorAddress.ts +38 -0
- package/src/actions/validators/utils/__tests__/validatorUtils.integration.test.ts +36 -0
- package/src/actions/validators/utils/getValidatorBoostApy.ts +59 -0
- package/src/contexts/BeraFlags/BeraFlags.tsx +69 -0
- package/src/contexts/BeraFlags/defaultFlags.ts +42 -0
- package/src/contexts/BexStatusProvider.tsx +125 -0
- package/src/contexts/HoneyConfigProvider.tsx +73 -0
- package/src/contexts/SwrFallback.tsx +34 -0
- package/src/contexts/TokensProvider.tsx +66 -0
- package/src/contexts/berajsProvider/context.tsx +49 -0
- package/src/contexts/berajsProvider/index.ts +2 -0
- package/src/contexts/berajsProvider/useBeraJs.ts +18 -0
- package/src/contexts/block-time-provider.tsx +34 -0
- package/src/contexts/index.ts +14 -0
- package/src/data/contracts.ts +398 -0
- package/src/enum/dex.ts +10 -0
- package/src/enum/index.ts +4 -0
- package/src/enum/polling.ts +8 -0
- package/src/enum/slippage.ts +19 -0
- package/src/enum/txnEnum.ts +101 -0
- package/src/errors/BeraError.ts +202 -0
- package/src/errors/InvalidArgumentError.ts +81 -0
- package/src/errors/NotFoundError.ts +34 -0
- package/src/errors/RequestError.ts +207 -0
- package/src/errors/TransactionFailedError.ts +93 -0
- package/src/errors/assert.ts +144 -0
- package/src/errors/assert.unit.test.ts +110 -0
- package/src/errors/errorMap.ts +1157 -0
- package/src/errors/getErrorMessage.ts +40 -0
- package/src/errors/getRevertReason.integration.test.ts +449 -0
- package/src/errors/getRevertReason.ts +179 -0
- package/src/errors/index.ts +8 -0
- package/src/errors/initBeraError.ts +46 -0
- package/src/errors/parseViemError.ts +239 -0
- package/src/hooks/bend/useGetConvertToAssets.ts +42 -0
- package/src/hooks/dex/useAggregatorsQuotes.ts +502 -0
- package/src/hooks/dex/useAggregatorsRouterFeeBps.ts +34 -0
- package/src/hooks/dex/useAllUserPools.ts +38 -0
- package/src/hooks/dex/useApiPool.ts +53 -0
- package/src/hooks/dex/useBexStatus.ts +1 -0
- package/src/hooks/dex/useCreatePool.ts +437 -0
- package/src/hooks/dex/useExploitedTokens.ts +57 -0
- package/src/hooks/dex/useGlobalLiquidityAndSwapVolume.ts +22 -0
- package/src/hooks/dex/useLiquidityMismatch.ts +195 -0
- package/src/hooks/dex/useLpPosition.ts +115 -0
- package/src/hooks/dex/useMultipleTokenApprovalsWithSlippage.ts +92 -0
- package/src/hooks/dex/useOnChainPoolData.ts +126 -0
- package/src/hooks/dex/usePollPoolCreationRelayerApproval.ts +54 -0
- package/src/hooks/dex/usePollVaultIsPaused.ts +30 -0
- package/src/hooks/dex/usePool.ts +59 -0
- package/src/hooks/dex/usePoolEvents.ts +22 -0
- package/src/hooks/dex/usePoolHistoricalData.ts +44 -0
- package/src/hooks/dex/usePools.ts +83 -0
- package/src/hooks/enso/useBendTransactionRequests.ts +247 -0
- package/src/hooks/enso/useEnsoZap.ts +166 -0
- package/src/hooks/enso/useZapTransactionRequests.ts +81 -0
- package/src/hooks/governance/useCreateProposal.ts +88 -0
- package/src/hooks/governance/useGetPastVotes.ts +63 -0
- package/src/hooks/governance/useHasVoted.ts +38 -0
- package/src/hooks/governance/useIsCanceller.ts +43 -0
- package/src/hooks/governance/usePollAllProposals.ts +232 -0
- package/src/hooks/governance/usePollProposal.ts +96 -0
- package/src/hooks/governance/usePollProposalThreshold.ts +41 -0
- package/src/hooks/governance/usePollProposalVotes.ts +64 -0
- package/src/hooks/governance/usePollUserDelegates.ts +70 -0
- package/src/hooks/governance/useProposalFromTx.ts +37 -0
- package/src/hooks/governance/useProposalSnapshot.ts +44 -0
- package/src/hooks/governance/useProposalState.ts +48 -0
- package/src/hooks/governance/useProposalTimelockState.ts +61 -0
- package/src/hooks/governance/useQuorum.ts +42 -0
- package/src/hooks/honey/useCappedGlobally.ts +92 -0
- package/src/hooks/honey/useCappedRelatively.ts +88 -0
- package/src/hooks/honey/useCollateralWeights.ts +48 -0
- package/src/hooks/honey/useHoneyAlerts.ts +314 -0
- package/src/hooks/honey/useHoneyBalances.ts +79 -0
- package/src/hooks/honey/useHoneyChartData.ts +17 -0
- package/src/hooks/honey/useHoneyGlobalData.ts +22 -0
- package/src/hooks/honey/useHoneySwapState.ts +202 -0
- package/src/hooks/honey/useHoneyVaultsBalance.ts +41 -0
- package/src/hooks/honey/useIsBadCollateralAsset.ts +73 -0
- package/src/hooks/honey/useIsBasketModeEnabled.ts +70 -0
- package/src/hooks/honey/usePythLatestPrices.ts +41 -0
- package/src/hooks/index.ts +124 -0
- package/src/hooks/perps/usePythUpdateFee.ts +43 -0
- package/src/hooks/pol/useBgtAprSimulation.ts +22 -0
- package/src/hooks/pol/useBgtUnstakedBalance.ts +50 -0
- package/src/hooks/pol/useClaimableFees.ts +38 -0
- package/src/hooks/pol/useEarnedStakedBeraVault.ts +59 -0
- package/src/hooks/pol/useHighestVaultsAPR.ts +57 -0
- package/src/hooks/pol/useOnChainRewardVault.ts +114 -0
- package/src/hooks/pol/usePollGlobalData.ts +31 -0
- package/src/hooks/pol/usePollMarkets.ts +32 -0
- package/src/hooks/pol/useQueuedBeraUnlock.ts +70 -0
- package/src/hooks/pol/useRewardTokenToBeraRate.ts +45 -0
- package/src/hooks/pol/useRewardVault.ts +51 -0
- package/src/hooks/pol/useRewardVaultBalanceFromStakingToken.ts +82 -0
- package/src/hooks/pol/useRewardVaultFromToken.ts +58 -0
- package/src/hooks/pol/useRewardVaultIncentives.ts +37 -0
- package/src/hooks/pol/useRewardVaultRewards.ts +37 -0
- package/src/hooks/pol/useRewardVaults.ts +45 -0
- package/src/hooks/pol/useStakedBeraSnapshots.ts +27 -0
- package/src/hooks/pol/useUserVaultInfo.ts +46 -0
- package/src/hooks/pol/useUserVaults.ts +40 -0
- package/src/hooks/pol/useVaultAddress.ts +31 -0
- package/src/hooks/pol/useVaultHistory.ts +29 -0
- package/src/hooks/pol/useVaultValidators.ts +33 -0
- package/src/hooks/tokens/useBeraCurrentPrice.ts +12 -0
- package/src/hooks/tokens/useMultipleTokenInformation.ts +62 -0
- package/src/hooks/tokens/usePollAllowances.ts +60 -0
- package/src/hooks/tokens/usePollBalance.ts +113 -0
- package/src/hooks/tokens/usePollWalletBalances.ts +75 -0
- package/src/hooks/tokens/useStakingTokenInformation.ts +54 -0
- package/src/hooks/tokens/useTokenCurrentPrice.ts +19 -0
- package/src/hooks/tokens/useTokenCurrentPrices.ts +57 -0
- package/src/hooks/tokens/useTokenInformation.ts +59 -0
- package/src/hooks/tokens/useTokens.ts +26 -0
- package/src/hooks/tokens/useTotalSupply.ts +22 -0
- package/src/hooks/transactions/TransactionStoreContext.tsx +59 -0
- package/src/hooks/transactions/transactionStore.ts +275 -0
- package/src/hooks/transactions/transactionStore.unit.test.ts +508 -0
- package/src/hooks/transactions/useAddRecentTransaction.ts +29 -0
- package/src/hooks/transactions/useRecentTransactions.ts +27 -0
- package/src/hooks/useBlockToTimestamp.ts +51 -0
- package/src/hooks/useContractWrite/index.ts +2 -0
- package/src/hooks/useContractWrite/stateReducer.ts +60 -0
- package/src/hooks/useContractWrite/types.ts +88 -0
- package/src/hooks/useContractWrite/useBeraContractWrite.ts +137 -0
- package/src/hooks/useGetVerifiedAbi.ts +47 -0
- package/src/hooks/useHistoryState.ts +64 -0
- package/src/hooks/usePrevious.ts +13 -0
- package/src/hooks/validators/useAllValidators.ts +48 -0
- package/src/hooks/validators/useApiEnrichedAllocation.ts +17 -0
- package/src/hooks/validators/useApiValidator.ts +37 -0
- package/src/hooks/validators/useBaselineRewardAllocation.ts +16 -0
- package/src/hooks/validators/useDailyValidatorBlockStats.ts +35 -0
- package/src/hooks/validators/useDefaultRewardAllocation.ts +32 -0
- package/src/hooks/validators/useManagedValidatorByAccount.ts +40 -0
- package/src/hooks/validators/useManagedValidatorRole.ts +119 -0
- package/src/hooks/validators/useOnChainValidator.ts +66 -0
- package/src/hooks/validators/useStakingPoolBatch.ts +45 -0
- package/src/hooks/validators/useSubgraphUserValidators.ts +36 -0
- package/src/hooks/validators/useUserActiveValidators.ts +44 -0
- package/src/hooks/validators/useUserBoostsOnValidator.ts +45 -0
- package/src/hooks/validators/useUserClaimableIncentives.ts +149 -0
- package/src/hooks/validators/useUserStakingPositions.ts +62 -0
- package/src/hooks/validators/useValidator.ts +83 -0
- package/src/hooks/validators/useValidatorAnalytics.ts +36 -0
- package/src/hooks/validators/useValidatorCommission.ts +36 -0
- package/src/hooks/validators/useValidatorEstimatedBgtPerYear.ts +24 -0
- package/src/hooks/validators/useValidatorQueuedCommission.ts +41 -0
- package/src/hooks/validators/useValidatorQueuedOperatorAddress.ts +39 -0
- package/src/hooks/validators/useValidatorQueuedRewardAllocation.ts +37 -0
- package/src/hooks/validators/useValidatorRewardAllocation.ts +36 -0
- package/src/hooks/validators/validatorRoleManager.ts +0 -0
- package/src/types/bribe-boost.ts +50 -0
- package/src/types/dex.ts +196 -0
- package/src/types/enso.ts +42 -0
- package/src/types/global.ts +230 -0
- package/src/types/governance.ts +174 -0
- package/src/types/honeySwap.ts +35 -0
- package/src/types/index.ts +8 -0
- package/src/types/pol.ts +52 -0
- package/src/types/staking.ts +7 -0
- package/src/utils/beraFetch.ts +55 -0
- package/src/utils/constants.ts +35 -0
- package/src/utils/formatAggregatorsQuotes.ts +57 -0
- package/src/utils/formatAggregatorsQuotes.unit.test.ts +191 -0
- package/src/utils/formatIncentivesTokenMap.ts +19 -0
- package/src/utils/formatInputTokenValue.ts +12 -0
- package/src/utils/formatNumber.ts +225 -0
- package/src/utils/formatNumber.unit.test.ts +245 -0
- package/src/utils/formatTimestamps.ts +155 -0
- package/src/utils/formatTimestamps.unit.test.ts +395 -0
- package/src/utils/formatTokenList.ts +61 -0
- package/src/utils/formatUsd.ts +46 -0
- package/src/utils/getContractName.ts +27 -0
- package/src/utils/getContractName.unit.test.ts +64 -0
- package/src/utils/getErrorResponse.ts +20 -0
- package/src/utils/getHoneySwapMessage.test.ts +116 -0
- package/src/utils/getHoneySwapMessage.ts +70 -0
- package/src/utils/getServerSideClient.ts +49 -0
- package/src/utils/getTestClient.ts +19 -0
- package/src/utils/hasAnyTruthyValues.ts +17 -0
- package/src/utils/index.ts +27 -0
- package/src/utils/isDifferenceExceedingThreshold.ts +13 -0
- package/src/utils/isSubgraphStale.ts +10 -0
- package/src/utils/math.ts +28 -0
- package/src/utils/math.unit.test.ts +49 -0
- package/src/utils/parseBaseArgs.ts +23 -0
- package/src/utils/parseBaseArgs.unit.test.ts +55 -0
- package/src/utils/poolNamings.ts +54 -0
- package/src/utils/pythHoneyUtils.ts +3 -0
- package/src/utils/sentryBeforeSend.ts +52 -0
- package/src/utils/test-utils.ts +2 -0
- package/src/utils/time.ts +106 -0
- package/src/utils/time.unit.test.ts +76 -0
- package/src/utils/tokenWrapping.ts +16 -0
- package/src/utils/tokens.ts +106 -0
- package/src/utils/tokens.unit.test.ts +98 -0
- package/src/utils/truncateHash.ts +20 -0
- package/src/utils/truncateHash.unit.test.ts +19 -0
- package/src/utils/validatorUptimeStatus.ts +30 -0
- package/dist/chunk-3V2MGZRD.mjs +0 -2
- package/dist/chunk-4E5JGLUM.cjs +0 -1
- package/dist/chunk-AHAZC5K3.mjs +0 -1
- package/dist/chunk-ELUMRVNE.mjs +0 -1
- package/dist/chunk-JHCSZSJS.mjs +0 -1
- package/dist/chunk-KIA6GUIN.cjs +0 -1
- package/dist/chunk-LX5CM4Y6.cjs +0 -1
- package/dist/chunk-LZPBQLKP.mjs +0 -3
- package/dist/chunk-M5BKM52U.cjs +0 -1
- package/dist/chunk-MTBICGRP.mjs +0 -1
- package/dist/chunk-WDFIETJS.cjs +0 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetPoolEvents,
|
|
3
|
+
type GetPoolEventsQuery,
|
|
4
|
+
type GetPoolEventsQueryVariables,
|
|
5
|
+
} from "@berachain/graphql/dex/api";
|
|
6
|
+
import type { GqlChain, GqlPoolEventType } from "@berachain/graphql/pol/api";
|
|
7
|
+
|
|
8
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
9
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
10
|
+
|
|
11
|
+
export async function getPoolEvents({
|
|
12
|
+
poolId,
|
|
13
|
+
typeInArray,
|
|
14
|
+
...args
|
|
15
|
+
}: {
|
|
16
|
+
poolId: string;
|
|
17
|
+
typeInArray: GqlPoolEventType[];
|
|
18
|
+
} & BeraJS.BaseFunctionArgs) {
|
|
19
|
+
const { config } = parseBaseArgs(args);
|
|
20
|
+
|
|
21
|
+
const bexApiGraphqlClient = getApolloClient("api", args);
|
|
22
|
+
const response = await bexApiGraphqlClient.query<
|
|
23
|
+
GetPoolEventsQuery,
|
|
24
|
+
GetPoolEventsQueryVariables
|
|
25
|
+
>({
|
|
26
|
+
query: GetPoolEvents,
|
|
27
|
+
variables: {
|
|
28
|
+
poolId,
|
|
29
|
+
typeIn: typeInArray,
|
|
30
|
+
chain: config.bex.chainName as GqlChain,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isHex } from "viem";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
GetPoolHistoricalData,
|
|
5
|
+
type GetPoolHistoricalDataQuery,
|
|
6
|
+
type GetPoolHistoricalDataQueryVariables,
|
|
7
|
+
type GqlChain,
|
|
8
|
+
type PoolHistoricalDataFragment,
|
|
9
|
+
} from "@berachain/graphql/dex/api";
|
|
10
|
+
|
|
11
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
12
|
+
import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
|
|
13
|
+
|
|
14
|
+
/** @deprecated */
|
|
15
|
+
export type PoolDayData = {
|
|
16
|
+
date: number;
|
|
17
|
+
tvlUsd: string;
|
|
18
|
+
volumeUsd: string;
|
|
19
|
+
feesUsd: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
interface GetPoolHistoricalDataProps {
|
|
23
|
+
poolId: string;
|
|
24
|
+
chain: GqlChain;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function getPoolHistoricalData({
|
|
28
|
+
poolId,
|
|
29
|
+
chain,
|
|
30
|
+
...args
|
|
31
|
+
}: GetPoolHistoricalDataProps & BeraJS.BaseFunctionArgs): Promise<
|
|
32
|
+
PoolHistoricalDataFragment[] | undefined
|
|
33
|
+
> {
|
|
34
|
+
if (!poolId || !isHex(poolId))
|
|
35
|
+
throw new InvalidArgumentError({
|
|
36
|
+
property: "poolId",
|
|
37
|
+
value: poolId,
|
|
38
|
+
expected: "hex string",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const bexApiGraphqlClient = getApolloClient("api", args);
|
|
42
|
+
|
|
43
|
+
const { data } = await bexApiGraphqlClient.query<
|
|
44
|
+
GetPoolHistoricalDataQuery,
|
|
45
|
+
GetPoolHistoricalDataQueryVariables
|
|
46
|
+
>({
|
|
47
|
+
query: GetPoolHistoricalData,
|
|
48
|
+
variables: { poolId, chain },
|
|
49
|
+
});
|
|
50
|
+
return data.poolGetSnapshots;
|
|
51
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { weightedPoolV4Abi_V2 } from "@berachain-foundation/berancer-sdk";
|
|
2
|
+
import type { Address, PublicClient } from "viem";
|
|
3
|
+
|
|
4
|
+
export interface PoolStatus {
|
|
5
|
+
isPoolInRecoveryMode: boolean;
|
|
6
|
+
isPoolPaused: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function getPoolPausedState({
|
|
10
|
+
publicClient,
|
|
11
|
+
poolAddress,
|
|
12
|
+
}: {
|
|
13
|
+
publicClient: PublicClient;
|
|
14
|
+
poolAddress: Address;
|
|
15
|
+
}) {
|
|
16
|
+
const abi = weightedPoolV4Abi_V2;
|
|
17
|
+
// NOTE: we are only intersted in functions that span both ABIs, so I'll use weighted here. For SOME REASON. Balancer did
|
|
18
|
+
// not include inRecoveryMode etc in the stable ABI (despite it EXISTING in both weighted/stable) see for yourself:
|
|
19
|
+
// <scanner>/address/0xF7F214A9543c1153eF5DF2edCd839074615F248c/contract/80000/readContract#F28
|
|
20
|
+
// ... so we will just use the weighted ABI here no matter the pool type, just be mindful not to call any type-specific functions
|
|
21
|
+
const results = await publicClient.multicall({
|
|
22
|
+
contracts: [
|
|
23
|
+
{
|
|
24
|
+
address: poolAddress,
|
|
25
|
+
abi,
|
|
26
|
+
functionName: "inRecoveryMode",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
address: poolAddress,
|
|
30
|
+
abi,
|
|
31
|
+
functionName: "getPausedState",
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
allowFailure: false, // NOTE: this disallows partial failures of the multicall
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
isPoolInRecoveryMode: results[0],
|
|
38
|
+
isPoolPaused: results[1][0],
|
|
39
|
+
} as PoolStatus;
|
|
40
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type MinimalToken,
|
|
3
|
+
mapPoolType,
|
|
4
|
+
type PoolState,
|
|
5
|
+
} from "@berachain-foundation/berancer-sdk";
|
|
6
|
+
import type { Address } from "viem";
|
|
7
|
+
|
|
8
|
+
import type { MinimalPoolFragment } from "@berachain/graphql/dex/api";
|
|
9
|
+
|
|
10
|
+
export const getPoolState = (apiPool: MinimalPoolFragment): PoolState => {
|
|
11
|
+
return {
|
|
12
|
+
type: mapPoolType(apiPool.type),
|
|
13
|
+
protocolVersion: apiPool.protocolVersion as 1 | 2 | 3,
|
|
14
|
+
tokens: apiPool.tokens.map<MinimalToken>(
|
|
15
|
+
(pt) =>
|
|
16
|
+
({
|
|
17
|
+
...pt,
|
|
18
|
+
address: pt.address as Address,
|
|
19
|
+
}) satisfies MinimalToken,
|
|
20
|
+
),
|
|
21
|
+
id: apiPool.id as Address,
|
|
22
|
+
address: apiPool.address as Address,
|
|
23
|
+
} satisfies PoolState;
|
|
24
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isHex } from "viem";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
GetSubgraphPool,
|
|
5
|
+
type GetSubgraphPoolQuery,
|
|
6
|
+
type GetSubgraphPoolQueryVariables,
|
|
7
|
+
} from "@berachain/graphql/dex/subgraph";
|
|
8
|
+
|
|
9
|
+
import { getApolloClient } from "~/actions/clients/getApolloClient";
|
|
10
|
+
|
|
11
|
+
export async function getSubgraphPool({
|
|
12
|
+
poolId,
|
|
13
|
+
...args
|
|
14
|
+
}: BeraJS.BaseFunctionArgs & {
|
|
15
|
+
poolId: string;
|
|
16
|
+
}) {
|
|
17
|
+
if (!isHex(poolId)) {
|
|
18
|
+
throw new Error("poolId is not a valid hex string");
|
|
19
|
+
}
|
|
20
|
+
const bexSubgraphClient = getApolloClient("bex.subgraph", args);
|
|
21
|
+
const res = await bexSubgraphClient.query<
|
|
22
|
+
GetSubgraphPoolQuery,
|
|
23
|
+
GetSubgraphPoolQueryVariables
|
|
24
|
+
>({
|
|
25
|
+
query: GetSubgraphPool,
|
|
26
|
+
variables: { id: poolId },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return res.data.pool;
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Address, isAddress, type PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { assertPublicClient, InvalidArgumentError } from "~/errors";
|
|
4
|
+
|
|
5
|
+
export interface GetTransactionCount {
|
|
6
|
+
address: Address | undefined;
|
|
7
|
+
publicClient: PublicClient;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type GetTransactionCountResponse = number | undefined;
|
|
11
|
+
|
|
12
|
+
export async function getTransactionCount({
|
|
13
|
+
address,
|
|
14
|
+
publicClient,
|
|
15
|
+
}: GetTransactionCount): Promise<GetTransactionCountResponse> {
|
|
16
|
+
assertPublicClient(publicClient);
|
|
17
|
+
|
|
18
|
+
if (!address || !isAddress(address))
|
|
19
|
+
throw new InvalidArgumentError({
|
|
20
|
+
property: "address",
|
|
21
|
+
value: address,
|
|
22
|
+
expected: "Address",
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const transactionCount = await publicClient.getTransactionCount({
|
|
26
|
+
address,
|
|
27
|
+
});
|
|
28
|
+
return transactionCount;
|
|
29
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PublicClient } from "viem";
|
|
2
|
+
|
|
3
|
+
import { balancerVaultAbi } from "~/abi/bex/balancerVault";
|
|
4
|
+
import { parseBaseArgs } from "~/utils/parseBaseArgs";
|
|
5
|
+
|
|
6
|
+
export async function getVaultPausedState({
|
|
7
|
+
publicClient,
|
|
8
|
+
...args
|
|
9
|
+
}: BeraJS.BaseFunctionArgs & {
|
|
10
|
+
publicClient: PublicClient;
|
|
11
|
+
}) {
|
|
12
|
+
const { config } = parseBaseArgs(args);
|
|
13
|
+
|
|
14
|
+
const vaultPausedState = await publicClient.readContract({
|
|
15
|
+
address: config.bex.vault,
|
|
16
|
+
abi: balancerVaultAbi,
|
|
17
|
+
functionName: "getPausedState",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
return vaultPausedState[0];
|
|
21
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { BundleAction, EnsoClient } from "@ensofinance/sdk";
|
|
2
|
+
import { type Address, ethAddress, type PublicClient, zeroAddress } from "viem";
|
|
3
|
+
|
|
4
|
+
import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
|
|
5
|
+
import type { GetZapTransactionResponse, Quantity } from "~/types";
|
|
6
|
+
import { getTransactionsFromBundle } from "./util";
|
|
7
|
+
|
|
8
|
+
export interface GetBendTransactionRequestsArgs {
|
|
9
|
+
fromAddress: Address;
|
|
10
|
+
amountIn: Quantity;
|
|
11
|
+
tokenIn: Address;
|
|
12
|
+
loanToken: Address;
|
|
13
|
+
bendVault: Address;
|
|
14
|
+
rewardVault?: Address;
|
|
15
|
+
chainId: number;
|
|
16
|
+
ensoClient: EnsoClient;
|
|
17
|
+
destinationChainId?: number;
|
|
18
|
+
slippage: number;
|
|
19
|
+
publicClient: PublicClient;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function getBendTransactionRequests({
|
|
23
|
+
fromAddress,
|
|
24
|
+
amountIn,
|
|
25
|
+
tokenIn,
|
|
26
|
+
loanToken,
|
|
27
|
+
bendVault,
|
|
28
|
+
rewardVault,
|
|
29
|
+
chainId,
|
|
30
|
+
ensoClient,
|
|
31
|
+
destinationChainId,
|
|
32
|
+
slippage,
|
|
33
|
+
publicClient,
|
|
34
|
+
}: GetBendTransactionRequestsArgs): Promise<GetZapTransactionResponse> {
|
|
35
|
+
if (!fromAddress) {
|
|
36
|
+
throw new InvalidArgumentError({
|
|
37
|
+
property: "fromAddress",
|
|
38
|
+
value: fromAddress,
|
|
39
|
+
expected: "string",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (loanToken === zeroAddress) loanToken = ethAddress;
|
|
43
|
+
|
|
44
|
+
const bundleActions: BundleAction[] = [
|
|
45
|
+
{
|
|
46
|
+
protocol: "enso",
|
|
47
|
+
action: "route",
|
|
48
|
+
args: {
|
|
49
|
+
tokenIn,
|
|
50
|
+
tokenOut: loanToken,
|
|
51
|
+
amountIn,
|
|
52
|
+
slippage: slippage * 100, // Enso expects slippage in basis points
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* If the zap is cross chain, we need to add the destination chain id and the refund receiver.
|
|
58
|
+
*
|
|
59
|
+
* Enso still need to update the sdk types to support this.
|
|
60
|
+
*/
|
|
61
|
+
if (destinationChainId && destinationChainId !== chainId) {
|
|
62
|
+
bundleActions[0].args = {
|
|
63
|
+
...bundleActions[0].args,
|
|
64
|
+
//@ts-expect-error enso are releasing a fix in the next 2 weeks for this.
|
|
65
|
+
destinationChainId: destinationChainId,
|
|
66
|
+
refundReceiver: fromAddress,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// vault output is the vault address
|
|
70
|
+
// vaults are in morpho-blue-vaults-v1
|
|
71
|
+
// markets are here morpho-markets-v1"
|
|
72
|
+
bundleActions.push({
|
|
73
|
+
protocol: "erc4626",
|
|
74
|
+
action: "deposit",
|
|
75
|
+
args: {
|
|
76
|
+
amountIn: { useOutputOfCallAt: 0 },
|
|
77
|
+
tokenIn: loanToken,
|
|
78
|
+
primaryAddress: bendVault,
|
|
79
|
+
tokenOut: bendVault,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
if (rewardVault) {
|
|
83
|
+
bundleActions.push(
|
|
84
|
+
{
|
|
85
|
+
protocol: "enso",
|
|
86
|
+
action: "balance",
|
|
87
|
+
args: {
|
|
88
|
+
token: bendVault,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
protocol: "erc20",
|
|
93
|
+
action: "approve",
|
|
94
|
+
args: {
|
|
95
|
+
amount: { useOutputOfCallAt: 2 },
|
|
96
|
+
spender: rewardVault,
|
|
97
|
+
token: bendVault,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
protocol: "enso",
|
|
102
|
+
action: "call",
|
|
103
|
+
args: {
|
|
104
|
+
address: rewardVault,
|
|
105
|
+
args: [fromAddress, { useOutputOfCallAt: 2 }],
|
|
106
|
+
method: "stakeOnBehalf",
|
|
107
|
+
abi: "function stakeOnBehalf(address account, uint256 amount) external",
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
protocol: "enso",
|
|
112
|
+
action: "balance",
|
|
113
|
+
args: {
|
|
114
|
+
token: rewardVault,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const bundle = await ensoClient.getBundleData(
|
|
121
|
+
{
|
|
122
|
+
fromAddress: fromAddress,
|
|
123
|
+
receiver: fromAddress,
|
|
124
|
+
spender: fromAddress,
|
|
125
|
+
chainId: chainId,
|
|
126
|
+
routingStrategy: "router",
|
|
127
|
+
},
|
|
128
|
+
bundleActions,
|
|
129
|
+
);
|
|
130
|
+
const transactions = await getTransactionsFromBundle({
|
|
131
|
+
fromAddress,
|
|
132
|
+
amountIn,
|
|
133
|
+
tokenIn,
|
|
134
|
+
chainId,
|
|
135
|
+
ensoClient,
|
|
136
|
+
bundle,
|
|
137
|
+
publicClient,
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
bundle,
|
|
141
|
+
transactions,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as Sentry from "@sentry/nextjs";
|
|
2
|
+
import {
|
|
3
|
+
afterEach,
|
|
4
|
+
beforeEach,
|
|
5
|
+
describe,
|
|
6
|
+
expect,
|
|
7
|
+
it,
|
|
8
|
+
type MockInstance,
|
|
9
|
+
vi,
|
|
10
|
+
} from "vitest";
|
|
11
|
+
|
|
12
|
+
import { wagmiConfig } from "@berachain/wagmi/config";
|
|
13
|
+
|
|
14
|
+
import { getEnsoClient } from "../clients/getEnsoClient";
|
|
15
|
+
import { getEnsoUserToken } from "./getEnsoUserToken";
|
|
16
|
+
|
|
17
|
+
describe("getEnsoUserToken", () => {
|
|
18
|
+
let fetchSpy: MockInstance<typeof global.fetch>;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
vi.clearAllMocks();
|
|
22
|
+
|
|
23
|
+
vi.mock(import("@sentry/nextjs"), () => ({
|
|
24
|
+
captureException: vi.fn(),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
fetchSpy = vi.spyOn(global, "fetch");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
vi.clearAllMocks();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const address = "0x79f453D56C4bC66586215827FbBc7B34Bc006b33";
|
|
35
|
+
it("should be using multicall for each chain", async () => {
|
|
36
|
+
const ensoClient = getEnsoClient();
|
|
37
|
+
|
|
38
|
+
const ensoUserToken = await getEnsoUserToken({
|
|
39
|
+
account: address,
|
|
40
|
+
wagmiConfig: wagmiConfig,
|
|
41
|
+
chainId: "all",
|
|
42
|
+
ensoClient: ensoClient,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(ensoUserToken.length).toBeGreaterThan(0);
|
|
46
|
+
|
|
47
|
+
expect(fetchSpy).toHaveBeenCalled();
|
|
48
|
+
expect(Sentry.captureException).not.toHaveBeenCalled();
|
|
49
|
+
|
|
50
|
+
const chains = Object.groupBy(ensoUserToken, (token) => token.chainId ?? 0);
|
|
51
|
+
const chainIds = Object.keys(chains)
|
|
52
|
+
.map(Number)
|
|
53
|
+
.filter((chainId) => chainId !== 0);
|
|
54
|
+
|
|
55
|
+
expect(fetchSpy).toHaveBeenCalledTimes(1 + chainIds.length);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { EnsoClient } from "@ensofinance/sdk";
|
|
2
|
+
import * as Sentry from "@sentry/nextjs";
|
|
3
|
+
import { type Config, getChains, multicall } from "@wagmi/core";
|
|
4
|
+
import { type Address, formatUnits } from "viem";
|
|
5
|
+
|
|
6
|
+
import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
|
|
7
|
+
import { initBeraError } from "~/errors/initBeraError";
|
|
8
|
+
import type { BalanceTokenWithMetadata } from "~/types/dex";
|
|
9
|
+
import { getBalanceCall } from "../tokens/getWalletBalances";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get user balances for each supported chain.
|
|
13
|
+
*
|
|
14
|
+
* This uses enso's balance endpoint to get the balances and RPC to get fresh balances.
|
|
15
|
+
*/
|
|
16
|
+
export async function getEnsoUserToken({
|
|
17
|
+
account,
|
|
18
|
+
wagmiConfig,
|
|
19
|
+
chainId,
|
|
20
|
+
ensoClient,
|
|
21
|
+
}: {
|
|
22
|
+
account: Address;
|
|
23
|
+
wagmiConfig: Config;
|
|
24
|
+
chainId: number | "all";
|
|
25
|
+
ensoClient: EnsoClient;
|
|
26
|
+
}): Promise<BalanceTokenWithMetadata[]> {
|
|
27
|
+
const ensoBalances = await ensoClient.getBalances({
|
|
28
|
+
useEoa: true,
|
|
29
|
+
chainId: chainId ?? "all",
|
|
30
|
+
eoaAddress: account,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const tokens: BalanceTokenWithMetadata[] = ensoBalances.map((balance) => ({
|
|
34
|
+
name: balance.name,
|
|
35
|
+
symbol: balance.symbol,
|
|
36
|
+
decimals: balance.decimals,
|
|
37
|
+
address: balance.token,
|
|
38
|
+
logoURI: balance.logoUri,
|
|
39
|
+
balance: BigInt(balance.amount),
|
|
40
|
+
formattedBalance: formatUnits(BigInt(balance.amount), balance.decimals),
|
|
41
|
+
chainId: Number(
|
|
42
|
+
// @ts-expect-error - balance.chainId is defined just not typed by enso
|
|
43
|
+
balance.chainId,
|
|
44
|
+
),
|
|
45
|
+
price: Number(balance.price),
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
const tokenByChainId = Object.groupBy(tokens, (a) => a.chainId ?? 0);
|
|
49
|
+
|
|
50
|
+
const balances = await Promise.allSettled(
|
|
51
|
+
Object.entries(tokenByChainId).map(async ([chainId, chainTokens]) => {
|
|
52
|
+
if (!chainTokens) return undefined;
|
|
53
|
+
const chainConfig = getChains(wagmiConfig).find(
|
|
54
|
+
(chain) => chain.id === Number(chainId),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
if (!chainConfig) {
|
|
58
|
+
// if we've queried a chain that is not supported, we need to return undefined
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const multicall3 = chainConfig.contracts?.multicall3;
|
|
63
|
+
|
|
64
|
+
const multicallAddress = multicall3?.address;
|
|
65
|
+
|
|
66
|
+
if (!multicallAddress) {
|
|
67
|
+
// if multicall is not supported on this chain, we need to use the enso balance
|
|
68
|
+
// first let's report the error, as this is likely unexpected
|
|
69
|
+
Sentry.captureException(
|
|
70
|
+
new InvalidArgumentError({
|
|
71
|
+
property: "multicallAddress",
|
|
72
|
+
value: multicallAddress,
|
|
73
|
+
expected: "Address",
|
|
74
|
+
chainId: Number(chainId),
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// we can return the tokens as is, as the balance is already set from the enso client
|
|
79
|
+
return chainTokens;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const balances = await multicall(wagmiConfig, {
|
|
83
|
+
chainId: Number(chainId),
|
|
84
|
+
contracts: chainTokens.map((token) =>
|
|
85
|
+
getBalanceCall({
|
|
86
|
+
token,
|
|
87
|
+
account,
|
|
88
|
+
multicallAddress,
|
|
89
|
+
}),
|
|
90
|
+
),
|
|
91
|
+
allowFailure: true,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const tokensWithBalances: BalanceTokenWithMetadata[] = [];
|
|
95
|
+
|
|
96
|
+
for (let index = 0; index < chainTokens.length; index++) {
|
|
97
|
+
const token = chainTokens[index];
|
|
98
|
+
if (balances[index].status === "success") {
|
|
99
|
+
tokensWithBalances.push({
|
|
100
|
+
...token,
|
|
101
|
+
balance: balances[index].result as bigint,
|
|
102
|
+
formattedBalance: formatUnits(
|
|
103
|
+
balances[index].result as bigint,
|
|
104
|
+
token.decimals,
|
|
105
|
+
),
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
console.error("error getting balance", balances[index].error);
|
|
109
|
+
captureException(initBeraError({ cause: balances[index].error }));
|
|
110
|
+
// uses enso balance as fallback
|
|
111
|
+
tokensWithBalances.push(token);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return tokensWithBalances;
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const flattenedBalances: BalanceTokenWithMetadata[] = [];
|
|
120
|
+
for (const result of balances) {
|
|
121
|
+
if (result.status === "fulfilled") {
|
|
122
|
+
flattenedBalances.push(...(result.value ?? []));
|
|
123
|
+
} else {
|
|
124
|
+
captureException(initBeraError({ cause: result.reason }));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return flattenedBalances.sort((a, b) => {
|
|
129
|
+
const aValue = Number(a.formattedBalance) * (a.price ?? 0);
|
|
130
|
+
const bValue = Number(b.formattedBalance) * (b.price ?? 0);
|
|
131
|
+
return bValue - aValue;
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Address, erc20Abi, ethAddress } from "viem";
|
|
2
|
+
|
|
3
|
+
import type { GetZapTransactions, GetZapTransactionsArgs } from "~/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get the zap transactions for a given bundle.
|
|
7
|
+
* @param args - The arguments for the zap transactions.
|
|
8
|
+
* @returns The the zap transaction & approval transaction if required.
|
|
9
|
+
*/
|
|
10
|
+
export const getTransactionsFromBundle = async ({
|
|
11
|
+
fromAddress,
|
|
12
|
+
amountIn,
|
|
13
|
+
tokenIn,
|
|
14
|
+
chainId,
|
|
15
|
+
ensoClient,
|
|
16
|
+
bundle,
|
|
17
|
+
publicClient,
|
|
18
|
+
}: GetZapTransactionsArgs): Promise<GetZapTransactions> => {
|
|
19
|
+
const transactions: GetZapTransactions = [];
|
|
20
|
+
/**
|
|
21
|
+
* If the token is not the native token, we need to check if approval is required.
|
|
22
|
+
*/
|
|
23
|
+
if (tokenIn !== ethAddress) {
|
|
24
|
+
const approvalRequest = await ensoClient.getApprovalData({
|
|
25
|
+
fromAddress,
|
|
26
|
+
tokenAddress: tokenIn,
|
|
27
|
+
chainId,
|
|
28
|
+
amount: amountIn,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// check if approval is actually required by checking current allowance
|
|
32
|
+
let requiresApproval = true;
|
|
33
|
+
if (publicClient) {
|
|
34
|
+
const currentAllowance = await publicClient.readContract({
|
|
35
|
+
address: tokenIn as Address,
|
|
36
|
+
abi: erc20Abi,
|
|
37
|
+
functionName: "allowance",
|
|
38
|
+
args: [fromAddress, approvalRequest.spender],
|
|
39
|
+
});
|
|
40
|
+
requiresApproval = currentAllowance < BigInt(amountIn);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Only add approval transaction if it's actually required
|
|
44
|
+
if (requiresApproval) {
|
|
45
|
+
transactions.push({
|
|
46
|
+
to: approvalRequest.tx.to,
|
|
47
|
+
data: approvalRequest.tx.data as `0x${string}`,
|
|
48
|
+
value: approvalRequest.tx.value as unknown as bigint,
|
|
49
|
+
gasLimit: BigInt(approvalRequest.gas),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
transactions.push({
|
|
54
|
+
to: bundle.tx.to,
|
|
55
|
+
data: bundle.tx.data as `0x${string}`,
|
|
56
|
+
value: bundle.tx.value as unknown as bigint,
|
|
57
|
+
gasLimit: BigInt(bundle.gas),
|
|
58
|
+
});
|
|
59
|
+
return transactions;
|
|
60
|
+
};
|