Types
Glossary of types exported from Box Common. These types are used across @decent.xyz/the-box
, @decent.xyz/box-hooks
, and @decent.xyz/box-ui
packages.
Address
type SolanaAddress = string;
type CosmosAddress = string;
type EvmAddress = `0x${string}`;
type Address = EvmAddress | SolanaAddress | CosmosAddress;
ActionType
Action types help define parameters for common transaction types. The ActionType
is a required argument to send any Decent transaction. Each ActionType
has a corresponding ActionConfig
.
ActionType | Description | ActionConfig |
---|---|---|
ActionType.EvmFunction | Build the calldata for any EVM transaction. Default option. | EvmFunction |
ActionType.SwapAction | Execute a cross-chain swap. | SwapActionConfig |
ActionType.NftMint | Mint an NFT. | NftMintConfig |
ActionType.NftPreferMint | Mint. If sold out, buy on secondary if there are available listings. | NftPreferMintConfig |
ActionType.NftFillAsk | Buy an NFT off secondaries. | NftFillAsk |
ActionType.EvmCalldataTx | Pass in the calldata required to execute the transaction. See example | EvmCalldataTx |
ActionConfig
Action types above extend BaseActionConfig
to fulfill the desired transaction. ActionConfig
is required to send any transaction.
BaseActionConfig
interface BaseActionConfig {
chainId: ChainId;
cost?: Payment;
allowSwapping?: boolean;
allowBridging?: boolean;
onlyAllowTokens?: Lookup<ChainId, Address[]>;
contractAddress?: Address;
}
Parameter | Description | Default |
---|---|---|
chainId | Chain ID of the destination network. | N/A |
cost | Token and value required to complete the transaction. | N/A |
allowSwapping | Optionally prevent any-token payments. | true |
allowBridging | Optionally prevent cross-chain transactions. | true |
onlyAllowTokens | Specify a target list of accepted tokens (e.g., only ETH & USDC). | Any token with DeFi liquidity. |
contractAddress | Target contract address to call in transaction. | N/A |
EvmFunction
{{
chainId: ChainId,
contractAddress: Address,
cost: Payment,
signature: string,
args: Array,
}}
Parameter | Description | Default |
---|---|---|
signature | Smart contract function signature for target action. | N/A |
args | Arguments required to fulfill signature. | N/A |
SwapActionConfig
enum SwapDirection {
EXACT_AMOUNT_IN = 'exact-amount-in',
EXACT_AMOUNT_OUT = 'exact-amount-out',
}
interface SwapActionConfig extends BaseActionConfig {
swapDirection: SwapDirection;
amount: bigint;
receiverAddress?: Address;
}
Parameter | Description | Default |
---|---|---|
swapDirection | Direction of swap calculation. | N/A |
amount | WEI requested to swap. | N/A |
receiverAddress | Target address to receive funds on destination chain. | Sender's wallet address. |
NftMintConfig
The NftMintConfig and EvmFunction configs are equivalent. Different action types exist strictly to help guide developer effort.
{{
chainId: ChainId,
contractAddress: Address,
cost: Payment,
signature: string,
args: Array,
}}
NftFillAskConfig
{{
chainId: ChainId,
contractAddress: Address,
tokenId: number,
}}
Parameter | Description | Default |
---|---|---|
tokenId | ID of NFT in collection to purchase. | ID of lowest priced NFT in collection. |
recipient | Optionally send purchased NFT to another wallet. | Sender's wallet address. |
NftPreferMintConfig
These additional parameters are to signal the end of an NFT's mint. Once the mint ends, Decent will automatically source the lowest priced available listing on secondary markets, so that users can continue to purchase NFTs from the same interface.
actionConfig={{
chainId: ChainId,
contractAddress: Address,
cost: Payment,
signature: string,
args: Array,
supplyConfig: {
maxCap?: number,
sellOutDate?: number,
}
}}
Parameter | Description | Default |
---|---|---|
maxCap | Total number of NFTs in collection. | undefined |
sellOutDate | Unix timestamp for NFT mint's end time. | undefined |
BoxActionRequest
Schema for arguments passed to the useBoxAction
hook or /getBoxAction
API endpoint.
interface BoxActionRequest {
sender: string;
srcToken: string;
srcChainId: ChainId;
dstToken: string;
dstChainId: ChainId;
slippage: number;
actionType: ActionType;
actionConfig: ActionConfig;
enable?: boolean;
}
Parameter | Description |
---|---|
srcToken & dstToken | ERC-20 token addresses. Use the zero address if it's a native token. Viem exports this. |
srcChainId & dstChainId | The chain ID's of the source and the destination chains. If your transaction is not crosschain, set them to the same ID. |
slippage | Amount of slippage you'd allow in your route. Cannot be zero, the default value is 1. |
actionType & actionConfig | Any of our supported action types and their corresponding action configs. |
enable (optional) | Set to false to disable the query for automatically running - similar to wagmi's enabled option. |
BoxActionResponse
Schema of the response from either the useBoxAction
hook or /getBoxAction
API endpoint.
Sample response
{
"tx": {
"to": "0x1572D48a52906B834FB236AA77831d669F6d87A1",
"chainId": 10,
"data": "0x49406927000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000005c00000000000000000000000000000000000000000000000000000000000000660000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002105000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda029130000000000000000000000005d7370fcd6e446bbc14a64c1effe5fbb1c89323200000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000052000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000600000000000000000000000001572d48a52906b834fb236aa77831d669f6d87a10000000000000000000000005d7370fcd6e446bbc14a64c1effe5fbb1c893232000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000000000000000000000000000000000000006000000000000000000000000043019f8be1f192587883b67dea2994999f5a2de20000000000000000000000005d7370fcd6e446bbc14a64c1effe5fbb1c893232000000000000000000000000000000000000000000000000016345785d8a0000000000000000000000000000000000000000000000000000000000000e7f7e4b0000000000000000000000004200000000000000000000000000000000000006000000000000000000000000833589fcd6edb6e08f4c7c32d4f71b54bda02913000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000002b4200000000000000000000000000000000000006000064833589fcd6edb6e08f4c7c32d4f71b54bda029130000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044a9059cbb0000000000000000000000005d7370fcd6e446bbc14a64c1effe5fbb1c893232000000000000000000000000000000000000000000000000000000000e7f7e4b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000001e8480b38801d6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035397ac36e0900000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004178cc11482be0f2c3e4b22d97144d3c0bfad88a13950f15d57a55a9497509dde731824c4ce494e21f20e76269020b19275ccae3821a10cfc83149d668056352ff1b00000000000000000000000000000000000000000000000000000000000000",
"value": "100268520989036041n"
},
"tokenPayment": {
"amount": "100000000000000000n",
"tokenAddress": "0x0000000000000000000000000000000000000000",
"chainId": 10,
"isNative": true,
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"amountOut": {
"amount": "243236427n",
"tokenAddress": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
"chainId": 8453,
"isNative": false,
"name": "USD Coin",
"symbol": "USDC",
"decimals": 6
},
"protocolFee": {
"amount": "210000000000000n",
"tokenAddress": "0x0000000000000000000000000000000000000000",
"chainId": 10,
"isNative": true,
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"applicationFee": {
"amount": "0n",
"tokenAddress": "0x0000000000000000000000000000000000000000",
"chainId": 10,
"isNative": true,
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"bridgeFee": {
"amount": "58520989036041n",
"tokenAddress": "0x0000000000000000000000000000000000000000",
"chainId": 10,
"isNative": true,
"name": "Ether",
"symbol": "ETH",
"decimals": 18
},
"bridgeIds": [
"decent"
],
"exchangeRate": 2432.36427,
"estimatedTxTime": 23
}
interface BoxActionResponse {
tx: {
to: Address; // `0x${string}`
chainId: ChainId;
data: Hash; // `0x${string}`
value: string; // bigint - e.g., "10000000n"
};
tokenPayment: Payment;
amountOut: Payment;
applicationFee: Payment;
exchangeRate: number;
bridgeId?: BridgeId;
estimatedTxTime: number;
}
Parameter | Description |
---|---|
tx | A Transaction object you can use to submit with your dapp |
tokenPayment | Source payment token for the action taken. |
applicationFee | Fee that the implementing application collects |
bridgeId | ID of the bridge used for this transaction. |
exchangeRate | Exchange rate between the source, tokenPayment.tokenAddress , and destination, amountOut.tokenAddress , tokens. |
estimatedTxTime | Estimated time until the destination tx confirms. |
ChainId
ChainId is an enum
that provides quick access to the Chain ID's of Decent's supported chains.
enum ChainId {
ETHEREUM = 1,
SEPOLIA = 11155111,
OPTIMISM = 10,
OPTIMISM_SEPOLIA = 11155420,
POLYGON = 137,
POLYGON_TESTNET = 80001,
ARBITRUM = 42161,
ARBITRUM_SEPOLIA = 421614,
BASE = 8453,
SOLANA_MAINNET = 1399811149,
...
}
TokenInfo
interface TokenId {
address: Address;
chainId: ChainId;
}
interface TokenInfo extends TokenId {
decimals: number;
symbol: string;
name: string;
isNative: boolean;
chainId: ChainId;
logo?: string;
}