🐬Message Dispatching using Yaru and Yaho

For relaying arbitrary message between Ethereum/Goerli and Gnosis Chain, several contracts need to be deployed on top of the current AMB deployments: Yaho, Yaru, AMB Message Relay, AMB Adapter, and Hashi. The addresses from this article are for Goerli <-> Gnosis Chain.

Prerequisite

For Goerli->Gnosis Direction:

  1. Deploy Yaho on Goerli, and Yaru on Gnosis Chain, with constructor _hashi: Hashi address on Gnosis Chain, _yaho: Yaho address on Goerli, _chainId: 5.

  2. Optional: Deploy Hashi Module for Safe that will be called by Yaru, i.e. Safe on Gnosis Chain.

  3. Deploy AMB Message Relay on Goerli, with constructor _amb: AMB address on Goerli, _yaho: Yaho address on Goerli.

  4. Deploy AMB Adapter on Gnosis Chain, with constructor _amb: AMB address on Gnosis Chain, _reporter: AMB Message Relay on Goerli, _chainId: bytes32(5) .

In the current deployment, gas is added as a parameter in dispatchMessagesToAdapters() to justify the amb's gas requirement. It is not added into the official hashi code at the moment as it might raise incompatibility issue for other adapters. Please be aware that these contracts might be changed anytime.

Workflow: Ethereum -> Gnosis Chain

  • User calls Yaho.dispatchMessagesToAdapters. Example

  • Yaho calls AMB Message Relay relayMessages which will eventually calls storeHashes from AMB Adapter on Gnosis Chain.

  • AMB Message Relay calls AMB requireToPassMessage, and the message will be relayed to AMB on Gnosis Chain.

  • Once the AMB Adapter storeHashes is called, MessageDispatched event will be emitted and user need messageId data from the event. Example

  • User calls Yaru.executeMessages with messageId and message as parameters. Example

Initiate Transaction

  1. Create function calldata for the contract you want to call on Gnosis Chain.

const calldata = contractInterface.encodeFunctionData(function_name, parameters)
  1. Optional: Create transaction calldata for Hashi Module.

This step is only needed when Safe is used.

const txData = hashi_module_interface.encodeFunctionData("executeTransaction", [
      ${contract_to_call_on_Gnosis_Chain},
      0,
      calldata,
      0,
]);
  1. Create message with format below: With Safe:

const message =
{
    to: ${Hashi Module address},
    toChainId: 100 // Gnosis Chain,
    data: ${tx_data}
}

Without Safe:

const message =
{
    to: ${Contract address on Gnosis Chain},
    toChainId: 100 // Gnosis Chain,
    data: ${calldata}
}
  1. Call Yaho.dispatchMessagesToAdapters([message],[AMB_Message_Relay_Address],[AMB_Adapter_Address]) using Safe or EOA.

  2. Once the transaction is created, you need to collect messsage Id from MessageDispatched event emitted from Yaho.

Claim Transaction

After the message is relayed to Gnosis Chain by AMB bridge, you can proceed to claim your transaction. Make sure that your message is stored by checking if the AMB Adapter contract emits HashStored event with the correct message Id.

  1. Call Yaru.executeMessages([message],[messageId],[Safe_from_Goerli or EOA from Goerli that calls Yaho],[AMB_Adapter_Address on Gnosis Chain])

Implement your hook

For a successful message execution to happen, the contract specified as message recipient on the destination chain must implement a hook to process correctly the message.data. The hook must revert unless the msg.sender matches the expected Yaru contract, Yaru.sender() matches the expected sender, and Yaru.adapters() matches the desired set of oracles that must have agreed on the reported hash.

Workflow: Gnosis Chain -> Ethereum

  • User calls Yaho.dispatchMessagesToAdapters. Example

  • Yaho calls AMB Message Relay relayMessages which will eventually calls storeHashes from AMB Adapter on Gnosis Chain.

  • AMB Message Relay calls AMB requireToPassMessage, and UserRequestsForSignature event will be emitted.

  • User calls AMB Helper contract's getSignature with the encodedData as parameters obtained from step3, the function will return signature.Tutorial

  • User calls AMB on Goerli's executeSignature with encodedData and signature as parameters. The storeHashes from AMB Adapter will be called, MessageDispatched event will be emitted and user need messageId data from the event. Example

  • User calls Yaru.executeMessages with messageId and message as parameters. Example

Last updated