Flow
- The trader approves an agent wallet with
setTradingDelegate. - The agent wallet is funded with native gas token.
- The backend builds the calldata for a normal trading action, such as
openTrade,closeTradeMarket,updateSl, orupdateTp. - The backend wraps that calldata in
delegatedTradingAction, passing the trader address and the action calldata. - The agent wallet submits the wrapped transaction to
GNSMultiCollatDiamond.
Approve a delegate
The trader must approve the delegate from their own wallet:setTradingDelegate replaces the previous delegate. Calling removeTradingDelegate clears it.
Submit from a backend signer
The agent wallet signs the wrapped transaction. The trader address is still passed into the wrapped call:openTrade with ERC-20 collateral requires the trader to have enough collateral and to have approved the diamond to pull that collateral.
Direct contract call
You can also build the wrapped calldata manually:Supported actions
Delegation is designed for trading and trade management. Common supported actions include:openTradecloseTradeMarketupdateSlupdateTpupdateOpenOrdercancelOpenOrderupdateLeverageincreasePositionSizedecreasePositionSizeupdateMaxClosingSlippagePcancelOrderAfterTimeout
withdrawPositivePnl. Any withdrawn PnL is transferred to the trader, not to the delegate.
Unsupported actions
Functions guarded bynotDelegatedAction cannot be executed through delegatedTradingAction. This includes native-token wrapper flows and trigger-order flows:
openTradeNativeincreasePositionSizeNativeupdateLeverageNativetriggerOrdertriggerOrderWithSignatures- nested
delegatedTradingAction
$APE does not follow ERC-20 approve and transferFrom semantics.
Security notes
Delegated trading is broad trading authority, not a granular permission system. A delegate cannot withdraw user funds to itself through the trading delegation flow, but it can submit trading actions that affect the trader’s positions and collateral. Recommended practices:- Use a dedicated agent wallet per integration or user group.
- Keep the agent wallet funded only with enough gas for expected operations.
- Let users revoke access with
removeTradingDelegate. - Enforce any additional policy, such as max trade size, allowed pairs, or disabled PnL withdrawals, in your backend before signing transactions.
- Treat backend policy as off-chain protection. The current on-chain delegation model does not enforce per-function, per-market, per-size, or expiry-scoped permissions.
