KIP-30: Copy Trading Account MVP
A proposal to implement a feature to allow traders to open copy trading accounts on Kwenta.
This proposal outlines a new feature on Kwenta which allows traders to open an account which copies the trades of another account. Traders will specify a cross-margin account and a list of assets to copy to create a new copy trading account. Once the account is created, keepers will listen to trades on the target account and rebalance the copy trading account to mirror market exposure.
- Traders have expressed interest in copying trades of other accounts on Kwenta. Since futures market trades are all executed on-chain, traders have access to historical trading data for every other trading account.
- Traders want to promote others to copy trade them in exchange for a share of their profits.
- Copy trading account: A cross-margin (CM) enabled smart contract account which mirrors trades from another CM account
- Target account: The account being copied by a copy trading account
MarginBase.sol contract provides users with an interface to manage margin and futures positions across many markets in a single transaction. Keepers will use these functions to copy positions from the target account and execute trades on the copy trading account. To enable these functions the
MarginBase.sol contract needs some new functionality:
- Stores the address of the target account (
- Stores an array of markets to be copied (
- Stores the max fee for any trade placed while rebalancing (
- Stores a mapping of addresses that opt out of copy trading (
mapping(address => uint8) targetAccountExcluded.)
- A function
rebalancewhich matches the market exposure between the copy trading account and the target account when they are imbalanced.
- Implements new access controls which prevent traders from submitting specific trades. Instead, these functions are delegated to a keeper account.
- Implements a new
withdrawfunction which closes positions proportionally and withdraws margin to the account owner.
Account creation follows a similar flow to cross margin, however users are required to specify two inputs at account creation time:
targetAccountExcluded value must return a false value for the
targetAccount. Once an account is created, the account owner can deposit sUSD to the account. The rebalance function is called on deposit to copy positions between the copy trading account and the target account.
copiedTrader account emits any
PositionModified event, the keeper calls
rebalance on the copy trading account. Rebalancing will open or close positions accordingly to give the copy trader the same market exposure as their target using the following logic:
marginTotal = marginFree + marginMarket1 + ... + marginMarketN
freeMarginPct = marginFree / marginTotal
marginPctMarket1 = marginMarket1 / marginTotal(calculate for all
leverageMarket1 = notionalSizeMarket1 / marginMarket1(calculate for all
- Modify positions such that
leverageMarketNare equal for all
copiedMarketsbetween the copy trading account and the target account
If any trade will execute with a fee greater than the account's
maxFee parameter, the transaction will revert.
The rebalance function has additional parameters to add or remove futures markets from
copiedMarkets. This features is convenient if a trader's risk tolerance for certain assets has changed or when new assets are listed on Kwenta. A trader can specify the markets to add or remove while rebalancing. Adding markets will open new positions, taking margin from existing positions accordingly. Removing markets will close the position in the specified market and increase positions on other markets.
Additionally, traders can specify an amount of margin to withdraw on rebalance. Keepers will always submit transactions with a value of 0. Users can submit transactions with any amount up to their
totalMargin, which will proportionally reduce position sizes and return margin to the trader.
Traders are opted in to copy trading by default, meaning any trader can create an account copying their trades. If traders would like to prevent accounts copying their trades, they can call a function on the factory contract which will prevent further copy trading accounts from being created. Any accounts created prior to this transaction will continue to exist and copy their trades.
Considerations and Risks
- Open interest caps could cause transactions to fail if the copy trading account trade sizes exceed caps during rebalancing
- Dynamic fees could cause the copy trader to pay significant fees compared to their target since the transactions are executed sequentially