@across-protocol/sdk 4.1.63 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/arch/evm/BlockUtils.d.ts +15 -0
- package/dist/cjs/arch/evm/BlockUtils.js +218 -0
- package/dist/cjs/arch/evm/BlockUtils.js.map +1 -0
- package/dist/cjs/arch/evm/SpokeUtils.d.ts +1 -1
- package/dist/cjs/arch/evm/SpokeUtils.js +6 -5
- package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/cjs/arch/evm/index.d.ts +1 -0
- package/dist/cjs/arch/evm/index.js +1 -0
- package/dist/cjs/arch/evm/index.js.map +1 -1
- package/dist/cjs/arch/svm/SpokeUtils.d.ts +20 -0
- package/dist/cjs/arch/svm/SpokeUtils.js +449 -0
- package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -0
- package/dist/cjs/arch/svm/constants.d.ts +2 -0
- package/dist/cjs/arch/svm/constants.js +7 -0
- package/dist/cjs/arch/svm/constants.js.map +1 -0
- package/dist/cjs/arch/svm/eventsClient.d.ts +26 -0
- package/dist/cjs/arch/svm/eventsClient.js +253 -0
- package/dist/cjs/arch/svm/eventsClient.js.map +1 -0
- package/dist/cjs/arch/svm/index.d.ts +5 -1
- package/dist/cjs/arch/svm/index.js +6 -2
- package/dist/cjs/arch/svm/index.js.map +1 -1
- package/dist/cjs/{svm → arch/svm}/types.d.ts +9 -4
- package/dist/cjs/arch/svm/types.js.map +1 -0
- package/dist/cjs/arch/svm/utils.d.ts +18 -0
- package/dist/cjs/arch/svm/utils.js +212 -0
- package/dist/cjs/arch/svm/utils.js.map +1 -0
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +7 -7
- package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/BaseAbstractClient.d.ts +6 -5
- package/dist/cjs/clients/BaseAbstractClient.js +30 -19
- package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +15 -11
- package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +114 -114
- package/dist/cjs/clients/HubPoolClient.d.ts +4 -3
- package/dist/cjs/clients/HubPoolClient.js +18 -17
- package/dist/cjs/clients/HubPoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +23 -20
- package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +23 -0
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +172 -0
- package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -0
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -5
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +54 -57
- package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/SpokePoolClient/index.d.ts +3 -0
- package/dist/cjs/clients/SpokePoolClient/index.js +8 -1
- package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
- package/dist/cjs/clients/index.d.ts +1 -1
- package/dist/cjs/clients/index.js +2 -1
- package/dist/cjs/clients/index.js.map +1 -1
- package/dist/cjs/clients/mocks/MockConfigStoreClient.d.ts +1 -1
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js +2 -2
- package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockHubPoolClient.js +2 -2
- package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js +7 -4
- package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.d.ts +33 -0
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js +184 -0
- package/dist/cjs/clients/mocks/MockSvmCpiEventsClient.js.map +1 -0
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.d.ts +30 -0
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js +90 -0
- package/dist/cjs/clients/mocks/MockSvmSpokePoolClient.js.map +1 -0
- package/dist/cjs/clients/mocks/index.d.ts +2 -0
- package/dist/cjs/clients/mocks/index.js +2 -0
- package/dist/cjs/clients/mocks/index.js.map +1 -1
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
- package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/ethereum.d.ts +4 -4
- package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +3 -2
- package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/cjs/gasPriceOracle/adapters/polygon.d.ts +3 -3
- package/dist/cjs/gasPriceOracle/adapters/solana.d.ts +4 -0
- package/dist/cjs/gasPriceOracle/adapters/solana.js +43 -0
- package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -0
- package/dist/cjs/gasPriceOracle/index.d.ts +1 -1
- package/dist/cjs/gasPriceOracle/oracle.d.ts +4 -3
- package/dist/cjs/gasPriceOracle/oracle.js +16 -9
- package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
- package/dist/cjs/gasPriceOracle/types.d.ts +6 -1
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/SpokePool.d.ts +13 -0
- package/dist/cjs/interfaces/SpokePool.js.map +1 -1
- package/dist/cjs/providers/index.d.ts +1 -1
- package/dist/cjs/providers/index.js +1 -2
- package/dist/cjs/providers/index.js.map +1 -1
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.d.ts +5 -0
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js +21 -0
- package/dist/cjs/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -0
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.d.ts +5 -0
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js +20 -0
- package/dist/cjs/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -0
- package/dist/cjs/providers/mocks/MockSolanaRpcFactory.d.ts +13 -0
- package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js +76 -0
- package/dist/cjs/providers/mocks/MockSolanaRpcFactory.js.map +1 -0
- package/dist/cjs/providers/mocks/index.d.ts +4 -0
- package/dist/cjs/providers/mocks/index.js +8 -0
- package/dist/cjs/providers/mocks/index.js.map +1 -0
- package/dist/cjs/providers/{mockProvider.js → mocks/mockEthersProvider.js} +2 -2
- package/dist/cjs/providers/mocks/mockEthersProvider.js.map +1 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +10 -8
- package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +8 -2
- package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/index.d.ts +1 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/index.js.map +1 -1
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +37 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +171 -0
- package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -0
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.d.ts +2 -0
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js +9 -3
- package/dist/cjs/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/cjs/utils/AddressUtils.d.ts +9 -3
- package/dist/cjs/utils/AddressUtils.js +36 -6
- package/dist/cjs/utils/AddressUtils.js.map +1 -1
- package/dist/cjs/utils/ArrayUtils.d.ts +1 -0
- package/dist/cjs/utils/ArrayUtils.js +6 -1
- package/dist/cjs/utils/ArrayUtils.js.map +1 -1
- package/dist/cjs/utils/BlockFinder.d.ts +22 -0
- package/dist/cjs/utils/BlockFinder.js +10 -0
- package/dist/cjs/utils/BlockFinder.js.map +1 -0
- package/dist/cjs/utils/BlockUtils.d.ts +2 -27
- package/dist/cjs/utils/BlockUtils.js +2 -208
- package/dist/cjs/utils/BlockUtils.js.map +1 -1
- package/dist/cjs/utils/EventUtils.d.ts +4 -4
- package/dist/cjs/utils/EventUtils.js +7 -4
- package/dist/cjs/utils/EventUtils.js.map +1 -1
- package/dist/cjs/utils/JSONUtils.js +3 -0
- package/dist/cjs/utils/JSONUtils.js.map +1 -1
- package/dist/cjs/utils/NumberUtils.d.ts +1 -0
- package/dist/cjs/utils/NumberUtils.js +7 -1
- package/dist/cjs/utils/NumberUtils.js.map +1 -1
- package/dist/cjs/utils/SpokeUtils.js +5 -0
- package/dist/cjs/utils/SpokeUtils.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/esm/arch/evm/BlockUtils.d.ts +24 -0
- package/dist/esm/arch/evm/BlockUtils.js +250 -0
- package/dist/esm/arch/evm/BlockUtils.js.map +1 -0
- package/dist/esm/arch/evm/SpokeUtils.d.ts +1 -1
- package/dist/esm/arch/evm/SpokeUtils.js +6 -5
- package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
- package/dist/esm/arch/evm/index.d.ts +1 -0
- package/dist/esm/arch/evm/index.js +1 -0
- package/dist/esm/arch/evm/index.js.map +1 -1
- package/dist/esm/arch/svm/SpokeUtils.d.ts +122 -0
- package/dist/esm/arch/svm/SpokeUtils.js +566 -0
- package/dist/esm/arch/svm/SpokeUtils.js.map +1 -0
- package/dist/esm/arch/svm/constants.d.ts +2 -0
- package/dist/esm/arch/svm/constants.js +3 -0
- package/dist/esm/arch/svm/constants.js.map +1 -0
- package/dist/esm/arch/svm/eventsClient.d.ts +87 -0
- package/dist/esm/arch/svm/eventsClient.js +316 -0
- package/dist/esm/arch/svm/eventsClient.js.map +1 -0
- package/dist/esm/arch/svm/index.d.ts +5 -1
- package/dist/esm/arch/svm/index.js +5 -1
- package/dist/esm/arch/svm/index.js.map +1 -1
- package/dist/esm/{svm → arch/svm}/types.d.ts +9 -4
- package/dist/esm/arch/svm/types.js.map +1 -0
- package/dist/esm/arch/svm/utils.d.ts +63 -0
- package/dist/esm/arch/svm/utils.js +258 -0
- package/dist/esm/arch/svm/utils.js.map +1 -0
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +7 -7
- package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/BaseAbstractClient.d.ts +6 -5
- package/dist/esm/clients/BaseAbstractClient.js +30 -19
- package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js +17 -14
- package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +1 -1
- package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
- package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +114 -114
- package/dist/esm/clients/HubPoolClient.d.ts +4 -3
- package/dist/esm/clients/HubPoolClient.js +19 -18
- package/dist/esm/clients/HubPoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +23 -20
- package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +66 -0
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +225 -0
- package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -0
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +7 -7
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +57 -59
- package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
- package/dist/esm/clients/SpokePoolClient/index.d.ts +8 -0
- package/dist/esm/clients/SpokePoolClient/index.js +10 -0
- package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
- package/dist/esm/clients/index.d.ts +1 -1
- package/dist/esm/clients/index.js +1 -1
- package/dist/esm/clients/index.js.map +1 -1
- package/dist/esm/clients/mocks/MockConfigStoreClient.d.ts +1 -1
- package/dist/esm/clients/mocks/MockConfigStoreClient.js +2 -2
- package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockHubPoolClient.js +2 -2
- package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSpokePoolClient.js +8 -5
- package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.d.ts +33 -0
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js +183 -0
- package/dist/esm/clients/mocks/MockSvmCpiEventsClient.js.map +1 -0
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.d.ts +30 -0
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js +89 -0
- package/dist/esm/clients/mocks/MockSvmSpokePoolClient.js.map +1 -0
- package/dist/esm/clients/mocks/index.d.ts +2 -0
- package/dist/esm/clients/mocks/index.js +2 -0
- package/dist/esm/clients/mocks/index.js.map +1 -1
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
- package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/ethereum.d.ts +4 -4
- package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js +3 -2
- package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
- package/dist/esm/gasPriceOracle/adapters/polygon.d.ts +4 -4
- package/dist/esm/gasPriceOracle/adapters/polygon.js +1 -1
- package/dist/esm/gasPriceOracle/adapters/solana.d.ts +8 -0
- package/dist/esm/gasPriceOracle/adapters/solana.js +43 -0
- package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -0
- package/dist/esm/gasPriceOracle/index.d.ts +1 -1
- package/dist/esm/gasPriceOracle/oracle.d.ts +4 -3
- package/dist/esm/gasPriceOracle/oracle.js +18 -9
- package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
- package/dist/esm/gasPriceOracle/types.d.ts +6 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +0 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces/SpokePool.d.ts +13 -0
- package/dist/esm/interfaces/SpokePool.js.map +1 -1
- package/dist/esm/providers/index.d.ts +1 -1
- package/dist/esm/providers/index.js +1 -2
- package/dist/esm/providers/index.js.map +1 -1
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.d.ts +5 -0
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js +19 -0
- package/dist/esm/providers/mocks/MockCachedSolanaRpcFactory.js.map +1 -0
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.d.ts +5 -0
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js +18 -0
- package/dist/esm/providers/mocks/MockRateLimitedSolanaRpcFactory.js.map +1 -0
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.d.ts +13 -0
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.js +74 -0
- package/dist/esm/providers/mocks/MockSolanaRpcFactory.js.map +1 -0
- package/dist/esm/providers/mocks/index.d.ts +4 -0
- package/dist/esm/providers/mocks/index.js +5 -0
- package/dist/esm/providers/mocks/index.js.map +1 -0
- package/dist/esm/providers/{mockProvider.js → mocks/mockEthersProvider.js} +2 -2
- package/dist/esm/providers/mocks/mockEthersProvider.js.map +1 -0
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +10 -8
- package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js +11 -5
- package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/index.d.ts +1 -0
- package/dist/esm/relayFeeCalculator/chain-queries/index.js +1 -0
- package/dist/esm/relayFeeCalculator/chain-queries/index.js.map +1 -1
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +84 -0
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +216 -0
- package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -0
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.d.ts +12 -1
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js +9 -4
- package/dist/esm/relayFeeCalculator/relayFeeCalculator.js.map +1 -1
- package/dist/esm/utils/AddressUtils.d.ts +9 -3
- package/dist/esm/utils/AddressUtils.js +41 -6
- package/dist/esm/utils/AddressUtils.js.map +1 -1
- package/dist/esm/utils/ArrayUtils.d.ts +6 -0
- package/dist/esm/utils/ArrayUtils.js +9 -0
- package/dist/esm/utils/ArrayUtils.js.map +1 -1
- package/dist/esm/utils/BlockFinder.d.ts +22 -0
- package/dist/esm/utils/BlockFinder.js +7 -0
- package/dist/esm/utils/BlockFinder.js.map +1 -0
- package/dist/esm/utils/BlockUtils.d.ts +2 -36
- package/dist/esm/utils/BlockUtils.js +2 -243
- package/dist/esm/utils/BlockUtils.js.map +1 -1
- package/dist/esm/utils/EventUtils.d.ts +4 -4
- package/dist/esm/utils/EventUtils.js +7 -4
- package/dist/esm/utils/EventUtils.js.map +1 -1
- package/dist/esm/utils/JSONUtils.js +3 -0
- package/dist/esm/utils/JSONUtils.js.map +1 -1
- package/dist/esm/utils/NumberUtils.d.ts +7 -0
- package/dist/esm/utils/NumberUtils.js +11 -0
- package/dist/esm/utils/NumberUtils.js.map +1 -1
- package/dist/esm/utils/SpokeUtils.js +5 -0
- package/dist/esm/utils/SpokeUtils.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/types/arch/evm/BlockUtils.d.ts +25 -0
- package/dist/types/arch/evm/BlockUtils.d.ts.map +1 -0
- package/dist/types/arch/evm/SpokeUtils.d.ts +1 -1
- package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
- package/dist/types/arch/evm/index.d.ts +1 -0
- package/dist/types/arch/evm/index.d.ts.map +1 -1
- package/dist/types/arch/svm/SpokeUtils.d.ts +123 -0
- package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -0
- package/dist/types/arch/svm/constants.d.ts +3 -0
- package/dist/types/arch/svm/constants.d.ts.map +1 -0
- package/dist/types/arch/svm/eventsClient.d.ts +88 -0
- package/dist/types/arch/svm/eventsClient.d.ts.map +1 -0
- package/dist/types/arch/svm/index.d.ts +5 -1
- package/dist/types/arch/svm/index.d.ts.map +1 -1
- package/dist/types/{svm → arch/svm}/types.d.ts +9 -4
- package/dist/types/arch/svm/types.d.ts.map +1 -0
- package/dist/types/arch/svm/utils.d.ts +64 -0
- package/dist/types/arch/svm/utils.d.ts.map +1 -0
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
- package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/BaseAbstractClient.d.ts +6 -5
- package/dist/types/clients/BaseAbstractClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +114 -114
- package/dist/types/clients/HubPoolClient.d.ts +4 -3
- package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
- package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +67 -0
- package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts.map +1 -0
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +7 -7
- package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/SpokePoolClient/index.d.ts +8 -0
- package/dist/types/clients/SpokePoolClient/index.d.ts.map +1 -1
- package/dist/types/clients/index.d.ts +1 -1
- package/dist/types/clients/index.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts +1 -1
- package/dist/types/clients/mocks/MockConfigStoreClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
- package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts +34 -0
- package/dist/types/clients/mocks/MockSvmCpiEventsClient.d.ts.map +1 -0
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts +31 -0
- package/dist/types/clients/mocks/MockSvmSpokePoolClient.d.ts.map +1 -0
- package/dist/types/clients/mocks/index.d.ts +2 -0
- package/dist/types/clients/mocks/index.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
- package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/ethereum.d.ts +4 -4
- package/dist/types/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/polygon.d.ts +4 -4
- package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/adapters/solana.d.ts +9 -0
- package/dist/types/gasPriceOracle/adapters/solana.d.ts.map +1 -0
- package/dist/types/gasPriceOracle/index.d.ts +1 -1
- package/dist/types/gasPriceOracle/index.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/oracle.d.ts +4 -3
- package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
- package/dist/types/gasPriceOracle/types.d.ts +6 -1
- package/dist/types/gasPriceOracle/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/interfaces/SpokePool.d.ts +13 -0
- package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
- package/dist/types/providers/index.d.ts +1 -1
- package/dist/types/providers/index.d.ts.map +1 -1
- package/dist/types/providers/mocks/MockCachedSolanaRpcFactory.d.ts +6 -0
- package/dist/types/providers/mocks/MockCachedSolanaRpcFactory.d.ts.map +1 -0
- package/dist/types/providers/mocks/MockRateLimitedSolanaRpcFactory.d.ts +6 -0
- package/dist/types/providers/mocks/MockRateLimitedSolanaRpcFactory.d.ts.map +1 -0
- package/dist/types/providers/mocks/MockSolanaRpcFactory.d.ts +14 -0
- package/dist/types/providers/mocks/MockSolanaRpcFactory.d.ts.map +1 -0
- package/dist/types/providers/mocks/index.d.ts +5 -0
- package/dist/types/providers/mocks/index.d.ts.map +1 -0
- package/dist/types/providers/{mockProvider.d.ts → mocks/mockEthersProvider.d.ts} +1 -1
- package/dist/types/providers/mocks/mockEthersProvider.d.ts.map +1 -0
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
- package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/index.d.ts +1 -0
- package/dist/types/relayFeeCalculator/chain-queries/index.d.ts.map +1 -1
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +85 -0
- package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -0
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts +12 -1
- package/dist/types/relayFeeCalculator/relayFeeCalculator.d.ts.map +1 -1
- package/dist/types/utils/AddressUtils.d.ts +9 -3
- package/dist/types/utils/AddressUtils.d.ts.map +1 -1
- package/dist/types/utils/ArrayUtils.d.ts +6 -0
- package/dist/types/utils/ArrayUtils.d.ts.map +1 -1
- package/dist/types/utils/BlockFinder.d.ts +23 -0
- package/dist/types/utils/BlockFinder.d.ts.map +1 -0
- package/dist/types/utils/BlockUtils.d.ts +2 -36
- package/dist/types/utils/BlockUtils.d.ts.map +1 -1
- package/dist/types/utils/EventUtils.d.ts +4 -4
- package/dist/types/utils/EventUtils.d.ts.map +1 -1
- package/dist/types/utils/JSONUtils.d.ts.map +1 -1
- package/dist/types/utils/NumberUtils.d.ts +7 -0
- package/dist/types/utils/NumberUtils.d.ts.map +1 -1
- package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/arch/evm/BlockUtils.ts +209 -0
- package/src/arch/evm/SpokeUtils.ts +5 -5
- package/src/arch/evm/index.ts +1 -0
- package/src/arch/svm/SpokeUtils.ts +581 -0
- package/src/arch/svm/constants.ts +2 -0
- package/src/arch/svm/eventsClient.ts +342 -0
- package/src/arch/svm/index.ts +5 -1
- package/src/{svm → arch/svm}/types.ts +21 -4
- package/src/arch/svm/utils.ts +233 -0
- package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -7
- package/src/clients/BaseAbstractClient.ts +20 -13
- package/src/clients/BundleDataClient/BundleDataClient.ts +28 -19
- package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +1 -1
- package/src/clients/HubPoolClient.ts +19 -19
- package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +23 -21
- package/src/clients/SpokePoolClient/SVMSpokePoolClient.ts +268 -0
- package/src/clients/SpokePoolClient/SpokePoolClient.ts +50 -59
- package/src/clients/SpokePoolClient/index.ts +11 -0
- package/src/clients/index.ts +1 -1
- package/src/clients/mocks/MockConfigStoreClient.ts +2 -2
- package/src/clients/mocks/MockHubPoolClient.ts +2 -2
- package/src/clients/mocks/MockSpokePoolClient.ts +9 -4
- package/src/clients/mocks/MockSvmCpiEventsClient.ts +226 -0
- package/src/clients/mocks/MockSvmSpokePoolClient.ts +119 -0
- package/src/clients/mocks/index.ts +2 -0
- package/src/constants.ts +1 -0
- package/src/gasPriceOracle/adapters/arbitrum.ts +5 -2
- package/src/gasPriceOracle/adapters/ethereum.ts +7 -4
- package/src/gasPriceOracle/adapters/linea-viem.ts +3 -1
- package/src/gasPriceOracle/adapters/polygon.ts +6 -6
- package/src/gasPriceOracle/adapters/solana.ts +45 -0
- package/src/gasPriceOracle/index.ts +1 -1
- package/src/gasPriceOracle/oracle.ts +20 -4
- package/src/gasPriceOracle/types.ts +7 -1
- package/src/index.ts +0 -1
- package/src/interfaces/SpokePool.ts +14 -0
- package/src/providers/index.ts +1 -1
- package/src/providers/mocks/MockCachedSolanaRpcFactory.ts +15 -0
- package/src/providers/mocks/MockRateLimitedSolanaRpcFactory.ts +14 -0
- package/src/providers/mocks/MockSolanaRpcFactory.ts +55 -0
- package/src/providers/mocks/index.ts +4 -0
- package/src/providers/{mockProvider.ts → mocks/mockEthersProvider.ts} +1 -1
- package/src/relayFeeCalculator/chain-queries/baseQuery.ts +11 -9
- package/src/relayFeeCalculator/chain-queries/factory.ts +24 -8
- package/src/relayFeeCalculator/chain-queries/index.ts +1 -0
- package/src/relayFeeCalculator/chain-queries/svmQuery.ts +225 -0
- package/src/relayFeeCalculator/relayFeeCalculator.ts +15 -3
- package/src/utils/AddressUtils.ts +49 -6
- package/src/utils/ArrayUtils.ts +12 -0
- package/src/utils/BlockFinder.ts +26 -0
- package/src/utils/BlockUtils.ts +5 -215
- package/src/utils/EventUtils.ts +11 -11
- package/src/utils/JSONUtils.ts +2 -0
- package/src/utils/NumberUtils.ts +10 -0
- package/src/utils/SpokeUtils.ts +7 -3
- package/src/utils/index.ts +1 -0
- package/dist/cjs/providers/mockProvider.js.map +0 -1
- package/dist/cjs/svm/eventsClient.d.ts +0 -15
- package/dist/cjs/svm/eventsClient.js +0 -157
- package/dist/cjs/svm/eventsClient.js.map +0 -1
- package/dist/cjs/svm/index.d.ts +0 -3
- package/dist/cjs/svm/index.js +0 -8
- package/dist/cjs/svm/index.js.map +0 -1
- package/dist/cjs/svm/types.js.map +0 -1
- package/dist/cjs/svm/utils/events.d.ts +0 -8
- package/dist/cjs/svm/utils/events.js +0 -47
- package/dist/cjs/svm/utils/events.js.map +0 -1
- package/dist/cjs/svm/utils/helpers.d.ts +0 -2
- package/dist/cjs/svm/utils/helpers.js +0 -19
- package/dist/cjs/svm/utils/helpers.js.map +0 -1
- package/dist/cjs/svm/utils/index.d.ts +0 -1
- package/dist/cjs/svm/utils/index.js +0 -5
- package/dist/cjs/svm/utils/index.js.map +0 -1
- package/dist/esm/providers/mockProvider.js.map +0 -1
- package/dist/esm/svm/eventsClient.d.ts +0 -51
- package/dist/esm/svm/eventsClient.js +0 -195
- package/dist/esm/svm/eventsClient.js.map +0 -1
- package/dist/esm/svm/index.d.ts +0 -3
- package/dist/esm/svm/index.js +0 -5
- package/dist/esm/svm/index.js.map +0 -1
- package/dist/esm/svm/types.js.map +0 -1
- package/dist/esm/svm/utils/events.d.ts +0 -17
- package/dist/esm/svm/utils/events.js +0 -55
- package/dist/esm/svm/utils/events.js.map +0 -1
- package/dist/esm/svm/utils/helpers.d.ts +0 -5
- package/dist/esm/svm/utils/helpers.js +0 -18
- package/dist/esm/svm/utils/helpers.js.map +0 -1
- package/dist/esm/svm/utils/index.d.ts +0 -1
- package/dist/esm/svm/utils/index.js +0 -2
- package/dist/esm/svm/utils/index.js.map +0 -1
- package/dist/types/providers/mockProvider.d.ts.map +0 -1
- package/dist/types/svm/eventsClient.d.ts +0 -52
- package/dist/types/svm/eventsClient.d.ts.map +0 -1
- package/dist/types/svm/index.d.ts +0 -4
- package/dist/types/svm/index.d.ts.map +0 -1
- package/dist/types/svm/types.d.ts.map +0 -1
- package/dist/types/svm/utils/events.d.ts +0 -18
- package/dist/types/svm/utils/events.d.ts.map +0 -1
- package/dist/types/svm/utils/helpers.d.ts +0 -6
- package/dist/types/svm/utils/helpers.d.ts.map +0 -1
- package/dist/types/svm/utils/index.d.ts +0 -2
- package/dist/types/svm/utils/index.d.ts.map +0 -1
- package/src/svm/eventsClient.ts +0 -199
- package/src/svm/index.ts +0 -3
- package/src/svm/utils/events.ts +0 -58
- package/src/svm/utils/helpers.ts +0 -9
- package/src/svm/utils/index.ts +0 -1
- /package/dist/cjs/{svm → arch/svm}/types.js +0 -0
- /package/dist/cjs/providers/{mockProvider.d.ts → mocks/mockEthersProvider.d.ts} +0 -0
- /package/dist/esm/{svm → arch/svm}/types.js +0 -0
- /package/dist/esm/providers/{mockProvider.d.ts → mocks/mockEthersProvider.d.ts} +0 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CachedSolanaRpcFactory } from "..";
|
|
2
|
+
import { MockRateLimitedSolanaRpcFactory } from "./MockRateLimitedSolanaRpcFactory";
|
|
3
|
+
|
|
4
|
+
// Creates mocked cached Solana RPC factory by using the mocked Solana RPC factory.
|
|
5
|
+
export class MockCachedSolanaRpcFactory extends CachedSolanaRpcFactory {
|
|
6
|
+
constructor(
|
|
7
|
+
mockRateLimitedSolanaRpcFactory: MockRateLimitedSolanaRpcFactory,
|
|
8
|
+
...cachedConstructorParams: ConstructorParameters<typeof CachedSolanaRpcFactory>
|
|
9
|
+
) {
|
|
10
|
+
super(...cachedConstructorParams);
|
|
11
|
+
|
|
12
|
+
this.rateLimitedTransport = mockRateLimitedSolanaRpcFactory.createTransport();
|
|
13
|
+
this.rateLimitedRpcClient = mockRateLimitedSolanaRpcFactory.createRpcClient();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RateLimitedSolanaRpcFactory } from "..";
|
|
2
|
+
import { MockSolanaRpcFactory } from "./MockSolanaRpcFactory";
|
|
3
|
+
|
|
4
|
+
// Creates mocked rate limited Solana RPC factory by using the mocked Solana RPC factory.
|
|
5
|
+
export class MockRateLimitedSolanaRpcFactory extends RateLimitedSolanaRpcFactory {
|
|
6
|
+
constructor(
|
|
7
|
+
mockSolanaRpcFactory: MockSolanaRpcFactory,
|
|
8
|
+
...rateLimitedConstructorParams: ConstructorParameters<typeof RateLimitedSolanaRpcFactory>
|
|
9
|
+
) {
|
|
10
|
+
super(...rateLimitedConstructorParams);
|
|
11
|
+
|
|
12
|
+
this.defaultTransport = mockSolanaRpcFactory.createTransport();
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { RpcResponse, RpcTransport } from "@solana/kit";
|
|
2
|
+
import { SolanaClusterRpcFactory } from "../solana";
|
|
3
|
+
|
|
4
|
+
type CachedResponse = { result: unknown } | { error: unknown } | { throwError: string };
|
|
5
|
+
|
|
6
|
+
// Exposes mocked RPC transport for Solana in the SolanaClusterRpcFactory class.
|
|
7
|
+
export class MockSolanaRpcFactory extends SolanaClusterRpcFactory {
|
|
8
|
+
private responseTime: number = 10; // in milliseconds
|
|
9
|
+
private responses: Map<string, CachedResponse> = new Map();
|
|
10
|
+
|
|
11
|
+
constructor(...clusterConstructorParams: ConstructorParameters<typeof SolanaClusterRpcFactory>) {
|
|
12
|
+
super(...clusterConstructorParams);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public createTransport(): RpcTransport {
|
|
16
|
+
return <TResponse>(...args: Parameters<RpcTransport>): Promise<TResponse> => {
|
|
17
|
+
return this.createMockRpcTransport()<TResponse>(...args);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public setResult(method: string, params: unknown[], result: unknown) {
|
|
22
|
+
const requestKey = JSON.stringify({ method, params });
|
|
23
|
+
this.responses.set(requestKey, { result });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public setError(method: string, params: unknown[], error: unknown) {
|
|
27
|
+
const requestKey = JSON.stringify({ method, params });
|
|
28
|
+
this.responses.set(requestKey, { error });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public setThrow(method: string, params: unknown[], throwError: string) {
|
|
32
|
+
const requestKey = JSON.stringify({ method, params });
|
|
33
|
+
this.responses.set(requestKey, { throwError });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public setResponseTime(responseTime: number) {
|
|
37
|
+
this.responseTime = responseTime;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private createMockRpcTransport(): RpcTransport {
|
|
41
|
+
return async <TResponse>({ payload }: Parameters<RpcTransport>[0]): Promise<RpcResponse<TResponse>> => {
|
|
42
|
+
const { method, params } = payload as { method: string; params?: unknown[] };
|
|
43
|
+
const requestKey = JSON.stringify({ method, params });
|
|
44
|
+
let jsonRpcResponse = this.responses.get(requestKey);
|
|
45
|
+
if (jsonRpcResponse === undefined) {
|
|
46
|
+
const requestKeyWithoutParams = JSON.stringify({ method, params: [] });
|
|
47
|
+
jsonRpcResponse = this.responses.get(requestKeyWithoutParams);
|
|
48
|
+
if (jsonRpcResponse === undefined) jsonRpcResponse = { result: null };
|
|
49
|
+
}
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, this.responseTime));
|
|
51
|
+
if ("throwError" in jsonRpcResponse) throw new Error(jsonRpcResponse.throwError);
|
|
52
|
+
return jsonRpcResponse as TResponse;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BigNumber, providers } from "ethers";
|
|
2
2
|
import { Block, BlockTag, FeeData, TransactionResponse } from "@ethersproject/abstract-provider";
|
|
3
|
-
import { bnZero } from "
|
|
3
|
+
import { bnZero } from "../../utils/BigNumberUtils";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @notice Class used to test GasPriceOracle which makes ethers provider calls to the following implemented
|
|
@@ -3,7 +3,7 @@ import { isL2Provider as isOptimismL2Provider } from "@eth-optimism/sdk/dist/l2-
|
|
|
3
3
|
|
|
4
4
|
import { PopulatedTransaction, providers, VoidSigner } from "ethers";
|
|
5
5
|
import { Coingecko } from "../../coingecko";
|
|
6
|
-
import { CHAIN_IDs
|
|
6
|
+
import { CHAIN_IDs } from "../../constants";
|
|
7
7
|
import { Deposit } from "../../interfaces";
|
|
8
8
|
import { SpokePool, SpokePool__factory } from "../../typechain";
|
|
9
9
|
import { populateV3Relay } from "../../arch/evm";
|
|
@@ -17,12 +17,12 @@ import {
|
|
|
17
17
|
fixedPointAdjustment,
|
|
18
18
|
} from "../../utils";
|
|
19
19
|
import assert from "assert";
|
|
20
|
-
import { Logger, QueryInterface } from "../relayFeeCalculator";
|
|
20
|
+
import { Logger, QueryInterface, getDefaultSimulatedRelayerAddress } from "../relayFeeCalculator";
|
|
21
21
|
import { Transport } from "viem";
|
|
22
|
-
import { getGasPriceEstimate } from "../../gasPriceOracle
|
|
22
|
+
import { getGasPriceEstimate, EvmGasPriceEstimate } from "../../gasPriceOracle";
|
|
23
23
|
type Provider = providers.Provider;
|
|
24
24
|
type OptimismProvider = L2Provider<Provider>;
|
|
25
|
-
type SymbolMappingType = Record<
|
|
25
|
+
export type SymbolMappingType = Record<
|
|
26
26
|
string,
|
|
27
27
|
{
|
|
28
28
|
addresses: Record<number, string>;
|
|
@@ -72,7 +72,7 @@ export class QueryBase implements QueryInterface {
|
|
|
72
72
|
*/
|
|
73
73
|
async getGasCosts(
|
|
74
74
|
deposit: Omit<Deposit, "messageHash">,
|
|
75
|
-
relayer =
|
|
75
|
+
relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
76
76
|
options: Partial<{
|
|
77
77
|
gasPrice: BigNumberish;
|
|
78
78
|
gasUnits: BigNumberish;
|
|
@@ -122,7 +122,7 @@ export class QueryBase implements QueryInterface {
|
|
|
122
122
|
*/
|
|
123
123
|
getUnsignedTxFromDeposit(
|
|
124
124
|
deposit: Omit<Deposit, "messageHash">,
|
|
125
|
-
relayer =
|
|
125
|
+
relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
126
126
|
): Promise<PopulatedTransaction> {
|
|
127
127
|
return populateV3Relay(this.spokePool, deposit, relayer);
|
|
128
128
|
}
|
|
@@ -135,7 +135,7 @@ export class QueryBase implements QueryInterface {
|
|
|
135
135
|
*/
|
|
136
136
|
async getNativeGasCost(
|
|
137
137
|
deposit: Omit<Deposit, "messageHash">,
|
|
138
|
-
relayer =
|
|
138
|
+
relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
139
139
|
): Promise<BigNumber> {
|
|
140
140
|
const unsignedTx = await this.getUnsignedTxFromDeposit(deposit, relayer);
|
|
141
141
|
const voidSigner = new VoidSigner(relayer, this.provider);
|
|
@@ -152,7 +152,7 @@ export class QueryBase implements QueryInterface {
|
|
|
152
152
|
*/
|
|
153
153
|
async getOpStackL1DataFee(
|
|
154
154
|
unsignedTx: PopulatedTransaction,
|
|
155
|
-
relayer =
|
|
155
|
+
relayer = getDefaultSimulatedRelayerAddress(unsignedTx.chainId),
|
|
156
156
|
options: Partial<{
|
|
157
157
|
opStackL2GasUnits: BigNumberish;
|
|
158
158
|
opStackL1DataFeeMultiplier: BigNumber;
|
|
@@ -213,7 +213,9 @@ export class QueryBase implements QueryInterface {
|
|
|
213
213
|
? Promise.resolve({ maxFeePerGas: _gasPrice })
|
|
214
214
|
: getGasPriceEstimate(provider, { chainId, baseFeeMultiplier, priorityFeeMultiplier, transport, unsignedTx }),
|
|
215
215
|
] as const;
|
|
216
|
-
const [nativeGasCost,
|
|
216
|
+
const [nativeGasCost, _gasPriceEstimate] = await Promise.all(queries);
|
|
217
|
+
// It should be safe to cast to an EvmGasPriceEstimate here since QueryBase is only used for EVM chains.
|
|
218
|
+
const gasPrice = (_gasPriceEstimate as EvmGasPriceEstimate).maxFeePerGas;
|
|
217
219
|
assert(nativeGasCost.gt(bnZero), "Gas cost should not be 0");
|
|
218
220
|
let tokenGasCost: BigNumber;
|
|
219
221
|
|
|
@@ -3,11 +3,13 @@ import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";
|
|
|
3
3
|
import { getDeployedAddress } from "@across-protocol/contracts";
|
|
4
4
|
import { asL2Provider } from "@eth-optimism/sdk";
|
|
5
5
|
import { providers } from "ethers";
|
|
6
|
-
import {
|
|
7
|
-
import { chainIsOPStack, isDefined } from "../../utils";
|
|
6
|
+
import { CUSTOM_GAS_TOKENS } from "../../constants";
|
|
7
|
+
import { chainIsOPStack, isDefined, chainIsSvm, SvmAddress } from "../../utils";
|
|
8
8
|
import { QueryBase } from "./baseQuery";
|
|
9
|
-
import {
|
|
9
|
+
import { SVMProvider as svmProvider } from "../../arch/svm";
|
|
10
|
+
import { DEFAULT_LOGGER, getDefaultSimulatedRelayerAddress, Logger } from "../relayFeeCalculator";
|
|
10
11
|
import { CustomGasTokenQueries } from "./customGasToken";
|
|
12
|
+
import { SvmQuery } from "./svmQuery";
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Some chains have a fixed gas price that is applied to the gas estimates. We should override
|
|
@@ -20,21 +22,21 @@ const fixedGasPrice = {
|
|
|
20
22
|
export class QueryBase__factory {
|
|
21
23
|
static create(
|
|
22
24
|
chainId: number,
|
|
23
|
-
provider: providers.Provider,
|
|
25
|
+
provider: providers.Provider | svmProvider,
|
|
24
26
|
symbolMapping = TOKEN_SYMBOLS_MAP,
|
|
25
27
|
spokePoolAddress = getDeployedAddress("SpokePool", chainId),
|
|
26
|
-
simulatedRelayerAddress =
|
|
28
|
+
simulatedRelayerAddress = getDefaultSimulatedRelayerAddress(chainId),
|
|
27
29
|
coingeckoProApiKey?: string,
|
|
28
30
|
logger: Logger = DEFAULT_LOGGER,
|
|
29
31
|
coingeckoBaseCurrency = "eth"
|
|
30
|
-
): QueryBase {
|
|
32
|
+
): QueryBase | SvmQuery {
|
|
31
33
|
assert(isDefined(spokePoolAddress));
|
|
32
34
|
|
|
33
35
|
const customGasTokenSymbol = CUSTOM_GAS_TOKENS[chainId];
|
|
34
36
|
if (customGasTokenSymbol) {
|
|
35
37
|
return new CustomGasTokenQueries({
|
|
36
38
|
queryBaseArgs: [
|
|
37
|
-
provider,
|
|
39
|
+
provider as providers.Provider,
|
|
38
40
|
symbolMapping,
|
|
39
41
|
spokePoolAddress,
|
|
40
42
|
simulatedRelayerAddress,
|
|
@@ -46,9 +48,23 @@ export class QueryBase__factory {
|
|
|
46
48
|
customGasTokenSymbol,
|
|
47
49
|
});
|
|
48
50
|
}
|
|
51
|
+
if (chainIsSvm(chainId)) {
|
|
52
|
+
return new SvmQuery(
|
|
53
|
+
provider as svmProvider,
|
|
54
|
+
symbolMapping,
|
|
55
|
+
SvmAddress.from(spokePoolAddress),
|
|
56
|
+
SvmAddress.from(simulatedRelayerAddress),
|
|
57
|
+
logger,
|
|
58
|
+
coingeckoProApiKey,
|
|
59
|
+
fixedGasPrice[chainId],
|
|
60
|
+
coingeckoBaseCurrency
|
|
61
|
+
);
|
|
62
|
+
}
|
|
49
63
|
|
|
50
64
|
// For OPStack chains, we need to wrap the provider in an L2Provider
|
|
51
|
-
provider = chainIsOPStack(chainId)
|
|
65
|
+
provider = chainIsOPStack(chainId)
|
|
66
|
+
? asL2Provider(provider as providers.Provider)
|
|
67
|
+
: (provider as providers.Provider);
|
|
52
68
|
|
|
53
69
|
return new QueryBase(
|
|
54
70
|
provider,
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { pipe } from "@solana/functional";
|
|
2
|
+
import { Coingecko } from "../../coingecko";
|
|
3
|
+
import { SymbolMappingType } from "./";
|
|
4
|
+
import { CHAIN_IDs } from "../../constants";
|
|
5
|
+
import { Deposit } from "../../interfaces";
|
|
6
|
+
import { getGasPriceEstimate, SvmGasPriceEstimate } from "../../gasPriceOracle";
|
|
7
|
+
import {
|
|
8
|
+
BigNumberish,
|
|
9
|
+
TransactionCostEstimate,
|
|
10
|
+
BigNumber,
|
|
11
|
+
SvmAddress,
|
|
12
|
+
toBN,
|
|
13
|
+
isDefined,
|
|
14
|
+
toAddressType,
|
|
15
|
+
} from "../../utils";
|
|
16
|
+
import { getDefaultSimulatedRelayerAddress, Logger, QueryInterface } from "../relayFeeCalculator";
|
|
17
|
+
import {
|
|
18
|
+
fillRelayInstruction,
|
|
19
|
+
createApproveInstruction,
|
|
20
|
+
createTokenAccountsInstruction,
|
|
21
|
+
SVMProvider,
|
|
22
|
+
SolanaVoidSigner,
|
|
23
|
+
getAssociatedTokenAddress,
|
|
24
|
+
} from "../../arch/svm";
|
|
25
|
+
import {
|
|
26
|
+
createTransactionMessage,
|
|
27
|
+
setTransactionMessageFeePayer,
|
|
28
|
+
setTransactionMessageLifetimeUsingBlockhash,
|
|
29
|
+
appendTransactionMessageInstructions,
|
|
30
|
+
getComputeUnitEstimateForTransactionMessageFactory,
|
|
31
|
+
fetchEncodedAccount,
|
|
32
|
+
IInstruction,
|
|
33
|
+
} from "@solana/kit";
|
|
34
|
+
import { TOKEN_PROGRAM_ADDRESS, getMintSize, getInitializeMintInstruction, fetchMint } from "@solana-program/token";
|
|
35
|
+
import { getCreateAccountInstruction } from "@solana-program/system";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A special QueryBase implementation for SVM used for querying gas costs, token prices, and decimals of various tokens
|
|
39
|
+
* on Solana.
|
|
40
|
+
*/
|
|
41
|
+
export class SvmQuery implements QueryInterface {
|
|
42
|
+
protected computeUnitEstimator;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Instantiates a SvmQuery instance
|
|
46
|
+
* @param provider A valid solana/kit rpc client.
|
|
47
|
+
* @param symbolMapping A mapping to valid ERC20 tokens and their respective characteristics
|
|
48
|
+
* @param spokePoolAddress The valid address of the Spoke Pool deployment
|
|
49
|
+
* @param simulatedRelayerAddress The address that these queries will reference as the sender. Note: This address must be approved for USDC
|
|
50
|
+
* @param logger A logging utility to report logs
|
|
51
|
+
* @param coingeckoProApiKey An optional CoinGecko API key that links to a PRO account
|
|
52
|
+
* @param fixedGasPrice Overrides the gas price with a fixed value. Note: primarily used for the Boba blockchain
|
|
53
|
+
* @param coingeckoBaseCurrency The basis currency that CoinGecko will use to resolve pricing
|
|
54
|
+
*/
|
|
55
|
+
constructor(
|
|
56
|
+
readonly provider: SVMProvider,
|
|
57
|
+
readonly symbolMapping: SymbolMappingType,
|
|
58
|
+
readonly spokePoolAddress: SvmAddress,
|
|
59
|
+
readonly simulatedRelayerAddress: SvmAddress,
|
|
60
|
+
readonly logger: Logger,
|
|
61
|
+
readonly coingeckoProApiKey?: string,
|
|
62
|
+
readonly fixedGasPrice?: BigNumberish,
|
|
63
|
+
readonly coingeckoBaseCurrency: string = "eth"
|
|
64
|
+
) {
|
|
65
|
+
this.computeUnitEstimator = getComputeUnitEstimateForTransactionMessageFactory({
|
|
66
|
+
rpc: provider,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves the current gas costs of performing a fillRelay contract at the referenced SpokePool.
|
|
72
|
+
* @param deposit V3 deposit instance.
|
|
73
|
+
* @param relayerAddress Relayer address to simulate with.
|
|
74
|
+
* @param options
|
|
75
|
+
* @param options.gasPrice Optional gas price to use for the simulation.
|
|
76
|
+
* @param options.gasUnits Optional gas units to use for the simulation.
|
|
77
|
+
* @param options.transport Optional transport object for custom gas price retrieval.
|
|
78
|
+
* @returns The gas estimate for this function call (multiplied with the optional buffer).
|
|
79
|
+
*/
|
|
80
|
+
async getGasCosts(
|
|
81
|
+
deposit: Omit<Deposit, "messageHash">,
|
|
82
|
+
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
83
|
+
options: Partial<{
|
|
84
|
+
gasPrice: BigNumberish;
|
|
85
|
+
gasUnits: BigNumberish;
|
|
86
|
+
baseFeeMultiplier: BigNumber;
|
|
87
|
+
priorityFeeMultiplier: BigNumber;
|
|
88
|
+
}> = {}
|
|
89
|
+
): Promise<TransactionCostEstimate> {
|
|
90
|
+
const relayer = _relayer ? toAddressType(_relayer).forceSvmAddress() : this.simulatedRelayerAddress;
|
|
91
|
+
|
|
92
|
+
const fillRelayTx = await this.getFillRelayTx(deposit, relayer.toBase58());
|
|
93
|
+
|
|
94
|
+
const [computeUnitsConsumed, _gasPriceEstimate] = await Promise.all([
|
|
95
|
+
toBN(await this.computeUnitEstimator(fillRelayTx)),
|
|
96
|
+
getGasPriceEstimate(this.provider, {
|
|
97
|
+
unsignedTx: fillRelayTx,
|
|
98
|
+
baseFeeMultiplier: options.baseFeeMultiplier,
|
|
99
|
+
priorityFeeMultiplier: options.priorityFeeMultiplier,
|
|
100
|
+
}),
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
// We can cast the gas price estimate to an SvmGasPriceEstimate here since the oracle should always
|
|
104
|
+
// query the Solana adapter.
|
|
105
|
+
const gasPriceEstimate = _gasPriceEstimate as SvmGasPriceEstimate;
|
|
106
|
+
const gasPrice = gasPriceEstimate.baseFee.add(
|
|
107
|
+
gasPriceEstimate.microLamportsPerComputeUnit.mul(computeUnitsConsumed).div(toBN(1_000_000)) // 1_000_000 microLamports/lamport.
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return {
|
|
111
|
+
nativeGasCost: computeUnitsConsumed,
|
|
112
|
+
tokenGasCost: gasPrice,
|
|
113
|
+
gasPrice,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* @notice Return the gas cost of a simulated transaction
|
|
119
|
+
* @param fillRelayTx FillRelay transaction
|
|
120
|
+
* @param relayer SVM address of the relayer
|
|
121
|
+
* @returns Estimated gas cost in compute units
|
|
122
|
+
*/
|
|
123
|
+
async getNativeGasCost(
|
|
124
|
+
deposit: Omit<Deposit, "messageHash">,
|
|
125
|
+
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
126
|
+
): Promise<BigNumber> {
|
|
127
|
+
const fillRelayTx = await this.getFillRelayTx(deposit, _relayer);
|
|
128
|
+
const computeUnitsConsumed = toBN(await this.computeUnitEstimator(fillRelayTx));
|
|
129
|
+
return computeUnitsConsumed;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @notice Return the fillRelay transaction for a given deposit
|
|
134
|
+
* @param deposit
|
|
135
|
+
* @param relayer SVM address of the relayer
|
|
136
|
+
* @returns FillRelay transaction
|
|
137
|
+
*/
|
|
138
|
+
async getFillRelayTx(
|
|
139
|
+
deposit: Omit<Deposit, "messageHash">,
|
|
140
|
+
_relayer = getDefaultSimulatedRelayerAddress(deposit.destinationChainId)
|
|
141
|
+
) {
|
|
142
|
+
const relayer = _relayer ? toAddressType(_relayer).forceSvmAddress() : this.simulatedRelayerAddress;
|
|
143
|
+
// If the user did not have a token account created on destination, then we need to include this as a gas cost.
|
|
144
|
+
const mint = toAddressType(deposit.outputToken).forceSvmAddress();
|
|
145
|
+
const owner = toAddressType(deposit.recipient).forceSvmAddress();
|
|
146
|
+
const associatedToken = await getAssociatedTokenAddress(owner, mint);
|
|
147
|
+
const simulatedSigner = SolanaVoidSigner(relayer.toBase58());
|
|
148
|
+
|
|
149
|
+
// If the recipient has an associated token account on destination, then skip generating the instruction for creating a new token account.
|
|
150
|
+
let recipientCreateTokenAccountInstructions: IInstruction[] | undefined = undefined;
|
|
151
|
+
const [associatedTokenAccountExists, mintInfo] = await Promise.all([
|
|
152
|
+
(await fetchEncodedAccount(this.provider, associatedToken)).exists,
|
|
153
|
+
fetchMint(this.provider, mint.toV2Address()),
|
|
154
|
+
]);
|
|
155
|
+
if (!associatedTokenAccountExists) {
|
|
156
|
+
const space = BigInt(getMintSize());
|
|
157
|
+
const rent = await this.provider.getMinimumBalanceForRentExemption(space).send();
|
|
158
|
+
const createAccountIx = getCreateAccountInstruction({
|
|
159
|
+
payer: simulatedSigner,
|
|
160
|
+
newAccount: SolanaVoidSigner(mint.toBase58()),
|
|
161
|
+
lamports: rent,
|
|
162
|
+
space,
|
|
163
|
+
programAddress: TOKEN_PROGRAM_ADDRESS,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const initializeMintIx = getInitializeMintInstruction({
|
|
167
|
+
mint: mint.toV2Address(),
|
|
168
|
+
decimals: mintInfo.data.decimals,
|
|
169
|
+
mintAuthority: owner.toV2Address(),
|
|
170
|
+
});
|
|
171
|
+
recipientCreateTokenAccountInstructions = [createAccountIx, initializeMintIx];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const [createTokenAccountsIx, approveIx, fillIx] = await Promise.all([
|
|
175
|
+
createTokenAccountsInstruction(mint, simulatedSigner),
|
|
176
|
+
createApproveInstruction(
|
|
177
|
+
mint,
|
|
178
|
+
deposit.outputAmount,
|
|
179
|
+
this.simulatedRelayerAddress,
|
|
180
|
+
this.spokePoolAddress,
|
|
181
|
+
mintInfo.data.decimals
|
|
182
|
+
),
|
|
183
|
+
fillRelayInstruction(this.spokePoolAddress, deposit, simulatedSigner, associatedToken),
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
// Get the most recent confirmed blockhash.
|
|
187
|
+
const recentBlockhash = await this.provider.getLatestBlockhash().send();
|
|
188
|
+
const fillRelayTx = pipe(
|
|
189
|
+
createTransactionMessage({ version: 0 }),
|
|
190
|
+
(tx) => setTransactionMessageFeePayer(relayer.toV2Address(), tx),
|
|
191
|
+
(tx) => setTransactionMessageLifetimeUsingBlockhash(recentBlockhash.value, tx),
|
|
192
|
+
(tx) =>
|
|
193
|
+
isDefined(recipientCreateTokenAccountInstructions)
|
|
194
|
+
? appendTransactionMessageInstructions(recipientCreateTokenAccountInstructions, tx)
|
|
195
|
+
: tx,
|
|
196
|
+
(tx) => appendTransactionMessageInstructions([createTokenAccountsIx, approveIx, fillIx], tx)
|
|
197
|
+
);
|
|
198
|
+
return fillRelayTx;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Retrieves the current price of a token
|
|
203
|
+
* @param tokenSymbol A valid [CoinGecko-ID](https://api.coingecko.com/api/v3/coins/list)
|
|
204
|
+
* @returns The resolved token price within the specified coingeckoBaseCurrency
|
|
205
|
+
*/
|
|
206
|
+
async getTokenPrice(tokenSymbol: string): Promise<number> {
|
|
207
|
+
if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
|
|
208
|
+
const coingeckoInstance = Coingecko.get(this.logger, this.coingeckoProApiKey);
|
|
209
|
+
const [, price] = await coingeckoInstance.getCurrentPriceByContract(
|
|
210
|
+
this.symbolMapping[tokenSymbol].addresses[CHAIN_IDs.MAINNET],
|
|
211
|
+
this.coingeckoBaseCurrency
|
|
212
|
+
);
|
|
213
|
+
return price;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Resolves the number of decimal places a token can have
|
|
218
|
+
* @param tokenSymbol A valid Across-Enabled Token ID
|
|
219
|
+
* @returns The number of decimals of precision for the corresponding tokenSymbol
|
|
220
|
+
*/
|
|
221
|
+
getTokenDecimals(tokenSymbol: string): number {
|
|
222
|
+
if (!this.symbolMapping[tokenSymbol]) throw new Error(`${tokenSymbol} does not exist in mapping`);
|
|
223
|
+
return this.symbolMapping[tokenSymbol].decimals;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_SIMULATED_RELAYER_ADDRESS,
|
|
4
|
+
DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM,
|
|
5
|
+
TOKEN_SYMBOLS_MAP,
|
|
6
|
+
} from "../constants";
|
|
3
7
|
import { Deposit } from "../interfaces";
|
|
4
8
|
import {
|
|
5
9
|
BigNumber,
|
|
@@ -18,6 +22,7 @@ import {
|
|
|
18
22
|
toBNWei,
|
|
19
23
|
isZeroAddress,
|
|
20
24
|
compareAddressesSimple,
|
|
25
|
+
chainIsSvm,
|
|
21
26
|
} from "../utils";
|
|
22
27
|
import { Transport } from "viem";
|
|
23
28
|
|
|
@@ -36,6 +41,7 @@ export interface QueryInterface {
|
|
|
36
41
|
}>
|
|
37
42
|
) => Promise<TransactionCostEstimate>;
|
|
38
43
|
getTokenPrice: (tokenSymbol: string) => Promise<number>;
|
|
44
|
+
getNativeGasCost: (deposit: Omit<Deposit, "messageHash">, relayer: string) => Promise<BigNumber>;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export const expectedCapitalCostsKeys = ["lowerBound", "upperBound", "cutoff", "decimals"];
|
|
@@ -105,6 +111,12 @@ export const DEFAULT_LOGGER: Logger = {
|
|
|
105
111
|
error: (...args) => console.error(args),
|
|
106
112
|
};
|
|
107
113
|
|
|
114
|
+
export function getDefaultSimulatedRelayerAddress(chainId?: number) {
|
|
115
|
+
return isDefined(chainId) && chainIsSvm(chainId)
|
|
116
|
+
? DEFAULT_SIMULATED_RELAYER_ADDRESS_SVM
|
|
117
|
+
: DEFAULT_SIMULATED_RELAYER_ADDRESS;
|
|
118
|
+
}
|
|
119
|
+
|
|
108
120
|
// Small amount to simulate filling with. Should be low enough to guarantee a successful fill.
|
|
109
121
|
const safeOutputAmount = toBN(100);
|
|
110
122
|
|
|
@@ -241,7 +253,7 @@ export class RelayFeeCalculator {
|
|
|
241
253
|
deposit: Deposit,
|
|
242
254
|
amountToRelay: BigNumberish,
|
|
243
255
|
simulateZeroFill = false,
|
|
244
|
-
relayerAddress =
|
|
256
|
+
relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
245
257
|
_tokenPrice?: number,
|
|
246
258
|
tokenMapping = TOKEN_SYMBOLS_MAP,
|
|
247
259
|
gasPrice?: BigNumberish,
|
|
@@ -480,7 +492,7 @@ export class RelayFeeCalculator {
|
|
|
480
492
|
deposit: Deposit,
|
|
481
493
|
amountToRelay?: BigNumberish,
|
|
482
494
|
simulateZeroFill = false,
|
|
483
|
-
relayerAddress =
|
|
495
|
+
relayerAddress = getDefaultSimulatedRelayerAddress(deposit.destinationChainId),
|
|
484
496
|
_tokenPrice?: number,
|
|
485
497
|
gasPrice?: BigNumberish,
|
|
486
498
|
gasUnits?: BigNumberish,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { providers, utils } from "ethers";
|
|
2
2
|
import bs58 from "bs58";
|
|
3
|
+
import { Address as V2Address } from "@solana/kit";
|
|
3
4
|
import { BigNumber, chainIsEvm } from "./";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -77,9 +78,9 @@ export function isValidEvmAddress(address: string): boolean {
|
|
|
77
78
|
* @returns a child `Address` type most fitting for the chain ID.
|
|
78
79
|
* @todo: Change this to `toAddress` once we remove the other `toAddress` function.
|
|
79
80
|
*/
|
|
80
|
-
export function toAddressType(address: string
|
|
81
|
+
export function toAddressType(address: string): Address | EvmAddress | SvmAddress {
|
|
81
82
|
try {
|
|
82
|
-
if (
|
|
83
|
+
if (utils.isHexString(address)) {
|
|
83
84
|
return EvmAddress.from(address);
|
|
84
85
|
}
|
|
85
86
|
return SvmAddress.from(address);
|
|
@@ -146,6 +147,11 @@ export class Address {
|
|
|
146
147
|
return this.toBytes32();
|
|
147
148
|
}
|
|
148
149
|
|
|
150
|
+
// Converts the address to a Buffer type.
|
|
151
|
+
toBuffer(): Buffer {
|
|
152
|
+
return Buffer.from(this.rawAddress);
|
|
153
|
+
}
|
|
154
|
+
|
|
149
155
|
// Implements `Hexable` for `Address`. Needed for encoding purposes. This class is treated by default as a bytes32 primitive type, but can change for subclasses.
|
|
150
156
|
toHexString(): string {
|
|
151
157
|
return this.toBytes32();
|
|
@@ -185,6 +191,16 @@ export class Address {
|
|
|
185
191
|
return utils.stripZeros(this.rawAddress).length === 0;
|
|
186
192
|
}
|
|
187
193
|
|
|
194
|
+
// Forces `rawAddress` to become an SvmAddress type. This will only throw if `rawAddress.length > 32`.
|
|
195
|
+
forceSvmAddress(): SvmAddress {
|
|
196
|
+
return SvmAddress.from(this.toBase58());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Forces `rawAddress` to become an EvmAddress type. This will throw if `rawAddress.length > 20`.
|
|
200
|
+
forceEvmAddress(): EvmAddress {
|
|
201
|
+
return EvmAddress.from(this.toEvmAddress());
|
|
202
|
+
}
|
|
203
|
+
|
|
188
204
|
// Checks if the other address is equivalent to this address.
|
|
189
205
|
eq(other: Address): boolean {
|
|
190
206
|
return this.toString() === other.toString();
|
|
@@ -223,8 +239,20 @@ export class EvmAddress extends Address {
|
|
|
223
239
|
}
|
|
224
240
|
|
|
225
241
|
// Constructs a new EvmAddress type.
|
|
226
|
-
static from(
|
|
227
|
-
|
|
242
|
+
static from(address: string, encoding: "base16" | "base58" = "base16"): EvmAddress {
|
|
243
|
+
if (encoding === "base16") {
|
|
244
|
+
return new this(utils.arrayify(address));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const decodedAddress = bs58.decode(address);
|
|
248
|
+
const padding = decodedAddress.subarray(0, 12);
|
|
249
|
+
const evmAddress = decodedAddress.subarray(12);
|
|
250
|
+
|
|
251
|
+
if (padding.length !== 12 || utils.stripZeros(padding).length !== 0 || evmAddress.length !== 20) {
|
|
252
|
+
throw new Error(`Not a valid base58-encoded EVM address: ${address}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return new this(evmAddress);
|
|
228
256
|
}
|
|
229
257
|
}
|
|
230
258
|
|
|
@@ -241,12 +269,27 @@ export class SvmAddress extends Address {
|
|
|
241
269
|
return this.toBase58();
|
|
242
270
|
}
|
|
243
271
|
|
|
272
|
+
// Small utility to convert an SvmAddress to a Solana Kit branded type.
|
|
273
|
+
toV2Address(): V2Address<string> {
|
|
274
|
+
return this.toBase58() as V2Address<string>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Forces an SvmAddress to an EVM address string by truncating the leading 12 bytes.
|
|
244
278
|
override toEvmAddress(): string {
|
|
245
279
|
return toAddress(`0x${this.toBytes32().slice(-40)}`);
|
|
246
280
|
}
|
|
247
281
|
|
|
248
282
|
// Constructs a new SvmAddress type.
|
|
249
|
-
static from(
|
|
250
|
-
|
|
283
|
+
static from(address: string, encoding: "base58" | "base16" = "base58"): SvmAddress {
|
|
284
|
+
if (encoding === "base58") {
|
|
285
|
+
return new this(bs58.decode(address));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const decodedAddress = utils.arrayify(address);
|
|
289
|
+
if (decodedAddress.length !== 32) {
|
|
290
|
+
throw new Error(`Not a valid base16-encoded SVM address: ${address}`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return new this(decodedAddress);
|
|
251
294
|
}
|
|
252
295
|
}
|
package/src/utils/ArrayUtils.ts
CHANGED
|
@@ -168,3 +168,15 @@ export function includesAsync<T>(
|
|
|
168
168
|
export function isArrayOf<T>(array: unknown, predicate: (value: unknown) => value is T): array is T[] {
|
|
169
169
|
return Array.isArray(array) && array.every(predicate);
|
|
170
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Checks if a value is a Uint8Array.
|
|
174
|
+
* @param value The value to check.
|
|
175
|
+
* @returns True if the value is a Uint8Array, false otherwise.
|
|
176
|
+
*/
|
|
177
|
+
export function isUint8Array(value: unknown): value is Uint8Array {
|
|
178
|
+
return (
|
|
179
|
+
Array.isArray(value) &&
|
|
180
|
+
value.every((item) => typeof item === "number" && Number.isInteger(item) && item >= 0 && item < 256)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type BlockFinderOpts = {
|
|
2
|
+
highBlock?: number;
|
|
3
|
+
highBlockOffset?: number;
|
|
4
|
+
blockRange?: number;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type BlockTimeAverage = {
|
|
8
|
+
average: number;
|
|
9
|
+
blockRange: number;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export interface Block {
|
|
14
|
+
hash: string;
|
|
15
|
+
number: number;
|
|
16
|
+
timestamp: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type BlockFinderHints = {
|
|
20
|
+
lowBlock?: number;
|
|
21
|
+
highBlock?: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export abstract class BlockFinder<TBlock extends Block> {
|
|
25
|
+
abstract getBlockForTimestamp(timestamp: number | string, hints: BlockFinderHints): Promise<TBlock>;
|
|
26
|
+
}
|