Intents
Intents are cryptographically signed off-chain expressions of what a user wishes to achieve. In the AFP, Intent Accounts submit intents to trading protocols, which are then submitted as components of a trade on-chain to be cleared.
Intent Structure
All trading protocols must implement interfaces to accept intents as inputs.
struct Intent {
address marginAccountID;
address intentAccountID;
bytes32 hash;
IntentData data;
bytes signature;
}
- marginAccountID - the margin account ID which has a funded margin account on the associated collateral asset
- intentAccountID - the intent account ID which has signed the intent (must be approved by the margin account)
- hash - the hash of the intent data
- data - the intent data containing the details of the intended trade
- signature - the signature of the intent, signed by the intent account ID
struct IntentData {
uint256 nonce;
address tradingProtocolID;
bytes32 productID;
uint256 limitPrice;
uint256 quantity;
uint256 maxTradingFeeRate;
uint256 goodUntil;
Side side;
}
- nonce - the unique nonce of the intent, used to prevent replay attacks
- tradingProtocolID - the trading protocol ID that is executing the intent (must match the msg.sender)
- productID - the product ID of the product being traded
- limitPrice - the limit price for the trade
- quantity - the maximum quantity to be traded
- maxTradingFeeRate - the maximum trading fee rate that the account is willing to pay to the trading protocol
- goodUntil - the time after which this intent expires
- side* - the side of the trade (BID or ASK)