CopyTradingVault
File:contracts/src/core/CopyTradingVault.solPattern: UUPS Upgradeable
Inherits:
Initializable, OwnableUpgradeable, UUPSUpgradeable
This is the heart of the protocol. Each vault is an independent ERC1967Proxy pointing at a shared CopyTradingVault implementation. It manages a pool of follower funds, routes trades through PaxDexAdapter, enforces risk constraints via RiskManager, and settles profits through RevenueSplitter.
State Variables
| Variable | Type | Description |
|---|---|---|
leader | address | Wallet that owns and controls this vault |
vaultName | string | Human-readable vault name |
baseAsset | address | ERC-20 token all followers deposit (e.g. USDC, PAX) |
riskManager | RiskManager | Risk validation contract |
dexAdapter | PaxDexAdapter | Swap routing adapter |
revenueSplitter | RevenueSplitter | Profit distribution contract |
followers | mapping(address => FollowerData) | Per-follower deposit and high water mark |
totalVaultTVL | uint256 | Sum of all follower deposits |
FollowerData Struct
Events
TradeExecuted
FollowerSubscribed
FollowerUnsubscribed
ProfitSettled
Functions
initialize
VaultFactory at proxy deployment time. Sets the vault owner (_leader) and wires all dependencies.
subscribe
amount of baseAsset into the vault. Transfers tokens from the follower to the vault contract, increments deposited and waterMark, adds to totalVaultTVL, emits FollowerSubscribed.
unsubscribe
amount. Calls settleFollowerProfit(msg.sender) first to clear any outstanding PnL, then reduces deposited, adjusts waterMark, and returns tokens.
executeGroupTrade
leader only (via onlyOwner)
- Calls
riskManager.validateTrade(leader)— reverts if vault is frozen or score is below threshold - Approves
dexAdapterto spendamountInoftokenIn - Calls
dexAdapter.swap(tokenIn, tokenOut, amountIn, amountOutMinimum) - Asserts
amountReceived >= amountOutMinimum(slippage guard) - Emits
TradeExecuted(tokenIn, tokenOut, amountIn)
settleFollowerProfit
- Calculates
realizedProfit = currentShareValue - waterMark - Approves
revenueSplitterto pull the profit - Calls
revenueSplitter.splitProfit(baseAsset, realizedProfit, leader)to distribute leader and protocol cuts - Transfers the remaining amount to the follower
- Resets
waterMark - Emits
ProfitSettled(follower, realizedProfit)
Security Notes
| Guard | What It Enforces |
|---|---|
onlyOwner | Only the vault leader can call executeGroupTrade |
RiskManager.validateTrade | Blocks trading if Argus score < 600 or vault is frozen |
settleFollowerProfit before exit | PnL always settles before funds leave the vault |
SafeERC20 | All token transfers use OpenZeppelin’s safe transfer wrapper |