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 |
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
actionConfig={{
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.
actionConfig={{
chainId: ChainId,
contractAddress: Address,
cost: Payment,
signature: string,
args: Array,
}}
NftFillAskConfig
actionConfig={{
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 |
Payment
interface TokenPayment {
amount: bigint;
isNative?: false;
tokenAddress: Address;
}
interface NativePayment {
amount: bigint;
isNative: true;
tokenAddress?: Address;
}
export type Payment = TokenPayment | NativePayment;
Parameter | Description | Default |
---|---|---|
amount | WEI required to complete tx | N/A |
isNative | Dictate if transaction in ERC20 or gas token | Required - set to true if native |
tokenAddress | ERC20 token address for tx | Required if !isNative |
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.
interface BoxActionResponse {
tx: Transaction;
tokenPayment?: Payment;
applicationFee?: Payment;
bridgeFee?: Payment;
bridgeId?: BridgeId;
};
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 |
bridgeFee | Fee that the bridge provider collects |
bridgeId | ID of the bridge used for this transaction. |
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;
}