Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

MayanAdapter

Git Source

Inherits: BaseAdapter

Title: MayanAdapter

Adapter for settling Mayan protocol claims and forwarding to MetaIntentReceiver

Uses pull configuration - any third-party settler can trigger settlements

Constants

MAYAN_CIRCLE

MayanCircle public immutable MAYAN_CIRCLE

FAST_MCTP

FastMCTP public immutable FAST_MCTP

SWIFT_DEST

SwiftDest public immutable SWIFT_DEST

CCTP_TOKEN_INDEX

uint256 internal constant CCTP_TOKEN_INDEX = 120

CCTP_RECIPIENT_INDEX

uint256 internal constant CCTP_RECIPIENT_INDEX = 152

CCTPV2_MESSAGE_BODY_INDEX

uint256 internal constant CCTPV2_MESSAGE_BODY_INDEX = 148

CCTPV2_SOURCE_TOKEN_INDEX

uint256 internal constant CCTPV2_SOURCE_TOKEN_INDEX = CCTPV2_MESSAGE_BODY_INDEX + 4

HOOK_DATA_INDEX

uint256 internal constant HOOK_DATA_INDEX = CCTPV2_MESSAGE_BODY_INDEX + 228

Functions

constructor

Constructor sets immutable references to Mayan contracts and receiver

constructor(address receiver, address payable mayanCircle, address payable fastMctp, address payable swiftDest)
    BaseAdapter(receiver);

Parameters

NameTypeDescription
receiveraddressAddress of the MetaIntentReceiver contract
mayanCircleaddress payableAddress of the MayanCircle contract
fastMctpaddress payableAddress of the FastMCTP contract
swiftDestaddress payableAddress of the SwiftDest contract

settleMayanCircle

Settle tokens from MayanCircle and forward to MetaIntentReceiver

function settleMayanCircle(
    bytes calldata cctpMsg,
    bytes calldata cctpSigs,
    bytes calldata encodedVm,
    MayanCircle.BridgeWithFeeParams calldata bridgeParams,
    RelayedOrderOutput calldata expectedOutput
) external payable returns (bytes32 payloadHash);

Parameters

NameTypeDescription
cctpMsgbytesThe CCTP message bytes
cctpSigsbytesThe CCTP attestation signatures
encodedVmbytesThe encoded Wormhole VM
bridgeParamsMayanCircle.BridgeWithFeeParamsThe bridge parameters containing custom payload
expectedOutputRelayedOrderOutputThe expected output details (amount is minimum required)

Returns

NameTypeDescription
payloadHashbytes32The payload hash returned by the receiver

settleFastMCTP

Settle tokens from FastMCTP and forward to MetaIntentReceiver

function settleFastMCTP(bytes calldata cctpMsg, bytes calldata cctpSigs, RelayedOrderOutput calldata expectedOutput)
    external
    payable
    returns (bytes32 payloadHash);

Parameters

NameTypeDescription
cctpMsgbytesThe CCTP V2 message bytes
cctpSigsbytesThe CCTP V2 attestation signatures
expectedOutputRelayedOrderOutputThe expected output details (amount is minimum required)

Returns

NameTypeDescription
payloadHashbytes32The payload hash returned by the receiver

settleSwiftDest

Settle tokens from SwiftDest and forward to MetaIntentReceiver

function settleSwiftDest(
    OrderParams calldata params,
    ExtraParams calldata extraParams,
    RelayedOrderOutput calldata expectedOutput
) external returns (bytes32 payloadHash);

Parameters

NameTypeDescription
paramsOrderParamsThe order parameters
extraParamsExtraParamsThe extra parameters containing custom payload hash
expectedOutputRelayedOrderOutputThe expected output details (amount is minimum required)

Returns

NameTypeDescription
payloadHashbytes32The payload hash returned by the receiver

_extractTokenFromCctpV1Msg

Extract token address from CCTP V1 message (MayanCircle)

function _extractTokenFromCctpV1Msg(bytes calldata cctpMsg) internal pure returns (address token);

Parameters

NameTypeDescription
cctpMsgbytesThe CCTP V1 message bytes

Returns

NameTypeDescription
tokenaddressThe token address extracted from the message

_extractTokenFromCctpV2Msg

Extract token address from CCTP V2 message (FastMCTP)

function _extractTokenFromCctpV2Msg(bytes calldata cctpMsg) internal pure returns (address token);

Parameters

NameTypeDescription
cctpMsgbytesThe CCTP V2 message bytes

Returns

NameTypeDescription
tokenaddressThe token address extracted from the message

_extractOrderIdFromCctpV2Msg

Extract orderId from CCTP V2 message hook data (FastMCTP)

Hook data format: payloadType(1) + destAddr(32) + gasDrop(8) + redeemFee(8) + referrerAddr(32) + referrerBps(1) + customPayload(32) Total: 84 bytes before customPayload, customPayload at index HOOK_DATA_INDEX + 82

function _extractOrderIdFromCctpV2Msg(bytes calldata cctpMsg) internal pure returns (bytes32 orderId);

Parameters

NameTypeDescription
cctpMsgbytesThe CCTP V2 message bytes

Returns

NameTypeDescription
orderIdbytes32The orderId extracted from the custom payload field

_fulfillToReceiverWithAmount

Internal helper to fulfill to receiver with a specific amount

This allows us to use the expectedOutput structure but with the actual received amount

function _fulfillToReceiverWithAmount(RelayedOrderOutput calldata baseOutput, uint256 actualAmount)
    internal
    returns (bytes32 payloadHash);

Parameters

NameTypeDescription
baseOutputRelayedOrderOutputThe base output structure (orderId, recipient, token, callData)
actualAmountuint256The actual amount received from Mayan

Returns

NameTypeDescription
payloadHashbytes32The payload hash returned by the receiver

_decodeMessage

Override _decodeMessage for BaseAdapter compliance

function _decodeMessage(bytes calldata message) internal pure override returns (RelayedOrderOutput memory output);

Parameters

NameTypeDescription
messagebytesThe encoded message bytes

Returns

NameTypeDescription
outputRelayedOrderOutputThe decoded RelayedOrderOutput

receive

receive() external payable override;

Errors

InvalidMayanContract

error InvalidMayanContract();

SettlementFailed

error SettlementFailed();

InsufficientSettlementAmount

error InsufficientSettlementAmount(uint256 received, uint256 expected);

InvalidCctpMessage

error InvalidCctpMessage();

OrderIdMismatch

error OrderIdMismatch(bytes32 expected, bytes32 actual);

TokenMismatch

error TokenMismatch(bytes32 expected, bytes32 actual);