// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
/// @title Glacis Commons
/// @dev Contract for utility functions and structures common to Glacis Client and Infrastructure
contract GlacisCommons {
struct GlacisData {
bytes32 messageId;
uint256 nonce;
address originalFrom;
address originalTo;
}
struct GlacisTokenData {
address glacisToken;
uint256 glacisTokenAmount;
}
struct GlacisRoute {
uint256 fromChainId; // 0 means any chain
address fromAddress; // 0x00 means any address
uint8 fromGmpId; // 0 means any GMP
}
/// @notice De-serialize a uint8 bitmap to an uint8 array
/// @param bitmap The bitmap to be de-serialized
/// @return The de-serialized array
function _uint8ToUint8Array(
uint8 bitmap
) internal pure returns (uint8[] memory) {
uint8[] memory result = new uint8[](8);
uint8 size;
for (uint8 i = 0; i < 8; i++) {
// Extract each bit from the uint8 value and store it as a uint8 element in the array
if ((bitmap >> i) & uint8(1) == uint8(1)) result[size++] = i + 1;
}
assembly {
mstore(result, size)
}
return result;
}
/// @notice Queries if a bit is ON on a bitmap
/// @param bitmap The bitmap to be queried
/// @param bitIndex The bitindex to query
/// @return True if the bit is on, false otherwise
function _isBitSet(
uint8 bitmap,
uint8 bitIndex
) internal pure returns (bool) {
return (bitmap & (uint8(1) << bitIndex)) != 0;
}
/// @notice Set a bit to ON on a bitmap
/// @param bitmap The bitmap to be modified
/// @param bitIndex The bitindex to set to 1
/// @return the modified bitmap with the bit set
function _setBit(
uint8 bitmap,
uint8 bitIndex
) internal pure returns (uint8) {
return bitmap | (uint8(1) << bitIndex);
}
}
/*
_______ _ _______ _______ _________ _______
( ____ \( \ ( ___ )( ____ \\__ __/( ____ \
| ( \/| ( | ( ) || ( \/ ) ( | ( \/
| | | | | (___) || | | | | (_____
| | ____ | | | ___ || | | | (_____ )
| | \_ )| | | ( ) || | | | ) |
| (___) || (____/\| ) ( || (____/\___) (___/\____) |
(_______)(_______/|/ \|(_______/\_______/\_______)
https://glacislabs.net
https://twitter.com/glacis_labs
*/
import {IGlacisRouterEvents} from "./IGlacisRouter.sol";
import {IXERC20} from "./IXERC20.sol";
import {IXERC20Lockbox} from "./IXERC20Lockbox.sol";
// File: @openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
// File: @openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
// File: @openzeppelin/contracts/token/ERC20/ERC20.sol
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* The default value of {decimals} is 18. To select a different value for
* {decimals} you should overload it.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(
address from,
address to,
uint256 amount
) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
function _approve(
address owner,
address spender,
uint256 amount
) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(
address owner,
address spender,
uint256 amount
) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
pragma solidity ^0.8.9;
contract GlacisLabs is ERC20 {
constructor() ERC20("Glacis Labs", "GLACIS") {
_mint(msg.sender, 1000000 * 10 ** decimals());
}
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
import {GlacisCommons} from "./GlacisCommons.sol";
import {IMessageDispatcher} from "./IMessageDispatcher.sol";
import {IMessageExecutor} from "./IMessageExecutor.sol";
abstract contract IGlacisRouterEvents is
GlacisCommons,
IMessageDispatcher,
IMessageExecutor
{
event GlacisAbstractRouter__MessageIdCreated(
bytes32 indexed messageId,
address indexed sender,
uint256 nonce
);
event GlacisRouter__ReceivedMessage(
bytes32 indexed messageId,
address indexed from,
uint256 indexed fromChainId,
address to
);
event GlacisRouter__MessageDispatched(
bytes32 indexed messageId,
address indexed from,
uint256 indexed toChainId,
address to,
bytes data,
uint8[] gmps,
uint256[] fees,
address refundAddress,
bool retriable
);
event GlacisRouter__MessageRetried(
bytes32 indexed messageId,
address indexed from,
uint256 indexed toChainId,
address to,
bytes data,
uint8[] gmps,
uint256[] fees,
address refundAddress
);
}
interface IGlacisRouter {
function route(
uint256 chainId,
address to,
bytes memory payload,
uint8[] memory gmps,
uint256[] memory fees,
address refundAddress,
bool retry
) external payable returns (bytes32);
function routeRetry(
uint256 chainId,
address to,
bytes memory payload,
uint8[] memory gmp,
uint256[] memory fees,
address refundAddress,
bytes32 messageId,
uint256 nonce
) external payable returns (bytes32);
function receiveMessage(
uint256 fromChainId,
bytes memory glacisPayload
) external;
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
/// An interface as described by EIP-5164. In Glacis' current implementation, messages are not dispatched with the
/// dispatchMessage function, hence its removal. The only adherence now is to the event, which the GlacisRouter will
/// use.
interface IMessageDispatcher {
/// The MessageDispatched event must be emitted by the MessageDispatcher when an individual message is dispatched.
event MessageDispatched(
bytes32 indexed messageId,
address indexed from,
uint256 indexed toChainId,
address to,
bytes data
);
}
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.18;
interface IMessageExecutor {
/// MessageIdExecuted must be emitted once a message or message batch has been executed.
event MessageIdExecuted(
uint256 indexed fromChainId,
bytes32 indexed messageId
);
/// MessageExecutors must revert if a messageId has already been executed and should emit a
/// MessageIdAlreadyExecuted custom error.
error MessageIdAlreadyExecuted(bytes32 messageId);
/// MessageExecutors must revert if an individual message fails and should emit a MessageFailure custom error.
error MessageFailure(bytes32 messageId, bytes errorData);
// This note from EIP-5164 seems repetitive as Axelar and the other chains already do this
// MessageExecutors MUST append the ABI-packed (messageId, fromChainId, from) to the calldata for each message
/// being executed. This allows the receiver of the message to verify the cross-chain sender and the chain that the
/// message is coming from.
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;
interface IXERC20 {
/**
* @notice Emits when a lockbox is set
*
* @param _lockbox The address of the lockbox
*/
event LockboxSet(address _lockbox);
/**
* @notice Emits when a limit is set
*
* @param _mintingLimit The updated minting limit we are setting to the bridge
* @param _burningLimit The updated burning limit we are setting to the bridge
* @param _bridge The address of the bridge we are setting the limit too
*/
event BridgeLimitsSet(
uint256 _mintingLimit,
uint256 _burningLimit,
address indexed _bridge
);
/**
* @notice Reverts when a user with too low of a limit tries to call mint/burn
*/
error IXERC20_NotHighEnoughLimits();
/**
* @notice Reverts when caller is not the factory
*/
error IXERC20_NotFactory();
struct Bridge {
BridgeParameters minterParams;
BridgeParameters burnerParams;
}
struct BridgeParameters {
uint256 timestamp;
uint256 ratePerSecond;
uint256 maxLimit;
uint256 currentLimit;
}
/**
* @notice Sets the lockbox address
*
* @param _lockbox The address of the lockbox
*/
function setLockbox(address _lockbox) external;
/**
* @notice Updates the limits of any bridge
* @dev Can only be called by the owner
* @param _mintingLimit The updated minting limit we are setting to the bridge
* @param _burningLimit The updated burning limit we are setting to the bridge
* @param _bridge The address of the bridge we are setting the limits too
*/
function setLimits(
address _bridge,
uint256 _mintingLimit,
uint256 _burningLimit
) external;
/**
* @notice Returns the max limit of a minter
*
* @param _minter The minter we are viewing the limits of
* @return _limit The limit the minter has
*/
function mintingMaxLimitOf(
address _minter
) external view returns (uint256 _limit);
/**
* @notice Returns the max limit of a bridge
*
* @param _bridge the bridge we are viewing the limits of
* @return _limit The limit the bridge has
*/
function burningMaxLimitOf(
address _bridge
) external view returns (uint256 _limit);
/**
* @notice Returns the current limit of a minter
*
* @param _minter The minter we are viewing the limits of
* @return _limit The limit the minter has
*/
function mintingCurrentLimitOf(
address _minter
) external view returns (uint256 _limit);
/**
* @notice Returns the current limit of a bridge
*
* @param _bridge the bridge we are viewing the limits of
* @return _limit The limit the bridge has
*/
function burningCurrentLimitOf(
address _bridge
) external view returns (uint256 _limit);
/**
* @notice Mints tokens for a user
* @dev Can only be called by a minter
* @param _user The address of the user who needs tokens minted
* @param _amount The amount of tokens being minted
*/
function mint(address _user, uint256 _amount) external;
/**
* @notice Burns tokens for a user
* @dev Can only be called by a minter
* @param _user The address of the user who needs tokens burned
* @param _amount The amount of tokens being burned
*/
function burn(address _user, uint256 _amount) external;
}
interface IXERC20GlacisExtension {
/**
* @notice Returns a token variant for a specific chainId if it exists.
*
* @param chainId The chainId of the token variant.
*/
function getTokenVariant(uint256 chainId) external view returns (address);
/**
* @notice Sets a token variant for a specific chainId.
*
* @param chainId The chainId of the token variant.
* @param variant The address of the token variant.
*/
function setTokenVariant(uint256 chainId, address variant) external;
}
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.18;
interface IXERC20Lockbox {
/**
* @notice Emitted when tokens are deposited into the lockbox
*/
event Deposit(address _sender, uint256 _amount);
/**
* @notice Emitted when tokens are withdrawn from the lockbox
*/
event Withdraw(address _sender, uint256 _amount);
/**
* @notice Reverts when a user tries to deposit native tokens on a non-native lockbox
*/
error IXERC20Lockbox_NotNative();
/**
* @notice Reverts when a user tries to deposit non-native tokens on a native lockbox
*/
error IXERC20Lockbox_Native();
/**
* @notice Reverts when a user tries to withdraw and the call fails
*/
error IXERC20Lockbox_WithdrawFailed();
/**
* @notice Deposit ERC20 tokens into the lockbox
*
* @param _amount The amount of tokens to deposit
*/
function deposit(uint256 _amount) external;
/**
* @notice Deposit ERC20 tokens into the lockbox, and send the XERC20 to a user
*
* @param _user The user to send the XERC20 to
* @param _amount The amount of tokens to deposit
*/
function depositTo(address _user, uint256 _amount) external;
/**
* @notice Deposit the native asset into the lockbox, and send the XERC20 to a user
*
* @param _user The user to send the XERC20 to
*/
function depositNativeTo(address _user) external payable;
/**
* @notice Withdraw ERC20 tokens from the lockbox
*
* @param _amount The amount of tokens to withdraw
*/
function withdraw(uint256 _amount) external;
/**
* @notice Withdraw ERC20 tokens from the lockbox
*
* @param _user The user to withdraw to
* @param _amount The amount of tokens to withdraw
*/
function withdrawTo(address _user, uint256 _amount) external;
}
{
"compilationTarget": {
"GlacisLabs.sol": "GlacisLabs"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]