The PUSD Connector Contract is a CosmWasm smart contract that facilitates cross-chain PUSD (Pegged USD) transfers and management. It acts as a bridge between different blockchain networks, allowing users to send and withdraw PUSD tokens across chains through the Paloma network.
Contract Name: crates.io:pusd-connector-cw
Version: 0.1.0
Author: Volume Finance
The contract consists of the following main components:
- State Management: Global state and chain-specific settings
- Execute Functions: Core business logic for cross-chain operations
- Query Functions: Read-only operations for state inspection
- Message Handlers: Entry points for contract interactions
pub struct State {
pub owner: Addr, // Contract owner with administrative privileges
pub pusd_manager: Addr, // PUSD manager contract address
}
pub struct ChainSetting {
pub job_id: String, // Paloma job ID for cross-chain operations
}
Purpose: Initializes the contract with owner and PUSD manager addresses.
Parameters:
deps: DepsMut
- Contract dependencies_env: Env
- Contract environmentinfo: MessageInfo
- Message sender informationmsg: InstantiateMsg
- Initialization message containingpusd_manager
address
Security Considerations:
- Only callable once during contract deployment
- Sets the initial owner to the message sender
- No validation of
pusd_manager
address format
Example Usage:
{
"instantiate": {
"pusd_manager": "cosmos1..."
}
}
Purpose: Handles contract migrations and version updates.
Parameters:
deps: DepsMut
- Contract dependencies_env: Env
- Contract environment_msg: MigrateMsg
- Migration message (currently empty)
Security Considerations:
- Updates contract version information
- No state modifications in current implementation
Purpose: Main entry point for all contract operations.
Parameters:
deps: DepsMut
- Contract dependencies_env: Env
- Contract environmentinfo: MessageInfo
- Message sender informationmsg: ExecuteMsg
- Execution message containing the operation to perform
Security Considerations:
- Routes to specific execute functions based on message type
- All operations require proper authorization checks
Purpose: Registers a new blockchain network for PUSD operations.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Unique identifier for the blockchainchain_setting: ChainSetting
- Configuration for the chain
Security Considerations:
- Authorization: Only the contract owner can register chains
- Validation: No validation of
chain_id
format or uniqueness - Storage: Saves chain settings to persistent storage
Example Usage:
{
"register_chain": {
"chain_id": "ethereum",
"chain_setting": {
"job_id": "job_123"
}
}
}
Purpose: Initiates a cross-chain PUSD transfer to a specified address.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifierto: String
- Destination address on target chainamount: Uint128
- Amount of PUSD to transfernonce: Uint128
- Unique transaction identifier
Security Considerations:
- Authorization: Only the contract owner can send PUSD
- Validation: No validation of destination address format
- Cross-chain: Creates a Paloma Skyway message for cross-chain transfer
- Token Construction: Dynamically constructs PUSD token denomination
Example Usage:
{
"send_pusd": {
"chain_id": "ethereum",
"to": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
"amount": "1000000",
"nonce": "12345"
}
}
Purpose: Withdraws PUSD tokens from the contract to a specified recipient.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Source blockchain identifierrecipient: String
- Recipient addressamount: Uint128
- Amount of PUSD to withdraw
Security Considerations:
- Authorization: Only the contract owner can withdraw PUSD
- External Call: Executes a message to the PUSD manager contract
- Token Transfer: Sends actual PUSD tokens to the recipient
- Validation: No validation of recipient address format
Example Usage:
{
"withdraw_pusd": {
"chain_id": "ethereum",
"recipient": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
"amount": "500000"
}
}
Purpose: Cancels a pending cross-chain transaction.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationtransaction_id: u64
- Unique transaction identifier to cancel
Security Considerations:
- Authorization: Only the contract owner can cancel transactions
- Assertion: Uses
assert!
macro instead of proper error handling - Cross-chain: Sends cancellation message through Paloma Skyway
Example Usage:
{
"cancel_tx": {
"transaction_id": 12345
}
}
Purpose: Updates the contract's global configuration (owner and PUSD manager).
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationowner: Option<Addr>
- New owner address (optional)pusd_manager: Option<Addr>
- New PUSD manager address (optional)
Security Considerations:
- Authorization: Only the current owner can change configuration
- Partial Updates: Allows updating only specific parameters
- State Mutation: Modifies global contract state
- Validation: No validation of new address formats
Example Usage:
{
"change_config": {
"owner": "cosmos1...",
"pusd_manager": "cosmos1..."
}
}
Purpose: Sets the Paloma address for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifier
Security Considerations:
- Authorization: Only the contract owner can set Paloma addresses
- Assertion: Uses
assert!
macro instead of proper error handling - Cross-chain: Executes through Paloma Scheduler with encoded function call
- Validation: No validation of chain_id existence
Example Usage:
{
"set_paloma": {
"chain_id": "ethereum"
}
}
Purpose: Updates the withdrawal limit for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_withdraw_limit: Uint256
- New withdrawal limit amount
Security Considerations:
- Authorization: Only the contract owner can update limits
- Assertion: Uses
assert!
macro instead of proper error handling - Cross-chain: Executes through Paloma Scheduler with encoded function call
- Data Conversion: Converts Uint256 to Ethereum Uint format
Example Usage:
{
"update_withdraw_limit": {
"chain_id": "ethereum",
"new_withdraw_limit": "1000000000000000000000000"
}
}
Purpose: Updates the PUSD contract address for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_pusd: String
- New PUSD contract address
Security Considerations:
- Authorization: Only the contract owner can update PUSD addresses
- Assertion: Uses
assert!
macro instead of proper error handling - Address Validation: Converts string to Ethereum Address format
- Cross-chain: Executes through Paloma Scheduler with encoded function call
Example Usage:
{
"update_pusd": {
"chain_id": "ethereum",
"new_pusd": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"
}
}
Purpose: Updates the PUSD manager address for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_pusd_manager: String
- New PUSD manager address
Security Considerations:
- Authorization: Only the contract owner can update manager addresses
- Assertion: Uses
assert!
macro instead of proper error handling - Address Validation: Converts string to Ethereum Address format
- Cross-chain: Executes through Paloma Scheduler with encoded function call
Example Usage:
{
"update_pusd_manager": {
"chain_id": "ethereum",
"new_pusd_manager": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"
}
}
Purpose: Updates the refund wallet address for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_refund_wallet: String
- New refund wallet address
Security Considerations:
- Authorization: Only the contract owner can update refund wallets
- Assertion: Uses
assert!
macro instead of proper error handling - Address Validation: Converts string to Ethereum Address format
- Cross-chain: Executes through Paloma Scheduler with encoded function call
Example Usage:
{
"update_refund_wallet": {
"chain_id": "ethereum",
"new_refund_wallet": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"
}
}
Purpose: Updates the gas fee for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_gas_fee: Uint256
- New gas fee amount
Security Considerations:
- Authorization: Only the contract owner can update gas fees
- Assertion: Uses
assert!
macro instead of proper error handling - Data Conversion: Converts Uint256 to Ethereum Uint format
- Cross-chain: Executes through Paloma Scheduler with encoded function call
Example Usage:
{
"update_gas_fee": {
"chain_id": "ethereum",
"new_gas_fee": "50000000000000000"
}
}
Purpose: Updates the service fee collector address for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_service_fee_collector: String
- New service fee collector address
Security Considerations:
- Authorization: Only the contract owner can update fee collectors
- Assertion: Uses
assert!
macro instead of proper error handling - Address Validation: Converts string to Ethereum Address format
- Cross-chain: Executes through Paloma Scheduler with encoded function call
Example Usage:
{
"update_service_fee_collector": {
"chain_id": "ethereum",
"new_service_fee_collector": "0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6"
}
}
Purpose: Updates the service fee amount for a specific blockchain.
Parameters:
deps: DepsMut
- Contract dependenciesinfo: MessageInfo
- Message sender informationchain_id: String
- Target blockchain identifiernew_service_fee: Uint256
- New service fee amount
Security Considerations:
- Authorization: Only the contract owner can update service fees
- Assertion: Uses
assert!
macro instead of proper error handling - Data Conversion: Converts Uint256 to Ethereum Uint format
- Cross-chain: Executes through Paloma Scheduler with encoded function call
Example Usage:
{
"update_service_fee": {
"chain_id": "ethereum",
"new_service_fee": "1000000000000000000"
}
}
Purpose: Main entry point for all read-only operations.
Parameters:
deps: Deps
- Contract dependencies_env: Env
- Contract environmentmsg: QueryMsg
- Query message containing the operation to perform
Purpose: Returns the current contract state.
Response: State
struct containing owner and PUSD manager addresses
Example Usage:
{
"get_state": {}
}
Purpose: Returns all registered chain settings.
Response: Array of ChainSettingInfo
containing chain IDs and job IDs
Example Usage:
{
"get_chain_settings": {}
}
- Inconsistent Authorization: Some functions use
assert!
macro while others use proper error handling - No Input Validation: Address formats and chain IDs are not validated
- Unsafe External Calls: Direct calls to PUSD manager without validation
- No Reentrancy Protection: Functions that make external calls lack reentrancy guards
- All administrative functions require owner authorization
- No role-based access control beyond owner
- No multi-signature or timelock mechanisms
- No validation of Ethereum address formats
- No validation of chain ID uniqueness
- No bounds checking on numeric parameters
- Relies on Paloma network for cross-chain operations
- No validation of cross-chain message integrity
- No timeout mechanisms for pending transactions
cosmwasm-std
: Core CosmWasm functionalityethabi
: Ethereum ABI encoding/decodingcw-storage-plus
: Enhanced storage utilitiesthiserror
: Error handling utilities
- Unit Tests: Test each function with valid and invalid inputs
- Integration Tests: Test cross-chain message flows
- Security Tests: Test authorization bypass attempts
- Fuzzing: Test with malformed input data
- Reentrancy Tests: Test external call scenarios
- Initial Configuration: Ensure proper owner and PUSD manager addresses
- Chain Registration: Register all supported chains before use
- Parameter Validation: Validate all configuration parameters
- Monitoring: Monitor cross-chain transaction status
- Upgrade Path: Plan for contract upgrades and migrations