A CosmWasm-based token purchasing system consisting of two smart contracts: Collector and Manager. These contracts facilitate cross-chain token operations, DEX exchanges, and PUSD (Paloma USD) management.
This project contains two main contracts:
- Collector Contract (
contracts/collector/
) - Handles token exchanges, cross-chain transfers, and PUSD operations - Manager Contract (
contracts/manager/
) - Manages cross-chain deployments, token transfers, and configuration settings
The Collector contract is responsible for:
- Executing DEX swaps via external routers
- Managing PUSD withdrawals and cross-chain transfers
- Handling cross-chain transactions via Paloma's Skyway
- Owner management for administrative functions
The Manager contract is responsible for:
- Deploying Paloma ERC20 tokens on external chains
- Managing cross-chain token transfers
- Configuring chain-specific settings
- Updating contract parameters on external chains
Purpose: Initializes the Collector contract with owner addresses.
Parameters:
owners: Vec<String>
- List of owner addresses who can execute privileged functions
Security: Only callable during contract deployment.
Example:
{
"owners": ["paloma1abc...", "paloma1def..."]
}
Purpose: Handles contract migrations and version updates.
Parameters: None (uses default MigrateMsg
)
Security: Only callable by contract admin.
Purpose: Executes token swaps via external DEX routers.
Parameters:
dex_router: Addr
- Address of the DEX router contractoperations: Vec<SwapOperation>
- List of swap operations to executeminimum_receive: Option<Uint128>
- Minimum amount to receive (slippage protection)to: Option<String>
- Recipient address for swapped tokensmax_spread: Option<Decimal>
- Maximum allowed spread percentagefunds: Vec<Coin>
- Tokens to swap
Security: Only callable by contract owners.
Example:
{
"exchange": {
"dex_router": "paloma1router...",
"operations": [
{
"astro_swap": {
"offer_asset_info": {
"native_token": {"denom": "uluna"}
},
"ask_asset_info": {
"token": {"contract_addr": "paloma1token..."}
}
}
}
],
"minimum_receive": "1000000",
"to": "paloma1recipient...",
"max_spread": "0.05",
"funds": [{"denom": "uluna", "amount": "1000000"}]
}
}
Purpose: Sends tokens to an EVM-compatible chain via Paloma's Skyway.
Parameters:
recipient: String
- EVM address to receive tokensamount: String
- Amount of tokens to sendchain_reference_id: String
- Target chain identifier
Security: Only callable by contract owners.
Example:
{
"send_to_evm": {
"recipient": "0x1234567890abcdef...",
"amount": "1000000000000000000",
"chain_reference_id": "ethereum"
}
}
Purpose: Cancels a pending cross-chain transaction.
Parameters:
transaction_id: u64
- ID of the transaction to cancel
Security: Only callable by contract owners.
Example:
{
"cancel_tx": {
"transaction_id": 12345
}
}
Purpose: Withdraws PUSD tokens to an external chain.
Parameters:
pusd_manager: Addr
- Address of the PUSD manager contractchain_id: String
- Target chain identifierrecipient: String
- EVM address to receive PUSDamount: Uint128
- Amount of PUSD to withdraw
Security: Only callable by contract owners.
Example:
{
"withdraw_pusd": {
"pusd_manager": "paloma1pusdmanager...",
"chain_id": "ethereum",
"recipient": "0x1234567890abcdef...",
"amount": "1000000000"
}
}
Purpose: Re-executes a failed PUSD withdrawal using the same nonce.
Parameters:
pusd_manager: Addr
- Address of the PUSD manager contractnonce: u64
- Nonce of the original withdrawal
Security: Only callable by contract owners.
Example:
{
"re_withdraw_pusd": {
"pusd_manager": "paloma1pusdmanager...",
"nonce": 12345
}
}
Purpose: Cancels a pending PUSD withdrawal.
Parameters:
pusd_manager: Addr
- Address of the PUSD manager contractnonce: u64
- Nonce of the withdrawal to cancel
Security: Only callable by contract owners.
Example:
{
"cancel_withdraw_pusd": {
"pusd_manager": "paloma1pusdmanager...",
"nonce": 12345
}
}
Purpose: Adds a new owner to the contract.
Parameters:
owner: String
- Address of the new owner
Security: Only callable by existing owners. Prevents duplicate owners.
Example:
{
"add_owner": {
"owner": "paloma1newowner..."
}
}
Purpose: Removes an owner from the contract.
Parameters:
owner: String
- Address of the owner to remove
Security: Only callable by existing owners. Ensures owner exists before removal.
Example:
{
"remove_owner": {
"owner": "paloma1oldowner..."
}
}
Purpose: Retrieves the current contract state.
Parameters: None
Returns: Contract state including owner addresses.
Example:
{
"get_state": {}
}
Purpose: Initializes the Manager contract with owner addresses and retry delay.
Parameters:
retry_delay: u64
- Delay between retry attempts for failed operationsowners: Vec<String>
- List of owner addresses
Security: Only callable during contract deployment.
Example:
{
"retry_delay": 3600,
"owners": ["paloma1abc...", "paloma1def..."]
}
Purpose: Deploys a new Paloma ERC20 token on an external chain.
Parameters:
chain_id: String
- Target chain identifierpaloma_denom: String
- Paloma denomination (e.g., "uluna")name: String
- Token namesymbol: String
- Token symboldecimals: u8
- Token decimal placesblueprint: String
- EVM address of the token blueprint contract
Security: Only callable by contract owners.
Example:
{
"deploy_paloma_erc20": {
"chain_id": "ethereum",
"paloma_denom": "uluna",
"name": "Luna Token",
"symbol": "LUNA",
"decimals": 18,
"blueprint": "0x1234567890abcdef..."
}
}
Purpose: Executes token swaps via external DEX routers (same as Collector).
Parameters: Same as Collector's Exchange function.
Security: Only callable by contract owners.
Purpose: Sends tokens to an external chain.
Parameters:
chain_id: String
- Target chain identifiertoken: String
- EVM address of the token contractto: String
- EVM address of the recipientamount: Uint128
- Amount of tokens to sendnonce: Uint128
- Unique nonce for the transaction
Security: Only callable by contract owners.
Example:
{
"send_token": {
"chain_id": "ethereum",
"token": "0x1234567890abcdef...",
"to": "0xabcdef1234567890...",
"amount": "1000000000000000000",
"nonce": "12345"
}
}
Purpose: Configures chain-specific job IDs for cross-chain operations.
Parameters:
chain_id: String
- Chain identifiercompass_job_id: String
- Job ID for compass operationsmain_job_id: String
- Job ID for main operations
Security: Only callable by contract owners.
Example:
{
"set_chain_setting": {
"chain_id": "ethereum",
"compass_job_id": "compass_eth_001",
"main_job_id": "main_eth_001"
}
}
Purpose: Sets the Paloma configuration on an external chain.
Parameters:
chain_id: String
- Target chain identifier
Security: Only callable by contract owners.
Example:
{
"set_paloma": {
"chain_id": "ethereum"
}
}
Purpose: Updates the compass contract address on an external chain.
Parameters:
chain_id: String
- Target chain identifiernew_compass: String
- New compass contract address
Security: Only callable by contract owners.
Example:
{
"update_compass": {
"chain_id": "ethereum",
"new_compass": "0x1234567890abcdef..."
}
}
Purpose: Updates the refund wallet address on an external chain.
Parameters:
chain_id: String
- Target chain identifiernew_refund_wallet: String
- New refund wallet address
Security: Only callable by contract owners.
Example:
{
"update_refund_wallet": {
"chain_id": "ethereum",
"new_refund_wallet": "0x1234567890abcdef..."
}
}
Purpose: Updates the gas fee configuration on an external chain.
Parameters:
chain_id: String
- Target chain identifiernew_gas_fee: Uint256
- New gas fee amount
Security: Only callable by contract owners.
Example:
{
"update_gas_fee": {
"chain_id": "ethereum",
"new_gas_fee": "20000000000000000"
}
}
Purpose: Updates the service fee collector address on an external chain.
Parameters:
chain_id: String
- Target chain identifiernew_service_fee_collector: String
- New service fee collector address
Security: Only callable by contract owners.
Example:
{
"update_service_fee_collector": {
"chain_id": "ethereum",
"new_service_fee_collector": "0x1234567890abcdef..."
}
}
Purpose: Updates the service fee amount on an external chain.
Parameters:
chain_id: String
- Target chain identifiernew_service_fee: Uint256
- New service fee amount
Security: Only callable by contract owners.
Example:
{
"update_service_fee": {
"chain_id": "ethereum",
"new_service_fee": "1000000000000000"
}
}
Purpose: Updates the contract configuration.
Parameters:
retry_delay: Option<u64>
- New retry delay (optional)
Security: Only callable by contract owners.
Example:
{
"update_config": {
"retry_delay": 7200
}
}
Purpose: Same as Collector contract's owner management functions.
Parameters: Same as Collector contract.
Security: Same as Collector contract.
Purpose: Retrieves the current contract state.
Parameters: None
Returns: Contract state including owner addresses and retry delay.
Purpose: Retrieves chain-specific settings.
Parameters:
chain_id: String
- Chain identifier
Returns: Chain settings including job IDs.
Example:
{
"get_chain_setting": {
"chain_id": "ethereum"
}
}
- All privileged functions require owner authentication
- Owner management functions prevent duplicate owners and ensure existence before removal
- No public functions that could be exploited by unauthorized users
- Address validation using
deps.api.addr_validate()
- Nonce-based transaction management to prevent replay attacks
- Slippage protection through
minimum_receive
andmax_spread
parameters
- Chain-specific job IDs ensure operations target correct chains
- Nonce-based transaction tracking prevents duplicate operations
- Cancellation mechanisms for failed or stuck transactions
- Immutable state storage using CosmWasm's storage patterns
- Proper error handling and rollback mechanisms
- Version tracking for contract migrations
- Rust 1.70+ and Cargo
- Docker (for optimized builds)
Currently, the test modules are empty. To add and run tests:
- Unit Tests: Add test functions within the
#[cfg(test)]
modules in each contract - Integration Tests: Create test files in
tests/
directory - Run Tests: Execute the following commands:
# Run all tests
cargo test
# Run tests for specific contract
cargo test -p collector
cargo test -p manager
# Run tests with output
cargo test -- --nocapture
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info};
use cosmwasm_std::{coins, Addr};
#[test]
fn test_instantiate() {
let mut deps = mock_dependencies();
let env = mock_env();
let info = mock_info("creator", &coins(1000, "earth"));
let msg = InstantiateMsg {
owners: vec!["owner1".to_string(), "owner2".to_string()],
};
let res = instantiate(deps.as_mut(), env, info, msg).unwrap();
assert_eq!(0, res.messages.len());
}
#[test]
fn test_unauthorized_access() {
// Test that non-owners cannot execute privileged functions
}
#[test]
fn test_owner_management() {
// Test adding and removing owners
}
}
# Build all contracts
cargo build --release
# Build specific contract
cargo build --release -p collector
cargo build --release -p manager
# Build optimized WASM (requires Docker)
./scripts/release_build.sh
After deployment, the compiled WASM files will be available in the artifacts/
directory:
collector.wasm
- Collector contract binarymanager.wasm
- Manager contract binary
- Deploy the Manager contract first
- Deploy the Collector contract
- Configure chain settings in the Manager contract
- Set up owner permissions
- cosmwasm-std: Core CosmWasm standard library
- cosmwasm-schema: Schema generation for messages
- cw-storage-plus: Enhanced storage utilities
- ethabi: Ethereum ABI encoding/decoding
- cw-multi-test: Testing framework
This project is licensed under the terms specified in the LICENSE file.