This CosmWasm smart contract facilitates cross-chain operations for the Palomagold token, including bridging, chain registration, and administrative updates. It is designed for secure, auditable, and upgradable deployments.
- State: Stores the contract owner and the Palomagold token denomination.
- ChainSetting: Stores per-chain configuration, including the job ID for cross-chain operations.
- Storage Keys:
STATE
: Singleton for contract state.CHAIN_SETTINGS
: Map of chain IDs to their settings.WITHDRAW_TIMESTAMP
: Map of (chain_id, nonce) to withdrawal timestamps (prevents replay attacks).
Unauthorized
: The sender is not the contract owner.Pending
: An operation is pending (e.g., release attempted too soon).Std
: Standard CosmWasm error.
Initializes the contract with the owner and Palomagold denomination.
Signature:
pub fn instantiate(deps: DepsMut, _env: Env, info: MessageInfo, msg: InstantiateMsg) -> Result<Response, ContractError>
Parameters:
palomagold_denom
(String): The denomination of the Palomagold token.
Example:
{
"palomagold_denom": "palomagold"
}
Upgrades the contract to a new version.
Signature:
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError>
Parameters: None (empty message).
Example:
{}
Handles all executable messages. Each variant is described below.
Registers a new chain and its settings. Only the owner can call this.
Signature:
ExecuteMsg::RegisterChain { chain_id, chain_setting }
Parameters:
chain_id
(String): The chain identifier.chain_setting
(ChainSetting): Containsjob_id
(String).
Example:
{
"register_chain": {
"chain_id": "eth-mainnet",
"chain_setting": { "job_id": "job123" }
}
}
Bridges Palomagold tokens to a recipient on another chain. Only the owner can call this.
Signature:
ExecuteMsg::SendPalomaGold { chain_id, recipient, amount }
Parameters:
chain_id
(String)recipient
(String)amount
(Uint128)
Example:
{
"send_paloma_gold": {
"chain_id": "eth-mainnet",
"recipient": "0xabc...",
"amount": "1000000"
}
}
Releases funds to a recipient on another chain after a delay. Only the owner can call this.
Signature:
ExecuteMsg::Release { chain_id, recipient, amount, nonce }
Parameters:
chain_id
(String)recipient
(String)amount
(Uint256)nonce
(Uint256)
Example:
{
"release": {
"chain_id": "eth-mainnet",
"recipient": "0xabc...",
"amount": "1000000",
"nonce": "1"
}
}
Cancels a pending cross-chain transaction. Only the owner can call this.
Signature:
ExecuteMsg::CancelTx { transaction_id }
Parameters:
transaction_id
(u64)
Example:
{
"cancel_tx": { "transaction_id": 42 }
}
Sets the Paloma address for a chain. Only the owner can call this.
Signature:
ExecuteMsg::SetPaloma { chain_id }
Parameters:
chain_id
(String)
Example:
{
"set_paloma": { "chain_id": "eth-mainnet" }
}
Updates the refund wallet address for a chain. Only the owner can call this.
Signature:
ExecuteMsg::UpdateRefundWallet { chain_id, new_refund_wallet }
Parameters:
chain_id
(String)new_refund_wallet
(String)
Example:
{
"update_refund_wallet": {
"chain_id": "eth-mainnet",
"new_refund_wallet": "0xdef..."
}
}
Updates the gas fee for a chain. Only the owner can call this.
Signature:
ExecuteMsg::UpdateGasFee { chain_id, new_gas_fee }
Parameters:
chain_id
(String)new_gas_fee
(Uint256)
Example:
{
"update_gas_fee": {
"chain_id": "eth-mainnet",
"new_gas_fee": "50000"
}
}
Updates the service fee collector address for a chain. Only the owner can call this.
Signature:
ExecuteMsg::UpdateServiceFeeCollector { chain_id, new_service_fee_collector }
Parameters:
chain_id
(String)new_service_fee_collector
(String)
Example:
{
"update_service_fee_collector": {
"chain_id": "eth-mainnet",
"new_service_fee_collector": "0x123..."
}
}
Updates the service fee for a chain. Only the owner can call this.
Signature:
ExecuteMsg::UpdateServiceFee { chain_id, new_service_fee }
Parameters:
chain_id
(String)new_service_fee
(Uint256)
Example:
{
"update_service_fee": {
"chain_id": "eth-mainnet",
"new_service_fee": "1000"
}
}
Handles all query messages.
Returns the Palomagold token balance held by the contract.
Signature:
QueryMsg::PalomagoldBalance {}
Returns:
balance
(Uint128): The contract's Palomagold balance.
Example:
{
"palomagold_balance": {}
}
Response:
{
"balance": "1000000"
}
- Authorization: All state-changing operations are restricted to the contract owner.
- Replay Protection: The
WITHDRAW_TIMESTAMP
map ensures that releases cannot be replayed within a short window. - Cross-Chain Safety: All cross-chain operations are routed through job IDs and payloads, ensuring traceability and auditability.
- Error Handling: Custom errors are used for unauthorized access and pending operations.
The src/bin/schema.rs
file generates JSON schema for all messages:
fn main() {
write_api! {
instantiate: InstantiateMsg,
execute: ExecuteMsg,
query: QueryMsg,
}
}
For questions or audits, contact the maintainers or open an issue in this repository.