User Configurations

Several tips for our bridge builders are given here!

Consumer

Deployment parameters

import "./base/BoolConsumerBase.sol";

contract UserMock is BoolConsumerBase {
    ...
    constructor(address anchor_) BoolConsumerBase(anchor_) {}
    ...
}

Remember to pass anchor to your contract constructor to match the fundamental requirement of implementing BoolConsumerBase.sol.

In addition, when updating consumer in a deployed Anchor, the Anchor contract will validate the consumer's configuration as follows:

require(
    IBoolConsumerBase(consumer_).anchor() == address(this),
    "Anchor: ANCHOR_MISMATCH"
);

Hence, please DO NOT misconfigure your consumer contract!

Alternatively, you can design an additional function in your consumer contract to update the address of the anchor. However, we do not recommend implementing this function in your contract since in terms of the users' trust, anchor should never be changed after the deployment.

Send cross-chain messages to Anchor

Each consumer contract implemented BoolConsumerBase.sol should have inherited the following internal function _sendToAnchor. It is the intermediary to send cross-chain messages to the connected Anchor contract.

function _sendToAnchor(
    address payable refundAddress,
    bytes32 crossType,
    bytes memory extraFeed,
    uint32 dstChainId,
    address dstAnchor,
    bytes memory payload
) internal virtual returns (bytes32 txUniqueIdentification)

A consumer contract must define an upper-level function to implement this core internal function and several tips are provided to implement _sendToAnchor:

  • pack the data to be executed on the destination chain into payload, such as using abi.encode to pack the target function's parameters.

  • pass the correct dstAnchor since cross-chain messages can only be transmitted to remote anchors within the same AMT bridge.

  • requestextraFeed from our primary contracts based on the value ofcrossType: either PURE_MESSAGE or VALUE_MESSAGE.

  • Leave extraFeed blank if PURE_MESSAGE selected.

  • VALUE_MESSAGE has not been enabled yet.

Receive a Message from Anchor

modifier onlyAnchor() {
    require(msg.sender == anchor, "BoolConsumerBase: NOT_ANCHOR");
    _;
}

function receiveFromAnchor(
    bytes memory payload
) external virtual override {}
  • A consumer contract must override receiveFromAnchor and define corresponding logic to parse payload sent from its corresponding Anchor.

  • Two basic operations should be included in the override function: decode payload and forward decoded data to subsequent functions.

  • One can use the provided modifier onlyAnchor to restrict the accessibility of receiveFromAnchor.

Anchor

Transfer the ownership of the Anchor contract

  • The default owner is the initial deployer of an Anchor. One can use owner to inquire about the address of the current owner.

  • The most important role played by the owner is to update the connected consumer.

  • The interface for transferring the ownership of an anchor can be found at transferOwnership.

Last updated