@0x/0x-parser
Version:
🧾 Designed for 0x integrators: This library parses 0x transactions on EVM blockchains into a format that is both user-friendly and easy to understand.
191 lines (180 loc) • 4.86 kB
text/typescript
import { defineChain } from "viem";
import {
bsc,
base,
mode,
blast,
linea,
scroll,
mantle,
plasma,
mainnet,
polygon,
arbitrum,
unichain,
optimism,
avalanche,
berachain,
worldchain,
monad,
abstract,
} from "viem/chains";
import type { SupportedChainId } from "./types";
// Robinhood Chain is not exported from viem/chains, so we define it locally.
export const robinhoodChain = defineChain({
id: 4663,
name: "Robinhood Chain",
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: { http: ["https://rpc.chain.robinhood.com"] },
},
blockExplorers: {
default: {
name: "Blockscout",
url: "https://robinhoodchain.blockscout.com",
},
},
contracts: {
multicall3: { address: "0xca11bde05977b3631167028862be2a173976ca11" },
},
});
export const FORWARDING_MULTICALL_ABI = [
{
"type": "receive",
"stateMutability": "payable"
},
{
"type": "function",
"name": "multicall",
"inputs": [
{
"name": "calls",
"type": "tuple[]",
"internalType": "struct IMultiCall.Call[]",
"components": [
{
"name": "target",
"type": "address",
"internalType": "address"
},
{
"name": "revertPolicy",
"type": "uint8",
"internalType": "enum IMultiCall.RevertPolicy"
},
{
"name": "value",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "data",
"type": "bytes",
"internalType": "bytes"
}
]
},
{
"name": "contextdepth",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "tuple[]",
"internalType": "struct IMultiCall.Result[]",
"components": [
{
"name": "success",
"type": "bool",
"internalType": "bool"
},
{
"name": "data",
"type": "bytes",
"internalType": "bytes"
}
]
}
],
"stateMutability": "payable"
}
]
export const SETTLER_META_TXN_ABI = [
{
inputs: [
{
components: [
{ internalType: "address", name: "recipient", type: "address" },
{
internalType: "contract IERC20",
name: "buyToken",
type: "address",
},
{ internalType: "uint256", name: "minAmountOut", type: "uint256" },
],
internalType: "struct SettlerBase.AllowedSlippage",
name: "slippage",
type: "tuple",
},
{ internalType: "bytes[]", name: "actions", type: "bytes[]" },
{ internalType: "bytes32", name: "", type: "bytes32" },
{ internalType: "address", name: "msgSender", type: "address" },
{ internalType: "bytes", name: "sig", type: "bytes" },
],
name: "executeMetaTxn",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
stateMutability: "nonpayable",
type: "function",
},
] as const;
export const FUNCTION_SELECTORS = { EXECUTE_META_TXN: "0xfd3ad6d4" };
export const SUPPORTED_CHAINS = [
bsc,
base,
mode,
blast,
linea,
scroll,
mantle,
plasma,
mainnet,
polygon,
arbitrum,
unichain,
optimism,
avalanche,
berachain,
worldchain,
monad,
abstract,
robinhoodChain,
];
export const NATIVE_SYMBOL_BY_CHAIN_ID: { [key in SupportedChainId]: string } =
{
[]: bsc.nativeCurrency.symbol,
[]: base.nativeCurrency.symbol,
[]: mode.nativeCurrency.symbol,
[]: blast.nativeCurrency.symbol,
[]: linea.nativeCurrency.symbol,
[]: scroll.nativeCurrency.symbol,
[]: mantle.nativeCurrency.symbol,
[]: monad.nativeCurrency.symbol,
[]: plasma.nativeCurrency.symbol,
[]: mainnet.nativeCurrency.symbol,
[]: polygon.nativeCurrency.symbol,
[]: unichain.nativeCurrency.symbol,
[]: optimism.nativeCurrency.symbol,
[]: arbitrum.nativeCurrency.symbol,
[]: avalanche.nativeCurrency.symbol,
[]: berachain.nativeCurrency.symbol,
[]: worldchain.nativeCurrency.symbol,
[]: abstract.nativeCurrency.symbol,
[]: robinhoodChain.nativeCurrency.symbol,
};
export const NATIVE_TOKEN_ADDRESS = `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`;
export const FORWARDING_MULTICALL_ADDRESS = `0x00000000000000cf9e3c5a26621af382fa17f24f`;
export const MULTICALL3_ADDRESS = `0xcA11bde05977b3631167028862bE2a173976CA11`;
export const ERC_4337_ENTRY_POINT = `0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789`;