Environment Setup
Creating the Environment File
The CTF Exchange requires specific environment variables for deployment. Create a.env file in the root directory:
Environment Variables Reference
Private key of the deployer account. This account will deploy the exchange contract and will have initial admin privileges that are later renounced.
Address that will be granted admin and operator roles after deployment. This address will maintain control after the deployer renounces their roles.
RPC endpoint for the target network (e.g., Polygon, Amoy testnet).
Address of the ERC20 collateral token (e.g., USDC) used for trading.
Address of the Conditional Tokens Framework (CTF) contract.
Address of the Polymarket proxy factory contract.
Address of the Gnosis Safe factory contract used for multisig support.
Deployment Script
Understanding the Deployment Flow
The exchange deployment script is located atsrc/exchange/scripts/ExchangeDeployment.s.sol. Here’s how it works:
Deployment Steps
Admin Role Assignment
The deployment script grants both admin and operator roles to the specified admin address:
addAdmin(admin)- Grants administrative privilegesaddOperator(admin)- Grants operator privileges for trading operations
Running the Deployment
Local Deployment (Testing)
Test your deployment script on a local Anvil instance:Testnet Deployment
Deploy to a testnet (e.g., Amoy):The
--verify flag will automatically verify your contract on the block explorer if you have an API key configured.Production Deployment
For mainnet deployment (e.g., Polygon), use additional safety flags:Current Deployments
The CTF Exchange is currently deployed on the following networks:Polygon Mainnet
Address:
0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982EView on Polygonscan →Amoy Testnet
Address:
0xdFE02Eb6733538f8Ea35D585af8DE5958AD99E40View on Amoy Explorer →Configuration Options
Solidity Compiler Settings
The compiler is configured infoundry.toml for optimal gas efficiency:
- Solidity Version: 0.8.15 (tested and audited)
- Optimizer Runs: 1,000,000 for maximum runtime gas optimization
Gas Reporting
Gas reporting is enabled for all contracts:Fuzz Testing Profiles
Two fuzz testing profiles are available:Post-Deployment Configuration
Registering Token Pairs
After deployment, token pairs must be registered before trading can begin:Adding Operators
Additional operators can be added for order matching:Pausing Trading
In emergency situations, trading can be paused:Security Considerations
Private Key Security
Never share or commit private keys. Use hardware wallets for production deployments.
Admin Controls
The admin address has significant control. Consider using a multisig wallet.
Testing
Always test deployments on testnet before mainnet deployment.
Verification
Verify contract source code on block explorers for transparency.