MagpieCCTPBridge
The MagpieCCTPBridge contract is designed for cross-chain token transfers and swaps, integrating various external libraries and interfaces. It inherits from Ownable2Step and Pausable for managing ownership and pausing functionalities. The contract uses the LibAsset library for asset operations and interacts with external interfaces like IMagpieCCTPBridge, IAxelarGateway, IAxelarGasService, and IReceiver. Key features include managing internal callers and deposits, updating critical addresses (WETH, token messenger, message transmitter, gateway, gas receiver), and performing token swaps with Magpie or user signatures. It ensures secure operations through signature verification and handles inbound and outbound swaps, bridging assets, and executing multiple function calls in a single transaction. The contract also supports incoming Ether transfers.
verifySignature
The verifySignature function is a private function that verifies the signature for a swap operation. It takes SwapData and a boolean flag useCaller as parameters. The function constructs a message based on the swap details, including whether an affiliate is involved, and uses assembly to efficiently handle the message data. It then calls LibRouter.verifySignature to validate the signature, ensuring the integrity and authenticity of the swap operation.
swapIn
The swapIn function is a private function that executes an inbound swap operation. It increments the swapSequence to ensure each swap has a unique sequence number and retrieves the current network ID and router address using assembly. The function verifies the signature of the swap operation through the verifySignature function, ensuring the authenticity of the transaction. If the swap data includes a permit, the function calls LibRouter.permit to handle the permit. It then transfers any associated fees using LibRouter.transferFees. The function prepares the deposit data by filling an encoded data structure and computing its hash. The actual swap is performed by calling LibBridge.swapIn, which returns the amount received from the swap. Finally, the function calls bridgeIn to handle the bridging of assets and checks for reentrancy by comparing the current swap sequence with the initial value. If they do not match, it reverts the transaction with a ReentrancyError. An event BridgeIn is emitted with the deposit data hash and nonce.
bridgeIn
The bridgeIn function handles the bridging of an inbound asset transfer into the contract. It approves the token messenger to spend the specified amount of the asset and prepares the data for the bridging operation using assembly. The function calls tokenMessengerAddress.execute to perform the bridging operation and reverts with BurnFailed if the operation fails. It then calls dataIn to handle the inbound data transfer and emits a BridgeIn event with the deposit data hash and nonce.
dataIn
The dataIn function executes an inbound data transfer, preparing the payload with the deposit data hash, amount, and asset address. It calls IAxelarGasService.payNativeGasForContractCall to pay the gas fee for the contract call and IAxelarGateway.callContract to execute the contract call on the destination chain.
execute
The execute function handles the execution of inbound messages from the Axelar gateway. It validates the contract call using IAxelarGateway.validateContractCall and reverts with NotApprovedByGateway if the validation fails. The function then calls addDeposit to add the validated deposit.
addDeposit
The addDeposit function adds a validated deposit to the contract, updating the deposit mapping with the amount and asset address from the payload. It emits a Deposit event with the deposit data hash and amount.
swapOut
The swapOut function handles outbound swap operations, restricted to internal callers. It retrieves the network ID and router address using assembly and prepares the message and attestation data for the swap. The function calls IReceiver.receiveMessage to process the message and reverts with MintFailed if the operation fails. It then retrieves the deposit amount from the deposit mapping and performs the swap using LibBridge.swapOut, returning the amount received from the swap.
multicall
The multicall function allows the contract owner to execute multiple function calls in a single transaction. It iterates over the provided data array and calls each function using Address.functionDelegateCall, returning the results of each call.
receive
receive function handles incoming Ether transfers.
Last updated