The Palomadex Trader is a Vyper smart contract that facilitates cross-chain token trading and liquidity operations through the Paloma network. The contract acts as a bridge between different blockchain networks, allowing users to purchase tokens, add/remove liquidity, and manage cross-chain operations.
Contract Version: 0.4.0
EVM Version: Cancun
License: Apache 2.0
Author: Volume.finance
- Compass Interface: Handles cross-chain token transfers via Paloma
- ERC20 Interface: Standard token operations
- Fee Management: Gas fees and service fees for operations
- Access Control: Paloma-based authorization system
compass: public(address) # Paloma compass contract address
refund_wallet: public(address) # Wallet receiving gas fees
gas_fee: public(uint256) # Gas fee amount in wei
service_fee_collector: public(address) # Service fee recipient
service_fee: public(uint256) # Service fee percentage (1e18 = 100%)
paloma: public(bytes32) # Paloma identifier
send_nonces: public(HashMap[uint256, bool]) # Nonce tracking for send operations
__init__(_compass: address, _refund_wallet: address, _gas_fee: uint256, _service_fee_collector: address, _service_fee: uint256)
Purpose: Initializes the contract with configuration parameters.
Parameters:
_compass
: Address of the Paloma compass contract_refund_wallet
: Address that receives gas fees_gas_fee
: Gas fee amount in wei_service_fee_collector
: Address that receives service fees_service_fee
: Service fee percentage (scaled by 1e18)
Security Considerations:
- All parameters are validated during deployment
- Events are emitted for all initial values
- No reentrancy protection needed (constructor)
Example Usage:
# Deployment script example
trader = project.trader.deploy(
compass="0x71956340a586db3afD10C2645Dbe8d065dD79AC8",
refund_wallet="0x6dc0A87638CD75Cc700cCdB226c7ab6C054bc70b",
gas_fee=3 * 10**15, # 0.003 ETH
service_fee_collector="0x9cf40152d7fb47dff8ad199282b002ca312ec818",
service_fee=10**16, # 1%
sender=deployer_account
)
Purpose: Initiates a cross-chain token purchase operation.
Parameters:
from_token
: Source token addressto_token
: Destination token addressamount
: Amount of source tokens to trade
Function Flow:
- Validates input parameters (non-zero addresses and amount)
- Handles gas fee collection from msg.value
- Transfers tokens from user to contract
- Calculates and deducts service fee
- Approves compass contract to spend tokens
- Sends tokens to Paloma via compass
- Emits Purchase event
Security Features:
@nonreentrant
protection against reentrancy attacks- Input validation for all parameters
- Safe token transfer operations
- Gas fee refund mechanism
Example Usage:
# Purchase 100 USDC for ETH
trader.purchase(
from_token="0xA0b86a33E6441b8c4C8C8C8C8C8C8C8C8C8C8C8C8", # USDC
to_token="0x0000000000000000000000000000000000000000", # ETH
amount=100 * 10**6, # 100 USDC (6 decimals)
value=0.01 * 10**18, # 0.01 ETH for gas fee
sender=user_account
)
Purpose: Adds liquidity to a cross-chain liquidity pool.
Parameters:
token0
: First token addresstoken1
: Second token addressamount0
: Amount of token0 to addamount1
: Amount of token1 to add
Function Flow:
- Validates token addresses and amounts
- Handles gas fee collection
- Transfers tokens from user to contract
- Approves compass for both tokens
- Sends tokens to Paloma via compass
- Emits AddLiquidity event
Security Features:
@nonreentrant
protection- Prevents adding same token as both token0 and token1
- Requires at least one token amount > 0
- Safe token operations
Example Usage:
# Add 1000 USDC and 0.5 ETH to liquidity pool
trader.add_liquidity(
token0="0xA0b86a33E6441b8c4C8C8C8C8C8C8C8C8C8C8C8C8", # USDC
token1="0x0000000000000000000000000000000000000000", # ETH
amount0=1000 * 10**6, # 1000 USDC
amount1=0.5 * 10**18, # 0.5 ETH
value=0.01 * 10**18, # Gas fee
sender=user_account
)
Purpose: Initiates liquidity removal from a cross-chain pool.
Parameters:
token0
: First token addresstoken1
: Second token addressamount
: Liquidity amount to remove
Function Flow:
- Handles gas fee collection
- Emits RemoveLiquidity event
- Actual token transfer handled by Paloma system
Security Features:
@nonreentrant
protection- Gas fee handling
- Event logging for tracking
Example Usage:
# Remove liquidity from USDC/ETH pool
trader.remove_liquidity(
token0="0xA0b86a33E6441b8c4C8C8C8C8C8C8C8C8C8C8C8C8", # USDC
token1="0x0000000000000000000000000000000000000000", # ETH
amount=100 * 10**18, # 100 LP tokens
value=0.01 * 10**18, # Gas fee
sender=user_account
)
send_token(tokens: DynArray[address, 64], to: address, amounts: DynArray[uint256, 64], nonce: uint256)
Purpose: Executes cross-chain token transfers initiated by Paloma.
Parameters:
tokens
: Array of token addresses (max 64)to
: Recipient addressamounts
: Array of token amountsnonce
: Unique identifier to prevent replay attacks
Function Flow:
- Validates caller is compass contract
- Validates Paloma identifier
- Checks nonce hasn't been used
- Validates arrays have same length
- Transfers tokens or ETH to recipient
- Marks nonce as used
- Emits TokenSent events
Security Features:
@nonreentrant
protection- Paloma authorization check
- Nonce replay protection
- Array length validation
- Safe token transfers
Example Usage:
# Called by compass contract after Paloma validation
trader.send_token(
tokens=["0xA0b86a33E6441b8c4C8C8C8C8C8C8C8C8C8C8C8C8"], # USDC
to="0x1234567890123456789012345678901234567890",
amounts=[100 * 10**6], # 100 USDC
nonce=12345,
sender=compass_contract
)
Purpose: Logs token deposits to Paloma system.
Parameters:
token
: Token identifier stringamount
: Deposit amount
Security Features:
- Input validation for token string and amount
- Event logging only (no actual token transfer)
Purpose: Logs token withdrawals from Paloma system.
Parameters:
token
: Token identifier stringamount
: Withdrawal amount
Security Features:
- Input validation
- Event logging only
Purpose: Logs reward claims from Paloma system.
Parameters:
token
: Token identifier string
Security Features:
- Input validation
- Event logging only
Purpose: Creates a time-locked position.
Parameters:
end_lock_time
: Lock expiration timestampamount
: Locked amount
Security Features:
- Validates lock time is in future
- Validates amount > 0
Purpose: Increases locked amount.
Parameters:
amount
: Additional amount to lock
Security Features:
- Validates amount > 0
Purpose: Extends lock duration.
Parameters:
end_lock_time
: New lock expiration timestamp
Security Features:
- Validates new time is in future
Purpose: Logs the withdrawal of a locked position.
Security Features:
- Event logging only
Purpose: Logs token deposits into the Paloma incentive system.
Parameters:
token
: Token identifier string (max 128 characters)amount
: Amount of tokens to deposit
Function Flow:
- Validates token string is not empty
- Validates amount is greater than 0
- Emits PalomaDeposit event for backend processing
Security Features:
- Input validation for token string and amount
- Event logging only (actual token handling by Paloma)
Example Usage:
# Log deposit of 1000 USDC into incentive system
trader.deposit(
token="USDC",
amount=1000 * 10**6,
sender=user_account
)
Purpose: Logs token withdrawals from the Paloma incentive system.
Parameters:
token
: Token identifier string (max 128 characters)amount
: Amount of tokens to withdraw
Function Flow:
- Validates token string is not empty
- Validates amount is greater than 0
- Emits PalomaWithdraw event for backend processing
Security Features:
- Input validation for token string and amount
- Event logging only (actual token handling by Paloma)
Example Usage:
# Log withdrawal of 500 USDC from incentive system
trader.withdraw(
token="USDC",
amount=500 * 10**6,
sender=user_account
)
Purpose: Claims rewards from the Paloma incentive system.
Parameters:
token
: Token identifier string for reward token
Function Flow:
- Validates token string is not empty
- Emits PalomaClaimReward event for backend processing
Security Features:
- Input validation for token string
- Event logging only (actual reward distribution by Paloma)
Example Usage:
# Claim GRAIL token rewards
trader.claim_reward(
token="GRAIL",
sender=user_account
)
Purpose: Creates a time-locked position in the vote-escrow system.
Parameters:
end_lock_time
: Lock expiration timestamp (must be in future)amount
: Amount of tokens to lock
Function Flow:
- Validates end_lock_time is in the future
- Validates amount is greater than 0
- Emits PalomaCreateLock event for backend processing
Security Features:
- Time validation (future timestamps only)
- Amount validation (positive values)
- Event logging only (actual lock management by Paloma)
Example Usage:
# Create 6-month lock with 1000 tokens
import time
six_months = int(time.time()) + (6 * 30 * 24 * 60 * 60)
trader.create_lock(
end_lock_time=six_months,
amount=1000 * 10**18,
sender=user_account
)
Purpose: Increases the amount of tokens in an existing lock.
Parameters:
amount
: Additional amount of tokens to lock
Function Flow:
- Validates amount is greater than 0
- Emits PalomaIncreaseLockAmount event for backend processing
Security Features:
- Amount validation (positive values)
- Event logging only (actual lock modification by Paloma)
Example Usage:
# Add 500 more tokens to existing lock
trader.increase_lock_amount(
amount=500 * 10**18,
sender=user_account
)
Purpose: Extends the duration of an existing lock.
Parameters:
end_lock_time
: New lock expiration timestamp (must be in future)
Function Flow:
- Validates end_lock_time is in the future
- Emits PalomaIncreaseEndLockTime event for backend processing
Security Features:
- Time validation (future timestamps only)
- Event logging only (actual lock modification by Paloma)
Example Usage:
# Extend lock to 12 months from now
import time
twelve_months = int(time.time()) + (12 * 30 * 24 * 60 * 60)
trader.increase_end_lock_time(
end_lock_time=twelve_months,
sender=user_account
)
Purpose: Withdraws tokens from an expired lock.
Function Flow:
- Emits PalomaWithdrawLock event for backend processing
- Paloma backend validates lock expiration before processing
Security Features:
- Lock expiration validation handled by Paloma backend
- Event logging only (actual token release by Paloma)
Example Usage:
# Withdraw tokens from expired lock
trader.withdraw_lock(sender=user_account)
Purpose: Forwards a specified amount of an ERC20 token from the user to the Paloma network via the Compass contract.
Parameters:
token
: ERC20 token address to forwardamount
: Amount of tokens to forward
Function Flow:
- Transfers tokens from user to contract
- Approves Compass contract to spend tokens
- Sends tokens to Paloma via Compass
- Emits PalomaSendToTraderCW event
Example Usage:
# Forward 1000 USDC to Paloma
trader.send_to_trader_cw(
token="0xA0b86a33E6441b8c4C8C8C8C8C8C8C8C8C8C8C8C8",
amount=1000 * 10**6,
sender=user_account
)
Purpose: Fallback function to accept plain ETH transfers. No state changes or event emission.
Purpose: Updates the compass contract address.
Parameters:
new_compass
: New compass contract address
Security Features:
- Only callable by current compass
- Checks SLC switch status
- Event logging
Purpose: Sets the Paloma identifier.
Security Features:
- Only callable by compass when paloma is empty
- Validates message data length
- One-time operation
Purpose: Updates the refund wallet address.
Parameters:
new_refund_wallet
: New refund wallet address
Security Features:
- Paloma authorization required
- Event logging
Purpose: Updates the gas fee amount.
Parameters:
new_gas_fee
: New gas fee in wei
Security Features:
- Paloma authorization required
- Event logging
Purpose: Updates the service fee collector address.
Parameters:
new_service_fee_collector
: New collector address
Security Features:
- Paloma authorization required
- Event logging
Purpose: Updates the service fee percentage (scaled by 1e18).
Parameters:
new_service_fee
: New service fee (must be < 1e18, i.e., < 100%)
Security Features:
- Paloma authorization required
- Validates fee < 100% (1e18)
- Event logging
- Purchase: Emitted when a cross-chain token purchase is initiated
- AddLiquidity: Emitted when liquidity is added to a cross-chain pool
- RemoveLiquidity: Emitted when liquidity removal is initiated
- TokenSent: Emitted when tokens are sent cross-chain via send_token
- PalomaDeposit: Emitted when tokens are deposited into the incentive system
- PalomaWithdraw: Emitted when tokens are withdrawn from the incentive system
- PalomaClaimReward: Emitted when rewards are claimed from the incentive system
- PalomaCreateLock: Emitted when a new time-locked position is created
- PalomaIncreaseLockAmount: Emitted when the amount in a lock is increased
- PalomaIncreaseEndLockTime: Emitted when a lock duration is extended
- PalomaWithdrawLock: Emitted when tokens are withdrawn from an expired lock
- UpdateCompass: Emitted when the compass contract address is updated
- UpdateRefundWallet: Emitted when the refund wallet address is updated
- UpdateGasFee: Emitted when the gas fee amount is updated
- UpdateServiceFeeCollector: Emitted when the service fee collector address is updated
- UpdateServiceFee: Emitted when the service fee percentage is updated
- SetPaloma: Emitted when the Paloma identifier is set
- PalomaSendToTraderCW: Emitted when tokens are forwarded to Paloma via send_to_trader_cw
- Compass Authorization: Critical functions require compass contract authorization
- Paloma Validation: Cross-chain operations validated via Paloma identifier
- Nonce Protection: Replay attack prevention via nonce tracking
- All external functions marked with
@nonreentrant
- Safe external calls with validation
- Address validation (non-zero addresses)
- Amount validation (positive values)
- Array length validation
- Time validation (future timestamps)
- Gas fees collected and sent to refund wallet
- Service fees calculated and sent to collector
- Fee percentages validated against maximum (100%)
- Safe ERC20 operations with revert on failure
- Balance checks before and after transfers
- Proper approval management
- Comprehensive event emission for all operations
- Indexed parameters for efficient filtering
- Audit trail for all state changes
Ethereum:
- Gas Fee: 0.003 ETH
- Service Fee: 1%
Polygon:
- Gas Fee: 0.1 MATIC
- Service Fee: 1%
- Service Fee Collector:
0x9cf40152d7fb47dff8ad199282b002ca312ec818
- Refund Wallet:
0x6dc0A87638CD75Cc700cCdB226c7ab6C054bc70b
- Unit Tests: Test each function with valid and invalid inputs
- Integration Tests: Test cross-chain operations end-to-end
- Security Tests: Test reentrancy, access control, and edge cases
- Gas Tests: Verify gas usage optimization
- Event Tests: Verify all events are emitted correctly
- Incentive Tests: Test deposit/withdraw/claim reward flows
- Lock Tests: Test vote-escrow lock creation, modification, and withdrawal
- Time Tests: Test lock time validation and expiration logic
- Access control validation
- Reentrancy protection
- Input validation
- Fee calculation accuracy
- Token transfer safety
- Event emission completeness
- Nonce replay protection
- Paloma integration security
- Gas optimization
- Error handling