This repository contains a CosmWasm smart contract for managing PUSD tokens with cross-chain functionality.
The PUSD Manager CW smart contract provides functionalities to manage PUSD tokens, including minting, burning, and transferring tokens across different blockchain networks. It is built using the CosmWasm framework and integrates with the Paloma network for cross-chain operations.
The contract maintains the following key data structures:
- State: Global contract configuration including owner, minter, retry delay, and token denomination
- ChainSettings: Per-chain configuration including job IDs and minimum withdrawal amounts
- WithdrawList: Pending withdrawal requests with nonces for tracking
- BurnInfo: Detailed information about each withdrawal request
- Owner: Has administrative privileges including configuration updates and chain registration
- Minter: Can mint and unmint PUSD tokens
- Users: Can initiate withdrawals and cancel their own withdrawal requests
- Nonce-based withdrawal tracking prevents replay attacks
- Retry delay mechanism prevents rapid withdrawal attempts
- Minimum amount validation prevents dust attacks
- Authorization checks on all administrative functions
Purpose: Initializes the contract with initial configuration Access: Public (contract deployment) Parameters:
retry_delay
: Time delay before withdrawal can be retried (seconds)minter
: Address authorized to mint/unmint PUSD tokensdenom
: Token denomination string
Security: Requires funds to be sent during instantiation Example:
{
"retry_delay": 3600,
"minter": "cosmos1...",
"denom": "factory/cosmos1.../pusd"
}
Purpose: Handles contract upgrades and state migration Access: Owner only Parameters:
minter
: New minter address for the upgraded contract
Security: Migrates existing state while updating minter permissions Example:
{
"minter": "cosmos1..."
}
Purpose: Registers a new blockchain network for cross-chain operations Access: Owner only Parameters:
chain_id
: Unique identifier for the blockchain networkchain_setting
: Configuration including job_id and minimum_amount
Security: Only owner can register new chains Example:
{
"chain_id": "ethereum",
"chain_setting": {
"job_id": "withdraw_job_001",
"minimum_amount": "1000000"
}
}
Purpose: Configures ERC20 token mapping for cross-chain bridge Access: Owner only Parameters:
chain_reference_id
: Target chain identifiererc20_address
: ERC20 contract address on target chain
Security: Only owner can configure bridge settings Example:
{
"chain_reference_id": "ethereum",
"erc20_address": "0x1234567890123456789012345678901234567890"
}
Purpose: Updates global contract configuration Access: Owner only Parameters:
retry_delay
: Optional new retry delay (must be > 0)owner
: Optional new owner address
Security: Only current owner can update configuration Example:
{
"retry_delay": 7200,
"owner": "cosmos1..."
}
Purpose: Mints PUSD tokens to a specified recipient Access: Owner only Parameters:
recipient
: Address to receive minted tokensamount
: Amount of PUSD tokens to mint
Security: Only owner can mint tokens; amount must be > 0 Example:
{
"recipient": "cosmos1...",
"amount": "1000000000"
}
Purpose: Burns PUSD tokens from the minter's balance Access: Minter only Parameters:
amount
: Amount of PUSD tokens to burn
Security: Only minter can unmint tokens; amount must be > 0 Example:
{
"amount": "1000000000"
}
Purpose: Initiates a cross-chain withdrawal of PUSD tokens Access: Any user with PUSD tokens Parameters:
chain_id
: Target blockchain networkrecipient
: Recipient address on target chain
Security:
- User must send PUSD tokens with the transaction
- Amount must exceed chain's minimum withdrawal amount
- Creates unique nonce for tracking Example:
{
"chain_id": "ethereum",
"recipient": "0x1234567890123456789012345678901234567890"
}
Purpose: Retries a failed withdrawal request Access: Original withdrawal initiator Parameters:
nonce
: Unique identifier of the withdrawal request
Security:
- Only original initiator can retry
- Must wait for retry_delay period
- Updates timestamp to prevent rapid retries Example:
{
"nonce": 123
}
Purpose: Burns PUSD tokens after successful cross-chain withdrawal Access: Owner only Parameters:
nonce
: Unique identifier of the withdrawal request
Security: Only owner can burn tokens; removes from withdraw list Example:
{
"nonce": 123
}
Purpose: Cancels a pending withdrawal and returns tokens Access: Original withdrawal initiator Parameters:
nonce
: Unique identifier of the withdrawal request
Security:
- Only original initiator can cancel
- Must wait for retry_delay period
- Returns tokens to initiator Example:
{
"nonce": 123
}
Purpose: Sets Paloma address on EVM Vyper contract Access: Owner only Parameters:
chain_id
: Target blockchain network
Security: Only owner can update Paloma address Example:
{
"chain_id": "ethereum"
}
Purpose: Updates compass address on EVM Vyper contract Access: Owner only Parameters:
chain_id
: Target blockchain networknew_compass
: New compass contract address
Security: Only owner can update compass address Example:
{
"chain_id": "ethereum",
"new_compass": "0x1234567890123456789012345678901234567890"
}
Purpose: Updates refund wallet address on EVM Vyper contract Access: Owner only Parameters:
chain_id
: Target blockchain networknew_refund_wallet
: New refund wallet address
Security: Only owner can update refund wallet Example:
{
"chain_id": "ethereum",
"new_refund_wallet": "0x1234567890123456789012345678901234567890"
}
Purpose: Updates redemption fee on EVM Vyper contract Access: Owner only Parameters:
chain_id
: Target blockchain networknew_redemption_fee
: New redemption fee amount
Security: Only owner can update redemption fee Example:
{
"chain_id": "ethereum",
"new_redemption_fee": "1000000"
}
Purpose: Returns current contract state Access: Public Returns: State object with owner, minter, retry_delay, denom, and last_nonce
Purpose: Returns all registered chain configurations Access: Public Returns: Array of ChainSettingInfo objects
Purpose: Returns job ID for a specific chain Access: Public Parameters:
chain_id
: Target blockchain network Returns: Job ID string
Purpose: Returns all pending withdrawal requests Access: Public Returns: Array of (nonce, BurnInfo) tuples
Purpose: Returns details of a specific withdrawal request Access: Public Parameters:
nonce
: Unique identifier of the withdrawal request Returns: BurnInfo object
Purpose: Checks if any withdrawals are eligible for retry Access: Public Returns: Boolean indicating if withdrawals can be retried
Purpose: Returns contract's PUSD token balance Access: Public Returns: BalanceResponse with current balance
pub struct State {
pub retry_delay: u64, // Time delay before withdrawal retry
pub owner: Addr, // Contract owner address
pub minter: Addr, // Token minter address
pub denom: String, // PUSD token denomination
pub last_nonce: u64, // Last used nonce for withdrawals
}
pub struct BurnInfo {
pub chain_id: String, // Target blockchain network
pub burner: Addr, // User who initiated withdrawal
pub recipient: String, // Recipient address on target chain
pub amount: u128, // Withdrawal amount
pub timestamp: Timestamp, // Withdrawal timestamp
}
pub struct ChainSetting {
pub job_id: String, // Paloma job identifier
pub minimum_amount: Uint128, // Minimum withdrawal amount
}
STATE
: Global contract stateCHAIN_SETTINGS
: Chain-specific configurationsWITHDRAW_LIST
: Pending withdrawal requests indexed by nonceTX_TIMESTAMP
: Transaction timestamps (unused in current implementation)
The contract uses custom error types defined in error.rs
:
MigrationFailed
: Contract migration errorsUnauthorized
: Access control violationsInvalidAmount
: Amount validation failuresInvalidChainId
: Chain ID validation errors
- Rust 1.70+
- Cargo
- CosmWasm 1.4+
- Paloma network integration
cargo wasm
cargo test
# Deploy with initial configuration
wasmd tx wasm instantiate <code_id> '{"retry_delay": 3600, "minter": "cosmos1...", "denom": "factory/cosmos1.../pusd"}' --from <key> --label "PUSD Manager" --gas auto --gas-adjustment 1.3
When auditing this contract, pay special attention to:
- Access Control: Verify all administrative functions are properly restricted
- Nonce Management: Ensure nonce uniqueness and proper incrementing
- Cross-Chain Validation: Verify chain_id and recipient address validation
- Amount Validation: Check minimum amount enforcement and overflow protection
- Timing Attacks: Verify retry delay mechanism effectiveness
- State Consistency: Ensure proper state updates across all operations
- Error Handling: Verify graceful error handling and proper rollbacks
- Reentrancy: Check for potential reentrancy vulnerabilities
- Gas Optimization: Verify gas usage patterns and limits
- Integration Security: Review Paloma network integration security
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.