x402Gateway
The x402Gateway (also known as the "Agent Paymaster") allows agents to pay for services in any token (ETH, LINK, etc.) while holding only agtrUSD. It performs atomic swaps and execution in a single transaction.
Functions
payServiceExactCost
function payServiceExactCost( address target, bytes calldata data, address paymentToken, uint256 paymentAmount, uint256 maxCostAgtrUsd ) external
Executes a service call on behalf of the agent, handling the currency conversion automatically.
Parameters
target: The address of the service contract to call.data: The calldata to execute on the target.paymentToken: The token strictly required by the service (e.g., LINK).paymentAmount: The amount of paymentToken required.maxCostAgtrUsd: The maximum amount of agtrUSD the agent is willing to spend (slippage protection + fees).
Logic Flow
- Transfers
maxCostAgtrUsdfrom agent to gateway. - Swaps just enough agtrUSD to get
paymentAmountofpaymentToken. - Calculates and takes the protocol fee (0.5%).
- Refunds any unused agtrUSD to the agent.
- Approves
paymentTokenfor the target. - Calls
targetwithdata.
Events
- ServicePaid(address indexed agent, address indexed target, address paymentToken, uint256 paymentAmount, uint256 costInAgtrUsd)
