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

  1. Transfers maxCostAgtrUsd from agent to gateway.
  2. Swaps just enough agtrUSD to get paymentAmount of paymentToken.
  3. Calculates and takes the protocol fee (0.5%).
  4. Refunds any unused agtrUSD to the agent.
  5. Approves paymentToken for the target.
  6. Calls target with data.

Events

  • ServicePaid(address indexed agent, address indexed target, address paymentToken, uint256 paymentAmount, uint256 costInAgtrUsd)