@berachain/berajs 0.1.1 → 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-BaNHEuck.d.cts → HoneyConfigProvider-6PXZJMSU.d.cts} +171 -171
- package/dist/{dex-D6IK-4D9.d.ts → HoneyConfigProvider-CwDFrt02.d.ts} +171 -171
- package/dist/abi/index.cjs +1 -1
- package/dist/abi/index.cjs.map +1 -1
- package/dist/abi/index.mjs +1 -1
- package/dist/actions/index.cjs +1 -1
- package/dist/actions/index.d.cts +7 -7
- package/dist/actions/index.d.ts +7 -7
- package/dist/actions/index.mjs +1 -1
- 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-GZ5YA2AZ.cjs → chunk-6VF3RF53.cjs} +3 -3
- package/dist/{chunk-GZ5YA2AZ.cjs.map → chunk-6VF3RF53.cjs.map} +1 -1
- package/dist/{chunk-3WCYP277.mjs → chunk-AMRJ4B36.mjs} +2 -2
- package/dist/chunk-EU4WFADK.cjs +2 -0
- package/dist/chunk-EU4WFADK.cjs.map +1 -0
- package/dist/{chunk-ZLCBHOSV.mjs → chunk-KMKUXP2S.mjs} +3 -3
- package/dist/chunk-OJXJ6CZ4.mjs +4 -0
- package/dist/{chunk-M5GUTM7K.mjs.map → chunk-OJXJ6CZ4.mjs.map} +1 -1
- package/dist/{chunk-V3PCHP2D.cjs → chunk-REDXXUK7.cjs} +2 -2
- package/dist/{chunk-V3PCHP2D.cjs.map → chunk-REDXXUK7.cjs.map} +1 -1
- package/dist/chunk-VYWYJR63.mjs +2 -0
- package/dist/chunk-VYWYJR63.mjs.map +1 -0
- package/dist/{chunk-GWBENQEV.cjs → chunk-XFPTQMAK.cjs} +3 -3
- package/dist/{chunk-GWBENQEV.cjs.map → chunk-XFPTQMAK.cjs.map} +1 -1
- package/dist/contexts/index.cjs +1 -1
- package/dist/contexts/index.d.cts +3 -3
- package/dist/contexts/index.d.ts +3 -3
- package/dist/contexts/index.mjs +1 -1
- package/dist/{getValidatorQueuedOperatorAddress-BhPVMCTj.d.ts → getValidatorQueuedOperatorAddress-9xY2RUGe.d.cts} +2 -2
- package/dist/{getValidatorQueuedOperatorAddress-Cmd7rgYK.d.cts → getValidatorQueuedOperatorAddress-Ne2zoiiV.d.ts} +2 -2
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +6 -6
- package/dist/hooks/index.d.ts +6 -6
- package/dist/hooks/index.mjs +2 -2
- package/dist/{staking-Bcb8DhoZ.d.cts → staking-F9Nx9TKD.d.ts} +1 -1
- package/dist/{staking-DvJOnMJG.d.ts → staking-f4BpYH7l.d.cts} +1 -1
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/{useHoneySwapState-DfmXCavx.d.cts → useHoneySwapState-C-9BV4VB.d.cts} +1 -1
- package/dist/{useHoneySwapState-AKDZI2MT.d.ts → useHoneySwapState-CUY5Sm1b.d.ts} +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.d.cts +4 -4
- package/dist/utils/index.d.ts +4 -4
- package/dist/utils/index.mjs +1 -1
- package/package.json +3 -2
- 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-5OAABMMU.mjs +0 -2
- package/dist/chunk-5OAABMMU.mjs.map +0 -1
- package/dist/chunk-EODAKI5K.cjs +0 -2
- package/dist/chunk-EODAKI5K.cjs.map +0 -1
- package/dist/chunk-IZDT74H4.mjs +0 -2
- package/dist/chunk-IZDT74H4.mjs.map +0 -1
- package/dist/chunk-M5GUTM7K.mjs +0 -4
- package/dist/chunk-YRJAQDEO.cjs +0 -2
- package/dist/chunk-YRJAQDEO.cjs.map +0 -1
- /package/dist/{chunk-3WCYP277.mjs.map → chunk-AMRJ4B36.mjs.map} +0 -0
- /package/dist/{chunk-ZLCBHOSV.mjs.map → chunk-KMKUXP2S.mjs.map} +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { formatUnits, parseUnits, zeroAddress } from "viem";
|
|
2
|
+
|
|
3
|
+
import { ChainId } from "@berachain/config/internal";
|
|
4
|
+
|
|
5
|
+
import { aggregatorsRouterAbi } from "~/abi";
|
|
6
|
+
import { BeraError } from "~/errors/BeraError";
|
|
7
|
+
import {
|
|
8
|
+
Aggregators,
|
|
9
|
+
type IAggregatorArgs,
|
|
10
|
+
type IRawAggregatorQuote,
|
|
11
|
+
} from "~/types";
|
|
12
|
+
import { SwapReferrer } from "~/types/dex";
|
|
13
|
+
import { BaseAggregator } from "./base";
|
|
14
|
+
|
|
15
|
+
class HaikuAggregator extends BaseAggregator {
|
|
16
|
+
name = Aggregators.Haiku;
|
|
17
|
+
supportedChains = [ChainId.MAINNET];
|
|
18
|
+
readonly type = "rest";
|
|
19
|
+
|
|
20
|
+
notFoundMessages: string[] = [
|
|
21
|
+
"token not found",
|
|
22
|
+
"Token is not supported",
|
|
23
|
+
"No route found for the given input or the liquidity is not enough",
|
|
24
|
+
"Invalid input amount. Please ensure the total amount of input is greater than 0.001 USD",
|
|
25
|
+
];
|
|
26
|
+
async getQuote({
|
|
27
|
+
tokenIn,
|
|
28
|
+
tokenOut,
|
|
29
|
+
amount,
|
|
30
|
+
slippage,
|
|
31
|
+
account = zeroAddress,
|
|
32
|
+
tokenInDecimals,
|
|
33
|
+
tokenOutDecimals,
|
|
34
|
+
aggregatorsFeeBps,
|
|
35
|
+
proxyAggregatorsThroughVercel = false,
|
|
36
|
+
referrer,
|
|
37
|
+
rewardVault,
|
|
38
|
+
}: IAggregatorArgs): Promise<IRawAggregatorQuote> {
|
|
39
|
+
if (tokenInDecimals === undefined || tokenOutDecimals === undefined) {
|
|
40
|
+
throw new BeraError({
|
|
41
|
+
message: "Missing required params",
|
|
42
|
+
level: "error",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.checkChainSupport();
|
|
47
|
+
const {
|
|
48
|
+
tokenInAddress,
|
|
49
|
+
tokenOutAddress,
|
|
50
|
+
isTokenInNative,
|
|
51
|
+
isTokenOutNative,
|
|
52
|
+
} = this.parseAddresses(tokenIn, tokenOut);
|
|
53
|
+
|
|
54
|
+
const inputAmountAfterFees = this.getAmountAfterFees(
|
|
55
|
+
amount,
|
|
56
|
+
aggregatorsFeeBps,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
// get route quote from haiku api
|
|
60
|
+
const quoteBody = {
|
|
61
|
+
intent: {
|
|
62
|
+
allowancesMode: "approve",
|
|
63
|
+
slippage: slippage / 100,
|
|
64
|
+
receiver: this.config.bex.aggregatorsRouterExecutor,
|
|
65
|
+
input_positions: {
|
|
66
|
+
[`bera:${tokenInAddress}`]: formatUnits(
|
|
67
|
+
BigInt(inputAmountAfterFees),
|
|
68
|
+
tokenInDecimals,
|
|
69
|
+
),
|
|
70
|
+
},
|
|
71
|
+
target_weights: {
|
|
72
|
+
[`bera:${tokenOutAddress}`]: 1, // 100% into the output token
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// haiku request to use separate API KEYs for zap and swap
|
|
78
|
+
// hence the separate proxy paths (api keys are used at the proxy level)
|
|
79
|
+
const proxyPath = referrer === SwapReferrer.ZAP ? "zap-haiku" : "haiku";
|
|
80
|
+
|
|
81
|
+
this.url = proxyAggregatorsThroughVercel
|
|
82
|
+
? `/api/aggregators?aggregator=haikuQuote`
|
|
83
|
+
: `${this.config.bex.aggregatorsProxyUrl}/${proxyPath}/v1/quoteIntent`;
|
|
84
|
+
|
|
85
|
+
const quoteResponse = await this.fetch(
|
|
86
|
+
// using vercel proxy in development to avoid CORS issues
|
|
87
|
+
this.url,
|
|
88
|
+
{
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: {
|
|
91
|
+
"Content-Type": "application/json",
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify(quoteBody),
|
|
94
|
+
},
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
const quoteData = await quoteResponse.json();
|
|
98
|
+
|
|
99
|
+
const formattedQuote = {
|
|
100
|
+
amountOut: parseUnits(
|
|
101
|
+
quoteData.balances[0].amount,
|
|
102
|
+
tokenOutDecimals,
|
|
103
|
+
).toString(),
|
|
104
|
+
amountIn: amount,
|
|
105
|
+
spender: this.config.bex.aggregatorsRouter,
|
|
106
|
+
name: this.name,
|
|
107
|
+
swapFeeBps: aggregatorsFeeBps!,
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// If no account, return quote early
|
|
111
|
+
if (account === zeroAddress) return formattedQuote;
|
|
112
|
+
|
|
113
|
+
this.url = proxyAggregatorsThroughVercel
|
|
114
|
+
? `/api/aggregators?aggregator=haikuSolve`
|
|
115
|
+
: `${this.config.bex.aggregatorsProxyUrl}/${proxyPath}/v1/solveIntent`;
|
|
116
|
+
|
|
117
|
+
const solveResponse = await this.fetch(this.url, {
|
|
118
|
+
method: "POST",
|
|
119
|
+
headers: {
|
|
120
|
+
"Content-Type": "application/json",
|
|
121
|
+
},
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
quoteId: quoteData.quoteId,
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const solveData = await solveResponse.json();
|
|
128
|
+
|
|
129
|
+
const inputData = this.getInputData({
|
|
130
|
+
tokenIn: tokenInAddress,
|
|
131
|
+
amountIn: amount,
|
|
132
|
+
isNative: isTokenInNative,
|
|
133
|
+
isPermit2Approval: true, // haiku requires permit2 approval
|
|
134
|
+
permit2SpenderAddress: this.config.bex.haikuAgentAddress,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const outputData = {
|
|
138
|
+
tokenOut: tokenOutAddress,
|
|
139
|
+
receiver: account,
|
|
140
|
+
minAmountOut: this.getMinAmountOut(formattedQuote.amountOut, slippage),
|
|
141
|
+
isNative: isTokenOutNative,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const aggregatorData = {
|
|
145
|
+
aggregator: solveData.to,
|
|
146
|
+
data: solveData.data,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
...formattedQuote,
|
|
151
|
+
calldata: {
|
|
152
|
+
params: [
|
|
153
|
+
inputData,
|
|
154
|
+
outputData,
|
|
155
|
+
aggregatorData,
|
|
156
|
+
{
|
|
157
|
+
rewardVault: rewardVault ?? zeroAddress,
|
|
158
|
+
isSwapAndStake: !!rewardVault,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
functionName: "swap",
|
|
162
|
+
abi: aggregatorsRouterAbi,
|
|
163
|
+
// send full amount to router first, which will deduct the swap fee before executing trade
|
|
164
|
+
value: isTokenInNative ? BigInt(amount) : BigInt("0"),
|
|
165
|
+
address: this.config.bex.aggregatorsRouter,
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export const haiku = new HaikuAggregator();
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { type Address, formatUnits } from "viem";
|
|
3
|
+
|
|
4
|
+
import { ChainId } from "@berachain/config/internal";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
getHoneyPreview,
|
|
8
|
+
type HoneyPreviewArgs,
|
|
9
|
+
HoneyPreviewMethod,
|
|
10
|
+
} from "~/actions/honey/getHoneyPreview";
|
|
11
|
+
import { getHoneyVaultsBalance } from "~/actions/honey/getHoneyVaultsBalance";
|
|
12
|
+
import { getSwapPayload } from "~/actions/honey/getSwapPayload";
|
|
13
|
+
import { isBasketModeEnabled } from "~/actions/honey/isBasketModeEnabled";
|
|
14
|
+
import type { HoneyConfigContextReturn } from "~/contexts/HoneyConfigProvider";
|
|
15
|
+
import { assertPublicClient } from "~/errors/assert";
|
|
16
|
+
import { BeraError } from "~/errors/BeraError";
|
|
17
|
+
import { InvalidArgumentError } from "~/errors/InvalidArgumentError";
|
|
18
|
+
import {
|
|
19
|
+
Aggregators,
|
|
20
|
+
type IAggregatorArgs,
|
|
21
|
+
type IRawAggregatorQuote,
|
|
22
|
+
type TokenWithMetadata,
|
|
23
|
+
} from "~/types/dex";
|
|
24
|
+
import { getHoneyToken, isToken } from "~/utils/tokens";
|
|
25
|
+
import { BaseAggregator } from "./base";
|
|
26
|
+
|
|
27
|
+
interface IHoneyNativeArgs
|
|
28
|
+
extends Omit<
|
|
29
|
+
IAggregatorArgs,
|
|
30
|
+
"slippage" | "feeBps" | "aggregatorsFeeBps" | "referrer"
|
|
31
|
+
> {}
|
|
32
|
+
|
|
33
|
+
function _getPreviewMethod(isMint: boolean): HoneyPreviewMethod {
|
|
34
|
+
return isMint ? HoneyPreviewMethod.Mint : HoneyPreviewMethod.Redeem;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class HoneyNativeAggregator extends BaseAggregator {
|
|
38
|
+
name = Aggregators.Honey;
|
|
39
|
+
supportedChains = [ChainId.MAINNET];
|
|
40
|
+
readonly type = "rpc";
|
|
41
|
+
|
|
42
|
+
readonly honeyToken: TokenWithMetadata = getHoneyToken(this);
|
|
43
|
+
/**
|
|
44
|
+
* Determines if the swap is a honey mint or redeem based on the tokenIn, tokenOut and the colalterals passed.
|
|
45
|
+
* @returns True if the swap is a honey mint or redeem
|
|
46
|
+
*/
|
|
47
|
+
static isHoneyNativeSwap({
|
|
48
|
+
tokenIn,
|
|
49
|
+
tokenOut,
|
|
50
|
+
honeyNativeState,
|
|
51
|
+
...args
|
|
52
|
+
}: BeraJS.BaseFunctionArgs & {
|
|
53
|
+
tokenIn: Address;
|
|
54
|
+
tokenOut: Address;
|
|
55
|
+
honeyNativeState?: Pick<HoneyConfigContextReturn, "collateralList">;
|
|
56
|
+
}) {
|
|
57
|
+
if (!honeyNativeState?.collateralList) return false;
|
|
58
|
+
|
|
59
|
+
const isMint = isToken(tokenOut, "HONEY", args);
|
|
60
|
+
const isRedeem = isToken(tokenIn, "HONEY", args);
|
|
61
|
+
|
|
62
|
+
if (!isMint && !isRedeem) return false;
|
|
63
|
+
|
|
64
|
+
return honeyNativeState.collateralList.some((coll) =>
|
|
65
|
+
isToken(coll.address, isMint ? tokenIn : tokenOut),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async getQuote({
|
|
70
|
+
tokenIn,
|
|
71
|
+
tokenOut,
|
|
72
|
+
amount,
|
|
73
|
+
publicClient,
|
|
74
|
+
account,
|
|
75
|
+
honeyNativeState,
|
|
76
|
+
}: IHoneyNativeArgs): Promise<IRawAggregatorQuote<false> | undefined> {
|
|
77
|
+
const { collateralList: collaterals } = honeyNativeState ?? {};
|
|
78
|
+
if (!collaterals) {
|
|
79
|
+
throw new InvalidArgumentError({
|
|
80
|
+
message: "Invalid Honey Context state",
|
|
81
|
+
property: "collaterals",
|
|
82
|
+
value: collaterals,
|
|
83
|
+
expected: "TokenWithOrder[]",
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
assertPublicClient(publicClient);
|
|
87
|
+
|
|
88
|
+
this.checkChainSupport();
|
|
89
|
+
|
|
90
|
+
const isMint = isToken(tokenOut, this.honeyToken);
|
|
91
|
+
|
|
92
|
+
// these should never happen but just in case
|
|
93
|
+
// checking that the tokenOut & tokenIn are correct to allow mint or redeem
|
|
94
|
+
if (
|
|
95
|
+
!HoneyNativeAggregator.isHoneyNativeSwap({
|
|
96
|
+
tokenIn: tokenIn as Address,
|
|
97
|
+
tokenOut: tokenOut as Address,
|
|
98
|
+
honeyNativeState,
|
|
99
|
+
})
|
|
100
|
+
) {
|
|
101
|
+
throw new BeraError({
|
|
102
|
+
message: "Honey Aggregator only supports minting or redeeming Honey",
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The collaterals on Honey are managed with a state that changes the order based on the selected collateral.
|
|
108
|
+
* hub does not do that, so we need to order the collaterals based on the tokenIn.
|
|
109
|
+
* The first collateral will be the tokenIn.
|
|
110
|
+
* */
|
|
111
|
+
const hubOrderedCollaterals = collaterals;
|
|
112
|
+
|
|
113
|
+
// Check if the token requested as collateral is a valid collateral token that can be used to mint or redeem honey
|
|
114
|
+
const collateral = collaterals.find((collateral) =>
|
|
115
|
+
isToken(
|
|
116
|
+
collateral.address,
|
|
117
|
+
isMint ? (tokenIn as Address) : (tokenOut as Address),
|
|
118
|
+
),
|
|
119
|
+
);
|
|
120
|
+
if (!collateral) {
|
|
121
|
+
throw new BeraError({
|
|
122
|
+
message: "This collateral is not part of the Honey protocol",
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/*
|
|
127
|
+
* honeyVaultBalances: Balances of the collateral's vault to check if the vault has enough liquidity
|
|
128
|
+
* isBasketMode: Whether the basket mode is enabled
|
|
129
|
+
*/
|
|
130
|
+
const [honeyVaultBalances, isBasketMode] = await Promise.all([
|
|
131
|
+
getHoneyVaultsBalance({
|
|
132
|
+
client: publicClient,
|
|
133
|
+
collateralList: [collateral],
|
|
134
|
+
}),
|
|
135
|
+
isBasketModeEnabled({
|
|
136
|
+
client: publicClient,
|
|
137
|
+
isMint,
|
|
138
|
+
collateralList: collaterals,
|
|
139
|
+
latestPrices: undefined, // no need to get the latest prices for the aggregator
|
|
140
|
+
isPythWrapperEnabled: false, // Pyth wrapper is not supported for the aggregator
|
|
141
|
+
}),
|
|
142
|
+
]);
|
|
143
|
+
if (!honeyVaultBalances) {
|
|
144
|
+
throw new BeraError({
|
|
145
|
+
message: "Failed to fetch the Honey vault balances",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Need this to prevent mint or redeem in case of a basket mode
|
|
149
|
+
if (isBasketMode) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const collateralVaultBalance = honeyVaultBalances[0];
|
|
154
|
+
|
|
155
|
+
// Order the collaterals manually
|
|
156
|
+
const collateralIdx = collateral.order;
|
|
157
|
+
if (hubOrderedCollaterals.length > 1 && collateralIdx !== 0) {
|
|
158
|
+
hubOrderedCollaterals.splice(collateralIdx, 1);
|
|
159
|
+
hubOrderedCollaterals.unshift(collateral);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// Honey's contract expects the amount to be in a raw format
|
|
163
|
+
const honeyFormattedAmountIn = formatUnits(
|
|
164
|
+
BigInt(amount),
|
|
165
|
+
isMint ? collateral.decimals : this.honeyToken.decimals,
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
// Parameters for the honey preview call
|
|
169
|
+
const quoteParams = {
|
|
170
|
+
client: publicClient,
|
|
171
|
+
collateral: collateral,
|
|
172
|
+
collateralList: collaterals,
|
|
173
|
+
amount: honeyFormattedAmountIn,
|
|
174
|
+
method: _getPreviewMethod(isMint),
|
|
175
|
+
latestPrices: undefined, // no need to get the latest prices for the aggregator
|
|
176
|
+
isPythWrapperEnabled: false, // Pyth wrapper is not supported for the aggregator
|
|
177
|
+
} satisfies HoneyPreviewArgs;
|
|
178
|
+
|
|
179
|
+
// Get the quote for the Honey mint
|
|
180
|
+
const quoteData = await getHoneyPreview(quoteParams);
|
|
181
|
+
|
|
182
|
+
if (!quoteData) {
|
|
183
|
+
throw new BeraError({
|
|
184
|
+
message: "Failed to fetch the Honey preview",
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// The quote contains the honey & the collaterals amount, but we'll only ever need honey
|
|
189
|
+
const { honey: honeyQuote, collaterals: collateralsQuote } = quoteData;
|
|
190
|
+
|
|
191
|
+
// check if the vault has enough liquidity to redeem the collateral
|
|
192
|
+
const haveEnoughLiquidity = !isMint
|
|
193
|
+
? new BigNumber(collateralVaultBalance?.formattedBalance ?? "0").gte(
|
|
194
|
+
formatUnits(
|
|
195
|
+
collateralsQuote[collateral.address],
|
|
196
|
+
collateral.decimals,
|
|
197
|
+
),
|
|
198
|
+
)
|
|
199
|
+
: true;
|
|
200
|
+
|
|
201
|
+
if (!haveEnoughLiquidity) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Get the swap payload for the Honey mint
|
|
207
|
+
* If the account is not provided, we will not get the payload
|
|
208
|
+
*/
|
|
209
|
+
const payload = account
|
|
210
|
+
? await getSwapPayload({
|
|
211
|
+
state: {
|
|
212
|
+
actionType: isMint ? "mint" : "redeem",
|
|
213
|
+
fromAmount: [honeyFormattedAmountIn],
|
|
214
|
+
collaterals: hubOrderedCollaterals,
|
|
215
|
+
isBasketModeEnabled: false, // In Hub, we don't support basket mode
|
|
216
|
+
},
|
|
217
|
+
account: account,
|
|
218
|
+
collateralList: hubOrderedCollaterals,
|
|
219
|
+
publicClient,
|
|
220
|
+
priceFeedMap: undefined,
|
|
221
|
+
isPythWrapperEnabled: false,
|
|
222
|
+
})
|
|
223
|
+
: undefined;
|
|
224
|
+
|
|
225
|
+
// In case the user is not connected the payload will not be generated but the preview yes
|
|
226
|
+
if (!payload && account) {
|
|
227
|
+
throw new BeraError({
|
|
228
|
+
message: "Failed to fetch the Honey swap payload",
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return {
|
|
233
|
+
amountIn: amount,
|
|
234
|
+
amountOut: isMint
|
|
235
|
+
? honeyQuote.toString()
|
|
236
|
+
: collateralsQuote[collateral.address].toString(),
|
|
237
|
+
spender: this.config.honey.factory,
|
|
238
|
+
name: Aggregators.Honey,
|
|
239
|
+
swapFeeBps: 0,
|
|
240
|
+
calldata: payload,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export const honeyNative = new HoneyNativeAggregator();
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { zeroAddress } from "viem";
|
|
2
|
+
|
|
3
|
+
import { ChainId } from "@berachain/config/internal";
|
|
4
|
+
|
|
5
|
+
import { aggregatorsRouterAbi } from "~/abi/bex/aggregatorsRouter";
|
|
6
|
+
import {
|
|
7
|
+
Aggregators,
|
|
8
|
+
type IAggregatorArgs,
|
|
9
|
+
type IRawAggregatorQuote,
|
|
10
|
+
} from "~/types";
|
|
11
|
+
import { BaseAggregator } from "./base";
|
|
12
|
+
|
|
13
|
+
class KyberSwapAggregator extends BaseAggregator {
|
|
14
|
+
name = Aggregators.KyberSwap;
|
|
15
|
+
supportedChains = [ChainId.MAINNET];
|
|
16
|
+
readonly type = "rest";
|
|
17
|
+
|
|
18
|
+
notFoundMessages = [
|
|
19
|
+
"token not found",
|
|
20
|
+
"route not found",
|
|
21
|
+
"amountIn is greater than max allowed",
|
|
22
|
+
];
|
|
23
|
+
async getQuote({
|
|
24
|
+
tokenIn,
|
|
25
|
+
tokenOut,
|
|
26
|
+
amount,
|
|
27
|
+
slippage,
|
|
28
|
+
account = zeroAddress,
|
|
29
|
+
aggregatorsFeeBps,
|
|
30
|
+
proxyAggregatorsThroughVercel = false,
|
|
31
|
+
rewardVault,
|
|
32
|
+
}: IAggregatorArgs): Promise<IRawAggregatorQuote> {
|
|
33
|
+
this.checkChainSupport();
|
|
34
|
+
const {
|
|
35
|
+
isTokenInNative,
|
|
36
|
+
isTokenOutNative,
|
|
37
|
+
tokenInAddress,
|
|
38
|
+
tokenOutAddress,
|
|
39
|
+
} = this.parseAddresses(tokenIn, tokenOut);
|
|
40
|
+
|
|
41
|
+
const inputAmountAfterFees = this.getAmountAfterFees(
|
|
42
|
+
amount,
|
|
43
|
+
aggregatorsFeeBps,
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
this.url = proxyAggregatorsThroughVercel
|
|
47
|
+
? `/api/aggregators?aggregator=kyberswapRoutes`
|
|
48
|
+
: `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/routes`;
|
|
49
|
+
|
|
50
|
+
const url = new URL(this.url);
|
|
51
|
+
// First, get route quote
|
|
52
|
+
url.searchParams.set("tokenIn", tokenInAddress);
|
|
53
|
+
url.searchParams.set("tokenOut", tokenOutAddress);
|
|
54
|
+
url.searchParams.set("amountIn", inputAmountAfterFees);
|
|
55
|
+
url.searchParams.set("slippageTolerance", (slippage / 100).toString());
|
|
56
|
+
url.searchParams.set("to", this.config.bex.aggregatorsRouterExecutor);
|
|
57
|
+
url.searchParams.set("clientData", JSON.stringify({ source: "berachain" }));
|
|
58
|
+
|
|
59
|
+
const routeResponse = await this.fetch(url);
|
|
60
|
+
|
|
61
|
+
const routeData = await routeResponse.json();
|
|
62
|
+
const formattedQuote = {
|
|
63
|
+
amountOut: routeData.data.routeSummary.amountOut,
|
|
64
|
+
amountIn: amount,
|
|
65
|
+
spender: this.config.bex.aggregatorsRouter,
|
|
66
|
+
name: this.name,
|
|
67
|
+
swapFeeBps: aggregatorsFeeBps!,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// If no account, return quote early
|
|
71
|
+
if (account === zeroAddress) return formattedQuote;
|
|
72
|
+
|
|
73
|
+
// Get the build route data for transaction
|
|
74
|
+
const buildRouteBody = {
|
|
75
|
+
routeSummary: routeData.data.routeSummary,
|
|
76
|
+
sender: this.config.bex.aggregatorsRouterExecutor,
|
|
77
|
+
recipient: this.config.bex.aggregatorsRouterExecutor,
|
|
78
|
+
slippageTolerance: slippage * 100, // kyberswap expects the slippage in basis points
|
|
79
|
+
deadline: Math.floor(Date.now() / 1000) + 60 * 5, // 5 minutes from now
|
|
80
|
+
source: "berachain",
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const params = url.searchParams.entries();
|
|
84
|
+
|
|
85
|
+
const buildUrl = new URL(
|
|
86
|
+
proxyAggregatorsThroughVercel
|
|
87
|
+
? `/api/aggregators?aggregator=kyberswapBuild`
|
|
88
|
+
: `${this.config.bex.aggregatorsProxyUrl}/kyberswap/berachain/api/v1/route/build`,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
for (const [key, value] of params) {
|
|
92
|
+
buildUrl.searchParams.set(key, value);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const buildRouteResponse = await this.fetch(buildUrl, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
body: JSON.stringify(buildRouteBody),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const buildData = await buildRouteResponse.json();
|
|
101
|
+
|
|
102
|
+
const inputData = this.getInputData({
|
|
103
|
+
tokenIn: tokenInAddress,
|
|
104
|
+
amountIn: amount,
|
|
105
|
+
isNative: isTokenInNative,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const outputData = {
|
|
109
|
+
tokenOut: tokenOutAddress,
|
|
110
|
+
receiver: account,
|
|
111
|
+
minAmountOut: this.getMinAmountOut(formattedQuote.amountOut, slippage),
|
|
112
|
+
isNative: isTokenOutNative,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const aggregatorData = {
|
|
116
|
+
aggregator: buildData.data.routerAddress,
|
|
117
|
+
data: buildData.data.data,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
...formattedQuote,
|
|
122
|
+
calldata: {
|
|
123
|
+
params: [
|
|
124
|
+
inputData,
|
|
125
|
+
outputData,
|
|
126
|
+
aggregatorData,
|
|
127
|
+
{
|
|
128
|
+
rewardVault: rewardVault ?? zeroAddress,
|
|
129
|
+
isSwapAndStake: !!rewardVault,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
functionName: "swap",
|
|
133
|
+
abi: aggregatorsRouterAbi,
|
|
134
|
+
// send full amount to router first, which will deduct the swap fee before executing trade
|
|
135
|
+
value: isTokenInNative ? BigInt(amount) : BigInt("0"),
|
|
136
|
+
address: this.config.bex.aggregatorsRouter,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const kyberswap = new KyberSwapAggregator();
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { zeroAddress } from "viem";
|
|
2
|
+
|
|
3
|
+
import { ChainId } from "@berachain/config/internal";
|
|
4
|
+
|
|
5
|
+
import { aggregatorsRouterAbi } from "~/abi/bex/aggregatorsRouter";
|
|
6
|
+
import {
|
|
7
|
+
Aggregators,
|
|
8
|
+
type IAggregatorArgs,
|
|
9
|
+
type IRawAggregatorQuote,
|
|
10
|
+
} from "~/types";
|
|
11
|
+
import { BaseAggregator } from "./base";
|
|
12
|
+
|
|
13
|
+
class OogaboogaAggregator extends BaseAggregator {
|
|
14
|
+
name = Aggregators.Oogabooga;
|
|
15
|
+
supportedChains = [ChainId.MAINNET];
|
|
16
|
+
readonly type = "rest";
|
|
17
|
+
|
|
18
|
+
async getQuote({
|
|
19
|
+
tokenIn,
|
|
20
|
+
tokenOut,
|
|
21
|
+
amount,
|
|
22
|
+
slippage,
|
|
23
|
+
account = zeroAddress,
|
|
24
|
+
aggregatorsFeeBps,
|
|
25
|
+
proxyAggregatorsThroughVercel = false,
|
|
26
|
+
rewardVault,
|
|
27
|
+
}: IAggregatorArgs): Promise<IRawAggregatorQuote> {
|
|
28
|
+
this.checkChainSupport();
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
tokenInAddress,
|
|
32
|
+
tokenOutAddress,
|
|
33
|
+
isTokenInNative,
|
|
34
|
+
isTokenOutNative,
|
|
35
|
+
} = this.parseAddresses(tokenIn, tokenOut);
|
|
36
|
+
|
|
37
|
+
const inputAmountAfterFees = this.getAmountAfterFees(
|
|
38
|
+
amount,
|
|
39
|
+
aggregatorsFeeBps,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const params = new URLSearchParams({
|
|
43
|
+
tokenIn: tokenInAddress,
|
|
44
|
+
tokenOut: tokenOutAddress,
|
|
45
|
+
amount: inputAmountAfterFees,
|
|
46
|
+
slippage: (slippage / 100).toString(),
|
|
47
|
+
to: this.config.bex.aggregatorsRouterExecutor,
|
|
48
|
+
referrer: this.config.bex.aggregatorsRouter,
|
|
49
|
+
});
|
|
50
|
+
this.url = proxyAggregatorsThroughVercel
|
|
51
|
+
? `/api/aggregators?aggregator=oogabooga&${params.toString()}`
|
|
52
|
+
: `${this.config.bex.aggregatorsProxyUrl}/oogabooga/v1/swap?${params.toString()}`;
|
|
53
|
+
|
|
54
|
+
const response = await this.fetch(this.url);
|
|
55
|
+
|
|
56
|
+
const quote = await response.json();
|
|
57
|
+
|
|
58
|
+
const formattedQuote = {
|
|
59
|
+
amountOut: quote.assumedAmountOut,
|
|
60
|
+
amountIn: amount,
|
|
61
|
+
spender: this.config.bex.aggregatorsRouter,
|
|
62
|
+
name: this.name,
|
|
63
|
+
priceImpactPercentage: quote.priceImpact,
|
|
64
|
+
swapFeeBps: aggregatorsFeeBps!,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// if no account, return quote early
|
|
68
|
+
if (account === zeroAddress) return formattedQuote;
|
|
69
|
+
|
|
70
|
+
const inputData = this.getInputData({
|
|
71
|
+
tokenIn: tokenInAddress,
|
|
72
|
+
amountIn: amount,
|
|
73
|
+
isNative: isTokenInNative,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const outputData = {
|
|
77
|
+
tokenOut: tokenOutAddress,
|
|
78
|
+
receiver: account,
|
|
79
|
+
minAmountOut: this.getMinAmountOut(formattedQuote.amountOut, slippage),
|
|
80
|
+
isNative: isTokenOutNative,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const aggregatorData = {
|
|
84
|
+
aggregator: quote.tx?.to,
|
|
85
|
+
data: quote.tx?.data,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
...formattedQuote,
|
|
90
|
+
calldata: {
|
|
91
|
+
params: [
|
|
92
|
+
inputData,
|
|
93
|
+
outputData,
|
|
94
|
+
aggregatorData,
|
|
95
|
+
{
|
|
96
|
+
rewardVault: rewardVault ?? zeroAddress,
|
|
97
|
+
isSwapAndStake: !!rewardVault,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
functionName: "swap",
|
|
101
|
+
abi: aggregatorsRouterAbi,
|
|
102
|
+
// send full amount to router first, which will deduct the swap fee before executing trade
|
|
103
|
+
value: isTokenInNative ? BigInt(amount) : BigInt("0"),
|
|
104
|
+
address: this.config.bex.aggregatorsRouter,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const oogabooga = new OogaboogaAggregator();
|