viem 2.53.1 → 2.54.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/CHANGELOG.md +55 -0
- package/_cjs/actions/index.js +3 -2
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/token/approve.js +62 -0
- package/_cjs/actions/token/approve.js.map +1 -0
- package/_cjs/actions/token/approveSync.js +25 -0
- package/_cjs/actions/token/approveSync.js.map +1 -0
- package/_cjs/actions/token/getAllowance.js +32 -0
- package/_cjs/actions/token/getAllowance.js.map +1 -0
- package/_cjs/actions/token/getBalance.js +41 -0
- package/_cjs/actions/token/getBalance.js.map +1 -0
- package/_cjs/actions/token/getMetadata.js +40 -0
- package/_cjs/actions/token/getMetadata.js.map +1 -0
- package/_cjs/actions/token/getTotalSupply.js +32 -0
- package/_cjs/actions/token/getTotalSupply.js.map +1 -0
- package/_cjs/actions/token/index.js +20 -0
- package/_cjs/actions/token/index.js.map +1 -0
- package/_cjs/actions/token/internal.js +125 -0
- package/_cjs/actions/token/internal.js.map +1 -0
- package/_cjs/actions/token/transfer.js +70 -0
- package/_cjs/actions/token/transfer.js.map +1 -0
- package/_cjs/actions/token/transferSync.js +25 -0
- package/_cjs/actions/token/transferSync.js.map +1 -0
- package/_cjs/chains/definitions/battlechain.js +31 -0
- package/_cjs/chains/definitions/battlechain.js.map +1 -0
- package/_cjs/chains/definitions/marooTestnet.js +30 -0
- package/_cjs/chains/definitions/marooTestnet.js.map +1 -0
- package/_cjs/chains/index.js +18 -14
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js +39 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/clients/createPublicClient.js.map +1 -1
- package/_cjs/clients/createWalletClient.js.map +1 -1
- package/_cjs/clients/decorators/public.js +11 -0
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/clients/decorators/wallet.js +8 -0
- package/_cjs/clients/decorators/wallet.js.map +1 -1
- package/_cjs/clients/transports/http.js +2 -1
- package/_cjs/clients/transports/http.js.map +1 -1
- package/_cjs/errors/encoding.js +9 -1
- package/_cjs/errors/encoding.js.map +1 -1
- package/_cjs/errors/request.js +24 -1
- package/_cjs/errors/request.js.map +1 -1
- package/_cjs/errors/transaction.js +9 -1
- package/_cjs/errors/transaction.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +9 -6
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Client.js.map +1 -1
- package/_cjs/tempo/Decorator.js +234 -215
- package/_cjs/tempo/Decorator.js.map +1 -1
- package/_cjs/tempo/actions/token.js +210 -112
- package/_cjs/tempo/actions/token.js.map +1 -1
- package/_cjs/tempo/internal/utils.js +108 -0
- package/_cjs/tempo/internal/utils.js.map +1 -1
- package/_cjs/tokens/defineToken.js +21 -0
- package/_cjs/tokens/defineToken.js.map +1 -0
- package/_cjs/tokens/definitions/alphausd.js +14 -0
- package/_cjs/tokens/definitions/alphausd.js.map +1 -0
- package/_cjs/tokens/definitions/betausd.js +14 -0
- package/_cjs/tokens/definitions/betausd.js.map +1 -0
- package/_cjs/tokens/definitions/brla.js +14 -0
- package/_cjs/tokens/definitions/brla.js.map +1 -0
- package/_cjs/tokens/definitions/cbbtc.js +14 -0
- package/_cjs/tokens/definitions/cbbtc.js.map +1 -0
- package/_cjs/tokens/definitions/chfau.js +14 -0
- package/_cjs/tokens/definitions/chfau.js.map +1 -0
- package/_cjs/tokens/definitions/cusd.js +14 -0
- package/_cjs/tokens/definitions/cusd.js.map +1 -0
- package/_cjs/tokens/definitions/dlusd.js +14 -0
- package/_cjs/tokens/definitions/dlusd.js.map +1 -0
- package/_cjs/tokens/definitions/eurau.js +14 -0
- package/_cjs/tokens/definitions/eurau.js.map +1 -0
- package/_cjs/tokens/definitions/eurce.js +15 -0
- package/_cjs/tokens/definitions/eurce.js.map +1 -0
- package/_cjs/tokens/definitions/frxusd.js +14 -0
- package/_cjs/tokens/definitions/frxusd.js.map +1 -0
- package/_cjs/tokens/definitions/gbpa.js +14 -0
- package/_cjs/tokens/definitions/gbpa.js.map +1 -0
- package/_cjs/tokens/definitions/gusd.js +14 -0
- package/_cjs/tokens/definitions/gusd.js.map +1 -0
- package/_cjs/tokens/definitions/iusd.js +14 -0
- package/_cjs/tokens/definitions/iusd.js.map +1 -0
- package/_cjs/tokens/definitions/pathusd.js +15 -0
- package/_cjs/tokens/definitions/pathusd.js.map +1 -0
- package/_cjs/tokens/definitions/reusd.js +14 -0
- package/_cjs/tokens/definitions/reusd.js.map +1 -0
- package/_cjs/tokens/definitions/rusd.js +14 -0
- package/_cjs/tokens/definitions/rusd.js.map +1 -0
- package/_cjs/tokens/definitions/sbc.js +14 -0
- package/_cjs/tokens/definitions/sbc.js.map +1 -0
- package/_cjs/tokens/definitions/siusd.js +14 -0
- package/_cjs/tokens/definitions/siusd.js.map +1 -0
- package/_cjs/tokens/definitions/stcusd.js +14 -0
- package/_cjs/tokens/definitions/stcusd.js.map +1 -0
- package/_cjs/tokens/definitions/susde.js +14 -0
- package/_cjs/tokens/definitions/susde.js.map +1 -0
- package/_cjs/tokens/definitions/syrupusdc.js +14 -0
- package/_cjs/tokens/definitions/syrupusdc.js.map +1 -0
- package/_cjs/tokens/definitions/thetausd.js +14 -0
- package/_cjs/tokens/definitions/thetausd.js.map +1 -0
- package/_cjs/tokens/definitions/usd1.js +14 -0
- package/_cjs/tokens/definitions/usd1.js.map +1 -0
- package/_cjs/tokens/definitions/usdb.js +14 -0
- package/_cjs/tokens/definitions/usdb.js.map +1 -0
- package/_cjs/tokens/definitions/usdc.js +41 -0
- package/_cjs/tokens/definitions/usdc.js.map +1 -0
- package/_cjs/tokens/definitions/usdce.js +15 -0
- package/_cjs/tokens/definitions/usdce.js.map +1 -0
- package/_cjs/tokens/definitions/usde.js +14 -0
- package/_cjs/tokens/definitions/usde.js.map +1 -0
- package/_cjs/tokens/definitions/usdt0.js +14 -0
- package/_cjs/tokens/definitions/usdt0.js.map +1 -0
- package/_cjs/tokens/definitions/wsrusd.js +14 -0
- package/_cjs/tokens/definitions/wsrusd.js.map +1 -0
- package/_cjs/tokens/index.js +64 -0
- package/_cjs/tokens/index.js.map +1 -0
- package/_cjs/utils/encoding/fromRlp.js +7 -4
- package/_cjs/utils/encoding/fromRlp.js.map +1 -1
- package/_cjs/utils/rpc/http.js +58 -3
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +4 -1
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/token/approve.js +123 -0
- package/_esm/actions/token/approve.js.map +1 -0
- package/_esm/actions/token/approveSync.js +50 -0
- package/_esm/actions/token/approveSync.js.map +1 -0
- package/_esm/actions/token/getAllowance.js +62 -0
- package/_esm/actions/token/getAllowance.js.map +1 -0
- package/_esm/actions/token/getBalance.js +70 -0
- package/_esm/actions/token/getBalance.js.map +1 -0
- package/_esm/actions/token/getMetadata.js +60 -0
- package/_esm/actions/token/getMetadata.js.map +1 -0
- package/_esm/actions/token/getTotalSupply.js +60 -0
- package/_esm/actions/token/getTotalSupply.js.map +1 -0
- package/_esm/actions/token/index.js +10 -0
- package/_esm/actions/token/index.js.map +1 -0
- package/_esm/actions/token/internal.js +188 -0
- package/_esm/actions/token/internal.js.map +1 -0
- package/_esm/actions/token/transfer.js +147 -0
- package/_esm/actions/token/transfer.js.map +1 -0
- package/_esm/actions/token/transferSync.js +54 -0
- package/_esm/actions/token/transferSync.js.map +1 -0
- package/_esm/chains/definitions/battlechain.js +28 -0
- package/_esm/chains/definitions/battlechain.js.map +1 -0
- package/_esm/chains/definitions/marooTestnet.js +27 -0
- package/_esm/chains/definitions/marooTestnet.js.map +1 -0
- package/_esm/chains/index.js +2 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js +53 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/clients/createPublicClient.js.map +1 -1
- package/_esm/clients/createWalletClient.js.map +1 -1
- package/_esm/clients/decorators/public.js +17 -0
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/clients/decorators/wallet.js +8 -0
- package/_esm/clients/decorators/wallet.js.map +1 -1
- package/_esm/clients/transports/http.js +2 -1
- package/_esm/clients/transports/http.js.map +1 -1
- package/_esm/errors/encoding.js +7 -0
- package/_esm/errors/encoding.js.map +1 -1
- package/_esm/errors/request.js +22 -0
- package/_esm/errors/request.js.map +1 -1
- package/_esm/errors/transaction.js +7 -0
- package/_esm/errors/transaction.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +3 -3
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Client.js.map +1 -1
- package/_esm/tempo/Decorator.js +234 -218
- package/_esm/tempo/Decorator.js.map +1 -1
- package/_esm/tempo/actions/token.js +335 -186
- package/_esm/tempo/actions/token.js.map +1 -1
- package/_esm/tempo/actions/wallet.js +1 -1
- package/_esm/tempo/internal/utils.js +154 -0
- package/_esm/tempo/internal/utils.js.map +1 -1
- package/_esm/tokens/defineToken.js +57 -0
- package/_esm/tokens/defineToken.js.map +1 -0
- package/_esm/tokens/definitions/alphausd.js +12 -0
- package/_esm/tokens/definitions/alphausd.js.map +1 -0
- package/_esm/tokens/definitions/betausd.js +12 -0
- package/_esm/tokens/definitions/betausd.js.map +1 -0
- package/_esm/tokens/definitions/brla.js +12 -0
- package/_esm/tokens/definitions/brla.js.map +1 -0
- package/_esm/tokens/definitions/cbbtc.js +12 -0
- package/_esm/tokens/definitions/cbbtc.js.map +1 -0
- package/_esm/tokens/definitions/chfau.js +12 -0
- package/_esm/tokens/definitions/chfau.js.map +1 -0
- package/_esm/tokens/definitions/cusd.js +12 -0
- package/_esm/tokens/definitions/cusd.js.map +1 -0
- package/_esm/tokens/definitions/dlusd.js +12 -0
- package/_esm/tokens/definitions/dlusd.js.map +1 -0
- package/_esm/tokens/definitions/eurau.js +12 -0
- package/_esm/tokens/definitions/eurau.js.map +1 -0
- package/_esm/tokens/definitions/eurce.js +13 -0
- package/_esm/tokens/definitions/eurce.js.map +1 -0
- package/_esm/tokens/definitions/frxusd.js +12 -0
- package/_esm/tokens/definitions/frxusd.js.map +1 -0
- package/_esm/tokens/definitions/gbpa.js +12 -0
- package/_esm/tokens/definitions/gbpa.js.map +1 -0
- package/_esm/tokens/definitions/gusd.js +12 -0
- package/_esm/tokens/definitions/gusd.js.map +1 -0
- package/_esm/tokens/definitions/iusd.js +12 -0
- package/_esm/tokens/definitions/iusd.js.map +1 -0
- package/_esm/tokens/definitions/pathusd.js +13 -0
- package/_esm/tokens/definitions/pathusd.js.map +1 -0
- package/_esm/tokens/definitions/reusd.js +12 -0
- package/_esm/tokens/definitions/reusd.js.map +1 -0
- package/_esm/tokens/definitions/rusd.js +12 -0
- package/_esm/tokens/definitions/rusd.js.map +1 -0
- package/_esm/tokens/definitions/sbc.js +12 -0
- package/_esm/tokens/definitions/sbc.js.map +1 -0
- package/_esm/tokens/definitions/siusd.js +12 -0
- package/_esm/tokens/definitions/siusd.js.map +1 -0
- package/_esm/tokens/definitions/stcusd.js +12 -0
- package/_esm/tokens/definitions/stcusd.js.map +1 -0
- package/_esm/tokens/definitions/susde.js +12 -0
- package/_esm/tokens/definitions/susde.js.map +1 -0
- package/_esm/tokens/definitions/syrupusdc.js +12 -0
- package/_esm/tokens/definitions/syrupusdc.js.map +1 -0
- package/_esm/tokens/definitions/thetausd.js +12 -0
- package/_esm/tokens/definitions/thetausd.js.map +1 -0
- package/_esm/tokens/definitions/usd1.js +12 -0
- package/_esm/tokens/definitions/usd1.js.map +1 -0
- package/_esm/tokens/definitions/usdb.js +12 -0
- package/_esm/tokens/definitions/usdb.js.map +1 -0
- package/_esm/tokens/definitions/usdc.js +67 -0
- package/_esm/tokens/definitions/usdc.js.map +1 -0
- package/_esm/tokens/definitions/usdce.js +13 -0
- package/_esm/tokens/definitions/usdce.js.map +1 -0
- package/_esm/tokens/definitions/usde.js +12 -0
- package/_esm/tokens/definitions/usde.js.map +1 -0
- package/_esm/tokens/definitions/usdt0.js +12 -0
- package/_esm/tokens/definitions/usdt0.js.map +1 -0
- package/_esm/tokens/definitions/wsrusd.js +12 -0
- package/_esm/tokens/definitions/wsrusd.js.map +1 -0
- package/_esm/tokens/index.js +32 -0
- package/_esm/tokens/index.js.map +1 -0
- package/_esm/utils/encoding/fromRlp.js +8 -5
- package/_esm/utils/encoding/fromRlp.js.map +1 -1
- package/_esm/utils/rpc/http.js +59 -4
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +5 -2
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/token/approve.d.ts +253 -0
- package/_types/actions/token/approve.d.ts.map +1 -0
- package/_types/actions/token/approveSync.d.ts +57 -0
- package/_types/actions/token/approveSync.d.ts.map +1 -0
- package/_types/actions/token/getAllowance.d.ts +77 -0
- package/_types/actions/token/getAllowance.d.ts.map +1 -0
- package/_types/actions/token/getBalance.d.ts +69 -0
- package/_types/actions/token/getBalance.d.ts.map +1 -0
- package/_types/actions/token/getMetadata.d.ts +43 -0
- package/_types/actions/token/getMetadata.d.ts.map +1 -0
- package/_types/actions/token/getTotalSupply.d.ts +63 -0
- package/_types/actions/token/getTotalSupply.d.ts.map +1 -0
- package/_types/actions/token/index.d.ts +9 -0
- package/_types/actions/token/index.d.ts.map +1 -0
- package/_types/actions/token/internal.d.ts +168 -0
- package/_types/actions/token/internal.d.ts.map +1 -0
- package/_types/actions/token/transfer.d.ts +288 -0
- package/_types/actions/token/transfer.d.ts.map +1 -0
- package/_types/actions/token/transferSync.d.ts +61 -0
- package/_types/actions/token/transferSync.d.ts.map +1 -0
- package/_types/chains/definitions/battlechain.d.ts +447 -0
- package/_types/chains/definitions/battlechain.d.ts.map +1 -0
- package/_types/chains/definitions/marooTestnet.d.ts +49 -0
- package/_types/chains/definitions/marooTestnet.d.ts.map +1 -0
- package/_types/chains/index.d.ts +2 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +24 -6
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/clients/createPublicClient.d.ts +4 -3
- package/_types/clients/createPublicClient.d.ts.map +1 -1
- package/_types/clients/createWalletClient.d.ts +4 -3
- package/_types/clients/createWalletClient.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +128 -3
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/clients/decorators/wallet.d.ts +208 -3
- package/_types/clients/decorators/wallet.d.ts.map +1 -1
- package/_types/clients/transports/http.d.ts +2 -0
- package/_types/clients/transports/http.d.ts.map +1 -1
- package/_types/errors/encoding.d.ts +8 -0
- package/_types/errors/encoding.d.ts.map +1 -1
- package/_types/errors/request.d.ts +11 -0
- package/_types/errors/request.d.ts.map +1 -1
- package/_types/errors/transaction.d.ts +8 -0
- package/_types/errors/transaction.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +4 -3
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/Client.d.ts +1 -1
- package/_types/tempo/Client.d.ts.map +1 -1
- package/_types/tempo/Decorator.d.ts +88 -5
- package/_types/tempo/Decorator.d.ts.map +1 -1
- package/_types/tempo/actions/token.d.ts +223 -151
- package/_types/tempo/actions/token.d.ts.map +1 -1
- package/_types/tempo/actions/wallet.d.ts +3 -3
- package/_types/tempo/internal/types.d.ts +17 -0
- package/_types/tempo/internal/types.d.ts.map +1 -1
- package/_types/tempo/internal/utils.d.ts +73 -0
- package/_types/tempo/internal/utils.d.ts.map +1 -1
- package/_types/tokens/defineToken.d.ts +112 -0
- package/_types/tokens/defineToken.d.ts.map +1 -0
- package/_types/tokens/definitions/alphausd.d.ts +11 -0
- package/_types/tokens/definitions/alphausd.d.ts.map +1 -0
- package/_types/tokens/definitions/betausd.d.ts +11 -0
- package/_types/tokens/definitions/betausd.d.ts.map +1 -0
- package/_types/tokens/definitions/brla.d.ts +11 -0
- package/_types/tokens/definitions/brla.d.ts.map +1 -0
- package/_types/tokens/definitions/cbbtc.d.ts +11 -0
- package/_types/tokens/definitions/cbbtc.d.ts.map +1 -0
- package/_types/tokens/definitions/chfau.d.ts +11 -0
- package/_types/tokens/definitions/chfau.d.ts.map +1 -0
- package/_types/tokens/definitions/cusd.d.ts +11 -0
- package/_types/tokens/definitions/cusd.d.ts.map +1 -0
- package/_types/tokens/definitions/dlusd.d.ts +11 -0
- package/_types/tokens/definitions/dlusd.d.ts.map +1 -0
- package/_types/tokens/definitions/eurau.d.ts +11 -0
- package/_types/tokens/definitions/eurau.d.ts.map +1 -0
- package/_types/tokens/definitions/eurce.d.ts +12 -0
- package/_types/tokens/definitions/eurce.d.ts.map +1 -0
- package/_types/tokens/definitions/frxusd.d.ts +11 -0
- package/_types/tokens/definitions/frxusd.d.ts.map +1 -0
- package/_types/tokens/definitions/gbpa.d.ts +11 -0
- package/_types/tokens/definitions/gbpa.d.ts.map +1 -0
- package/_types/tokens/definitions/gusd.d.ts +11 -0
- package/_types/tokens/definitions/gusd.d.ts.map +1 -0
- package/_types/tokens/definitions/iusd.d.ts +11 -0
- package/_types/tokens/definitions/iusd.d.ts.map +1 -0
- package/_types/tokens/definitions/pathusd.d.ts +12 -0
- package/_types/tokens/definitions/pathusd.d.ts.map +1 -0
- package/_types/tokens/definitions/reusd.d.ts +11 -0
- package/_types/tokens/definitions/reusd.d.ts.map +1 -0
- package/_types/tokens/definitions/rusd.d.ts +11 -0
- package/_types/tokens/definitions/rusd.d.ts.map +1 -0
- package/_types/tokens/definitions/sbc.d.ts +11 -0
- package/_types/tokens/definitions/sbc.d.ts.map +1 -0
- package/_types/tokens/definitions/siusd.d.ts +11 -0
- package/_types/tokens/definitions/siusd.d.ts.map +1 -0
- package/_types/tokens/definitions/stcusd.d.ts +11 -0
- package/_types/tokens/definitions/stcusd.d.ts.map +1 -0
- package/_types/tokens/definitions/susde.d.ts +11 -0
- package/_types/tokens/definitions/susde.d.ts.map +1 -0
- package/_types/tokens/definitions/syrupusdc.d.ts +11 -0
- package/_types/tokens/definitions/syrupusdc.d.ts.map +1 -0
- package/_types/tokens/definitions/thetausd.d.ts +11 -0
- package/_types/tokens/definitions/thetausd.d.ts.map +1 -0
- package/_types/tokens/definitions/usd1.d.ts +11 -0
- package/_types/tokens/definitions/usd1.d.ts.map +1 -0
- package/_types/tokens/definitions/usdb.d.ts +11 -0
- package/_types/tokens/definitions/usdb.d.ts.map +1 -0
- package/_types/tokens/definitions/usdc.d.ts +67 -0
- package/_types/tokens/definitions/usdc.d.ts.map +1 -0
- package/_types/tokens/definitions/usdce.d.ts +12 -0
- package/_types/tokens/definitions/usdce.d.ts.map +1 -0
- package/_types/tokens/definitions/usde.d.ts +11 -0
- package/_types/tokens/definitions/usde.d.ts.map +1 -0
- package/_types/tokens/definitions/usdt0.d.ts +11 -0
- package/_types/tokens/definitions/usdt0.d.ts.map +1 -0
- package/_types/tokens/definitions/wsrusd.d.ts +11 -0
- package/_types/tokens/definitions/wsrusd.d.ts.map +1 -0
- package/_types/tokens/index.d.ts +31 -0
- package/_types/tokens/index.d.ts.map +1 -0
- package/_types/utils/encoding/fromRlp.d.ts +2 -2
- package/_types/utils/encoding/fromRlp.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts +6 -2
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts +2 -2
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/actions/index.ts +1 -0
- package/actions/token/approve.ts +202 -0
- package/actions/token/approveSync.ts +95 -0
- package/actions/token/getAllowance.ts +105 -0
- package/actions/token/getBalance.ts +115 -0
- package/actions/token/getMetadata.ts +98 -0
- package/actions/token/getTotalSupply.ts +97 -0
- package/actions/token/index.ts +9 -0
- package/actions/token/internal.ts +367 -0
- package/actions/token/transfer.ts +230 -0
- package/actions/token/transferSync.ts +99 -0
- package/chains/definitions/battlechain.ts +28 -0
- package/chains/definitions/marooTestnet.ts +27 -0
- package/chains/index.ts +2 -0
- package/clients/createClient.ts +90 -8
- package/clients/createPublicClient.ts +22 -4
- package/clients/createWalletClient.ts +22 -4
- package/clients/decorators/public.ts +166 -4
- package/clients/decorators/wallet.ts +242 -3
- package/clients/transports/http.ts +4 -0
- package/errors/encoding.ts +11 -0
- package/errors/request.ts +17 -0
- package/errors/transaction.ts +11 -0
- package/errors/version.ts +1 -1
- package/index.ts +7 -0
- package/package.json +6 -1
- package/tempo/Client.ts +4 -2
- package/tempo/Decorator.ts +398 -337
- package/tempo/actions/token.ts +519 -296
- package/tempo/actions/wallet.ts +3 -3
- package/tempo/internal/types.ts +19 -0
- package/tempo/internal/utils.ts +204 -0
- package/tokens/defineToken.ts +142 -0
- package/tokens/definitions/alphausd.ts +13 -0
- package/tokens/definitions/betausd.ts +13 -0
- package/tokens/definitions/brla.ts +13 -0
- package/tokens/definitions/cbbtc.ts +13 -0
- package/tokens/definitions/chfau.ts +13 -0
- package/tokens/definitions/cusd.ts +13 -0
- package/tokens/definitions/dlusd.ts +13 -0
- package/tokens/definitions/eurau.ts +13 -0
- package/tokens/definitions/eurce.ts +14 -0
- package/tokens/definitions/frxusd.ts +13 -0
- package/tokens/definitions/gbpa.ts +13 -0
- package/tokens/definitions/gusd.ts +13 -0
- package/tokens/definitions/iusd.ts +13 -0
- package/tokens/definitions/pathusd.ts +14 -0
- package/tokens/definitions/reusd.ts +13 -0
- package/tokens/definitions/rusd.ts +13 -0
- package/tokens/definitions/sbc.ts +13 -0
- package/tokens/definitions/siusd.ts +13 -0
- package/tokens/definitions/stcusd.ts +13 -0
- package/tokens/definitions/susde.ts +13 -0
- package/tokens/definitions/syrupusdc.ts +13 -0
- package/tokens/definitions/thetausd.ts +13 -0
- package/tokens/definitions/usd1.ts +13 -0
- package/tokens/definitions/usdb.ts +13 -0
- package/tokens/definitions/usdc.ts +67 -0
- package/tokens/definitions/usdce.ts +14 -0
- package/tokens/definitions/usde.ts +13 -0
- package/tokens/definitions/usdt0.ts +13 -0
- package/tokens/definitions/wsrusd.ts +13 -0
- package/tokens/index.ts +31 -0
- package/tokens/package.json +6 -0
- package/utils/encoding/fromRlp.ts +22 -3
- package/utils/rpc/http.ts +70 -2
- package/utils/transaction/parseTransaction.ts +7 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { Account } from '../../accounts/types.js'
|
|
2
|
+
import type { Client } from '../../clients/createClient.js'
|
|
3
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
4
|
+
import { erc20Abi } from '../../constants/abis.js'
|
|
5
|
+
import type { Tokens } from '../../tokens/defineToken.js'
|
|
6
|
+
import type { Chain } from '../../types/chain.js'
|
|
7
|
+
import { readContract } from '../public/readContract.js'
|
|
8
|
+
import {
|
|
9
|
+
type Amount,
|
|
10
|
+
defineCall,
|
|
11
|
+
type ReadParameters,
|
|
12
|
+
resolveToken,
|
|
13
|
+
resolveTokenWithDecimals,
|
|
14
|
+
type TokenParameters,
|
|
15
|
+
toAmount,
|
|
16
|
+
} from './internal.js'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Gets the total supply of an ERC-20 token.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { createClient, http } from 'viem'
|
|
24
|
+
* import { mainnet } from 'viem/chains'
|
|
25
|
+
* import { token } from 'viem/actions'
|
|
26
|
+
*
|
|
27
|
+
* const client = createClient({ chain: mainnet, transport: http() })
|
|
28
|
+
*
|
|
29
|
+
* const totalSupply = await token.getTotalSupply(client, {
|
|
30
|
+
* token: '0x...',
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param client - Client.
|
|
35
|
+
* @param parameters - Parameters.
|
|
36
|
+
* @returns The token total supply, in base units and human-readable form.
|
|
37
|
+
*/
|
|
38
|
+
export async function getTotalSupply<
|
|
39
|
+
chain extends Chain | undefined,
|
|
40
|
+
account extends Account | undefined,
|
|
41
|
+
tokens extends Tokens | undefined = undefined,
|
|
42
|
+
>(
|
|
43
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
44
|
+
parameters: getTotalSupply.Parameters<chain, tokens>,
|
|
45
|
+
): Promise<getTotalSupply.ReturnValue> {
|
|
46
|
+
const { decimals, token, ...rest } = parameters
|
|
47
|
+
const [amount, { decimals: resolved }] = await Promise.all([
|
|
48
|
+
readContract(client, {
|
|
49
|
+
...rest,
|
|
50
|
+
...getTotalSupply.call(client, { token } as never),
|
|
51
|
+
}),
|
|
52
|
+
resolveTokenWithDecimals(client, {
|
|
53
|
+
decimals,
|
|
54
|
+
token,
|
|
55
|
+
}),
|
|
56
|
+
])
|
|
57
|
+
return toAmount(amount as bigint, resolved)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export namespace getTotalSupply {
|
|
61
|
+
export type Args<
|
|
62
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
63
|
+
tokens extends Tokens | undefined = Tokens | undefined,
|
|
64
|
+
> = TokenParameters<chain, tokens>
|
|
65
|
+
export type Parameters<
|
|
66
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
67
|
+
tokens extends Tokens | undefined = Tokens | undefined,
|
|
68
|
+
> = Omit<ReadParameters, 'account'> & Args<chain, tokens>
|
|
69
|
+
export type ReturnValue = Amount
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Defines a call to the `totalSupply` function.
|
|
73
|
+
*
|
|
74
|
+
* Can be passed as a parameter to `multicall`, `simulateContract`, or any
|
|
75
|
+
* other action that accepts a contract call. The token is selected by `token`
|
|
76
|
+
* symbol (resolved from the client's `tokens` array) or contract address.
|
|
77
|
+
*
|
|
78
|
+
* @param client - Client.
|
|
79
|
+
* @param args - Arguments.
|
|
80
|
+
* @returns The call.
|
|
81
|
+
*/
|
|
82
|
+
export function call<
|
|
83
|
+
chain extends Chain | undefined,
|
|
84
|
+
account extends Account | undefined,
|
|
85
|
+
tokens extends Tokens | undefined = undefined,
|
|
86
|
+
>(
|
|
87
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
88
|
+
args: Args<chain, tokens>,
|
|
89
|
+
) {
|
|
90
|
+
return defineCall({
|
|
91
|
+
address: resolveToken(client, args).address,
|
|
92
|
+
abi: erc20Abi,
|
|
93
|
+
args: [],
|
|
94
|
+
functionName: 'totalSupply',
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// biome-ignore lint/performance/noBarrelFile: entrypoint module
|
|
2
|
+
export { approve } from './approve.js'
|
|
3
|
+
export { approveSync } from './approveSync.js'
|
|
4
|
+
export { getAllowance } from './getAllowance.js'
|
|
5
|
+
export { getBalance } from './getBalance.js'
|
|
6
|
+
export { getMetadata } from './getMetadata.js'
|
|
7
|
+
export { getTotalSupply } from './getTotalSupply.js'
|
|
8
|
+
export { transfer } from './transfer.js'
|
|
9
|
+
export { transferSync } from './transferSync.js'
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
import type { Abi, AbiStateMutability, Address } from 'abitype'
|
|
2
|
+
import type { Account } from '../../accounts/types.js'
|
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
5
|
+
import { erc20Abi } from '../../constants/abis.js'
|
|
6
|
+
import type { ResolvedToken, Token, Tokens } from '../../tokens/defineToken.js'
|
|
7
|
+
import type { Chain } from '../../types/chain.js'
|
|
8
|
+
import type {
|
|
9
|
+
ContractFunctionName,
|
|
10
|
+
ContractFunctionParameters,
|
|
11
|
+
ExtractAbiItem,
|
|
12
|
+
} from '../../types/contract.js'
|
|
13
|
+
import type { Hex } from '../../types/misc.js'
|
|
14
|
+
import type { UnionPick } from '../../types/utils.js'
|
|
15
|
+
import { isAddress } from '../../utils/address/isAddress.js'
|
|
16
|
+
import { isAddressEqual } from '../../utils/address/isAddressEqual.js'
|
|
17
|
+
import { encodeFunctionData } from '../../utils/index.js'
|
|
18
|
+
import { formatUnits } from '../../utils/unit/formatUnits.js'
|
|
19
|
+
import { parseUnits } from '../../utils/unit/parseUnits.js'
|
|
20
|
+
import type { ReadContractParameters as viem_ReadContractParameters } from '../public/readContract.js'
|
|
21
|
+
import { readContract } from '../public/readContract.js'
|
|
22
|
+
import type { WriteContractSyncParameters as viem_WriteContractSyncParameters } from '../wallet/writeContractSync.js'
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Union of symbols of the Client's declared `tokens` whose `addresses` include
|
|
26
|
+
* the Client's `chain.id`. Collapses to `never` when there is no chain mapping
|
|
27
|
+
* (no `tokens`, no `chain`, a widened `chain.id`, or widened token symbols).
|
|
28
|
+
*
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export type TokenName<
|
|
32
|
+
chain extends Chain | undefined,
|
|
33
|
+
tokens extends Tokens | undefined,
|
|
34
|
+
> = chain extends { id: infer chainId extends number }
|
|
35
|
+
? number extends chainId
|
|
36
|
+
? never
|
|
37
|
+
: tokens extends Tokens
|
|
38
|
+
? TokenSymbolForChain<tokens[number], chainId>
|
|
39
|
+
: never
|
|
40
|
+
: never
|
|
41
|
+
|
|
42
|
+
type TokenSymbolForChain<token, chainId extends number> = token extends Token
|
|
43
|
+
? chainId extends keyof token['addresses']
|
|
44
|
+
? token['symbol'] extends string
|
|
45
|
+
? string extends token['symbol']
|
|
46
|
+
? never
|
|
47
|
+
: Lowercase<token['symbol']>
|
|
48
|
+
: never
|
|
49
|
+
: never
|
|
50
|
+
: never
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Selects an ERC-20 token by `token`, which is either the symbol of a token
|
|
54
|
+
* declared on the Client's `tokens` array or a contract `address`.
|
|
55
|
+
*
|
|
56
|
+
* When `token` is a declared symbol (or an address that matches a declared
|
|
57
|
+
* token), token metadata is resolved from the Client's `tokens` array.
|
|
58
|
+
*/
|
|
59
|
+
export type TokenParameter<
|
|
60
|
+
chain extends Chain | undefined,
|
|
61
|
+
tokens extends Tokens | undefined,
|
|
62
|
+
> = {
|
|
63
|
+
/**
|
|
64
|
+
* Token to operate on: either the symbol of a token declared on the Client's
|
|
65
|
+
* `tokens` array (with an address for the Client's `chain.id`), or a
|
|
66
|
+
* contract `address`.
|
|
67
|
+
*/
|
|
68
|
+
token: TokenName<chain, tokens> | Address
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type TokenParameters<
|
|
72
|
+
chain extends Chain | undefined,
|
|
73
|
+
tokens extends Tokens | undefined,
|
|
74
|
+
> = TokenParameter<chain, tokens> & {
|
|
75
|
+
/**
|
|
76
|
+
* Decimals used to convert between base units and the human-readable amount.
|
|
77
|
+
* Inferred from the Client's `tokens` array when `token` matches a declared
|
|
78
|
+
* token; otherwise fetched from the token contract when needed.
|
|
79
|
+
*/
|
|
80
|
+
decimals?: number | undefined
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A token amount, expressed both in the token's base units (`amount`) and as a
|
|
85
|
+
* human-readable decimal string (`formatted`, derived from the token's
|
|
86
|
+
* `decimals`).
|
|
87
|
+
*/
|
|
88
|
+
export type Amount = {
|
|
89
|
+
/** Amount in the token's base units. */
|
|
90
|
+
amount: bigint
|
|
91
|
+
/** Token decimals used to derive `formatted`. */
|
|
92
|
+
decimals: number
|
|
93
|
+
/** Amount formatted as a human-readable decimal string. */
|
|
94
|
+
formatted: string
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** A write amount: a base-unit bigint, or an explicit formatted helper. */
|
|
98
|
+
export type AmountInput =
|
|
99
|
+
| bigint
|
|
100
|
+
| {
|
|
101
|
+
/** Token decimals used to parse `formatted`. */
|
|
102
|
+
decimals?: number | undefined
|
|
103
|
+
/** Human-readable decimal amount. */
|
|
104
|
+
formatted: string
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Shapes a base-unit value into an {@link Amount} (base units, `decimals`, and
|
|
109
|
+
* human-readable `formatted` string).
|
|
110
|
+
*
|
|
111
|
+
* @param amount - Amount in base units.
|
|
112
|
+
* @param decimals - Token decimals used to format the amount.
|
|
113
|
+
* @returns The {@link Amount}.
|
|
114
|
+
*/
|
|
115
|
+
export function toAmount(amount: bigint, decimals: number): Amount {
|
|
116
|
+
return { amount, decimals, formatted: formatUnits(amount, decimals) }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Resolves a write amount to base units.
|
|
121
|
+
*
|
|
122
|
+
* @param amount - Base-unit amount, or formatted helper.
|
|
123
|
+
* @param decimals - Token decimals used to parse formatted amounts.
|
|
124
|
+
* @returns Amount in base units.
|
|
125
|
+
*/
|
|
126
|
+
export function toBaseUnits(
|
|
127
|
+
amount: AmountInput,
|
|
128
|
+
decimals: number | undefined,
|
|
129
|
+
): bigint {
|
|
130
|
+
if (typeof amount === 'bigint') return amount
|
|
131
|
+
const resolved = amount.decimals ?? decimals
|
|
132
|
+
return parseUnits(amount.formatted, requireTokenDecimals(resolved))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Requires resolved token decimals for parsing or formatting amounts.
|
|
137
|
+
*
|
|
138
|
+
* @param decimals - Token decimals.
|
|
139
|
+
* @returns Token decimals.
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export function requireTokenDecimals(decimals: number | undefined): number {
|
|
143
|
+
if (decimals === undefined)
|
|
144
|
+
throw new Error(
|
|
145
|
+
'Token decimals are required. Pass `amount.decimals` or select a declared token.',
|
|
146
|
+
)
|
|
147
|
+
return decimals
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Resolves the decimals used for formatting a write amount.
|
|
152
|
+
*
|
|
153
|
+
* @param amount - Base-unit amount, or formatted helper.
|
|
154
|
+
* @param decimals - Token decimals.
|
|
155
|
+
* @returns Token decimals, overridden by the formatted helper when present.
|
|
156
|
+
*/
|
|
157
|
+
export function resolveAmountDecimals(
|
|
158
|
+
amount: AmountInput,
|
|
159
|
+
decimals: number | undefined,
|
|
160
|
+
): number | undefined {
|
|
161
|
+
if (typeof amount === 'bigint') return decimals
|
|
162
|
+
return amount.decimals ?? decimals
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Resolves the token contract `address` and `decimals` from a `token`, which is
|
|
167
|
+
* either the symbol of a token declared on the client's `tokens` array or a
|
|
168
|
+
* contract `address`.
|
|
169
|
+
*
|
|
170
|
+
* When `token` is a declared symbol, the `address` and `decimals` are resolved
|
|
171
|
+
* from the Client's `tokens` array for the Client's `chain.id` (`decimals` can
|
|
172
|
+
* be overridden via the explicit `decimals`). When `token` is an address, its
|
|
173
|
+
* `decimals` is inferred from the Client's `tokens` array when the address
|
|
174
|
+
* matches a declared token, otherwise taken from the explicit `decimals`.
|
|
175
|
+
*
|
|
176
|
+
* @param client - Client.
|
|
177
|
+
* @param parameters - Parameters.
|
|
178
|
+
* @returns The resolved `address` and `decimals`.
|
|
179
|
+
*/
|
|
180
|
+
export function resolveToken(
|
|
181
|
+
client: Client<Transport, Chain | undefined>,
|
|
182
|
+
parameters: resolveToken.Parameters,
|
|
183
|
+
): { address: Address; decimals: number | undefined } {
|
|
184
|
+
const { decimals, token } = parameters
|
|
185
|
+
|
|
186
|
+
const declared = findDeclaredToken(client, token)
|
|
187
|
+
if (declared)
|
|
188
|
+
return {
|
|
189
|
+
address: declared.address,
|
|
190
|
+
decimals: decimals ?? declared.decimals,
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isAddress(token, { strict: false }))
|
|
194
|
+
return {
|
|
195
|
+
address: token,
|
|
196
|
+
decimals: decimals ?? inferDecimals(client, token),
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
throw new Error(
|
|
200
|
+
`Token "${token}" is not a declared ERC-20 token on the client's \`tokens\` array (with an address for the client's chain), and is not a valid address.`,
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export namespace resolveToken {
|
|
205
|
+
export type Parameters = {
|
|
206
|
+
/** Decimals, if provided explicitly. */
|
|
207
|
+
decimals?: number | undefined
|
|
208
|
+
/** Token symbol (declared on the client's `tokens` array) or contract address. */
|
|
209
|
+
token: string
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Finds the declared token on the Client's `tokens` array matching `token`
|
|
215
|
+
* (either a token symbol or contract `address`), resolved to a {@link ResolvedToken}
|
|
216
|
+
* for the Client's `chain.id`. Returns `undefined` when no declared token
|
|
217
|
+
* matches, or the matching token has no address for the Client's chain.
|
|
218
|
+
*
|
|
219
|
+
* @param client - Client.
|
|
220
|
+
* @param token - Token symbol (declared on the client's `tokens` array) or contract address.
|
|
221
|
+
* @returns The matching resolved token config, or `undefined`.
|
|
222
|
+
*/
|
|
223
|
+
export function findDeclaredToken(
|
|
224
|
+
client: Client<Transport, Chain | undefined>,
|
|
225
|
+
token: string,
|
|
226
|
+
): ResolvedToken | undefined {
|
|
227
|
+
const tokens = client.tokens
|
|
228
|
+
const chainId = client.chain?.id
|
|
229
|
+
if (!tokens || chainId === undefined) return undefined
|
|
230
|
+
|
|
231
|
+
const bySymbol = findTokenBySymbol(tokens, token)
|
|
232
|
+
if (bySymbol) return resolveTokenForChain(bySymbol, chainId)
|
|
233
|
+
|
|
234
|
+
if (isAddress(token, { strict: false }))
|
|
235
|
+
for (const token_ of tokens) {
|
|
236
|
+
const resolved = resolveTokenForChain(token_, chainId)
|
|
237
|
+
if (resolved && isAddressEqual(resolved.address, token)) return resolved
|
|
238
|
+
}
|
|
239
|
+
return undefined
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Resolves a {@link Token} to a {@link ResolvedToken} for `chainId`, or
|
|
244
|
+
* `undefined` when the token has no address for `chainId`. @internal
|
|
245
|
+
*/
|
|
246
|
+
function resolveTokenForChain(
|
|
247
|
+
token: Token,
|
|
248
|
+
chainId: number,
|
|
249
|
+
): ResolvedToken | undefined {
|
|
250
|
+
const address = (token.addresses as Record<number, Address>)[chainId]
|
|
251
|
+
if (!address) return undefined
|
|
252
|
+
return {
|
|
253
|
+
address,
|
|
254
|
+
currency: token.currency,
|
|
255
|
+
decimals: token.decimals,
|
|
256
|
+
name: token.name,
|
|
257
|
+
popular: token.popular,
|
|
258
|
+
symbol: token.symbol,
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** Finds a {@link Token} by symbol (case-insensitively) on a `tokens` array. @internal */
|
|
263
|
+
function findTokenBySymbol(tokens: Tokens, symbol: string): Token | undefined {
|
|
264
|
+
const lowerSymbol = symbol.toLowerCase()
|
|
265
|
+
for (const token of tokens) {
|
|
266
|
+
if (token.symbol?.toLowerCase() === lowerSymbol) return token
|
|
267
|
+
}
|
|
268
|
+
return undefined
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Infers a token's `decimals` from the Client's `tokens` array by matching
|
|
273
|
+
* `address` against each token's address for the Client's `chain.id`.
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
function inferDecimals(
|
|
277
|
+
client: Client<Transport, Chain | undefined>,
|
|
278
|
+
address: Address,
|
|
279
|
+
): number | undefined {
|
|
280
|
+
const tokens = client.tokens
|
|
281
|
+
const chainId = client.chain?.id
|
|
282
|
+
if (tokens && chainId !== undefined)
|
|
283
|
+
for (const token of tokens) {
|
|
284
|
+
const resolved = resolveTokenForChain(token, chainId)
|
|
285
|
+
if (resolved && isAddressEqual(resolved.address, address))
|
|
286
|
+
return resolved.decimals
|
|
287
|
+
}
|
|
288
|
+
return undefined
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Resolves token decimals, fetching from the token contract when they are not
|
|
293
|
+
* provided explicitly or declared on the client.
|
|
294
|
+
* @internal
|
|
295
|
+
*/
|
|
296
|
+
export async function resolveTokenWithDecimals(
|
|
297
|
+
client: Client<Transport, Chain | undefined>,
|
|
298
|
+
parameters: resolveToken.Parameters,
|
|
299
|
+
): Promise<{ address: Address; decimals: number }> {
|
|
300
|
+
const { address, decimals } = resolveToken(client, parameters)
|
|
301
|
+
if (decimals !== undefined) return { address, decimals }
|
|
302
|
+
return {
|
|
303
|
+
address,
|
|
304
|
+
decimals: await readContract(client, {
|
|
305
|
+
abi: erc20Abi,
|
|
306
|
+
address,
|
|
307
|
+
functionName: 'decimals',
|
|
308
|
+
}),
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Picks the transaction-override fields shared by write actions, so the
|
|
314
|
+
* action-specific args (`token`, `amount`, `to`, etc.) don't leak into
|
|
315
|
+
* `estimateContractGas` / `simulateContract` requests. @internal
|
|
316
|
+
*/
|
|
317
|
+
export function pickWriteParameters(parameters: Record<string, unknown>) {
|
|
318
|
+
const { account, chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce } =
|
|
319
|
+
parameters
|
|
320
|
+
return { account, chain, gas, maxFeePerGas, maxPriorityFeePerGas, nonce }
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export type ReadParameters = Pick<
|
|
324
|
+
viem_ReadContractParameters<never, never, never>,
|
|
325
|
+
'account' | 'blockNumber' | 'blockOverrides' | 'blockTag' | 'stateOverride'
|
|
326
|
+
>
|
|
327
|
+
|
|
328
|
+
export type WriteParameters<
|
|
329
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
330
|
+
account extends Account | undefined = Account | undefined,
|
|
331
|
+
> = UnionPick<
|
|
332
|
+
viem_WriteContractSyncParameters<never, never, never, chain, account>,
|
|
333
|
+
| 'account'
|
|
334
|
+
| 'chain'
|
|
335
|
+
| 'gas'
|
|
336
|
+
| 'maxFeePerGas'
|
|
337
|
+
| 'maxPriorityFeePerGas'
|
|
338
|
+
| 'nonce'
|
|
339
|
+
| 'throwOnReceiptRevert'
|
|
340
|
+
>
|
|
341
|
+
|
|
342
|
+
export function defineCall<
|
|
343
|
+
const abi extends Abi,
|
|
344
|
+
const functionName extends ContractFunctionName<abi, AbiStateMutability>,
|
|
345
|
+
call extends ContractFunctionParameters<
|
|
346
|
+
abi,
|
|
347
|
+
AbiStateMutability,
|
|
348
|
+
functionName
|
|
349
|
+
>,
|
|
350
|
+
>(
|
|
351
|
+
call:
|
|
352
|
+
| call
|
|
353
|
+
| ContractFunctionParameters<abi, AbiStateMutability, functionName>,
|
|
354
|
+
): ContractFunctionParameters<
|
|
355
|
+
[ExtractAbiItem<abi, functionName>],
|
|
356
|
+
AbiStateMutability,
|
|
357
|
+
functionName
|
|
358
|
+
> & {
|
|
359
|
+
data: Hex
|
|
360
|
+
to: Address
|
|
361
|
+
} {
|
|
362
|
+
return {
|
|
363
|
+
...(call as any),
|
|
364
|
+
data: encodeFunctionData(call as never),
|
|
365
|
+
to: call.address,
|
|
366
|
+
} as const
|
|
367
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { Address } from 'abitype'
|
|
2
|
+
import type { Account } from '../../accounts/types.js'
|
|
3
|
+
import type { Client } from '../../clients/createClient.js'
|
|
4
|
+
import type { Transport } from '../../clients/transports/createTransport.js'
|
|
5
|
+
import { erc20Abi } from '../../constants/abis.js'
|
|
6
|
+
import type { BaseErrorType } from '../../errors/base.js'
|
|
7
|
+
import type { Tokens } from '../../tokens/defineToken.js'
|
|
8
|
+
import type { Chain } from '../../types/chain.js'
|
|
9
|
+
import type { Log } from '../../types/log.js'
|
|
10
|
+
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
|
|
11
|
+
import { estimateContractGas } from '../public/estimateContractGas.js'
|
|
12
|
+
import {
|
|
13
|
+
type SimulateContractReturnType,
|
|
14
|
+
simulateContract,
|
|
15
|
+
} from '../public/simulateContract.js'
|
|
16
|
+
import type { WriteContractReturnType } from '../wallet/writeContract.js'
|
|
17
|
+
import { writeContract } from '../wallet/writeContract.js'
|
|
18
|
+
import type { writeContractSync } from '../wallet/writeContractSync.js'
|
|
19
|
+
import {
|
|
20
|
+
type AmountInput,
|
|
21
|
+
defineCall,
|
|
22
|
+
pickWriteParameters,
|
|
23
|
+
resolveToken,
|
|
24
|
+
type TokenParameter,
|
|
25
|
+
toBaseUnits,
|
|
26
|
+
type WriteParameters,
|
|
27
|
+
} from './internal.js'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Transfers ERC-20 tokens to another address.
|
|
31
|
+
*
|
|
32
|
+
* Pass `from` to transfer on behalf of another address using an allowance
|
|
33
|
+
* (calls `transferFrom`); otherwise transfers from the caller (calls
|
|
34
|
+
* `transfer`).
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { createClient, http } from 'viem'
|
|
39
|
+
* import { mainnet } from 'viem/chains'
|
|
40
|
+
* import { privateKeyToAccount } from 'viem/accounts'
|
|
41
|
+
* import { token } from 'viem/actions'
|
|
42
|
+
*
|
|
43
|
+
* const client = createClient({
|
|
44
|
+
* account: privateKeyToAccount('0x...'),
|
|
45
|
+
* chain: mainnet,
|
|
46
|
+
* transport: http(),
|
|
47
|
+
* })
|
|
48
|
+
*
|
|
49
|
+
* const hash = await token.transfer(client, {
|
|
50
|
+
* amount: 100000000n,
|
|
51
|
+
* to: '0x...',
|
|
52
|
+
* token: '0x...',
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Transfer on behalf of another address (via an allowance).
|
|
59
|
+
* const hash = await token.transfer(client, {
|
|
60
|
+
* amount: 100000000n,
|
|
61
|
+
* from: '0x...',
|
|
62
|
+
* to: '0x...',
|
|
63
|
+
* token: '0x...',
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @param client - Client.
|
|
68
|
+
* @param parameters - Parameters.
|
|
69
|
+
* @returns The transaction hash.
|
|
70
|
+
*/
|
|
71
|
+
export async function transfer<
|
|
72
|
+
chain extends Chain | undefined,
|
|
73
|
+
account extends Account | undefined,
|
|
74
|
+
tokens extends Tokens | undefined = undefined,
|
|
75
|
+
>(
|
|
76
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
77
|
+
parameters: transfer.Parameters<chain, account, tokens>,
|
|
78
|
+
): Promise<transfer.ReturnValue> {
|
|
79
|
+
return transfer.inner(writeContract, client, parameters)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export namespace transfer {
|
|
83
|
+
export type Args<
|
|
84
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
85
|
+
tokens extends Tokens | undefined = Tokens | undefined,
|
|
86
|
+
> = {
|
|
87
|
+
/** Amount to transfer in base units, or as a formatted helper. */
|
|
88
|
+
amount: AmountInput
|
|
89
|
+
/** Address to transfer tokens from (uses an allowance via `transferFrom`). */
|
|
90
|
+
from?: Address | undefined
|
|
91
|
+
/** Address to transfer tokens to. */
|
|
92
|
+
to: Address
|
|
93
|
+
} & TokenParameter<chain, tokens>
|
|
94
|
+
export type Parameters<
|
|
95
|
+
chain extends Chain | undefined = Chain | undefined,
|
|
96
|
+
account extends Account | undefined = Account | undefined,
|
|
97
|
+
tokens extends Tokens | undefined = Tokens | undefined,
|
|
98
|
+
> = WriteParameters<chain, account> & Args<chain, tokens>
|
|
99
|
+
export type ReturnValue = WriteContractReturnType
|
|
100
|
+
// TODO: exhaustive error type
|
|
101
|
+
export type ErrorType = BaseErrorType
|
|
102
|
+
|
|
103
|
+
/** @internal */
|
|
104
|
+
export async function inner<
|
|
105
|
+
action extends typeof writeContract | typeof writeContractSync,
|
|
106
|
+
chain extends Chain | undefined,
|
|
107
|
+
account extends Account | undefined,
|
|
108
|
+
tokens extends Tokens | undefined = undefined,
|
|
109
|
+
>(
|
|
110
|
+
action: action,
|
|
111
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
112
|
+
parameters: transfer.Parameters<chain, account, tokens>,
|
|
113
|
+
): Promise<ReturnType<action>> {
|
|
114
|
+
return (await action(client, {
|
|
115
|
+
...parameters,
|
|
116
|
+
...transfer.call(client, parameters as never),
|
|
117
|
+
} as never)) as never
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Defines a call to the `transfer` (or `transferFrom`, when `from` is given)
|
|
122
|
+
* function.
|
|
123
|
+
*
|
|
124
|
+
* Can be passed as a parameter to `estimateContractGas`, `simulateContract`,
|
|
125
|
+
* `sendCalls`, `sendTransaction` (`calls`), or `multicall`. The token is
|
|
126
|
+
* selected by `token`, which is either a token symbol (resolved from the
|
|
127
|
+
* client's `tokens` array) or a contract `address`; `amount.decimals`
|
|
128
|
+
* is inferred from declared client tokens when omitted.
|
|
129
|
+
*
|
|
130
|
+
* @param client - Client.
|
|
131
|
+
* @param parameters - Parameters.
|
|
132
|
+
* @returns The call.
|
|
133
|
+
*/
|
|
134
|
+
export function call<
|
|
135
|
+
chain extends Chain | undefined,
|
|
136
|
+
account extends Account | undefined,
|
|
137
|
+
tokens extends Tokens | undefined = undefined,
|
|
138
|
+
>(
|
|
139
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
140
|
+
parameters: Args<chain, tokens>,
|
|
141
|
+
) {
|
|
142
|
+
return defineCall(getCall(client, parameters as transfer.Args))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Estimates the gas required to transfer ERC-20 tokens. `amount.decimals` is
|
|
147
|
+
* inferred from declared client tokens when omitted.
|
|
148
|
+
*
|
|
149
|
+
* @param client - Client.
|
|
150
|
+
* @param parameters - Parameters.
|
|
151
|
+
* @returns The gas estimate.
|
|
152
|
+
*/
|
|
153
|
+
export async function estimateGas<
|
|
154
|
+
chain extends Chain | undefined,
|
|
155
|
+
account extends Account | undefined,
|
|
156
|
+
tokens extends Tokens | undefined = undefined,
|
|
157
|
+
>(
|
|
158
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
159
|
+
parameters: transfer.Parameters<chain, account, tokens>,
|
|
160
|
+
): Promise<bigint> {
|
|
161
|
+
return estimateContractGas(client, {
|
|
162
|
+
...pickWriteParameters(parameters as never),
|
|
163
|
+
...transfer.call(client, parameters as never),
|
|
164
|
+
} as never)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Simulates a transfer of ERC-20 tokens. `amount.decimals` is inferred from
|
|
169
|
+
* declared client tokens when omitted.
|
|
170
|
+
*
|
|
171
|
+
* @param client - Client.
|
|
172
|
+
* @param parameters - Parameters.
|
|
173
|
+
* @returns The simulation result and write request.
|
|
174
|
+
*/
|
|
175
|
+
export async function simulate<
|
|
176
|
+
chain extends Chain | undefined,
|
|
177
|
+
account extends Account | undefined,
|
|
178
|
+
tokens extends Tokens | undefined = undefined,
|
|
179
|
+
>(
|
|
180
|
+
client: Client<Transport, chain, account, undefined, undefined, tokens>,
|
|
181
|
+
parameters: transfer.Parameters<chain, account, tokens>,
|
|
182
|
+
): Promise<
|
|
183
|
+
SimulateContractReturnType<typeof erc20Abi, 'transfer' | 'transferFrom'>
|
|
184
|
+
> {
|
|
185
|
+
return simulateContract(client, {
|
|
186
|
+
...pickWriteParameters(parameters as never),
|
|
187
|
+
...transfer.call(client, parameters as never),
|
|
188
|
+
} as never) as never
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Extracts the `Transfer` event from logs.
|
|
193
|
+
*
|
|
194
|
+
* @param logs - The logs.
|
|
195
|
+
* @returns The `Transfer` event.
|
|
196
|
+
*/
|
|
197
|
+
export function extractEvent(logs: Log[]) {
|
|
198
|
+
const [log] = parseEventLogs({
|
|
199
|
+
abi: erc20Abi,
|
|
200
|
+
logs,
|
|
201
|
+
eventName: 'Transfer',
|
|
202
|
+
strict: true,
|
|
203
|
+
})
|
|
204
|
+
if (!log) throw new Error('`Transfer` event not found.')
|
|
205
|
+
return log
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** Builds the underlying `transfer`/`transferFrom` contract call. @internal */
|
|
210
|
+
function getCall(
|
|
211
|
+
client: Client<Transport, Chain | undefined>,
|
|
212
|
+
parameters: transfer.Args,
|
|
213
|
+
) {
|
|
214
|
+
const { amount, from, to, token } = parameters
|
|
215
|
+
const { address, decimals } = resolveToken(client, { token })
|
|
216
|
+
const value = toBaseUnits(amount, decimals)
|
|
217
|
+
if (from)
|
|
218
|
+
return {
|
|
219
|
+
abi: erc20Abi,
|
|
220
|
+
address,
|
|
221
|
+
args: [from, to, value],
|
|
222
|
+
functionName: 'transferFrom',
|
|
223
|
+
} as const
|
|
224
|
+
return {
|
|
225
|
+
abi: erc20Abi,
|
|
226
|
+
address,
|
|
227
|
+
args: [to, value],
|
|
228
|
+
functionName: 'transfer',
|
|
229
|
+
} as const
|
|
230
|
+
}
|