axelar-gmp-sdk-solidity

Solidity API

BaseAmplifierGateway

BASE_AMPLIFIER_GATEWAY_SLOT

bytes32 BASE_AMPLIFIER_GATEWAY_SLOT

This slot contains the storage for this contract in an upgrade-compatible manner keccak256(‘BaseAmplifierGateway.Slot’) - 1;

MESSAGE_NONEXISTENT

bytes32 MESSAGE_NONEXISTENT

Message can be in one of three states: non-existent, approved, or executed Non-existent: The message has not been seen before. Equal to 0 Approved: The message has been seen and approved. Equal to keccak256 of the message data Executed: The message has been seen and executed. Equal to 1

MESSAGE_EXECUTED

bytes32 MESSAGE_EXECUTED

BaseAmplifierGatewayStorage

Storage for this contract

Parameters

| Name | Type | Description | | —- | —- | ———– |

struct BaseAmplifierGatewayStorage {
  mapping(bytes32 => bytes32) messages;
}

callContract

function callContract(string destinationChain, string destinationContractAddress, bytes payload) external

Sends a message to the specified destination chain and address with a given payload. This function is the entry point for general message passing between chains.

Parameters

Name Type Description
destinationChain string The chain where the destination contract exists. A registered chain name on Axelar must be used here
destinationContractAddress string The address of the contract to call on the destination chain
payload bytes The payload to be sent to the destination contract

isMessageApproved

function isMessageApproved(string sourceChain, string messageId, string sourceAddress, address contractAddress, bytes32 payloadHash) external view returns (bool)

Checks if a message is approved.

Determines whether a given message, identified by the sourceChain and messageId, is approved.

Parameters

Name Type Description
sourceChain string The name of the source chain.
messageId string The unique identifier of the message.
sourceAddress string The address of the sender on the source chain.
contractAddress address The address of the contract where the call will be executed.
payloadHash bytes32 The keccak256 hash of the payload data.

Return Values

Name Type Description
[0] bool True if the contract call is approved, false otherwise.

isMessageExecuted

function isMessageExecuted(string sourceChain, string messageId) external view returns (bool)

Checks if a message is executed.

Determines whether a given message, identified by the sourceChain and messageId is executed.

Parameters

Name Type Description
sourceChain string The name of the source chain.
messageId string The unique identifier of the message.

Return Values

Name Type Description
[0] bool True if the message is executed, false otherwise.

validateMessage

function validateMessage(string sourceChain, string messageId, string sourceAddress, bytes32 payloadHash) external returns (bool valid)

Validates if a message is approved. If message was in approved status, status is updated to executed to avoid replay.

Parameters

Name Type Description
sourceChain string The name of the source chain.
messageId string The unique identifier of the message.
sourceAddress string The address of the sender on the source chain.
payloadHash bytes32 The keccak256 hash of the payload data.

Return Values

Name Type Description
valid bool True if the message is approved, false otherwise.

messageToCommandId

function messageToCommandId(string sourceChain, string messageId) public pure returns (bytes32)

Compute the commandId for a message.

Parameters

Name Type Description
sourceChain string The name of the source chain as registered on Axelar.
messageId string The unique message id for the message.

Return Values

Name Type Description
[0] bytes32 The commandId for the message.

isCommandExecuted

function isCommandExecuted(bytes32 commandId) public view returns (bool)

The below methods are available for backwards compatibility with the original AxelarExecutable Other implementations can skip these methods.

isContractCallApproved

function isContractCallApproved(bytes32 commandId, string sourceChain, string sourceAddress, address contractAddress, bytes32 payloadHash) external view returns (bool)

Checks if a contract call is approved.

Determines whether a given contract call, identified by the commandId and payloadHash, is approved.

Parameters

Name Type Description
commandId bytes32 The identifier of the command to check.
sourceChain string The name of the source chain.
sourceAddress string The address of the sender on the source chain.
contractAddress address The address of the contract where the call will be executed.
payloadHash bytes32 The keccak256 hash of the payload data.

Return Values

Name Type Description
[0] bool True if the contract call is approved, false otherwise.

validateContractCall

function validateContractCall(bytes32 commandId, string sourceChain, string sourceAddress, bytes32 payloadHash) external returns (bool valid)

Validates and approves a contract call.

Validates the given contract call information and marks it as approved if valid.

Parameters

Name Type Description
commandId bytes32 The identifier of the command to validate.
sourceChain string The name of the source chain.
sourceAddress string The address of the sender on the source chain.
payloadHash bytes32 The keccak256 hash of the payload data.

Return Values

Name Type Description
valid bool True if the contract call is validated and approved, false otherwise.

_approveMessages

function _approveMessages(struct Message[] messages) internal

Approves an array of messages.

Parameters

Name Type Description
messages struct Message[] The array of messages to verify.

_isMessageApproved

function _isMessageApproved(bytes32 commandId, string sourceChain, string sourceAddress, address contractAddress, bytes32 payloadHash) internal view returns (bool)

_validateMessage

function _validateMessage(bytes32 commandId, string sourceChain, string sourceAddress, bytes32 payloadHash) internal returns (bool valid)

For backwards compatibility with validateContractCall, commandId is used here instead of messageId.

Return Values

Name Type Description
valid bool True if message is valid

_approveMessage

function _approveMessage(struct Message message) internal

Approves a message if it hasn’t been approved before. The message status is set to approved.

_messageHash

function _messageHash(bytes32 commandId, string sourceChain, string sourceAddress, address contractAddress, bytes32 payloadHash) internal pure returns (bytes32)

For backwards compatibility with validateContractCall, commandId is used here instead of messageId.

Return Values

Name Type Description
[0] bytes32 bytes32 the message hash