Проверенный контрактЧастичноеBUSL-1.1
AxelarAdapter
Адрес0xf3e560dd7e7edda6c2e41cb2e034219a5d4c7de5
- Баланс
0 ETH
- Транзакций
0
- Компилятор
solc 0.8.28
- Тот же код
Только этот контракт
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 1 прогонов
- Версия EVM
- cancun
- Лицензия
- BUSL-1.1
- Совпадение
- Частичноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 282 934
- Транзакция создания
- 0x057b3e295a…9eda3c6b6f
11 файлов
- src/adapters/AxelarAdapter.solглавный5,45 КБ
- src/adapters/interfaces/IAxelarAdapter.sol5,04 КБ
- src/admin/interfaces/IAdapterGasService.sol1,55 КБ
- src/admin/interfaces/IAdapterWiring.sol1,6 КБ
- src/core/messaging/interfaces/IAdapter.sol2,55 КБ
- src/core/messaging/interfaces/IAdapterEntrypoint.sol2,83 КБ
- src/core/messaging/interfaces/IMessageGas.sol1,74 КБ
- src/core/messaging/interfaces/IMessageHandler.sol592 Б
- src/misc/Auth.sol866 Б
- src/misc/interfaces/IAuth.sol768 Б
- src/misc/libraries/CastLib.sol1,77 КБ
src/adapters/AxelarAdapter.sol
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;
import {
IAxelarAdapter,
IAdapter,
IAxelarGateway,
IAxelarGasService,
AxelarSource,
AxelarDestination,
IAxelarExecutable
} from "./interfaces/IAxelarAdapter.sol";
import {Auth} from "../misc/Auth.sol";
import {CastLib} from "../misc/libraries/CastLib.sol";
import {IAdapterEntrypoint} from "../core/messaging/interfaces/IAdapterEntrypoint.sol";
import {IAdapterWiring} from "../admin/interfaces/IAdapterWiring.sol";
import {IAdapterGasService} from "../admin/interfaces/IAdapterGasService.sol";
/// @title Axelar Adapter
/// @notice Routing contract that integrates with an Axelar Gateway
/// @dev Replay protection is enforced by the Axelar Gateway via `validateContractCall()`,
/// which marks each command ID as consumed and reverts on reuse.
contract AxelarAdapter is Auth, IAxelarAdapter {
using CastLib for *;
IAdapterEntrypoint public immutable entrypoint;
IAxelarGateway public immutable axelarGateway;
IAxelarGasService public immutable axelarGasService;
mapping(string axelarId => AxelarSource) public sources;
mapping(uint16 centrifugeId => AxelarDestination) public destinations;
constructor(IAdapterEntrypoint entrypoint_, address axelarGateway_, address axelarGasService_, address deployer)
Auth(deployer)
{
entrypoint = entrypoint_;
axelarGateway = IAxelarGateway(axelarGateway_);
axelarGasService = IAxelarGasService(axelarGasService_);
}
//----------------------------------------------------------------------------------------------
// Network wiring
//----------------------------------------------------------------------------------------------
/// @inheritdoc IAdapterWiring
function wire(uint16 centrifugeId, bytes memory data) external auth {
(string memory axelarId, string memory adapter) = abi.decode(data, (string, string));
// keccak256("") is not empty, so a cleared source would still match a sender with no address
sources[axelarId] =
AxelarSource(centrifugeId, bytes(adapter).length == 0 ? bytes32(0) : keccak256(bytes(adapter)));
destinations[centrifugeId] = AxelarDestination(axelarId, adapter);
emit Wire(centrifugeId, axelarId, adapter);
}
/// @inheritdoc IAdapterWiring
function isWired(uint16 centrifugeId, bytes memory data) external view returns (bool) {
(string memory axelarId,) = abi.decode(data, (string, string));
return bytes(destinations[centrifugeId].axelarId).length != 0 || sources[axelarId].addressHash != bytes32(0);
}
//----------------------------------------------------------------------------------------------
// Incoming
//----------------------------------------------------------------------------------------------
/// @inheritdoc IAxelarExecutable
function execute(
bytes32 commandId,
string calldata sourceAxelarId,
string calldata sourceAddress,
bytes calldata payload
) public {
AxelarSource memory source = sources[sourceAxelarId];
require(
source.addressHash != bytes32("") && source.addressHash == keccak256(bytes(sourceAddress)), InvalidAddress()
);
require(
axelarGateway.validateContractCall(commandId, sourceAxelarId, sourceAddress, keccak256(payload)),
NotApprovedByGateway()
);
entrypoint.handle(source.centrifugeId, payload);
}
//----------------------------------------------------------------------------------------------
// Outgoing
//----------------------------------------------------------------------------------------------
/// @inheritdoc IAdapter
function send(
uint16 centrifugeId,
bytes calldata payload,
uint256,
/* gasLimit */
address refund
)
external
payable
returns (bytes32 adapterData)
{
require(msg.sender == address(entrypoint), NotEntrypoint());
AxelarDestination memory destination = destinations[centrifugeId];
require(bytes(destination.axelarId).length != 0, UnknownChainId());
axelarGasService.payNativeGasForContractCall{value: msg.value}(
address(this), destination.axelarId, destination.addr, payload, refund
);
axelarGateway.callContract(destination.axelarId, destination.addr, payload);
adapterData = bytes32("");
}
/// @inheritdoc IAdapter
function estimate(uint16 centrifugeId, bytes calldata payload, uint256 gasLimit) external view returns (uint256) {
AxelarDestination memory destination = destinations[centrifugeId];
require(bytes(destination.axelarId).length != 0, UnknownChainId());
return axelarGasService.estimateGasFee(
destination.axelarId, destination.addr, payload, gasLimit + _receiveCost(centrifugeId), bytes("")
);
}
/// @dev Receive reserve added to the requested gas limit. The gas service holds what this path costs
/// and what each destination charges for it, so the adapter only names itself.
function _receiveCost(uint16 centrifugeId) internal view returns (uint256) {
IAdapterGasService gasService = IAdapterGasService(address(entrypoint.messageGas()));
return gasService.receiveCost(centrifugeId, "axelar");
}
}
src/adapters/interfaces/IAxelarAdapter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IAdapter} from "../../core/messaging/interfaces/IAdapter.sol";
import {IAdapterEntrypoint} from "../../core/messaging/interfaces/IAdapterEntrypoint.sol";
import {IAdapterWiring} from "../../admin/interfaces/IAdapterWiring.sol";
// From https://github.com/axelarnetwork/axelar-cgp-solidity/blob/main/contracts/interfaces/IAxelarGateway.sol
interface IAxelarGateway {
function callContract(string calldata destinationChain, string calldata contractAddress, bytes calldata payload)
external;
function validateContractCall(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash
) external returns (bool);
}
interface IAxelarGasService {
// From
// https://github.com/axelarnetwork/axelar-gmp-sdk-solidity/blob/00682b6c3db0cc922ec0c4ea3791852c93d7ae31/contracts/gas-estimation/InterchainGasEstimation.sol#L48
function estimateGasFee(
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
uint256 executionGasLimit,
bytes calldata params
) external view returns (uint256 gasEstimate);
// From https://github.com/axelarnetwork/axelar-cgp-solidity/blob/main/contracts/interfaces/IAxelarGasService.sol
function payNativeGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;
}
// From
// https://github.com/axelarnetwork/axelar-gmp-sdk-solidity/blob/00682b6c3db0cc922ec0c4ea3791852c93d7ae31/contracts/interfaces/IAxelarExecutable.sol#L14
interface IAxelarExecutable {
/**
* @dev Thrown when a function is called with an invalid address.
*/
error InvalidAddress();
/**
* @dev Thrown when the call is not approved by the Axelar Gateway.
*/
error NotApprovedByGateway();
/**
* @notice Executes the specified command sent from another chain.
* @dev This function is called by the Axelar Gateway to carry out cross-chain commands.
* Reverts if the call is not approved by the gateway or other checks fail.
* @param commandId The identifier of the command to execute.
* @param sourceChain The name of the source chain from where the command originated.
* @param sourceAddress The address on the source chain that sent the command.
* @param payload The payload of the command to be executed. This typically includes the function selector and
* encoded arguments.
*/
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external;
}
struct AxelarSource {
uint16 centrifugeId;
bytes32 addressHash;
}
struct AxelarDestination {
string axelarId;
string addr;
}
/// @title IAxelarAdapter
/// @notice Cross-chain messaging adapter for Axelar network
/// @dev Bridges messages between Centrifuge chains using Axelar's General Message Passing (GMP)
interface IAxelarAdapter is IAdapter, IAdapterWiring, IAxelarExecutable {
//----------------------------------------------------------------------------------------------
// Events
//----------------------------------------------------------------------------------------------
event Wire(uint16 indexed centrifugeId, string indexed axelarId, string adapter);
//----------------------------------------------------------------------------------------------
// View methods
//----------------------------------------------------------------------------------------------
/// @notice The MultiAdapter that receives decoded inbound messages from this adapter
function entrypoint() external view returns (IAdapterEntrypoint);
/// @notice Axelar's General Message Passing gateway used for cross-chain message dispatch and validation
function axelarGateway() external view returns (IAxelarGateway);
/// @notice Axelar's gas service used to estimate and pay for cross-chain execution costs
function axelarGasService() external view returns (IAxelarGasService);
/// @notice Returns the source configuration for a given axelar chain id
/// @param axelarId The Axelar ID of the remote chain
/// @return centrifugeId The remote chain id
/// @return addressHash The hash of the remote axelar adapter address
function sources(string calldata axelarId) external view returns (uint16 centrifugeId, bytes32 addressHash);
/// @notice Returns the destination configuration for a given chain id
/// @param centrifugeId The remote chain id
/// @return axelarId The Axelar ID of the remote chain
/// @return addr The address of the remote axelar adapter
function destinations(uint16 centrifugeId) external view returns (string memory axelarId, string memory addr);
}
src/admin/interfaces/IAdapterGasService.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IMessageGas} from "../../core/messaging/interfaces/IMessageGas.sol";
/// @title IAdapterGasService
/// @notice What an adapter needs from the gas service, on top of the message properties the core reads.
/// @dev Adapters reach the gas service through `MultiAdapter.messageGas()`, which is typed as
/// the core interface and must stay that way: the core has no business knowing that a receive
/// path has a cost. Adapters cast to this, which is where that knowledge belongs, because the
/// gas service is not a core contract and may assume things about the adapters it prices.
interface IAdapterGasService is IMessageGas {
error UnknownAdapter();
/// @notice Gas an adapter must reserve for its own receive path on `centrifugeId`, on top of the
/// message gas limit it is asked to deliver. In gas, not in the native token `estimate` quotes.
/// @dev An adapter names itself and nothing else: what its receive path consumes and what each
/// chain charges for it are both held by the gas service, so a repricing, a rebenchmark or a
/// new chain never reaches adapter code. `adapter` is a short-string id, the same way
/// {IMultiAdapter-file} names a dependency, so adapters can be added or retired without
/// holding an order or leaving a retired index behind.
function receiveCost(uint16 centrifugeId, bytes32 adapter) external view returns (uint128);
}
src/admin/interfaces/IAdapterWiring.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title IAdapterWiring
/// @notice Interface for cross-chain bridge adapters that support wiring configuration
/// @dev Only bridge adapters implement this interface.
/// Local adapters (e.g. StandbyAdapter) do not support wiring operations.
interface IAdapterWiring {
/// @notice Wire the adapter to a remote chain
/// @dev If this is rewiring a previously wired centrifugeId, it might be necessary
/// to call first with an empty destination for the previous configuration, to reset.
/// @param centrifugeId The chain ID to wire to
/// @param data ABI-encoded adapter-specific configuration data
function wire(uint16 centrifugeId, bytes memory data) external;
/// @notice Whether `wire(centrifugeId, data)` would overwrite an existing binding
/// @dev `wire()` writes two mappings: the destination for `centrifugeId` and the source for the bridge
/// id carried in `data`. This is true when either is already set, so a first-time wire can neither
/// re-point a chain nor steal a bridge id that another chain's inbound messages arrive under. False
/// again after a reset (a `wire()` with an empty destination). The OpsGuardian may only wire
/// adapters for which this is false.
/// @param centrifugeId The chain ID to check
/// @param data ABI-encoded adapter-specific configuration data, as `wire()` would receive it
function isWired(uint16 centrifugeId, bytes memory data) external view returns (bool);
}
src/core/messaging/interfaces/IAdapter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @notice Cross-chain transport used by `MultiAdapter` to carry protocol payloads between chains.
/// @dev Implementations MUST NOT revert in `send` or `estimate` for a route they are configured for.
/// `MultiAdapter` fans every outgoing payload out over the whole active adapter set and bubbles any
/// revert, and `Gateway` estimates before it dispatches, so one failing adapter vetoes all outbound
/// traffic of the pools that configure it, even when the remaining adapters would satisfy the
/// threshold on their own. Adapters placed after the failing one are never reached either, so a
/// `StandbyAdapter` does not get to record its send, and nothing is queued for later repayment since
/// the revert precedes the underpaid bookkeeping. Rotating away from such an adapter cannot go
/// through the hub, which would send over the same broken set: see {IMultiAdapter-setAdapters} for
/// the recovery runbook.
interface IAdapter {
//----------------------------------------------------------------------------------------------
// Errors
//----------------------------------------------------------------------------------------------
error NotEntrypoint();
error UnknownChainId();
//----------------------------------------------------------------------------------------------
// Outgoing
//----------------------------------------------------------------------------------------------
/// @notice Send a payload to the destination chain
/// @param centrifugeId The destination chain ID
/// @param payload The message payload to send
/// @param gasLimit The gas limit for execution on the destination chain
/// @param refund The address to receive any excess payment refund
/// @return adapterData Adapter-specific data returned from the send operation
function send(uint16 centrifugeId, bytes calldata payload, uint256 gasLimit, address refund)
external
payable
returns (bytes32 adapterData);
/// @notice Estimate the total cost in native gas tokens
/// @param centrifugeId The destination chain ID
/// @param payload The message payload to send
/// @param gasLimit The gas limit for execution on the destination chain
/// @return The estimated cost in native gas tokens
function estimate(uint16 centrifugeId, bytes calldata payload, uint256 gasLimit) external view returns (uint256);
}
src/core/messaging/interfaces/IAdapterEntrypoint.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import {IMessageGas} from "./IMessageGas.sol";
import {IMessageHandler} from "./IMessageHandler.sol";
/// @notice Thin entrypoint that adapters use to reach the MultiAdapter. Extends {IMessageHandler} (the regular
/// vote-and-maybe-execute path) with the proof-adapter primitives {vote} and {execute}, which decouple
/// voting from execution. Adapters depend on this small interface instead of the full {IMultiAdapter}.
interface IAdapterEntrypoint is IMessageHandler {
//----------------------------------------------------------------------------------------------
// Errors
//----------------------------------------------------------------------------------------------
/// @notice Dispatched when {execute} is called for a payload whose votes have not reached the threshold
/// (i.e. some required adapter has not delivered its proof yet).
error NotEnoughVotes();
//----------------------------------------------------------------------------------------------
// Incoming
//----------------------------------------------------------------------------------------------
/// @notice Records the calling adapter's vote for `payload` WITHOUT ever executing it, even once the
/// threshold is reached. Proof adapters call this on receipt; execution is deferred to {execute}.
/// @dev Unlike `handle()`, this never forwards to the gateway and never consumes votes, so a cheap proof
/// delivery can never trigger an under-funded inline execution.
/// @param centrifugeId Source chain identifier
/// @param payload The wrapped payload (session-id prefixed) to vote on
function vote(uint16 centrifugeId, bytes calldata payload) external;
/// @notice Executes a payload whose votes have already reached the threshold,
/// consuming the quorum's votes. Does NOT cast a vote of its own.
/// @dev Reverts with {NotEnoughVotes} if the threshold is not met.
/// @param centrifugeId Source chain identifier
/// @param payload The wrapped payload (session-id prefixed) to execute
function execute(uint16 centrifugeId, bytes calldata payload) external;
//----------------------------------------------------------------------------------------------
// View methods
//----------------------------------------------------------------------------------------------
/// @notice Gas properties of the messages this carries. An adapter that prices its own receive path
/// reads the reference from here and casts to the interface that prices it, so replacing it
/// is a single file() and never an adapter redeploy.
function messageGas() external view returns (IMessageGas);
}
src/core/messaging/interfaces/IMessageGas.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @notice Defines the gas properties of raw messages.
/// @dev Values only: how a message is framed or attributed is `IMessageParser`, which is read from the
/// processor instead, so that filing this interface cannot alter source-chain authentication.
interface IMessageGas {
/// @notice Gas limit for the execution cost of an individual message in a remote chain from the adapter.
/// @dev NOTE: In the future we could want to dispatch:
/// - by destination chain (for non-EVM chains)
/// - by message type
/// - by inspecting the payload checking different subsmessages that alter the endpoint processing
/// @param centrifugeId Where to the cost is defined
/// @param message Individual message
/// @return Estimated cost in WEI units
function messageOverallGasLimit(uint16 centrifugeId, bytes calldata message) external view returns (uint128);
/// @notice Similar to messageOverallGasLimit but taking only into account the exact gas to process it from the Gateway
/// for processing the message without any extra addition
function messageProcessingGasLimit(uint16 centrifugeId, bytes calldata message) external view returns (uint128);
/// @notice Maximum Gas limit for a batch, determined how much the destination chain can process
/// @param centrifugeId Destination where to the maximum cost is defined
function maxBatchGasLimit(uint16 centrifugeId) external view returns (uint128);
/// @notice Gas reserved in every message budget to handle a worst-case processor revert.
function messageFailureGasReserve() external view returns (uint128);
}
src/core/messaging/interfaces/IMessageHandler.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @notice Generic interface for entities that handle incoming messages
interface IMessageHandler {
//----------------------------------------------------------------------------------------------
// Incoming
//----------------------------------------------------------------------------------------------
/// @notice Handling incoming messages
/// @param centrifugeId Source chain
/// @param message Incoming message
function handle(uint16 centrifugeId, bytes calldata message) external;
}
src/misc/Auth.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
import {IAuth} from "./interfaces/IAuth.sol";
/// @title Auth
/// @notice Simple authentication pattern
/// @author Based on code from https://github.com/makerdao/dss
abstract contract Auth is IAuth {
/// @inheritdoc IAuth
mapping(address => uint256) public wards;
constructor(address initialWard) {
wards[initialWard] = 1;
emit Rely(initialWard);
}
/// @dev Check if the msg.sender has permissions
modifier auth() {
require(wards[msg.sender] == 1, NotAuthorized());
_;
}
/// @inheritdoc IAuth
function rely(address user) public auth {
wards[user] = 1;
emit Rely(user);
}
/// @inheritdoc IAuth
function deny(address user) public auth {
wards[user] = 0;
emit Deny(user);
}
}
src/misc/interfaces/IAuth.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
interface IAuth {
event Rely(address indexed user);
event Deny(address indexed user);
error NotAuthorized();
/// @notice Returns whether the target is a ward (has admin access)
/// @param target The address to check for ward status
/// @return The ward status (1 if ward, 0 if not)
function wards(address target) external view returns (uint256);
/// @notice Make user a ward (give them admin access)
/// @param user The address to grant ward status to
function rely(address user) external;
/// @notice Remove user as a ward (remove admin access)
/// @param user The address to remove ward status from
function deny(address user) external;
}
src/misc/libraries/CastLib.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.28;
/// @title CastLib
library CastLib {
error PrefixNotZero();
error SizeNot128();
function toAddressLeftPadded(bytes32 addr) internal pure returns (address) {
require(bytes12(addr) == 0, PrefixNotZero());
return address(uint160(uint256(addr)));
}
function toBytes32LeftPadded(address addr) internal pure returns (bytes32) {
return bytes32(uint256(uint160(addr)));
}
function toAddress(bytes32 addr) internal pure returns (address) {
require(uint96(uint256(addr)) == 0, PrefixNotZero());
return address(bytes20(addr));
}
function toBytes32(address addr) internal pure returns (bytes32) {
return bytes32(bytes20(addr));
}
/// @dev Adds zero padding
function toBytes32(string memory source) internal pure returns (bytes32) {
return bytes32(bytes(source));
}
/// @dev Removes zero padding
function bytes128ToString(bytes memory _bytes128) internal pure returns (string memory) {
require(_bytes128.length == 128, SizeNot128());
uint8 i = 0;
while (i < 128 && _bytes128[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
for (uint8 j; j < i; j++) {
bytesArray[j] = _bytes128[j];
}
return string(bytesArray);
}
function toString(bytes32 _bytes32) internal pure returns (string memory) {
uint8 i = 0;
while (i < 32 && _bytes32[i] != 0) {
i++;
}
bytes memory bytesArray = new bytes(i);
for (i = 0; i < 32 && _bytes32[i] != 0; i++) {
bytesArray[i] = _bytes32[i];
}
return string(bytesArray);
}
}
Настройки компилятораПоказать
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": true
},
"libraries": {},
"optimizer": {
"runs": 1,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/halmos-cheatcodes/src/",
"@chimera/=lib/chimera/src/",
"safe-utils/=lib/safe-utils/src/",
"safe-smart-account/=lib/safe-utils/lib/safe-smart-account/contracts/",
"solidity-http/=lib/safe-utils/lib/solidity-http/src/",
"solidity-stringutils/=lib/safe-utils/lib/solidity-stringutils/src/",
"@recon/=lib/setup-helpers/src/",
"chimera/=lib/chimera/src/",
"ds-test/=lib/chimera/lib/forge-std/lib/ds-test/src/",
"setup-helpers/=lib/setup-helpers/src/",
"src/=src/",
"test/=test/",
"createx-forge/=lib/createx-forge/",
"create3-gate/=lib/create3-gate/",
"lib/create3-gate/:createx-forge/script/=script/utils/createx/",
"enso-weiroll/=lib/enso-weiroll/contracts/"
]
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.