@khalani-labs/arcadia-sdk
v0.0.7
Published
A lightweight SDK for interacting with Arcadia contracts using ethers.js
Maintainers
Readme
Khalani SDK Documentation
Table of Contents
Initialize Arcadia SDK
Example
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const walletService = arcadiaSDK.walletServiceWallet Functions
getArcadiaChainInfo
Returns information about Arcadia chain based on the specified network.
Location: Wallet class
Parameters: none
Returns:
interface ArcadiaChainInfo {
chainId: number
name: string
rpcUrl: string[]
}Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const walletService = arcadiaSDK.walletService
const chainInfo = walletService.getArcadiaChainInfo()getArcadiaRPCUrl
Returns the RPC URL for the Arcadia chain.
Location: Wallet class
Parameters: none
Returns: string - The RPC URL for the specified network
Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const walletService = arcadiaSDK.walletService
const rpcUrl = walletService.getArcadiaRPCUrl()getMedusaRPCUrl
Returns the RPC URL for the Medusa service.
Location: Wallet class
Parameters: none
Returns: string - The Medusa RPC URL for the specified network
Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const walletService = arcadiaSDK.walletService
const medusaUrl = walletService.getMedusaRPCUrl()Contract Functions
getMTokenAddress
Returns the address of an mToken based on the underlying token and network.
Location: Contract class
Parameters:
chainId: number // The chain id
tokenAddress: string // Spoke token addressReturns: string - The address of the corresponding mToken
Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const contractService = arcadiaSDK.contractService
const mTokenAddress = contractService.getMTokenAddress(1, '0x1234567890abcdef')getIntentBookABI
Returns the constant ABI for the IntentBook contract.
Location: Contract class
Parameters: none
Returns: A constant value (using as const) representing the IntentBook ABI.
Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const contractService = arcadiaSDK.contractService
const intentBookABI = contractService.getIntentBookABI()getMTokenABI
Returns the constant ABI for the MToken contract.
Location: Contract class
Parameters: none
Returns: A constant value (using as const) representing the MToken ABI.
Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const contractService = arcadiaSDK.contractService
const mTokenABI = contractService.getMTokenABI()getAssetReservesABI
Returns the constant ABI for the AssetReserves contract.
Location: Contract class
Parameters: none
Returns: A constant value (using as const) representing the AssetReserves ABI.
Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const contractService = arcadiaSDK.contractService
const mTokenABI = contractService.getAssetReservesABI()Deposit Functions
| Function | Description |
| ----------------------- | ------------------------------------------------------ |
| ensureERC20Allowance | Checks and approves ERC-20 allowance if needed. |
| depositTraditional | Deposits tokens using traditional transferFrom. |
| depositWithPermit2 | Deposits tokens using Uniswap Permit2 signed approval. |
| populateTraditionalTx | Builds a raw transaction for traditional deposit. |
| populatePermit2Tx | Builds a raw transaction for Permit2 deposit. |
ensureERC20Allowance
Ensures the AssetReserves contract has enough ERC-20 token allowance, sending an approve transaction if the current allowance is below the required amount.
public async ensureERC20Allowance(
chainId: number,
tokenAddress: string,
requiredAmount: bigint
): Promise<ContractTransactionReceipt | null>Location: DepositService class
Parameters:
chainId— The ID of the blockchain network (e.g., 1 for Ethereum Mainnet)tokenAddress— The ERC-20 token contract addressrequiredAmount— The minimum amount of tokens that must be approved
Returns:
ContractTransactionReceiptif an approve transaction was submittednullif the existing allowance already meets or exceedsrequiredAmount
depositTraditional
Calls the Solidity function:
function deposit(
address token,
uint256 amount,
uint32 destChain
) external payableTransfers tokens via transferFrom without Permit2.
public async depositTraditional(
tokenAddress: `0x${string}`,
amount: bigint
): Promise<ContractTransactionReceipt>Location: DepositService class
Parameters:
chainId— Destination chain IDtokenAddress— Token contract address
Returns:
ContractTransactionReceiptof the deposit call
depositWithPermit2
Calls the extended Solidity function:
function deposit(
address token,
uint256 amount,
uint32 destChain,
uint256 permitNonce,
uint256 deadline,
bytes signature
) external payableUses Uniswap Permit2 for off-chain approval.
public async depositWithPermit2(
tokenAddress: string,
amount: bigint,
nonce: bigint,
deadline: bigint,
account: string,
signature: `0x${string}`
): Promise<ContractTransactionReceipt>Location: DepositService class
Parameters:
chainId— Destination chain IDtokenAddress— Token contract addressamount— Token amount to depositnonce— Permit2 nonce valuedeadline— Permit2 deadline timestampaccount— Wallet address of the depositorsignature— EIP-712 Permit2 signature
Returns:
ContractTransactionReceiptof the deposit call
populateTraditionalTx
Builds a plain transaction object for signing and broadcasting later.
public populateTraditionalTx(
fromChainId: number,
toChainId: number,
tokenAddress: string,
tokenAmount: bigint
): PopulatedTransactionLocation: DepositService class
Returns:
- A
PopulatedTransactionready to be signed
populatePermit2Tx
Builds a plain transaction object for Permit2 deposit.
public populatePermit2Tx(args: {
fromChainId: number
toChainId: number
tokenAddress: string
tokenAmount: bigint
permitNonce: bigint
deadline: bigint
signature: `0x${string}`
}): PopulatedTransactionLocation: DepositService class
Returns:
- A
PopulatedTransactionready to be signed
getGasValue
Returns the gas value needed to cover the protocol fee when calling deposit functions.
public getGasValue = (): BigNumberLocation: DepositService class
Returns:
- A
BigNumberready to be passed
Usage Example
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const sdk = new ArcadiaSDK('EthersV5')
const depositService = sdk.depositService
// 1. Traditional flow:
await depositService.ensureERC20Allowance(1, tokenAddress, amount)
const receipt1 = await depositService.depositTraditional(
1,
tokenAddress,
amount,
)
// 2. Permit2 flow:
const { nonce, deadline, signature } = await depositService.signPermit2Message(
1,
tokenAddress,
amount,
intentNonce,
intentDeadline,
)
const receipt2 = await depositService.depositWithPermit2(
1,
tokenAddress,
amount,
nonce,
deadline,
sdk.wallet.getUserAddress(),
signature,
)
// 3. Or build raw tx:
const txData = depositService.populateTraditionalTx(1, 5, tokenAddress, amount)
// sign & send txData with your wallet…Intent Functions
buildSignIntentPayload
Creates a payload for signing an intent.
Location: Intent service
Parameters:
interface SignIntentPayloadProps {
refineResult: {
outcome: {
author: string
ttl: string
nonce: string
srcMToken: string
srcAmount: string
outcome: {
mAmounts: string[]
mTokens: string[]
outcomeAssetStructure: string
fillStructure: string
}
}
}
account: string
}Returns:
interface SignIntentPayload {
domain: typeof intentDomain
types: typeof intentTypes
message: {
author: `0x${string}`
ttl: bigint
nonce: bigint
srcMToken: `0x${string}`
srcAmount: bigint
outcome: {
mTokens: `0x${string}`[]
mAmounts: bigint[]
outcomeAssetStructure: OutcomeAssetStructure
fillStructure: FillStructure
}
}
primaryType: string
account: string
}Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const intentService = arcadiaSDK.intentService
const signPayload = intentService.buildSignIntentPayload({
refineResult: {
outcome: {
author: '0xSenderAddress',
ttl: '1234567890',
nonce: '1',
srcMToken: '0xTokenAddress',
srcAmount: '1000000000000000000',
outcome: {
mAmounts: ['1000000000000000000'],
mTokens: ['0xReceiverTokenAddress'],
outcomeAssetStructure: 'AnySingle',
fillStructure: 'Exact',
},
},
},
account: '0xSenderAddress',
})proposeIntent
Proposing a new intent.
Location: Intent service
Parameters:
interface ProposeIntentPayloadProps {
refineResult: {
outcome: {
author: string
ttl: string
nonce: string
srcMToken: string
srcAmount: string
outcome: {
mAmounts: string[]
mTokens: string[]
outcomeAssetStructure: string
fillStructure: string
}
}
}
signature: string
}Returns:
type ProposeIntentResult = stringExample:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const intentService = arcadiaSDK.intentService
const refineResult = {
outcome: {
author: '0xAuthorAddress',
ttl: '1234567890',
nonce: '1',
srcMToken: '0xTokenAddress',
srcAmount: '1000000000000000000',
outcome: {
mAmounts: ['2000000000000000000'],
mTokens: ['0xTargetTokenAddress'],
outcomeAssetStructure: 'AnySingle',
fillStructure: 'Exact',
},
},
}
const signature = '0xSignatureHex'
const proposePayload = intentService.proposeIntent(refineResult, signature)getIntentStatus
Querying the status of an intent.
Location: Intent service
Parameters:
interface GetIntentStatusPayloadProps {
intentId: string
}Returns:
enum RpcIntentState {
NonExistent = 'NonExistent',
Open = 'Open',
Locked = 'Locked',
Solved = 'Solved',
Settled = 'Settled',
Expired = 'Expired',
Cancelled = 'Cancelled',
}Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const intentService = arcadiaSDK.intentService
const statusPayload = intentService.buildGetIntentStatusPayload({
intentId: '0x123456789abcdef',
})buildGetIntentNoncePayload
Creates a payload for getting the next nonce for an intent.
Location: Intent service
Parameters:
interface GetIntentNoncePayloadProps {
address: string // Address to get the nonce for
}Returns:
interface GetIntentNoncePayload {
name: string // RPC method name
params: string[]
abi: InterfaceAbi
}Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const intentService = arcadiaSDK.intentService
const noncePayload = intentService.buildGetIntentNoncePayload({
address: '0xUserWalletAddress',
})Refine Functions
createRefine
Creating a new Refine transaction.
Location: Refine service
Parameters:
interface CreateRefinePayloadProps {
args: {
accountAddress: string
fromChainId: number
fromTokenAddress: string
amount: bigint
toChainId: number
toTokenAddress: string
currentNonce: bigint
}
}Returns:
The createRefine function returns an ID that can be used later to query Refine
type CreateRefineResult = stringExample:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const refineService = arcadiaSDK.refineService
const createPayload = refineService.createRefine({
accountAddress: '0xSenderAddress',
fromChainId: 31337,
fromTokenAddress: '0xTokenAddress',
amount: BigInt('1000000000000000000'),
toChainId: 31337,
toTokenAddress: '0xTokenAddress',
currentNonce: BigInt(1),
})queryRefine
Querying information about a Refine transaction.
Location: Refine service
Parameters:
interface QueryRefinePayloadProps {
refineId: string // ID of the Refine transaction to query
}Returns:
export type RefineResultOrNotFound = RefineResult | RefineResultStatus
export interface RefineResult {
Refinement: {
author: string
ttl: string
nonce: string
srcMToken: string
srcAmount: string
outcome: {
mAmounts: string[]
mTokens: string[]
outcomeAssetStructure: string
fillStructure: string
}
}
}
export enum RefineResultStatus {
RefinementNotFound = 'RefinementNotFound',
}Example:
import { ArcadiaSDK } from 'arcadia-sdk-wip'
const arcadiaSDK = new ArcadiaSDK('EthersV5')
const refineService = arcadiaSDK.refineService
const queryPayload = refineService.queryRefine('0x123456789abcdef')Notes
This documentation provides detailed interface definitions for the main functions in the Khalani SDK standalone module. For complete usage documentation, refer to the full SDK documentation. Each function's actual implementation may require additional parameters or have specific behavior based on the network or context.
To use these functions, you'll typically need to initialize the appropriate service or utility class with configuration settings specific to your environment.
