Contract Source Code:
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
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;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the value {ERC20} uses, unless this function is
* overridden;
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
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;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
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;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
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;
}
_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;
_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;
}
_totalSupply -= amount;
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
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);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(
address from,
address to,
uint256 amount
) internal virtual {}
}
// SPDX-License-Identifier: MIT
// 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);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
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);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @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);
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// OSEAN DAO token contract for ETHEREUM - https://osean.online
// Official telegram: https://t.me/oseadao
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "./supertoken/Base.sol";
import "./interfaces/Uniswap.sol";
contract Osean is ERC20, Base {
struct UpdateLimitParams {
bool isMint;
uint32 siblingChainSlug;
uint256 maxLimit;
uint256 ratePerSecond;
}
bytes32 constant RESCUE_ROLE = keccak256("RESCUE_ROLE");
bytes32 constant LIMIT_UPDATER_ROLE = keccak256("LIMIT_UPDATER_ROLE");
// bridge contract address which provides AMB support
IMessageBridge public bridge__;
// siblingChainSlug => mintLimitParams
mapping(uint32 => LimitParams) _receivingLimitParams;
// siblingChainSlug => burnLimitParams
mapping(uint32 => LimitParams) _sendingLimitParams;
// siblingChainSlug => receiver => identifier => amount
mapping(uint32 => mapping(address => mapping(bytes32 => uint256)))
public pendingMints;
// siblingChainSlug => amount
mapping(uint32 => uint256) public siblingPendingMints;
////////////////////////////////////////////////////////
////////////////////// ERRORS //////////////////////////
////////////////////////////////////////////////////////
error SiblingNotSupported();
error MessageIdMisMatched();
error ZeroAmount();
error NotMessageBridge();
error InvalidReceiver();
error InvalidSiblingChainSlug();
////////////////////////////////////////////////////////
////////////////////// EVENTS //////////////////////////
////////////////////////////////////////////////////////
// emitted when limit params are updated
event LimitParamsUpdated(UpdateLimitParams[] updates);
// emitted when message bridge is updated
event MessageBridgeUpdated(address newBridge);
// emitted at source when tokens are bridged to a sibling chain
event BridgeTokens(
uint32 siblingChainSlug,
address withdrawer,
address receiver,
uint256 bridgedAmount,
bytes32 identifier
);
// emitted when pending tokens are minted to the receiver
event PendingTokensBridged(
uint32 siblingChainSlug,
address receiver,
uint256 mintAmount,
uint256 pendingAmount,
bytes32 identifier
);
// emitted when transfer reaches limit and token mint is added to pending queue
event TokensPending(
uint32 siblingChainSlug,
address receiver,
uint256 pendingAmount,
uint256 totalPendingAmount,
bytes32 identifier
);
// emitted when pending tokens are minted as limits are replenished
event TokensBridged(
uint32 siblingChainSlug,
address receiver,
uint256 mintAmount,
uint256 totalAmount,
bytes32 identifier
);
// Mapping to exclude some contracts from fees. Transfers are excluded from fees if address in this mapping is recipient or sender.
mapping (address => bool) public excludedFromFees;
// Yacht funds wallet address that will be used for DAO treasury and buy Yachts.
address payable public oseanWalletAddress;
// Marketing wallet address used for funding marketing.
address payable public marketingWalletAddress;
// Developer wallet address used for funding the team.
address payable public developerWalletAddress;
// Liquidity wallet address used to hold the 75% of OSEAN tokens for the liquidity pool.
// After these coins are moved to the DEX, this address will no longer be used.
address public liquidityWalletAddress;
// Address of the wallet that will keep OSEAN tokens for burn.
address payable public tobeburntWalletAddress;
// Address of the contract responsible for the air dropping.
address public airDropWalletAddress;
// The PancakeSwap router address for swapping OSEAN tokens for WBNB.
address public uniswapRouterAddress;
// The initial block timestamp of the token contract.
uint256 public initialTimeStamp;
// Yacht transaction fee - deployed at 1%.
uint256 public yachtTransactionFeePercent = 1;
// Developer team transaction fee - deployed at 1%.
uint256 public developerFeePercent = 1;
// Marketing transaction fee - deployed at 1%.
uint256 public marketingFeePercent = 1;
// Marketing transaction fee - deployed at 1%.
uint256 public burnFeePercent = 1;
// PancakeSwap router interface.
IUniswapV2Router02 private uniswapRouter;
// Address of the WBNB to OSEAN token pair on PancakeSwap.
address public uniswapPair;
/**
* @notice constructor for creating Osean.
* @param owner_ owner of this contract
* @param initialSupply initial supply of Osean token
* @param bridge_ message bridge address
*/
constructor(
uint256 initialSupply,
address owner_,
address bridge_,
address payable _oseanWalletAddress,
address payable _marketingWalletAddress,
address payable _developerWalletAddress,
address _liquidityWalletAddress,
address payable _tobeburntWalletAddress,
address _airDropWalletAddress,
address _uniswapRouterAddress,
address executionHelper_
) ERC20("Osean", "OSEAN") AccessControl(owner_) {
bridge__ = IMessageBridge(bridge_);
executionHelper__ = ExecutionHelper(executionHelper_);
initialTimeStamp = block.timestamp;
oseanWalletAddress = _oseanWalletAddress;
marketingWalletAddress = _marketingWalletAddress;
developerWalletAddress = _developerWalletAddress;
liquidityWalletAddress = _liquidityWalletAddress;
tobeburntWalletAddress = _tobeburntWalletAddress;
airDropWalletAddress = _airDropWalletAddress;
uniswapRouterAddress = _uniswapRouterAddress;
excludedFromFees[oseanWalletAddress] = true;
excludedFromFees[marketingWalletAddress] = true;
excludedFromFees[developerWalletAddress] = true;
excludedFromFees[liquidityWalletAddress] = true;
excludedFromFees[tobeburntWalletAddress] = true;
excludedFromFees[airDropWalletAddress] = true;
_mint(marketingWalletAddress, (initialSupply) * 5 / 100);
_mint(developerWalletAddress, (initialSupply) * 10 / 100);
_mint(liquidityWalletAddress, (initialSupply) * 75 / 100);
_mint(airDropWalletAddress, (initialSupply) * 10 / 100);
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(uniswapRouterAddress);
uniswapRouter = _uniswapV2Router;
_approve(address(this), address(uniswapRouter), initialSupply);
uniswapPair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
IERC20(uniswapPair).approve(address(uniswapRouter), type(uint256).max);
}
/**
* @notice this function is used to update message bridge
* @dev it can only be updated by owner
* @dev should be carefully migrated as it can risk user funds
* @param bridge_ new bridge address
*/
function updateMessageBridge(address bridge_) external onlyOwner {
bridge__ = IMessageBridge(bridge_);
emit MessageBridgeUpdated(bridge_);
}
/**
* @notice this function is used to set bridge limits
* @dev it can only be updated by owner
* @param updates_ can be used to set mint and burn limits for all siblings in one call.
*/
function updateLimitParams(
UpdateLimitParams[] calldata updates_
) external onlyRole(LIMIT_UPDATER_ROLE) {
for (uint256 i; i < updates_.length; i++) {
if (updates_[i].isMint) {
_consumePartLimit(
0,
_receivingLimitParams[updates_[i].siblingChainSlug]
); // to keep current limit in sync
_receivingLimitParams[updates_[i].siblingChainSlug]
.maxLimit = updates_[i].maxLimit;
_receivingLimitParams[updates_[i].siblingChainSlug]
.ratePerSecond = updates_[i].ratePerSecond;
} else {
_consumePartLimit(
0,
_sendingLimitParams[updates_[i].siblingChainSlug]
); // to keep current limit in sync
_sendingLimitParams[updates_[i].siblingChainSlug]
.maxLimit = updates_[i].maxLimit;
_sendingLimitParams[updates_[i].siblingChainSlug]
.ratePerSecond = updates_[i].ratePerSecond;
}
}
emit LimitParamsUpdated(updates_);
}
/**
* @notice this function is called by users to bridge their funds to a sibling chain
* @dev it is payable to receive message bridge fees to be paid.
* @param receiver_ address receiving bridged tokens
* @param siblingChainSlug_ The unique identifier of the sibling chain.
* @param sendingAmount_ amount bridged
* @param msgGasLimit_ min gas limit needed for execution at destination
* @param payload_ payload which is executed at destination with bridged amount at receiver address.
* @param options_ additional message bridge options can be provided using this param
*/
function bridge(
address receiver_,
uint32 siblingChainSlug_,
uint256 sendingAmount_,
uint256 msgGasLimit_,
bytes calldata payload_,
bytes calldata options_
) external payable {
if (_sendingLimitParams[siblingChainSlug_].maxLimit == 0)
revert SiblingNotSupported();
if (sendingAmount_ == 0) revert ZeroAmount();
_consumeFullLimit(
sendingAmount_,
_sendingLimitParams[siblingChainSlug_]
); // reverts on limit hit
_burn(msg.sender, sendingAmount_);
bytes32 messageId = bridge__.getMessageId(siblingChainSlug_);
// important to get message id as it is used as an
// identifier for pending amount and payload caching
bytes32 returnedMessageId = bridge__.outbound{value: msg.value}(
siblingChainSlug_,
msgGasLimit_,
abi.encode(receiver_, sendingAmount_, messageId, payload_),
options_
);
if (returnedMessageId != messageId) revert MessageIdMisMatched();
emit BridgeTokens(
siblingChainSlug_,
msg.sender,
receiver_,
sendingAmount_,
messageId
);
}
/**
* @notice this function can be used to mint funds which were in pending state due to limits
* @param receiver_ address receiving bridged tokens
* @param siblingChainSlug_ The unique identifier of the sibling chain.
* @param identifier_ message identifier where message was received to mint funds
*/
function mintPendingFor(
address receiver_,
uint32 siblingChainSlug_,
bytes32 identifier_
) external nonReentrant {
if (_receivingLimitParams[siblingChainSlug_].maxLimit == 0)
revert SiblingNotSupported();
uint256 pendingMint = pendingMints[siblingChainSlug_][receiver_][
identifier_
];
(uint256 consumedAmount, uint256 pendingAmount) = _consumePartLimit(
pendingMint,
_receivingLimitParams[siblingChainSlug_]
);
pendingMints[siblingChainSlug_][receiver_][identifier_] = pendingAmount;
siblingPendingMints[siblingChainSlug_] -= consumedAmount;
_mint(receiver_, consumedAmount);
address receiver = pendingExecutions[identifier_].receiver;
if (pendingAmount == 0 && receiver != address(0)) {
if (receiver_ != receiver) revert InvalidReceiver();
uint32 siblingChainSlug = pendingExecutions[identifier_]
.siblingChainSlug;
if (siblingChainSlug != siblingChainSlug_)
revert InvalidSiblingChainSlug();
// execute
pendingExecutions[identifier_].isAmountPending = false;
bool success = executionHelper__.execute(
receiver_,
pendingExecutions[identifier_].payload
);
if (success) _clearPayload(identifier_);
}
emit PendingTokensBridged(
siblingChainSlug_,
receiver_,
consumedAmount,
pendingAmount,
identifier_
);
}
/**
* @notice this function receives the message from message bridge
* @dev Only bridge can call this function.
* @param siblingChainSlug_ The unique identifier of the sibling chain.
* @param payload_ payload which is decoded to get `receiver`, `amount to mint`, `message id` and `payload` to execute after token transfer.
*/
function inbound(
uint32 siblingChainSlug_,
bytes memory payload_
) external payable override nonReentrant {
if (msg.sender != address(bridge__)) revert NotMessageBridge();
if (_receivingLimitParams[siblingChainSlug_].maxLimit == 0)
revert SiblingNotSupported();
(
address receiver,
uint256 mintAmount,
bytes32 identifier,
bytes memory execPayload
) = abi.decode(payload_, (address, uint256, bytes32, bytes));
(uint256 consumedAmount, uint256 pendingAmount) = _consumePartLimit(
mintAmount,
_receivingLimitParams[siblingChainSlug_]
);
if (receiver == address(this) || receiver == address(bridge__))
revert CannotExecuteOnBridgeContracts();
_mint(receiver, consumedAmount);
if (pendingAmount > 0) {
pendingMints[siblingChainSlug_][receiver][
identifier
] = pendingAmount;
siblingPendingMints[siblingChainSlug_] += pendingAmount;
// if pending amount is more than 0, payload is cached
if (execPayload.length > 0)
_cachePayload(
identifier,
true,
siblingChainSlug_,
receiver,
execPayload
);
emit TokensPending(
siblingChainSlug_,
receiver,
pendingAmount,
pendingMints[siblingChainSlug_][receiver][identifier],
identifier
);
} else if (execPayload.length > 0) {
// execute
bool success = executionHelper__.execute(receiver, execPayload);
if (!success)
_cachePayload(
identifier,
false,
siblingChainSlug_,
receiver,
execPayload
);
}
emit TokensBridged(
siblingChainSlug_,
receiver,
consumedAmount,
mintAmount,
identifier
);
}
function getCurrentReceivingLimit(
uint32 siblingChainSlug_
) external view returns (uint256) {
return _getCurrentLimit(_receivingLimitParams[siblingChainSlug_]);
}
function getCurrentSendingLimit(
uint32 siblingChainSlug_
) external view returns (uint256) {
return _getCurrentLimit(_sendingLimitParams[siblingChainSlug_]);
}
function getReceivingLimitParams(
uint32 siblingChainSlug_
) external view returns (LimitParams memory) {
return _receivingLimitParams[siblingChainSlug_];
}
function getSendingLimitParams(
uint32 siblingChainSlug_
) external view returns (LimitParams memory) {
return _sendingLimitParams[siblingChainSlug_];
}
/**
* @notice Rescues funds from the contract if they are locked by mistake.
* @param token_ The address of the token contract.
* @param rescueTo_ The address where rescued tokens need to be sent.
* @param amount_ The amount of tokens to be rescued.
*/
function rescueFunds(
address token_,
address rescueTo_,
uint256 amount_
) external onlyRole(RESCUE_ROLE) {
RescueFundsLib.rescueFunds(token_, rescueTo_, amount_);
}
/**
* Returns the contract address
* Return contract address
*/
function getContractAddress() public view returns (address){
return address(this);
}
/**
* @dev Adds a user to be excluded from fees.
* @param user address of the user to be excluded from fees.
*/
function excludeUserFromFees(address user) public onlyOwner {
excludedFromFees[user] = true;
}
/**
* @dev Gets the current timestamp, used for testing + verification
* @return the the timestamp of the current block
*/
function getCurrentTimestamp() public view returns (uint256) {
return block.timestamp;
}
/**
* @dev Removes a user from the fee exclusion.
* @param user address of the user than will now have to pay transaction fees.
*/
function includeUsersInFees(address user) public onlyOwner {
excludedFromFees[user] = false;
}
// Internal Transfer function override to collect taxes only on Swap.
function _transfer(address sender, address recipient, uint256 amount) internal virtual override {
// Check in exchanges between wallets for 1% of total supply
if (sender != uniswapPair && recipient != uniswapPair && !excludedFromFees[sender] && !excludedFromFees[recipient]) {
require((balanceOf(recipient) + amount) < (totalSupply() / 75), "You can't have more than 1% of the total supply.");
}
//when to collect taxes
if((sender == uniswapPair || recipient == uniswapPair) && !excludedFromFees[sender] && !excludedFromFees[recipient]) {
//Investor cannot have more than 1% of total supply
if(sender == uniswapPair && !excludedFromFees[sender] && !excludedFromFees[recipient]) {
require((balanceOf(recipient) + amount) < (totalSupply() / 75), "You can't have more than 1% of the total supply.");
}
// Yacht transaction fee.
uint256 yachtFee = (amount * yachtTransactionFeePercent) / 100;
// Marketing team transaction fee.
uint256 marketingFee = (amount * marketingFeePercent) / 100;
// Developer team transaction fee.
uint256 developerFee = (amount * developerFeePercent) / 100;
// Burn fee
uint256 burnFee = (amount * burnFeePercent) / 100;
// The total fee to send to the contract address.
uint256 totalFee = yachtFee + marketingFee + developerFee + burnFee;
// Sends the transaction fees to the contract address
super._transfer(sender, address(this), totalFee);
// Prepares amount afterfees
amount -= totalFee;
}
super._transfer(sender, recipient, amount);
}
/**
* @dev Swaps OSEAN tokens from transaction fees to ETH.
* @param amount the amount of OSEAN tokens to swap
*/
function swapOSEANForETH(uint256 amount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapRouter.WETH();
_approve(address(this), address(uniswapRouter), amount);
uniswapRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
amount,
0,
path,
address(this),
block.timestamp
);
}
/**
* @dev Sends ETH to transaction fee wallets after OSEAN swaps.
* @param amount the amount to be transfered
*/
function sendFeesToWallets(uint256 amount) private {
uint256 totalFee = yachtTransactionFeePercent + marketingFeePercent + developerFeePercent + burnFeePercent;
oseanWalletAddress.transfer((amount * yachtTransactionFeePercent) / totalFee);
marketingWalletAddress.transfer((amount * marketingFeePercent) / totalFee);
developerWalletAddress.transfer((amount * developerFeePercent) / totalFee);
tobeburntWalletAddress.transfer((amount * burnFeePercent) / totalFee);
}
/**
* @dev Swaps OSEAN to ETH.
*/
function swapFeesManually() public onlyOwner {
uint256 contractOSEANBalance = balanceOf(address(this));
if (contractOSEANBalance > 0) {
swapOSEANForETH(contractOSEANBalance);
}
}
/**
* @dev Sends ETH to Wallets
*/
function disperseFeesManually() public onlyOwner {
uint256 contractETHBalance = address(this).balance;
sendFeesToWallets(contractETHBalance);
}
receive() external payable {}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./Ownable.sol";
/**
* @title AccessControl
* @dev This abstract contract implements access control mechanism based on roles.
* Each role can have one or more addresses associated with it, which are granted
* permission to execute functions with the onlyRole modifier.
*/
abstract contract AccessControl is Ownable {
/**
* @dev A mapping of roles to a mapping of addresses to boolean values indicating whether or not they have the role.
*/
mapping(bytes32 => mapping(address => bool)) private _permits;
/**
* @dev Emitted when a role is granted to an address.
*/
event RoleGranted(bytes32 indexed role, address indexed grantee);
/**
* @dev Emitted when a role is revoked from an address.
*/
event RoleRevoked(bytes32 indexed role, address indexed revokee);
/**
* @dev Error message thrown when an address does not have permission to execute a function with onlyRole modifier.
*/
error NoPermit(bytes32 role);
/**
* @dev Constructor that sets the owner of the contract.
*/
constructor(address owner_) Ownable(owner_) {}
/**
* @dev Modifier that restricts access to addresses having roles
* Throws an error if the caller do not have permit
*/
modifier onlyRole(bytes32 role) {
if (!_permits[role][msg.sender]) revert NoPermit(role);
_;
}
/**
* @dev Checks and reverts if an address do not have a specific role.
* @param role_ The role to check.
* @param address_ The address to check.
*/
function _checkRole(bytes32 role_, address address_) internal virtual {
if (!_hasRole(role_, address_)) revert NoPermit(role_);
}
/**
* @dev Grants a role to a given address.
* @param role_ The role to grant.
* @param grantee_ The address to grant the role to.
* Emits a RoleGranted event.
* Can only be called by the owner of the contract.
*/
function grantRole(
bytes32 role_,
address grantee_
) external virtual onlyOwner {
_grantRole(role_, grantee_);
}
/**
* @dev Revokes a role from a given address.
* @param role_ The role to revoke.
* @param revokee_ The address to revoke the role from.
* Emits a RoleRevoked event.
* Can only be called by the owner of the contract.
*/
function revokeRole(
bytes32 role_,
address revokee_
) external virtual onlyOwner {
_revokeRole(role_, revokee_);
}
/**
* @dev Internal function to grant a role to a given address.
* @param role_ The role to grant.
* @param grantee_ The address to grant the role to.
* Emits a RoleGranted event.
*/
function _grantRole(bytes32 role_, address grantee_) internal {
_permits[role_][grantee_] = true;
emit RoleGranted(role_, grantee_);
}
/**
* @dev Internal function to revoke a role from a given address.
* @param role_ The role to revoke.
* @param revokee_ The address to revoke the role from.
* Emits a RoleRevoked event.
*/
function _revokeRole(bytes32 role_, address revokee_) internal {
_permits[role_][revokee_] = false;
emit RoleRevoked(role_, revokee_);
}
/**
* @dev Checks whether an address has a specific role.
* @param role_ The role to check.
* @param address_ The address to check.
* @return A boolean value indicating whether or not the address has the role.
*/
function hasRole(
bytes32 role_,
address address_
) external view returns (bool) {
return _hasRole(role_, address_);
}
function _hasRole(
bytes32 role_,
address address_
) internal view returns (bool) {
return _permits[role_][address_];
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
abstract contract Gauge {
struct LimitParams {
uint256 lastUpdateTimestamp;
uint256 ratePerSecond;
uint256 maxLimit;
uint256 lastUpdateLimit;
}
error AmountOutsideLimit();
function _getCurrentLimit(
LimitParams storage _params
) internal view returns (uint256 _limit) {
uint256 timeElapsed = block.timestamp - _params.lastUpdateTimestamp;
uint256 limitIncrease = timeElapsed * _params.ratePerSecond;
if (limitIncrease + _params.lastUpdateLimit > _params.maxLimit) {
_limit = _params.maxLimit;
} else {
_limit = limitIncrease + _params.lastUpdateLimit;
}
}
function _consumePartLimit(
uint256 amount_,
LimitParams storage _params
) internal returns (uint256 consumedAmount, uint256 pendingAmount) {
uint256 currentLimit = _getCurrentLimit(_params);
_params.lastUpdateTimestamp = block.timestamp;
if (currentLimit >= amount_) {
_params.lastUpdateLimit = currentLimit - amount_;
consumedAmount = amount_;
pendingAmount = 0;
} else {
_params.lastUpdateLimit = 0;
consumedAmount = currentLimit;
pendingAmount = amount_ - currentLimit;
}
}
function _consumeFullLimit(
uint256 amount_,
LimitParams storage _params
) internal {
uint256 currentLimit = _getCurrentLimit(_params);
if (currentLimit >= amount_) {
_params.lastUpdateTimestamp = block.timestamp;
_params.lastUpdateLimit = currentLimit - amount_;
} else {
revert AmountOutsideLimit();
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title Ownable
* @dev The Ownable contract provides a simple way to manage ownership of a contract
* and allows for ownership to be transferred to a nominated address.
*/
abstract contract Ownable {
address private _owner;
address private _nominee;
event OwnerNominated(address indexed nominee);
event OwnerClaimed(address indexed claimer);
error OnlyOwner();
error OnlyNominee();
/**
* @dev Sets the contract's owner to the address that is passed to the constructor.
*/
constructor(address owner_) {
_claimOwner(owner_);
}
/**
* @dev Modifier that restricts access to only the contract's owner.
* Throws an error if the caller is not the owner.
*/
modifier onlyOwner() {
if (msg.sender != _owner) revert OnlyOwner();
_;
}
/**
* @dev Returns the current owner of the contract.
*/
function owner() external view returns (address) {
return _owner;
}
/**
* @dev Returns the current nominee for ownership of the contract.
*/
function nominee() external view returns (address) {
return _nominee;
}
/**
* @dev Allows the current owner to nominate a new owner for the contract.
* Throws an error if the caller is not the owner.
* Emits an `OwnerNominated` event with the address of the nominee.
*/
function nominateOwner(address nominee_) external {
if (msg.sender != _owner) revert OnlyOwner();
_nominee = nominee_;
emit OwnerNominated(_nominee);
}
/**
* @dev Allows the nominated owner to claim ownership of the contract.
* Throws an error if the caller is not the nominee.
* Sets the nominated owner as the new owner of the contract.
* Emits an `OwnerClaimed` event with the address of the new owner.
*/
function claimOwner() external {
if (msg.sender != _nominee) revert OnlyNominee();
_claimOwner(msg.sender);
}
/**
* @dev Internal function that sets the owner of the contract to the specified address
* and sets the nominee to address(0).
*/
function _claimOwner(address claimer_) internal {
_owner = claimer_;
_nominee = address(0);
emit OwnerClaimed(claimer_);
}
}
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
}
interface IUniswapV2Pair {
function sync() external;
}
interface IUniswapV2Router01 {
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidity(
address tokenA,
address tokenB,
uint256 amountADesired,
uint256 amountBDesired,
uint256 amountAMin,
uint256 amountBMin,
address to,
uint256 deadline
)
external
returns (
uint256 amountA,
uint256 amountB,
uint256 liquidity
);
function addLiquidityETH(
address token,
uint256 amountTokenDesired,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
)
external
payable
returns (
uint256 amountToken,
uint256 amountETH,
uint256 liquidity
);
}
interface IUniswapV2Router02 is IUniswapV2Router01 {
function removeLiquidityETHSupportingFeeOnTransferTokens(
address token,
uint256 liquidity,
uint256 amountTokenMin,
uint256 amountETHMin,
address to,
uint256 deadline
) external returns (uint256 amountETH);
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactTokensForTokensSupportingFeeOnTransferTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable;
function swapExactETHForTokens(
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external payable;
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library ExcessivelySafeCall {
uint constant LOW_28_MASK =
0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
/// @notice Use when you _really_ really _really_ don't trust the called
/// contract. This prevents the called contract from causing reversion of
/// the caller in as many ways as we can.
/// @dev The main difference between this and a solidity low-level call is
/// that we limit the number of bytes that the callee can cause to be
/// copied to caller memory. This prevents stupid things like malicious
/// contracts returning 10,000,000 bytes causing a local OOG when copying
/// to memory.
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
/// @return success and returndata, as `.call()`. Returndata is capped to
/// `_maxCopy` bytes.
function excessivelySafeCall(
address _target,
uint _gas,
uint16 _maxCopy,
bytes memory _calldata
) internal returns (bool, bytes memory) {
// set up for assembly call
uint _toCopy;
bool _success;
bytes memory _returnData = new bytes(_maxCopy);
// dispatch message to recipient
// by assembly calling "handle" function
// we call via assembly to avoid memcopying a very large returndata
// returned by a malicious contract
assembly {
_success := call(
_gas, // gas
_target, // recipient
0, // ether value
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
0 // outlen
)
// limit our copy to 256 bytes
_toCopy := returndatasize()
if gt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytes
mstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]
returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
/// @notice Use when you _really_ really _really_ don't trust the called
/// contract. This prevents the called contract from causing reversion of
/// the caller in as many ways as we can.
/// @dev The main difference between this and a solidity low-level call is
/// that we limit the number of bytes that the callee can cause to be
/// copied to caller memory. This prevents stupid things like malicious
/// contracts returning 10,000,000 bytes causing a local OOG when copying
/// to memory.
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
/// @return success and returndata, as `.call()`. Returndata is capped to
/// `_maxCopy` bytes.
function excessivelySafeStaticCall(
address _target,
uint _gas,
uint16 _maxCopy,
bytes memory _calldata
) internal view returns (bool, bytes memory) {
// set up for assembly call
uint _toCopy;
bool _success;
bytes memory _returnData = new bytes(_maxCopy);
// dispatch message to recipient
// by assembly calling "handle" function
// we call via assembly to avoid memcopying a very large returndata
// returned by a malicious contract
assembly {
_success := staticcall(
_gas, // gas
_target, // recipient
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
0 // outlen
)
// limit our copy to 256 bytes
_toCopy := returndatasize()
if gt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytes
mstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]
returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
/**
* @notice Swaps function selectors in encoded contract calls
* @dev Allows reuse of encoded calldata for functions with identical
* argument types but different names. It simply swaps out the first 4 bytes
* for the new selector. This function modifies memory in place, and should
* only be used with caution.
* @param _newSelector The new 4-byte selector
* @param _buf The encoded contract args
*/
function swapSelector(
bytes4 _newSelector,
bytes memory _buf
) internal pure {
require(_buf.length >= 4);
uint _mask = LOW_28_MASK;
assembly {
// load the first word of
let _word := mload(add(_buf, 0x20))
// mask out the top 4 bytes
// /x
_word := and(_word, _mask)
_word := or(_newSelector, _word)
mstore(add(_buf, 0x20), _word)
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "solmate/src/utils/SafeTransferLib.sol";
error ZeroAddress();
/**
* @title RescueFundsLib
* @dev A library that provides a function to rescue funds from a contract.
*/
library RescueFundsLib {
/**
* @dev The address used to identify ETH.
*/
address public constant ETH_ADDRESS =
address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
/**
* @dev thrown when the given token address don't have any code
*/
error InvalidTokenAddress();
/**
* @dev Rescues funds from a contract.
* @param token_ The address of the token contract.
* @param rescueTo_ The address of the user.
* @param amount_ The amount of tokens to be rescued.
*/
function rescueFunds(
address token_,
address rescueTo_,
uint256 amount_
) internal {
if (rescueTo_ == address(0)) revert ZeroAddress();
if (token_ == ETH_ADDRESS) {
SafeTransferLib.safeTransferETH(rescueTo_, amount_);
} else {
if (token_.code.length == 0) revert InvalidTokenAddress();
SafeTransferLib.safeTransfer(ERC20(token_), rescueTo_, amount_);
}
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "solmate/src/utils/ReentrancyGuard.sol";
import {RescueFundsLib} from "../libraries/RescueFundsLib.sol";
import {Gauge} from "../common/Gauge.sol";
import {AccessControl} from "../common/AccessControl.sol";
import "./ISuperTokenOrVault.sol";
import "./IMessageBridge.sol";
import "./ExecutionHelper.sol";
/**
* @title Base contract for super token and vault
* @notice It contains relevant execution payload storages.
* @dev This contract implements Socket's IPlug to enable message bridging and IMessageBridge
* to support any type of message bridge.
*/
abstract contract Base is
ReentrancyGuard,
Gauge,
ISuperTokenOrVault,
AccessControl
{
/**
* @notice this struct stores relevant details for a pending payload execution
* @param receiver address of receiver where payload executes.
* @param payload payload to be executed
* @param isAmountPending if amount to be bridged is pending
*/
struct PendingExecutionDetails {
bool isAmountPending;
uint32 siblingChainSlug;
address receiver;
bytes payload;
}
ExecutionHelper public executionHelper__;
// messageId => PendingExecutionDetails
mapping(bytes32 => PendingExecutionDetails) public pendingExecutions;
////////////////////////////////////////////////////////
////////////////////// ERRORS //////////////////////////
////////////////////////////////////////////////////////
error InvalidExecutionRetry();
error PendingAmount();
error CannotExecuteOnBridgeContracts();
// emitted when a execution helper is updated
event ExecutionHelperUpdated(address executionHelper);
/**
* @notice this function is used to update execution helper contract
* @dev it can only be updated by owner
* @param executionHelper_ new execution helper address
*/
function updateExecutionHelper(
address executionHelper_
) external onlyOwner {
executionHelper__ = ExecutionHelper(executionHelper_);
emit ExecutionHelperUpdated(executionHelper_);
}
/**
* @notice this function can be used to retry a payload execution if it was not successful.
* @param msgId_ The unique identifier of the bridging message.
*/
function retryPayloadExecution(bytes32 msgId_) external nonReentrant {
PendingExecutionDetails storage details = pendingExecutions[msgId_];
if (details.isAmountPending) revert PendingAmount();
if (details.receiver == address(0)) revert InvalidExecutionRetry();
bool success = executionHelper__.execute(
details.receiver,
details.payload
);
if (success) _clearPayload(msgId_);
}
/**
* @notice this function caches the execution payload details if the amount to be bridged
* is not pending or execution is reverting
*/
function _cachePayload(
bytes32 msgId_,
bool isAmountPending_,
uint32 siblingChainSlug_,
address receiver_,
bytes memory payload_
) internal {
pendingExecutions[msgId_].receiver = receiver_;
pendingExecutions[msgId_].payload = payload_;
pendingExecutions[msgId_].siblingChainSlug = siblingChainSlug_;
pendingExecutions[msgId_].isAmountPending = isAmountPending_;
}
/**
* @notice this function clears the payload details once execution succeeds
*/
function _clearPayload(bytes32 msgId_) internal {
pendingExecutions[msgId_].receiver = address(0);
pendingExecutions[msgId_].payload = bytes("");
pendingExecutions[msgId_].siblingChainSlug = 0;
pendingExecutions[msgId_].isAmountPending = false;
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../libraries/ExcessivelySafeCall.sol";
/**
* @title ExecutionHelper
* @notice It is an untrusted contract used for payload execution by Super token and Vault.
*/
contract ExecutionHelper {
using ExcessivelySafeCall for address;
uint16 private constant MAX_COPY_BYTES = 0;
/**
* @notice this function is used to execute a payload at target_
* @dev receiver address cannot be this contract address.
* @param target_ address of target.
* @param payload_ payload to be executed at target.
*/
function execute(
address target_,
bytes memory payload_
) external returns (bool success) {
if (target_ == address(this)) return false;
(success, ) = target_.excessivelySafeCall(
gasleft(),
MAX_COPY_BYTES,
payload_
);
}
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IMessageBridge
* @notice It should be implemented by message bridge integrated to Super token and Vault.
*/
interface IMessageBridge {
/**
* @notice calls socket's outbound function which transmits msg to `siblingChainSlug_`.
* @dev Only super token or vault can call this contract
* @param siblingChainSlug_ The unique identifier of the sibling chain.
* @param msgGasLimit_ min gas limit needed to execute the message on sibling
* @param payload_ payload which should be executed at the sibling chain.
* @param options_ extra bytes memory can be used by other protocol plugs for additional options
*/
function outbound(
uint32 siblingChainSlug_,
uint256 msgGasLimit_,
bytes memory payload_,
bytes memory options_
) external payable returns (bytes32 messageId_);
/**
* @notice this function is used to calculate message id before sending outbound().
* @param siblingChainSlug_ The unique identifier of the sibling chain.
* @return message id
*/
function getMessageId(
uint32 siblingChainSlug_
) external view returns (bytes32);
}
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title ISuperTokenOrVault
* @notice It should be implemented Super token and Vault for plugs to communicate.
*/
interface ISuperTokenOrVault {
/**
* @dev this should be only executable by socket.
* @notice executes the message received from source chain.
* @notice It is expected to have original sender checks in the destination plugs using payload.
* @param siblingChainSlug_ chain slug of source.
* @param payload_ the data which is needed to decode receiver, amount, msgId and payload.
*/
function inbound(
uint32 siblingChainSlug_,
bytes memory payload_
) external payable;
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
uint256 private locked = 1;
modifier nonReentrant() virtual {
require(locked == 1, "REENTRANCY");
locked = 2;
_;
locked = 1;
}
}
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}