@eth-optimism/actions-sdk 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__mocks__/MockAssets.d.ts +17 -2
- package/dist/__mocks__/MockAssets.d.ts.map +1 -1
- package/dist/__mocks__/MockAssets.js +49 -6
- package/dist/__mocks__/MockAssets.js.map +1 -1
- package/dist/__tests__/actions.test.js +1 -1
- package/dist/__tests__/actions.test.js.map +1 -1
- package/dist/actions.d.ts +17 -13
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +46 -27
- package/dist/actions.js.map +1 -1
- package/dist/constants/assets.d.ts +215 -4
- package/dist/constants/assets.d.ts.map +1 -1
- package/dist/constants/assets.js +734 -11
- package/dist/constants/assets.js.map +1 -1
- package/dist/constants/providers.d.ts +6 -0
- package/dist/constants/providers.d.ts.map +1 -0
- package/dist/constants/providers.js +6 -0
- package/dist/constants/providers.js.map +1 -0
- package/dist/constants/supportedChains.d.ts +2 -2
- package/dist/constants/supportedChains.d.ts.map +1 -1
- package/dist/constants/supportedChains.js +12 -2
- package/dist/constants/supportedChains.js.map +1 -1
- package/dist/ens/EnsNamespace.d.ts +57 -0
- package/dist/ens/EnsNamespace.d.ts.map +1 -0
- package/dist/ens/EnsNamespace.js +158 -0
- package/dist/ens/EnsNamespace.js.map +1 -0
- package/dist/ens/EnsNamespace.spec.d.ts +2 -0
- package/dist/ens/EnsNamespace.spec.d.ts.map +1 -0
- package/dist/ens/EnsNamespace.spec.js +144 -0
- package/dist/ens/EnsNamespace.spec.js.map +1 -0
- package/dist/ens/errors.d.ts +24 -0
- package/dist/ens/errors.d.ts.map +1 -0
- package/dist/ens/errors.js +35 -0
- package/dist/ens/errors.js.map +1 -0
- package/dist/ens/index.d.ts +4 -0
- package/dist/ens/index.d.ts.map +1 -0
- package/dist/ens/index.js +4 -0
- package/dist/ens/index.js.map +1 -0
- package/dist/ens/types.d.ts +63 -0
- package/dist/ens/types.d.ts.map +1 -0
- package/dist/ens/types.js +14 -0
- package/dist/ens/types.js.map +1 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/lend/__mocks__/MockLendProvider.d.ts +1 -1
- package/dist/lend/__mocks__/MockLendProvider.d.ts.map +1 -1
- package/dist/lend/__mocks__/MockLendProvider.js +7 -2
- package/dist/lend/__mocks__/MockLendProvider.js.map +1 -1
- package/dist/lend/core/LendProvider.d.ts +12 -8
- package/dist/lend/core/LendProvider.d.ts.map +1 -1
- package/dist/lend/core/LendProvider.js +15 -21
- package/dist/lend/core/LendProvider.js.map +1 -1
- package/dist/lend/namespaces/BaseLendNamespace.d.ts +2 -6
- package/dist/lend/namespaces/BaseLendNamespace.d.ts.map +1 -1
- package/dist/lend/namespaces/BaseLendNamespace.js.map +1 -1
- package/dist/lend/namespaces/__tests__/BaseLendNamespace.spec.js +7 -4
- package/dist/lend/namespaces/__tests__/BaseLendNamespace.spec.js.map +1 -1
- package/dist/lend/providers/aave/AaveLendProvider.d.ts +1 -6
- package/dist/lend/providers/aave/AaveLendProvider.d.ts.map +1 -1
- package/dist/lend/providers/aave/AaveLendProvider.js +3 -6
- package/dist/lend/providers/aave/AaveLendProvider.js.map +1 -1
- package/dist/lend/providers/aave/__tests__/AaveLendProvider.test.js +14 -6
- package/dist/lend/providers/aave/__tests__/AaveLendProvider.test.js.map +1 -1
- package/dist/lend/providers/aave/addresses.d.ts +13 -39
- package/dist/lend/providers/aave/addresses.d.ts.map +1 -1
- package/dist/lend/providers/aave/addresses.js +65 -60
- package/dist/lend/providers/aave/addresses.js.map +1 -1
- package/dist/lend/providers/aave/sdk.d.ts +2 -2
- package/dist/lend/providers/aave/sdk.d.ts.map +1 -1
- package/dist/lend/providers/aave/sdk.js +6 -28
- package/dist/lend/providers/aave/sdk.js.map +1 -1
- package/dist/lend/providers/morpho/MorphoLendProvider.d.ts +1 -6
- package/dist/lend/providers/morpho/MorphoLendProvider.d.ts.map +1 -1
- package/dist/lend/providers/morpho/MorphoLendProvider.js +4 -13
- package/dist/lend/providers/morpho/MorphoLendProvider.js.map +1 -1
- package/dist/lend/providers/morpho/__tests__/api.test.js +52 -43
- package/dist/lend/providers/morpho/__tests__/api.test.js.map +1 -1
- package/dist/lend/providers/morpho/__tests__/sdk.test.js +41 -42
- package/dist/lend/providers/morpho/__tests__/sdk.test.js.map +1 -1
- package/dist/lend/providers/morpho/api.d.ts +3 -7
- package/dist/lend/providers/morpho/api.d.ts.map +1 -1
- package/dist/lend/providers/morpho/api.js +2 -2
- package/dist/lend/providers/morpho/api.js.map +1 -1
- package/dist/lend/providers/morpho/contracts.d.ts +11 -10
- package/dist/lend/providers/morpho/contracts.d.ts.map +1 -1
- package/dist/lend/providers/morpho/contracts.js +43 -10
- package/dist/lend/providers/morpho/contracts.js.map +1 -1
- package/dist/lend/providers/morpho/sdk.d.ts +7 -2
- package/dist/lend/providers/morpho/sdk.d.ts.map +1 -1
- package/dist/lend/providers/morpho/sdk.js +67 -63
- package/dist/lend/providers/morpho/sdk.js.map +1 -1
- package/dist/nodeActionsFactory.d.ts +1 -1
- package/dist/reactActionsFactory.d.ts +1 -1
- package/dist/services/ChainManager.d.ts +15 -8
- package/dist/services/ChainManager.d.ts.map +1 -1
- package/dist/services/ChainManager.js +9 -0
- package/dist/services/ChainManager.js.map +1 -1
- package/dist/services/__mocks__/MockChainManager.d.ts +5 -4
- package/dist/services/__mocks__/MockChainManager.d.ts.map +1 -1
- package/dist/services/__mocks__/MockChainManager.js +5 -0
- package/dist/services/__mocks__/MockChainManager.js.map +1 -1
- package/dist/services/tokenBalance.d.ts +1 -1
- package/dist/services/tokenBalance.d.ts.map +1 -1
- package/dist/services/tokenBalance.js +31 -30
- package/dist/services/tokenBalance.js.map +1 -1
- package/dist/services/tokenBalance.spec.js +20 -24
- package/dist/services/tokenBalance.spec.js.map +1 -1
- package/dist/swap/__mocks__/MockSwapProvider.d.ts +20 -8
- package/dist/swap/__mocks__/MockSwapProvider.d.ts.map +1 -1
- package/dist/swap/__mocks__/MockSwapProvider.js +52 -29
- package/dist/swap/__mocks__/MockSwapProvider.js.map +1 -1
- package/dist/swap/core/SwapProvider.d.ts +105 -16
- package/dist/swap/core/SwapProvider.d.ts.map +1 -1
- package/dist/swap/core/SwapProvider.js +215 -37
- package/dist/swap/core/SwapProvider.js.map +1 -1
- package/dist/swap/core/__tests__/SwapProvider.test.js +115 -9
- package/dist/swap/core/__tests__/SwapProvider.test.js.map +1 -1
- package/dist/swap/core/markets.d.ts +47 -0
- package/dist/swap/core/markets.d.ts.map +1 -0
- package/dist/swap/core/markets.js +65 -0
- package/dist/swap/core/markets.js.map +1 -0
- package/dist/swap/index.d.ts +2 -0
- package/dist/swap/index.d.ts.map +1 -1
- package/dist/swap/index.js +1 -0
- package/dist/swap/index.js.map +1 -1
- package/dist/swap/namespaces/ActionsSwapNamespace.d.ts +2 -2
- package/dist/swap/namespaces/ActionsSwapNamespace.js +2 -2
- package/dist/swap/namespaces/BaseSwapNamespace.d.ts +50 -8
- package/dist/swap/namespaces/BaseSwapNamespace.d.ts.map +1 -1
- package/dist/swap/namespaces/BaseSwapNamespace.js +144 -16
- package/dist/swap/namespaces/BaseSwapNamespace.js.map +1 -1
- package/dist/swap/namespaces/WalletSwapNamespace.d.ts +20 -7
- package/dist/swap/namespaces/WalletSwapNamespace.d.ts.map +1 -1
- package/dist/swap/namespaces/WalletSwapNamespace.js +44 -15
- package/dist/swap/namespaces/WalletSwapNamespace.js.map +1 -1
- package/dist/swap/namespaces/__tests__/BaseSwapNamespace.spec.js +150 -11
- package/dist/swap/namespaces/__tests__/BaseSwapNamespace.spec.js.map +1 -1
- package/dist/swap/namespaces/__tests__/WalletSwapNamespace.spec.js +85 -8
- package/dist/swap/namespaces/__tests__/WalletSwapNamespace.spec.js.map +1 -1
- package/dist/swap/providers/uniswap/UniswapSwapProvider.d.ts +10 -42
- package/dist/swap/providers/uniswap/UniswapSwapProvider.d.ts.map +1 -1
- package/dist/swap/providers/uniswap/UniswapSwapProvider.js +81 -139
- package/dist/swap/providers/uniswap/UniswapSwapProvider.js.map +1 -1
- package/dist/swap/providers/uniswap/__tests__/UniswapSwapProvider.test.js +10 -9
- package/dist/swap/providers/uniswap/__tests__/UniswapSwapProvider.test.js.map +1 -1
- package/dist/swap/providers/uniswap/__tests__/sdk.test.js +17 -17
- package/dist/swap/providers/uniswap/__tests__/sdk.test.js.map +1 -1
- package/dist/swap/providers/uniswap/addresses.d.ts +5 -0
- package/dist/swap/providers/uniswap/addresses.d.ts.map +1 -1
- package/dist/swap/providers/uniswap/addresses.js +1 -1
- package/dist/swap/providers/uniswap/addresses.js.map +1 -1
- package/dist/swap/providers/uniswap/encoding.d.ts +4 -4
- package/dist/swap/providers/uniswap/encoding.js +17 -17
- package/dist/swap/providers/uniswap/markets.d.ts +19 -0
- package/dist/swap/providers/uniswap/markets.d.ts.map +1 -0
- package/dist/swap/providers/uniswap/markets.js +48 -0
- package/dist/swap/providers/uniswap/markets.js.map +1 -0
- package/dist/swap/providers/uniswap/types.d.ts +4 -3
- package/dist/swap/providers/uniswap/types.d.ts.map +1 -1
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.d.ts +50 -0
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.js +140 -0
- package/dist/swap/providers/velodrome/VelodromeSwapProvider.js.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.network.test.d.ts +2 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.network.test.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.network.test.js +255 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.network.test.js.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.routing.test.d.ts +2 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.routing.test.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.routing.test.js +166 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.routing.test.js.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.d.ts +2 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.js +420 -0
- package/dist/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.js.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.cl.test.d.ts +2 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.cl.test.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.cl.test.js +51 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.cl.test.js.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.helpers.d.ts +14 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.helpers.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.helpers.js +13 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.helpers.js.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.v2.test.d.ts +2 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.v2.test.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.v2.test.js +173 -0
- package/dist/swap/providers/velodrome/__tests__/encoding.v2.test.js.map +1 -0
- package/dist/swap/providers/velodrome/abis.d.ts +396 -0
- package/dist/swap/providers/velodrome/abis.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/abis.js +257 -0
- package/dist/swap/providers/velodrome/abis.js.map +1 -0
- package/dist/swap/providers/velodrome/addresses.d.ts +39 -0
- package/dist/swap/providers/velodrome/addresses.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/addresses.js +57 -0
- package/dist/swap/providers/velodrome/addresses.js.map +1 -0
- package/dist/swap/providers/velodrome/config.d.ts +22 -0
- package/dist/swap/providers/velodrome/config.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/config.js +29 -0
- package/dist/swap/providers/velodrome/config.js.map +1 -0
- package/dist/swap/providers/velodrome/encoding/helpers.d.ts +37 -0
- package/dist/swap/providers/velodrome/encoding/helpers.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/encoding/helpers.js +60 -0
- package/dist/swap/providers/velodrome/encoding/helpers.js.map +1 -0
- package/dist/swap/providers/velodrome/encoding/index.d.ts +8 -0
- package/dist/swap/providers/velodrome/encoding/index.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/encoding/index.js +5 -0
- package/dist/swap/providers/velodrome/encoding/index.js.map +1 -0
- package/dist/swap/providers/velodrome/encoding/poolRouter.d.ts +39 -0
- package/dist/swap/providers/velodrome/encoding/poolRouter.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/encoding/poolRouter.js +83 -0
- package/dist/swap/providers/velodrome/encoding/poolRouter.js.map +1 -0
- package/dist/swap/providers/velodrome/encoding/routers/approval.d.ts +15 -0
- package/dist/swap/providers/velodrome/encoding/routers/approval.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/encoding/routers/approval.js +33 -0
- package/dist/swap/providers/velodrome/encoding/routers/approval.js.map +1 -0
- package/dist/swap/providers/velodrome/encoding/routers/cl.d.ts +40 -0
- package/dist/swap/providers/velodrome/encoding/routers/cl.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/encoding/routers/cl.js +80 -0
- package/dist/swap/providers/velodrome/encoding/routers/cl.js.map +1 -0
- package/dist/swap/providers/velodrome/encoding/routers/v2.d.ts +42 -0
- package/dist/swap/providers/velodrome/encoding/routers/v2.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/encoding/routers/v2.js +166 -0
- package/dist/swap/providers/velodrome/encoding/routers/v2.js.map +1 -0
- package/dist/swap/providers/velodrome/markets.d.ts +21 -0
- package/dist/swap/providers/velodrome/markets.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/markets.js +69 -0
- package/dist/swap/providers/velodrome/markets.js.map +1 -0
- package/dist/swap/providers/velodrome/types.d.ts +31 -0
- package/dist/swap/providers/velodrome/types.d.ts.map +1 -0
- package/dist/swap/providers/velodrome/types.js +2 -0
- package/dist/swap/providers/velodrome/types.js.map +1 -0
- package/dist/types/actions.d.ts +44 -9
- package/dist/types/actions.d.ts.map +1 -1
- package/dist/types/asset.d.ts +7 -9
- package/dist/types/asset.d.ts.map +1 -1
- package/dist/types/chain.d.ts +2 -2
- package/dist/types/chain.d.ts.map +1 -1
- package/dist/types/lend/base.d.ts +6 -6
- package/dist/types/lend/base.d.ts.map +1 -1
- package/dist/types/lend/base.js.map +1 -1
- package/dist/types/lend/contracts.d.ts +2 -1
- package/dist/types/lend/contracts.d.ts.map +1 -1
- package/dist/types/providers.d.ts +21 -0
- package/dist/types/providers.d.ts.map +1 -0
- package/dist/types/providers.js +2 -0
- package/dist/types/providers.js.map +1 -0
- package/dist/types/swap/base.d.ts +136 -35
- package/dist/types/swap/base.d.ts.map +1 -1
- package/dist/types/swap/base.js.map +1 -1
- package/dist/utils/approve.d.ts +82 -0
- package/dist/utils/approve.d.ts.map +1 -0
- package/dist/utils/{permit2.js → approve.js} +48 -14
- package/dist/utils/approve.js.map +1 -0
- package/dist/utils/approve.test.d.ts +2 -0
- package/dist/utils/approve.test.d.ts.map +1 -0
- package/dist/utils/{permit2.test.js → approve.test.js} +95 -2
- package/dist/utils/approve.test.js.map +1 -0
- package/dist/utils/assets.d.ts +6 -0
- package/dist/utils/assets.d.ts.map +1 -1
- package/dist/utils/assets.js +10 -0
- package/dist/utils/assets.js.map +1 -1
- package/dist/utils/ens.d.ts +25 -0
- package/dist/utils/ens.d.ts.map +1 -0
- package/dist/utils/ens.js +53 -0
- package/dist/utils/ens.js.map +1 -0
- package/dist/utils/ens.test.d.ts +2 -0
- package/dist/utils/ens.test.d.ts.map +1 -0
- package/dist/utils/ens.test.js +75 -0
- package/dist/utils/ens.test.js.map +1 -0
- package/dist/utils/validateAddresses.d.ts +32 -0
- package/dist/utils/validateAddresses.d.ts.map +1 -0
- package/dist/utils/validateAddresses.js +103 -0
- package/dist/utils/validateAddresses.js.map +1 -0
- package/dist/utils/validateAddresses.test.d.ts +2 -0
- package/dist/utils/validateAddresses.test.d.ts.map +1 -0
- package/dist/utils/validateAddresses.test.js +314 -0
- package/dist/utils/validateAddresses.test.js.map +1 -0
- package/dist/utils/validation.d.ts +5 -0
- package/dist/utils/validation.d.ts.map +1 -1
- package/dist/utils/validation.js +10 -0
- package/dist/utils/validation.js.map +1 -1
- package/dist/wallet/core/namespace/WalletNamespace.d.ts +21 -9
- package/dist/wallet/core/namespace/WalletNamespace.d.ts.map +1 -1
- package/dist/wallet/core/namespace/WalletNamespace.js +44 -15
- package/dist/wallet/core/namespace/WalletNamespace.js.map +1 -1
- package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js +4 -4
- package/dist/wallet/core/namespace/__tests__/WalletNamespace.spec.js.map +1 -1
- package/dist/wallet/core/providers/hosted/abstract/HostedWalletProvider.d.ts +4 -16
- package/dist/wallet/core/providers/hosted/abstract/HostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/core/providers/hosted/abstract/HostedWalletProvider.js.map +1 -1
- package/dist/wallet/core/providers/hosted/types/index.d.ts +6 -11
- package/dist/wallet/core/providers/hosted/types/index.d.ts.map +1 -1
- package/dist/wallet/core/providers/smart/default/DefaultSmartWalletProvider.d.ts +2 -9
- package/dist/wallet/core/providers/smart/default/DefaultSmartWalletProvider.d.ts.map +1 -1
- package/dist/wallet/core/providers/smart/default/DefaultSmartWalletProvider.js.map +1 -1
- package/dist/wallet/core/wallets/abstract/Wallet.d.ts +6 -17
- package/dist/wallet/core/wallets/abstract/Wallet.d.ts.map +1 -1
- package/dist/wallet/core/wallets/abstract/Wallet.js +7 -6
- package/dist/wallet/core/wallets/abstract/Wallet.js.map +1 -1
- package/dist/wallet/core/wallets/abstract/__mocks__/TestWallet.d.ts +10 -1
- package/dist/wallet/core/wallets/abstract/__mocks__/TestWallet.d.ts.map +1 -1
- package/dist/wallet/core/wallets/abstract/__mocks__/TestWallet.js +2 -2
- package/dist/wallet/core/wallets/abstract/__mocks__/TestWallet.js.map +1 -1
- package/dist/wallet/core/wallets/abstract/__tests__/Wallet.spec.js +12 -4
- package/dist/wallet/core/wallets/abstract/__tests__/Wallet.spec.js.map +1 -1
- package/dist/wallet/core/wallets/smart/default/DefaultSmartWallet.d.ts +3 -10
- package/dist/wallet/core/wallets/smart/default/DefaultSmartWallet.d.ts.map +1 -1
- package/dist/wallet/core/wallets/smart/default/DefaultSmartWallet.js.map +1 -1
- package/dist/wallet/core/wallets/smart/default/__tests__/DefaultSmartWallet.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.d.ts +3 -10
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.js.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.d.ts +2 -4
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.d.ts.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js +6 -8
- package/dist/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.js.map +1 -1
- package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js +4 -4
- package/dist/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/node/providers/hosted/turnkey/TurnkeyHostedWalletProvider.d.ts +2 -9
- package/dist/wallet/node/providers/hosted/turnkey/TurnkeyHostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/node/providers/hosted/turnkey/TurnkeyHostedWalletProvider.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.d.ts +3 -10
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.d.ts.map +1 -1
- package/dist/wallet/node/wallets/hosted/privy/PrivyWallet.js.map +1 -1
- package/dist/wallet/node/wallets/hosted/turnkey/TurnkeyWallet.d.ts +3 -10
- package/dist/wallet/node/wallets/hosted/turnkey/TurnkeyWallet.d.ts.map +1 -1
- package/dist/wallet/node/wallets/hosted/turnkey/TurnkeyWallet.js.map +1 -1
- package/dist/wallet/react/providers/hosted/dynamic/DynamicHostedWalletProvider.d.ts +3 -9
- package/dist/wallet/react/providers/hosted/dynamic/DynamicHostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/react/providers/hosted/dynamic/DynamicHostedWalletProvider.js +3 -2
- package/dist/wallet/react/providers/hosted/dynamic/DynamicHostedWalletProvider.js.map +1 -1
- package/dist/wallet/react/providers/hosted/privy/PrivyHostedWalletProvider.d.ts +3 -9
- package/dist/wallet/react/providers/hosted/privy/PrivyHostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/react/providers/hosted/privy/PrivyHostedWalletProvider.js +3 -2
- package/dist/wallet/react/providers/hosted/privy/PrivyHostedWalletProvider.js.map +1 -1
- package/dist/wallet/react/providers/hosted/turnkey/TurnkeyHostedWalletProvider.d.ts +3 -9
- package/dist/wallet/react/providers/hosted/turnkey/TurnkeyHostedWalletProvider.d.ts.map +1 -1
- package/dist/wallet/react/providers/hosted/turnkey/TurnkeyHostedWalletProvider.js +3 -2
- package/dist/wallet/react/providers/hosted/turnkey/TurnkeyHostedWalletProvider.js.map +1 -1
- package/dist/wallet/react/providers/registry/ReactHostedWalletProviderRegistry.d.ts +2 -4
- package/dist/wallet/react/providers/registry/ReactHostedWalletProviderRegistry.d.ts.map +1 -1
- package/dist/wallet/react/providers/registry/ReactHostedWalletProviderRegistry.js +11 -13
- package/dist/wallet/react/providers/registry/ReactHostedWalletProviderRegistry.js.map +1 -1
- package/dist/wallet/react/providers/registry/__tests__/ReactHostedWalletProviderRegistry.spec.js +6 -6
- package/dist/wallet/react/providers/registry/__tests__/ReactHostedWalletProviderRegistry.spec.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/DynamicWallet.d.ts +5 -10
- package/dist/wallet/react/wallets/hosted/dynamic/DynamicWallet.d.ts.map +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/DynamicWallet.js +3 -3
- package/dist/wallet/react/wallets/hosted/dynamic/DynamicWallet.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/__mocks__/DynamicWalletMock.d.ts +2 -6
- package/dist/wallet/react/wallets/hosted/dynamic/__mocks__/DynamicWalletMock.d.ts.map +1 -1
- package/dist/wallet/react/wallets/hosted/dynamic/__mocks__/DynamicWalletMock.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/privy/PrivyWallet.d.ts +5 -10
- package/dist/wallet/react/wallets/hosted/privy/PrivyWallet.d.ts.map +1 -1
- package/dist/wallet/react/wallets/hosted/privy/PrivyWallet.js +3 -3
- package/dist/wallet/react/wallets/hosted/privy/PrivyWallet.js.map +1 -1
- package/dist/wallet/react/wallets/hosted/turnkey/TurnkeyWallet.d.ts +5 -10
- package/dist/wallet/react/wallets/hosted/turnkey/TurnkeyWallet.d.ts.map +1 -1
- package/dist/wallet/react/wallets/hosted/turnkey/TurnkeyWallet.js +2 -2
- package/dist/wallet/react/wallets/hosted/turnkey/TurnkeyWallet.js.map +1 -1
- package/package.json +3 -2
- package/src/__mocks__/MockAssets.ts +54 -6
- package/src/__tests__/actions.test.ts +1 -1
- package/src/actions.ts +73 -61
- package/src/constants/assets.ts +781 -10
- package/src/constants/providers.ts +5 -0
- package/src/constants/supportedChains.ts +22 -2
- package/src/ens/EnsNamespace.spec.ts +171 -0
- package/src/ens/EnsNamespace.ts +210 -0
- package/src/ens/errors.ts +45 -0
- package/src/ens/index.ts +12 -0
- package/src/ens/types.ts +76 -0
- package/src/index.ts +59 -8
- package/src/lend/__mocks__/MockLendProvider.ts +8 -3
- package/src/lend/core/LendProvider.ts +27 -28
- package/src/lend/namespaces/BaseLendNamespace.ts +2 -6
- package/src/lend/namespaces/__tests__/BaseLendNamespace.spec.ts +12 -5
- package/src/lend/providers/aave/AaveLendProvider.ts +3 -7
- package/src/lend/providers/aave/__tests__/AaveLendProvider.test.ts +16 -7
- package/src/lend/providers/aave/addresses.ts +82 -64
- package/src/lend/providers/aave/sdk.ts +11 -36
- package/src/lend/providers/morpho/MorphoLendProvider.ts +4 -16
- package/src/lend/providers/morpho/__tests__/api.test.ts +65 -44
- package/src/lend/providers/morpho/__tests__/sdk.test.ts +43 -43
- package/src/lend/providers/morpho/api.ts +7 -8
- package/src/lend/providers/morpho/contracts.ts +62 -13
- package/src/lend/providers/morpho/sdk.ts +85 -63
- package/src/services/ChainManager.ts +22 -21
- package/src/services/__mocks__/MockChainManager.ts +12 -7
- package/src/services/tokenBalance.spec.ts +20 -24
- package/src/services/tokenBalance.ts +39 -33
- package/src/swap/__mocks__/MockSwapProvider.ts +77 -42
- package/src/swap/core/SwapProvider.ts +309 -50
- package/src/swap/core/__tests__/SwapProvider.test.ts +151 -9
- package/src/swap/core/markets.ts +104 -0
- package/src/swap/index.ts +5 -0
- package/src/swap/namespaces/ActionsSwapNamespace.ts +2 -2
- package/src/swap/namespaces/BaseSwapNamespace.ts +215 -18
- package/src/swap/namespaces/WalletSwapNamespace.ts +61 -14
- package/src/swap/namespaces/__tests__/BaseSwapNamespace.spec.ts +245 -14
- package/src/swap/namespaces/__tests__/WalletSwapNamespace.spec.ts +103 -8
- package/src/swap/providers/uniswap/UniswapSwapProvider.ts +110 -195
- package/src/swap/providers/uniswap/__tests__/UniswapSwapProvider.test.ts +12 -12
- package/src/swap/providers/uniswap/__tests__/sdk.test.ts +19 -20
- package/src/swap/providers/uniswap/addresses.ts +3 -1
- package/src/swap/providers/uniswap/encoding.ts +22 -22
- package/src/swap/providers/uniswap/markets.ts +84 -0
- package/src/swap/providers/uniswap/types.ts +4 -3
- package/src/swap/providers/velodrome/VelodromeSwapProvider.ts +226 -0
- package/src/swap/providers/velodrome/__tests__/VelodromeSwapProvider.network.test.ts +341 -0
- package/src/swap/providers/velodrome/__tests__/VelodromeSwapProvider.routing.test.ts +202 -0
- package/src/swap/providers/velodrome/__tests__/VelodromeSwapProvider.test.ts +507 -0
- package/src/swap/providers/velodrome/__tests__/encoding.cl.test.ts +69 -0
- package/src/swap/providers/velodrome/__tests__/encoding.helpers.ts +20 -0
- package/src/swap/providers/velodrome/__tests__/encoding.v2.test.ts +235 -0
- package/src/swap/providers/velodrome/abis.ts +264 -0
- package/src/swap/providers/velodrome/addresses.ts +107 -0
- package/src/swap/providers/velodrome/config.ts +46 -0
- package/src/swap/providers/velodrome/encoding/helpers.ts +82 -0
- package/src/swap/providers/velodrome/encoding/index.ts +7 -0
- package/src/swap/providers/velodrome/encoding/poolRouter.ts +124 -0
- package/src/swap/providers/velodrome/encoding/routers/approval.ts +45 -0
- package/src/swap/providers/velodrome/encoding/routers/cl.ts +156 -0
- package/src/swap/providers/velodrome/encoding/routers/v2.ts +267 -0
- package/src/swap/providers/velodrome/markets.ts +100 -0
- package/src/swap/providers/velodrome/types.ts +30 -0
- package/src/types/actions.ts +49 -9
- package/src/types/asset.ts +12 -9
- package/src/types/chain.ts +2 -2
- package/src/types/lend/base.ts +6 -6
- package/src/types/lend/contracts.ts +5 -1
- package/src/types/providers.ts +22 -0
- package/src/types/swap/base.ts +150 -36
- package/src/utils/{permit2.test.ts → approve.test.ts} +117 -1
- package/src/utils/{permit2.ts → approve.ts} +67 -14
- package/src/utils/assets.ts +14 -0
- package/src/utils/ens.test.ts +104 -0
- package/src/utils/ens.ts +85 -0
- package/src/utils/validateAddresses.test.ts +439 -0
- package/src/utils/validateAddresses.ts +153 -0
- package/src/utils/validation.ts +11 -0
- package/src/wallet/core/namespace/WalletNamespace.ts +70 -16
- package/src/wallet/core/namespace/__tests__/WalletNamespace.spec.ts +8 -4
- package/src/wallet/core/providers/hosted/abstract/HostedWalletProvider.ts +5 -17
- package/src/wallet/core/providers/hosted/types/index.ts +9 -11
- package/src/wallet/core/providers/smart/default/DefaultSmartWalletProvider.ts +5 -17
- package/src/wallet/core/wallets/abstract/Wallet.ts +18 -22
- package/src/wallet/core/wallets/abstract/__mocks__/TestWallet.ts +13 -1
- package/src/wallet/core/wallets/abstract/__tests__/Wallet.spec.ts +21 -5
- package/src/wallet/core/wallets/smart/default/DefaultSmartWallet.ts +5 -17
- package/src/wallet/core/wallets/smart/default/__tests__/DefaultSmartWallet.spec.ts +0 -1
- package/src/wallet/node/providers/hosted/privy/PrivyHostedWalletProvider.ts +3 -10
- package/src/wallet/node/providers/hosted/registry/NodeHostedWalletProviderRegistry.ts +8 -8
- package/src/wallet/node/providers/hosted/registry/__tests__/NodeHostedWalletProviderRegistry.spec.ts +4 -4
- package/src/wallet/node/providers/hosted/turnkey/TurnkeyHostedWalletProvider.ts +3 -10
- package/src/wallet/node/wallets/hosted/privy/PrivyWallet.ts +5 -17
- package/src/wallet/node/wallets/hosted/turnkey/TurnkeyWallet.ts +5 -17
- package/src/wallet/react/providers/hosted/dynamic/DynamicHostedWalletProvider.ts +7 -11
- package/src/wallet/react/providers/hosted/privy/PrivyHostedWalletProvider.ts +7 -11
- package/src/wallet/react/providers/hosted/turnkey/TurnkeyHostedWalletProvider.ts +7 -11
- package/src/wallet/react/providers/registry/ReactHostedWalletProviderRegistry.ts +23 -10
- package/src/wallet/react/providers/registry/__tests__/ReactHostedWalletProviderRegistry.spec.ts +6 -6
- package/src/wallet/react/wallets/hosted/dynamic/DynamicWallet.ts +10 -18
- package/src/wallet/react/wallets/hosted/dynamic/__mocks__/DynamicWalletMock.ts +2 -6
- package/src/wallet/react/wallets/hosted/privy/PrivyWallet.ts +10 -18
- package/src/wallet/react/wallets/hosted/turnkey/TurnkeyWallet.ts +10 -18
- package/dist/supported/tokens.d.ts +0 -25
- package/dist/supported/tokens.d.ts.map +0 -1
- package/dist/supported/tokens.js +0 -44
- package/dist/supported/tokens.js.map +0 -1
- package/dist/utils/permit2.d.ts +0 -46
- package/dist/utils/permit2.d.ts.map +0 -1
- package/dist/utils/permit2.js.map +0 -1
- package/dist/utils/permit2.test.d.ts +0 -2
- package/dist/utils/permit2.test.d.ts.map +0 -1
- package/dist/utils/permit2.test.js.map +0 -1
- package/src/supported/tokens.ts +0 -66
|
@@ -3,12 +3,15 @@ import { decodeFunctionData } from 'viem'
|
|
|
3
3
|
import { describe, expect, it, vi } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
+
buildApprovalTxIfNeeded,
|
|
7
|
+
buildErc20ApprovalTx,
|
|
6
8
|
buildPermit2ApprovalTx,
|
|
7
9
|
buildTokenApprovalTx,
|
|
8
10
|
checkPermit2Allowance,
|
|
9
11
|
checkTokenAllowance,
|
|
10
12
|
DEFAULT_PERMIT2_EXPIRY_SECONDS,
|
|
11
|
-
|
|
13
|
+
getApprovalDeficit,
|
|
14
|
+
} from '@/utils/approve.js'
|
|
12
15
|
|
|
13
16
|
const PERMIT2_ABI = [
|
|
14
17
|
{
|
|
@@ -140,3 +143,116 @@ describe('buildPermit2ApprovalTx', () => {
|
|
|
140
143
|
)
|
|
141
144
|
})
|
|
142
145
|
})
|
|
146
|
+
|
|
147
|
+
describe('buildErc20ApprovalTx', () => {
|
|
148
|
+
it('builds approval for exact amount', () => {
|
|
149
|
+
const tx = buildErc20ApprovalTx(TOKEN, SPENDER, 500000n)
|
|
150
|
+
|
|
151
|
+
expect(tx.to).toBe(TOKEN)
|
|
152
|
+
expect(tx.value).toBe(0n)
|
|
153
|
+
expect(tx.data).toMatch(/^0x/)
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
describe('getApprovalDeficit', () => {
|
|
158
|
+
it('returns 0n when allowance is sufficient', async () => {
|
|
159
|
+
const publicClient = {
|
|
160
|
+
readContract: vi.fn().mockResolvedValue(1000000n),
|
|
161
|
+
} as unknown as PublicClient
|
|
162
|
+
|
|
163
|
+
const deficit = await getApprovalDeficit({
|
|
164
|
+
publicClient,
|
|
165
|
+
token: TOKEN,
|
|
166
|
+
owner: OWNER,
|
|
167
|
+
spender: SPENDER,
|
|
168
|
+
amount: 500000n,
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
expect(deficit).toBe(0n)
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('returns deficit when allowance is insufficient', async () => {
|
|
175
|
+
const publicClient = {
|
|
176
|
+
readContract: vi.fn().mockResolvedValue(300000n),
|
|
177
|
+
} as unknown as PublicClient
|
|
178
|
+
|
|
179
|
+
const deficit = await getApprovalDeficit({
|
|
180
|
+
publicClient,
|
|
181
|
+
token: TOKEN,
|
|
182
|
+
owner: OWNER,
|
|
183
|
+
spender: SPENDER,
|
|
184
|
+
amount: 500000n,
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
expect(deficit).toBe(200000n)
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('returns full amount when allowance is zero', async () => {
|
|
191
|
+
const publicClient = {
|
|
192
|
+
readContract: vi.fn().mockResolvedValue(0n),
|
|
193
|
+
} as unknown as PublicClient
|
|
194
|
+
|
|
195
|
+
const deficit = await getApprovalDeficit({
|
|
196
|
+
publicClient,
|
|
197
|
+
token: TOKEN,
|
|
198
|
+
owner: OWNER,
|
|
199
|
+
spender: SPENDER,
|
|
200
|
+
amount: 500000n,
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
expect(deficit).toBe(500000n)
|
|
204
|
+
})
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
describe('buildApprovalTxIfNeeded', () => {
|
|
208
|
+
it('returns undefined when allowance is sufficient', async () => {
|
|
209
|
+
const publicClient = {
|
|
210
|
+
readContract: vi.fn().mockResolvedValue(1000000n),
|
|
211
|
+
} as unknown as PublicClient
|
|
212
|
+
|
|
213
|
+
const tx = await buildApprovalTxIfNeeded({
|
|
214
|
+
publicClient,
|
|
215
|
+
token: TOKEN,
|
|
216
|
+
owner: OWNER,
|
|
217
|
+
spender: SPENDER,
|
|
218
|
+
amount: 500000n,
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
expect(tx).toBeUndefined()
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
it('returns approval tx for the deficit only', async () => {
|
|
225
|
+
const publicClient = {
|
|
226
|
+
readContract: vi.fn().mockResolvedValue(300000n),
|
|
227
|
+
} as unknown as PublicClient
|
|
228
|
+
|
|
229
|
+
const tx = await buildApprovalTxIfNeeded({
|
|
230
|
+
publicClient,
|
|
231
|
+
token: TOKEN,
|
|
232
|
+
owner: OWNER,
|
|
233
|
+
spender: SPENDER,
|
|
234
|
+
amount: 500000n,
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
expect(tx).toBeDefined()
|
|
238
|
+
expect(tx!.to).toBe(TOKEN)
|
|
239
|
+
expect(tx!.value).toBe(0n)
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
it('returns approval for full amount when allowance is zero', async () => {
|
|
243
|
+
const publicClient = {
|
|
244
|
+
readContract: vi.fn().mockResolvedValue(0n),
|
|
245
|
+
} as unknown as PublicClient
|
|
246
|
+
|
|
247
|
+
const tx = await buildApprovalTxIfNeeded({
|
|
248
|
+
publicClient,
|
|
249
|
+
token: TOKEN,
|
|
250
|
+
owner: OWNER,
|
|
251
|
+
spender: SPENDER,
|
|
252
|
+
amount: 500000n,
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
expect(tx).toBeDefined()
|
|
256
|
+
expect(tx!.to).toBe(TOKEN)
|
|
257
|
+
})
|
|
258
|
+
})
|
|
@@ -75,25 +75,15 @@ export async function checkPermit2Allowance(params: {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
|
-
* Build ERC20 token approval transaction to Permit2
|
|
78
|
+
* Build ERC20 token approval transaction to Permit2.
|
|
79
|
+
* Uses maxUint256 — the Uniswap-canonical pattern.
|
|
80
|
+
* Permit2 is immutable with no owner; spending is scoped by its own allowance system.
|
|
79
81
|
*/
|
|
80
82
|
export function buildTokenApprovalTx(
|
|
81
83
|
token: Address,
|
|
82
84
|
permit2Address: Address,
|
|
83
85
|
): TransactionData {
|
|
84
|
-
|
|
85
|
-
abi: erc20Abi,
|
|
86
|
-
functionName: 'approve',
|
|
87
|
-
// ERC20 -> Permit2: maxUint256 is the Uniswap-canonical pattern.
|
|
88
|
-
// Permit2 is immutable with no owner — spending is scoped by its own allowance system.
|
|
89
|
-
args: [permit2Address, maxUint256],
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
to: token,
|
|
94
|
-
data,
|
|
95
|
-
value: 0n,
|
|
96
|
-
}
|
|
86
|
+
return buildErc20ApprovalTx(token, permit2Address, maxUint256)
|
|
97
87
|
}
|
|
98
88
|
|
|
99
89
|
/**
|
|
@@ -142,3 +132,66 @@ export async function checkTokenAllowance(params: {
|
|
|
142
132
|
args: [owner, spender],
|
|
143
133
|
})
|
|
144
134
|
}
|
|
135
|
+
|
|
136
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
137
|
+
// Generic ERC20 approval utilities
|
|
138
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Build an ERC20 approve transaction.
|
|
142
|
+
* @param token - ERC20 token address
|
|
143
|
+
* @param spender - Address to approve
|
|
144
|
+
* @param amount - Amount to approve
|
|
145
|
+
* @returns Transaction data for the approval
|
|
146
|
+
*/
|
|
147
|
+
export function buildErc20ApprovalTx(
|
|
148
|
+
token: Address,
|
|
149
|
+
spender: Address,
|
|
150
|
+
amount: bigint,
|
|
151
|
+
): TransactionData {
|
|
152
|
+
return {
|
|
153
|
+
to: token,
|
|
154
|
+
data: encodeFunctionData({
|
|
155
|
+
abi: erc20Abi,
|
|
156
|
+
functionName: 'approve',
|
|
157
|
+
args: [spender, amount],
|
|
158
|
+
}),
|
|
159
|
+
value: 0n,
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Compute how much additional ERC20 approval is needed.
|
|
165
|
+
* Returns 0n if current allowance is sufficient.
|
|
166
|
+
* @param params - Token, owner, spender, required amount, and public client
|
|
167
|
+
* @returns The deficit (required - current), or 0n if already sufficient
|
|
168
|
+
*/
|
|
169
|
+
export async function getApprovalDeficit(params: {
|
|
170
|
+
publicClient: PublicClient
|
|
171
|
+
token: Address
|
|
172
|
+
owner: Address
|
|
173
|
+
spender: Address
|
|
174
|
+
amount: bigint
|
|
175
|
+
}): Promise<bigint> {
|
|
176
|
+
const current = await checkTokenAllowance(params)
|
|
177
|
+
return current >= params.amount ? 0n : params.amount - current
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Build an ERC20 approval transaction only if needed, approving only the deficit.
|
|
182
|
+
* Checks the current on-chain allowance, returns undefined if already sufficient.
|
|
183
|
+
* @param params - Token, owner, spender, required amount, and public client
|
|
184
|
+
* @returns Approval transaction for the deficit amount, or undefined if allowance is sufficient
|
|
185
|
+
*/
|
|
186
|
+
export async function buildApprovalTxIfNeeded(params: {
|
|
187
|
+
publicClient: PublicClient
|
|
188
|
+
token: Address
|
|
189
|
+
owner: Address
|
|
190
|
+
spender: Address
|
|
191
|
+
amount: bigint
|
|
192
|
+
}): Promise<TransactionData | undefined> {
|
|
193
|
+
const deficit = await getApprovalDeficit(params)
|
|
194
|
+
return deficit > 0n
|
|
195
|
+
? buildErc20ApprovalTx(params.token, params.spender, deficit)
|
|
196
|
+
: undefined
|
|
197
|
+
}
|
package/src/utils/assets.ts
CHANGED
|
@@ -86,3 +86,17 @@ export function getAssetAddress(
|
|
|
86
86
|
}
|
|
87
87
|
return address
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get all non-native contract addresses for an asset across all chains, lowercased.
|
|
92
|
+
* @param asset - Asset to extract addresses from
|
|
93
|
+
* @returns Array of lowercased contract addresses
|
|
94
|
+
*/
|
|
95
|
+
export function getAllAssetAddresses(asset: Asset): string[] {
|
|
96
|
+
return Object.values(asset.address)
|
|
97
|
+
.filter(
|
|
98
|
+
(addr): addr is Exclude<typeof addr, undefined | 'native'> =>
|
|
99
|
+
addr !== undefined && addr !== 'native',
|
|
100
|
+
)
|
|
101
|
+
.map((addr) => addr.toLowerCase())
|
|
102
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { Address, PublicClient } from 'viem'
|
|
2
|
+
import { zeroAddress } from 'viem'
|
|
3
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
4
|
+
|
|
5
|
+
import { resolveAddress } from '@/utils/ens.js'
|
|
6
|
+
|
|
7
|
+
const REAL_ADDRESS = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045' as Address
|
|
8
|
+
const ZERO_ADDRESS = zeroAddress
|
|
9
|
+
|
|
10
|
+
function mockClient(
|
|
11
|
+
returnValue: Address | null,
|
|
12
|
+
rejects = false,
|
|
13
|
+
): PublicClient {
|
|
14
|
+
const getEnsAddress = rejects
|
|
15
|
+
? vi.fn().mockRejectedValue(new Error('network error'))
|
|
16
|
+
: vi.fn().mockResolvedValue(returnValue)
|
|
17
|
+
return { getEnsAddress } as unknown as PublicClient
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe('resolveAddress', () => {
|
|
21
|
+
describe('hex address input', () => {
|
|
22
|
+
it('returns a valid hex address as-is', async () => {
|
|
23
|
+
expect(await resolveAddress(REAL_ADDRESS)).toBe(REAL_ADDRESS)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('does not require a mainnet client for hex addresses', async () => {
|
|
27
|
+
await expect(resolveAddress(REAL_ADDRESS)).resolves.toBe(REAL_ADDRESS)
|
|
28
|
+
})
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
describe('ENS name input', () => {
|
|
32
|
+
it('resolves a valid ENS name', async () => {
|
|
33
|
+
const client = mockClient(REAL_ADDRESS)
|
|
34
|
+
const result = await resolveAddress('vitalik.eth', client)
|
|
35
|
+
expect(result).toBe(REAL_ADDRESS)
|
|
36
|
+
expect(client.getEnsAddress).toHaveBeenCalledWith({ name: 'vitalik.eth' })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('normalises the ENS name before resolving', async () => {
|
|
40
|
+
const client = mockClient(REAL_ADDRESS)
|
|
41
|
+
await resolveAddress('Vitalik.ETH', client)
|
|
42
|
+
expect(client.getEnsAddress).toHaveBeenCalledWith({ name: 'vitalik.eth' })
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('throws EnsNotConfiguredError when no mainnet client is provided', async () => {
|
|
46
|
+
const { EnsNotConfiguredError } = await import('@/ens/errors.js')
|
|
47
|
+
await expect(resolveAddress('vitalik.eth')).rejects.toThrow(
|
|
48
|
+
EnsNotConfiguredError,
|
|
49
|
+
)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('includes chain ID 1 in the error when no mainnet client provided', async () => {
|
|
53
|
+
await expect(resolveAddress('vitalik.eth')).rejects.toThrow('1')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('throws when ENS name cannot be resolved (returns null)', async () => {
|
|
57
|
+
const client = mockClient(null)
|
|
58
|
+
await expect(resolveAddress('unresolvable.eth', client)).rejects.toThrow(
|
|
59
|
+
'"unresolvable.eth" could not be resolved',
|
|
60
|
+
)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('throws when ENS name resolves to zero address', async () => {
|
|
64
|
+
const client = mockClient(ZERO_ADDRESS)
|
|
65
|
+
await expect(resolveAddress('zero.eth', client)).rejects.toThrow(
|
|
66
|
+
'zero address',
|
|
67
|
+
)
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('throws with RPC error label on network failure', async () => {
|
|
71
|
+
const client = mockClient(null, true)
|
|
72
|
+
await expect(resolveAddress('vitalik.eth', client)).rejects.toThrow(
|
|
73
|
+
'RPC error',
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('preserves the original cause on RPC failure', async () => {
|
|
78
|
+
const client = mockClient(null, true)
|
|
79
|
+
let caught: Error | undefined
|
|
80
|
+
try {
|
|
81
|
+
await resolveAddress('vitalik.eth', client)
|
|
82
|
+
} catch (e) {
|
|
83
|
+
caught = e as Error
|
|
84
|
+
}
|
|
85
|
+
expect(caught?.cause).toBeInstanceOf(Error)
|
|
86
|
+
expect((caught?.cause as Error).message).toBe('network error')
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
describe('invalid input', () => {
|
|
91
|
+
it('throws for ENS-shaped strings that fail normalisation', async () => {
|
|
92
|
+
// Has a dot so satisfies EnsName, but contains invalid ENS characters
|
|
93
|
+
await expect(
|
|
94
|
+
resolveAddress('not!valid.eth', {} as PublicClient),
|
|
95
|
+
).rejects.toThrow('Invalid address or ENS name')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('includes the invalid input in the error message', async () => {
|
|
99
|
+
await expect(
|
|
100
|
+
resolveAddress('!!bad!!.eth', {} as PublicClient),
|
|
101
|
+
).rejects.toThrow('"!!bad!!.eth"')
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
})
|
package/src/utils/ens.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Address, PublicClient } from 'viem'
|
|
2
|
+
import { isAddress, isAddressEqual, zeroAddress } from 'viem'
|
|
3
|
+
import { normalize } from 'viem/ens'
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
EnsNotConfiguredError,
|
|
7
|
+
EnsResolutionError,
|
|
8
|
+
EnsRpcError,
|
|
9
|
+
} from '@/ens/errors.js'
|
|
10
|
+
import type { EnsName } from '@/ens/types.js'
|
|
11
|
+
|
|
12
|
+
export { type EnsName, isEnsName } from '@/ens/types.js'
|
|
13
|
+
|
|
14
|
+
/** Resolves an ENS name or address to a checksummed hex Address, or returns undefined. */
|
|
15
|
+
export type RecipientResolver = (
|
|
16
|
+
recipient: Address | EnsName | undefined,
|
|
17
|
+
) => Promise<Address | undefined>
|
|
18
|
+
|
|
19
|
+
/** Pass-through resolver used when no ENS resolution is configured. Throws on ENS names. */
|
|
20
|
+
export const passthroughResolver: RecipientResolver = (r) => {
|
|
21
|
+
if (r !== undefined && !isAddress(r, { strict: false })) {
|
|
22
|
+
throw new Error(`ENS resolution is not configured; received "${r}"`)
|
|
23
|
+
}
|
|
24
|
+
return Promise.resolve(r as Address | undefined)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Low-level utility to resolve an ENS name or hex address to a checksummed hex address.
|
|
29
|
+
* Use this when you manage your own viem PublicClient (e.g. inside providers or scripts).
|
|
30
|
+
*
|
|
31
|
+
* If you have an {@link Actions} instance, prefer `actions.ens.getAddress()` instead —
|
|
32
|
+
* it handles client lookup and fallback automatically from your chain configuration.
|
|
33
|
+
*
|
|
34
|
+
* Hex addresses (0x...) are returned as-is after format validation.
|
|
35
|
+
* ENS names require a mainnet public client for on-chain resolution.
|
|
36
|
+
* @param input - Hex address (0x...) or ENS name (e.g. "vitalik.eth")
|
|
37
|
+
* @param mainnetClient - Public client connected to Ethereum mainnet (required for ENS names)
|
|
38
|
+
* @returns Resolved hex address
|
|
39
|
+
* @throws {EnsNotConfiguredError} If mainnet client is not provided
|
|
40
|
+
* @throws {EnsResolutionError} If the name is invalid or cannot be resolved
|
|
41
|
+
* @throws {EnsRpcError} If the RPC call fails
|
|
42
|
+
*/
|
|
43
|
+
export async function resolveAddress(
|
|
44
|
+
input: Address | EnsName,
|
|
45
|
+
mainnetClient?: PublicClient,
|
|
46
|
+
): Promise<Address> {
|
|
47
|
+
if (isAddress(input, { strict: false })) return input
|
|
48
|
+
|
|
49
|
+
if (!mainnetClient) throw new EnsNotConfiguredError()
|
|
50
|
+
|
|
51
|
+
const normalized = (() => {
|
|
52
|
+
try {
|
|
53
|
+
return normalize(input)
|
|
54
|
+
} catch (cause) {
|
|
55
|
+
throw new EnsResolutionError(
|
|
56
|
+
`Invalid address or ENS name: "${input}"`,
|
|
57
|
+
input,
|
|
58
|
+
{ cause },
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
})()
|
|
62
|
+
|
|
63
|
+
const resolved = await mainnetClient
|
|
64
|
+
.getEnsAddress({ name: normalized })
|
|
65
|
+
.catch((cause: unknown) => {
|
|
66
|
+
throw new EnsRpcError(
|
|
67
|
+
`ENS resolution failed for "${input}": RPC error`,
|
|
68
|
+
input,
|
|
69
|
+
{ cause },
|
|
70
|
+
)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
if (!resolved)
|
|
74
|
+
throw new EnsResolutionError(
|
|
75
|
+
`ENS name "${input}" could not be resolved`,
|
|
76
|
+
input,
|
|
77
|
+
)
|
|
78
|
+
if (isAddressEqual(resolved, zeroAddress)) {
|
|
79
|
+
throw new EnsResolutionError(
|
|
80
|
+
`ENS name "${input}" resolved to the zero address`,
|
|
81
|
+
input,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
return resolved
|
|
85
|
+
}
|