Contract

Solidity contract for the Autonomous Airdrop example

Introduction

Contract code is all in /contracts/src. The main files of interest are AutonomousAirdrop.sol and AxiomV2Client.sol.

WARNING: This code is not audited and is only provided as an example.

AxiomV2Client.sol

AxiomV2Client is a useful reference implementation for the callback, which will be called in this form from the Prover. The axiomV2Callback function receives the callback, runs the internal and overrideable _validateAxiomV2Call and _axiomV2Callback functions.

function axiomV2Callback(
    uint64 sourceChainId,
    address callerAddr,
    bytes32 querySchema,
    bytes32 queryHash,
    bytes32[] calldata axiomResults,
    bytes calldata callbackExtraData
) external {
    require(msg.sender == axiomV2QueryAddress, "AxiomV2Client: caller must be axiomV2QueryAddress");
    emit AxiomV2Call(sourceChainId, callerAddr, querySchema, queryHash);

    _validateAxiomV2Call(sourceChainId, callerAddr, querySchema);
    _axiomV2Callback(sourceChainId, callerAddr, querySchema,queryHash, axiomResults, callbackExtraData);
}

AutonomousAirdrop.sol

In our AutonomousAirdrop contract, we inherit AxiomV2Client and proceed to override the _validateAxiomV2Call and _axiomV2Callback functions in order for us to do our validation on the callback.

Callback

Inside AutonomousAirdrop.sol, we override _axiomV2Callback. Inside this function, we do a number of things:

  1. Decode the callbackExtraData to be the user's address, which was checked earlier

  2. Parse the eventSchema, userEventAddress, and blockNumber from the results array

  3. Validate the results

  4. Transfer the tokens to the user

  5. Emit the ClaimAirdrop event

Last updated