// 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
// OpenZeppelin Contracts (last updated v4.8.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.openzeppelin.com/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;
// 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);
}
/**
* @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.5.0) (token/ERC20/extensions/ERC20Burnable.sol)
pragma solidity ^0.8.0;
import "../ERC20.sol";
import "../../../utils/Context.sol";
/**
* @dev Extension of {ERC20} that allows token holders to destroy both their own
* tokens and those that they have an allowance for, in a way that can be
* recognized off-chain (via event analysis).
*/
abstract contract ERC20Burnable is Context, ERC20 {
/**
* @dev Destroys `amount` tokens from the caller.
*
* See {ERC20-_burn}.
*/
function burn(uint256 amount) public virtual {
_burn(_msgSender(), amount);
}
/**
* @dev Destroys `amount` tokens from `account`, deducting from the caller's
* allowance.
*
* See {ERC20-_burn} and {ERC20-allowance}.
*
* Requirements:
*
* - the caller must have allowance for ``accounts``'s tokens of at least
* `amount`.
*/
function burnFrom(address account, uint256 amount) public virtual {
_spendAllowance(account, _msgSender(), amount);
_burn(account, amount);
}
}
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.10;
/**
* @title library for Errors mapping
* @author Souq.Finance
* @notice Defines the output of error messages reverted by the contracts of the Souq protocol
* @notice License: https://souq-nft-amm-v1.s3.amazonaws.com/LICENSE.md
*/
library Errors {
string public constant ADDRESS_IS_ZERO = "ADDRESS_IS_ZERO";
string public constant NOT_ENOUGH_USER_BALANCE = "NOT_ENOUGH_USER_BALANCE";
string public constant NOT_ENOUGH_APPROVED = "NOT_ENOUGH_APPROVED";
string public constant INVALID_AMOUNT = "INVALID_AMOUNT";
string public constant AMM_PAUSED = "AMM_PAUSED";
string public constant VAULT_PAUSED = "VAULT_PAUSED";
string public constant FLASHLOAN_DISABLED = "FLASHLOAN_DISABLED";
string public constant ADDRESSES_REGISTRY_NOT_SET = "ADDRESSES_REGISTRY_NOT_SET";
string public constant UPGRADEABILITY_DISABLED = "UPGRADEABILITY_DISABLED";
string public constant CALLER_NOT_UPGRADER = "CALLER_NOT_UPGRADER";
string public constant CALLER_NOT_POOL_ADMIN = "CALLER_NOT_POOL_ADMIN";
string public constant CALLER_NOT_ACCESS_ADMIN = "CALLER_NOT_ACCESS_ADMIN";
string public constant CALLER_NOT_POOL_ADMIN_OR_OPERATIONS = "CALLER_NOT_POOL_ADMIN_OR_OPERATIONS";
string public constant CALLER_NOT_ORACLE_ADMIN = "CALLER_NOT_ORACLE_ADMIN";
string public constant CALLER_NOT_TIMELOCK="CALLER_NOT_TIMELOCK";
string public constant CALLER_NOT_TIMELOCK_ADMIN="CALLER_NOT_TIMELOCK_ADMIN";
string public constant ADDRESS_IS_PROXY = "ADDRESS_IS_PROXY";
string public constant ARRAY_NOT_SAME_LENGTH = "ARRAY_NOT_SAME_LENGTH";
string public constant NO_SUB_POOL_AVAILABLE = "NO_SUB_POOL_AVAILABLE";
string public constant LIQUIDITY_MODE_RESTRICTED = "LIQUIDITY_MODE_RESTRICTED";
string public constant TVL_LIMIT_REACHED = "TVL_LIMIT_REACHED";
string public constant CALLER_MUST_BE_POOL = "CALLER_MUST_BE_POOL";
string public constant CANNOT_RESCUE_POOL_TOKEN = "CANNOT_RESCUE_POOL_TOKEN";
string public constant CALLER_MUST_BE_STABLEYIELD_ADMIN = "CALLER_MUST_BE_STABLEYIELD_ADMIN";
string public constant CALLER_MUST_BE_STABLEYIELD_LENDER = "CALLER_MUST_BE_STABLEYIELD_LENDER";
string public constant FUNCTION_REQUIRES_ACCESS_NFT = "FUNCTION_REQUIRES_ACCESS_NFT";
string public constant FEE_OUT_OF_BOUNDS = "FEE_OUT_OF_BOUNDS";
string public constant ONLY_ADMIN_CAN_ADD_LIQUIDITY = "ONLY_ADMIN_CAN_ADD_LIQUIDITY";
string public constant NOT_ENOUGH_POOL_RESERVE = "NOT_ENOUGH_POOL_RESERVE";
string public constant NOT_ENOUGH_SUBPOOL_RESERVE = "NOT_ENOUGH_SUBPOOL_RESERVE";
string public constant NOT_ENOUGH_SUBPOOL_SHARES = "NOT_ENOUGH_SUBPOOL_SHARES";
string public constant SUBPOOL_DISABLED = "SUBPOOL_DISABLED";
string public constant ADDRESS_NOT_CONNECTOR_ADMIN = "ADDRESS_NOT_CONNECTOR_ADMIN";
string public constant WITHDRAW_LIMIT_REACHED = "WITHDRAW_LIMIT_REACHED";
string public constant DEPOSIT_LIMIT_REACHED = "DEPOSIT_LIMIT_REACHED";
string public constant SHARES_VALUE_EXCEEDS_TARGET = "SHARES_VALUE_EXCEEDS_TARGET";
string public constant SHARES_VALUE_BELOW_TARGET = "SHARES_VALUE_BELOW_TARGET";
string public constant SHARES_TARGET_EXCEEDS_RESERVE = "SHARES_TARGET_EXCEEDS_RESERVE";
string public constant SWAPPING_SHARES_TEMPORARY_DISABLED_DUE_TO_LOW_CONDITIONS =
"SWAPPING_SHARES_TEMPORARY_DISABLED_DUE_TO_LOW_CONDITIONS";
string public constant ADDING_SHARES_TEMPORARY_DISABLED_DUE_TO_LOW_CONDITIONS =
"ADDING_SHARES_TEMPORARY_DISABLED_DUE_TO_LOW_CONDITIONS";
string public constant UPGRADE_DISABLED = "UPGRADE_DISABLED";
string public constant USER_CANNOT_BE_CONTRACT = "USER_CANNOT_BE_CONTRACT";
string public constant DEADLINE_NOT_FOUND = "DEADLINE_NOT_FOUND";
string public constant FLASHLOAN_PROTECTION_ENABLED = "FLASHLOAN_PROTECTION_ENABLED";
string public constant INVALID_POOL_ADDRESS = "INVALID_POOL_ADDRESS";
string public constant INVALID_SUBPOOL_ID = "INVALID_SUBPOOL_ID";
string public constant INVALID_YIELD_DISTRIBUTOR_ADDRESS="INVALID_YIELD_DISTRIBUTOR_ADDRESS";
string public constant YIELD_DISTRIBUTOR_NOT_FOUND="YIELD_DISTRIBUTOR_NOT_FOUND";
string public constant INVALID_TOKEN_ID="INVALID_TOKEN_ID";
string public constant INVALID_VAULT_ADDRESS = "INVALID_VAULT_ADDRESS";
string public constant VAULT_NOT_FOUND="VAULT_NOT_FOUND";
string public constant INVALID_TOKEN_ADDRESS="INVALID_TOKEN_ADDRESS";
string public constant INVALID_STAKING_CONTRACT="INVALID_STAKING_CONTRACT";
string public constant STAKING_CONTRACT_NOT_FOUND="STAKING_CONTRACT_NOT_FOUND";
string public constant INVALID_SWAP_CONTRACT="INVALID_SWAP_CONTRACT";
string public constant SWAP_CONTRACT_NOT_FOUND="SWAP_CONTRACT_NOT_FOUND";
string public constant INVALID_ORACLE_CONNECTOR="INVALID_ORACLE_CONNECTOR";
string public constant ORACLE_CONNECTOR_NOT_FOUND="ORACLE_CONNECTOR_NOT_FOUND";
string public constant INVALID_COLLECTION_CONTRACT="INVALID_COLLECTION_CONTRACT";
string public constant COLLECTION_CONTRACT_NOT_FOUND="COLLECTION_CONTRACT_NOT_FOUND";
string public constant INVALID_STABLECOIN_YIELD_CONNECTOR="INVALID_STABLECOIN_YIELD_CONNECTOR";
string public constant STABLECOIN_YIELD_CONNECTOR_NOT_FOUND="STABLECOIN_YIELD_CONNECTOR_NOT_FOUND";
string public constant TIMELOCK_USES_ACCESS_CONTROL="TIMELOCK_USES_ACCESS_CONTROL";
}
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.10;
/**
* @title IAddressesRegistry
* @author Souq.Finance
* @notice Defines the interface of the addresses registry.
* @notice License: https://souq-nft-amm-v1.s3.amazonaws.com/LICENSE.md
*/
interface IAddressesRegistry {
/**
* @dev Emitted when the connectors router address is updated.
* @param oldAddress The old address
* @param newAddress The new address
*/
event RouterUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the Access manager address is updated.
* @param oldAddress The old address
* @param newAddress The new address
*/
event AccessManagerUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the access admin address is updated.
* @param oldAddress The old address
* @param newAddress The new address
*/
event AccessAdminUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when the collection connector address is updated.
* @param oldAddress the old address
* @param newAddress the new address
*/
event CollectionConnectorUpdated(address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when a specific pool factory address is updated.
* @param id The short id of the pool factory.
* @param oldAddress The old address
* @param newAddress The new address
*/
event PoolFactoryUpdated(bytes32 id, address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when a specific pool factory address is added.
* @param id The short id of the pool factory.
* @param newAddress The new address
*/
event PoolFactoryAdded(bytes32 id, address indexed newAddress);
/**
* @dev Emitted when a specific vault factory address is updated.
* @param id The short id of the vault factory.
* @param oldAddress The old address
* @param newAddress The new address
*/
event VaultFactoryUpdated(bytes32 id, address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when a specific vault factory address is added.
* @param id The short id of the vault factory.
* @param newAddress The new address
*/
event VaultFactoryAdded(bytes32 id, address indexed newAddress);
/**
* @dev Emitted when a any address is updated.
* @param id The full id of the address.
* @param oldAddress The old address
* @param newAddress The new address
*/
event AddressUpdated(bytes32 id, address indexed oldAddress, address indexed newAddress);
/**
* @dev Emitted when a proxy is deployed for an implementation
* @param id The full id of the address to be saved
* @param logic The address of the implementation
* @param proxy The address of the proxy deployed in that id slot
*/
event ProxyDeployed(bytes32 id, address indexed logic, address indexed proxy);
/**
* @dev Emitted when a proxy is deployed for an implementation
* @param id The full id of the address to be upgraded
* @param newLogic The address of the new implementation
* @param proxy The address of the proxy that was upgraded
*/
event ProxyUpgraded(bytes32 id, address indexed newLogic, address indexed proxy);
/**
* @notice Returns the address of the identifier.
* @param _id The id of the contract
* @return The Pool proxy address
*/
function getAddress(bytes32 _id) external view returns (address);
/**
* @notice Sets the address of the identifier.
* @param _id The id of the contract
* @param _add The address to set
*/
function setAddress(bytes32 _id, address _add) external;
/**
* @notice Returns the address of the connectors router defined as: CONNECTORS_ROUTER
* @return The address
*/
function getConnectorsRouter() external view returns (address);
/**
* @notice Sets the address of the Connectors router.
* @param _add The address to set
*/
function setConnectorsRouter(address _add) external;
/**
* @notice Returns the address of access manager defined as: ACCESS_MANAGER
* @return The address
*/
function getAccessManager() external view returns (address);
/**
* @notice Sets the address of the Access Manager.
* @param _add The address to set
*/
function setAccessManager(address _add) external;
/**
* @notice Returns the address of access admin defined as: ACCESS_ADMIN
* @return The address
*/
function getAccessAdmin() external view returns (address);
/**
* @notice Sets the address of the Access Admin.
* @param _add The address to set
*/
function setAccessAdmin(address _add) external;
/**
* @notice Returns the address of the specific pool factory short id
* @param _id The pool factory id such as "SVS"
* @return The address
*/
function getPoolFactoryAddress(bytes32 _id) external view returns (address);
/**
* @notice Returns the full id of pool factory short id
* @param _id The pool factory id such as "SVS"
* @return The full id
*/
function getIdFromPoolFactory(bytes32 _id) external view returns (bytes32);
/**
* @notice Sets the address of a specific pool factory using short id.
* @param _id the pool factory short id
* @param _add The address to set
*/
function setPoolFactory(bytes32 _id, address _add) external;
/**
* @notice adds a new pool factory with address and short id. The short id will be converted to full id and saved.
* @param _id the pool factory short id
* @param _add The address to add
*/
function addPoolFactory(bytes32 _id, address _add) external;
/**
* @notice Returns the address of the specific vault factory short id
* @param _id The vault id such as "SVS"
* @return The address
*/
function getVaultFactoryAddress(bytes32 _id) external view returns (address);
/**
* @notice Returns the full id of vault factory id
* @param _id The vault factory id such as "SVS"
* @return The full id
*/
function getIdFromVaultFactory(bytes32 _id) external view returns (bytes32);
/**
* @notice Sets the address of a specific vault factory using short id.
* @param _id the vault factory short id
* @param _add The address to set
*/
function setVaultFactory(bytes32 _id, address _add) external;
/**
* @notice adds a new vault factory with address and short id. The short id will be converted to full id and saved.
* @param _id the vault factory short id
* @param _add The address to add
*/
function addVaultFactory(bytes32 _id, address _add) external;
/**
* @notice Deploys a proxy for an implimentation and initializes then saves in the registry.
* @param _id the full id to be saved.
* @param _logic The address of the implementation
* @param _data The initialization low data
*/
function updateImplementation(bytes32 _id, address _logic, bytes memory _data) external;
/**
* @notice Updates a proxy with a new implementation logic while keeping the store intact.
* @param _id the full id to be saved.
* @param _logic The address of the new implementation
*/
function updateProxy(bytes32 _id, address _logic) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC1155 compliant contract, as defined in the
* https://eips.ethereum.org/EIPS/eip-1155[EIP].
*
* _Available since v3.1._
*/
interface IERC1155 is IERC165 {
/**
* @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.
*/
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
/**
* @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
* transfers.
*/
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
/**
* @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
* `approved`.
*/
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
/**
* @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
*
* If an {URI} event was emitted for `id`, the standard
* https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
* returned by {IERC1155MetadataURI-uri}.
*/
event URI(string value, uint256 indexed id);
/**
* @dev Returns the amount of tokens of token type `id` owned by `account`.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function balanceOf(address account, uint256 id) external view returns (uint256);
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
*
* Requirements:
*
* - `accounts` and `ids` must have the same length.
*/
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
/**
* @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
*
* Emits an {ApprovalForAll} event.
*
* Requirements:
*
* - `operator` cannot be the caller.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
*
* See {setApprovalForAll}.
*/
function isApprovedForAll(address account, address operator) external view returns (bool);
/**
* @dev Transfers `amount` tokens of token type `id` from `from` to `to`.
*
* Emits a {TransferSingle} event.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
* - `from` must have a balance of tokens of type `id` of at least `amount`.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
* acceptance magic value.
*/
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
/**
* @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
*
* Emits a {TransferBatch} event.
*
* Requirements:
*
* - `ids` and `amounts` must have the same length.
* - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
* acceptance magic value.
*/
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
// 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: AGPL-3.0
pragma solidity 0.8.10;
/**
* @title ILPToken
* @author Souq.Finance
* @notice Defines the interface of the LP token of 1155 MMEs
* @notice License: https://souq-nft-amm-v1.s3.amazonaws.com/LICENSE.md
*/
interface ILPToken {
/**
* @dev Mints LP tokens to the provided address. Can only be called by the pool.
* @param to the address to mint the tokens to
* @param amount the amount to mint
*/
function mint(address to, uint256 amount) external;
/**
* @dev Burns LP tokens from the provided address. Can only be called by the pool.
* @param from the address to burn from
* @param amount the amount to burn
*/
function burn(address from, uint256 amount) external;
/**
* @dev Unpauses all token transfers. Can only be called by the pool.
*/
function unpause() external;
/**
* @dev Pauses all token transfers. Can only be called by the pool.
*/
function pause() external;
/**
* @dev Check if the LP Token is paused
* @return bool true=paused
*/
function checkPaused() external view returns (bool);
/**
* @dev Returns the balance of LP tokens for the provided address.
* @param account The account to check balance of
* @return uint256 The amount of LP Tokens owned
*/
function getBalanceOf(address account) external view returns (uint256);
/**
* @dev Approves a specific amount of a token for the pool.
* @param token The token address to approve
* @param amount The amount of tokens to approve
*/
function setApproval20(address token, uint256 amount) external;
/**
* @dev Function to rescue and send ERC20 tokens (different than the tokens used by the pool) to a receiver called by the admin
* @param token The address of the token contract
* @param amount The amount of tokens
* @param receiver The address of the receiver
*/
function RescueTokens(address token, uint256 amount, address receiver) external;
/**
* @dev Function to get the the total LP tokens
* @return uint256 The total number of LP tokens in circulation
*/
function getTotal() external view returns (uint256);
}
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import {IAddressesRegistry} from "../interfaces/IAddressesRegistry.sol";
import {Errors} from "../libraries/Errors.sol";
import {ILPToken} from "../interfaces/ILPToken.sol";
/**
* @title LPToken
* @author Souq.Finance
* @notice The LP Token contract of each liquidity pool
* @notice License: https://souq-nft-amm-v1.s3.amazonaws.com/LICENSE.md
*/
contract LPToken is ILPToken, ERC20, ERC20Burnable, Pausable {
address internal _underlyingAsset;
IAddressesRegistry internal immutable addressesRegistry;
address public immutable pool;
uint8 public immutable tokenDecimals;
constructor(
address _pool,
address registry,
address[] memory tokens,
string memory symbol,
string memory name,
uint8 _decimals
) ERC20(name, symbol) {
tokenDecimals = _decimals;
pool = _pool;
addressesRegistry = IAddressesRegistry(registry);
for (uint256 i = 0; i < tokens.length; i++) {
IERC1155(tokens[i]).setApprovalForAll(address(pool), true);
}
}
/**
* @dev modifier for when the the msg sender is the liquidity pool that created it only
*/
modifier onlyPool() {
require(_msgSender() == address(pool), Errors.CALLER_MUST_BE_POOL);
_;
}
/**
* @dev Returns the number of decimals for this token. Public due to override.
* @return uint8 the number of decimals
*/
function decimals() public view override returns (uint8) {
return tokenDecimals;
}
/// @inheritdoc ILPToken
function getTotal() external view returns (uint256) {
return totalSupply();
}
/// @inheritdoc ILPToken
function getBalanceOf(address account) external view returns (uint256) {
return balanceOf(account);
}
/// @inheritdoc ILPToken
function pause() external onlyPool {
//_pause already emits an event
_pause();
}
/// @inheritdoc ILPToken
function unpause() external onlyPool {
//_unpause already emits an event
_unpause();
}
/// @inheritdoc ILPToken
function checkPaused() external view returns (bool) {
return paused();
}
/// @inheritdoc ILPToken
function setApproval20(address token, uint256 amount) external onlyPool {
IERC20(token).approve(pool, amount);
}
/// @inheritdoc ILPToken
function mint(address to, uint256 amount) external onlyPool {
//_mint already emits a transfer event
_mint(to, amount);
}
/// @inheritdoc ILPToken
function burn(address from, uint256 amount) external onlyPool {
//_burn already emits a transfer event
_burn(from, amount);
}
/// @inheritdoc ILPToken
function RescueTokens(address token, uint256 amount, address receiver) external onlyPool {
//event emitted in the pool logic library
IERC20(token).transfer(receiver, amount);
}
/**
* @dev Implementation of the ERC1155 token received hook.
*/
function onERC1155Received(address, address, uint256, uint256, bytes memory) external virtual returns (bytes4) {
return this.onERC1155Received.selector;
}
/**
* @dev Implementation of the ERC1155 batch token received hook.
*/
function onERC1155BatchReceived(address, address, uint256[] memory, uint256[] memory, bytes memory) external virtual returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
{
"compilationTarget": {
"contracts/amm/LPToken.sol": "LPToken"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "none",
"useLiteralContent": true
},
"optimizer": {
"details": {
"constantOptimizer": true,
"cse": true,
"deduplicate": true,
"inliner": true,
"jumpdestRemover": true,
"orderLiterals": true,
"peephole": true,
"yul": true,
"yulDetails": {
"optimizerSteps": "dhfoDgvulfnTUtnIf [xa[r]scLM cCTUtTOntnfDIul Lcul Vcul [j] Tpeul xa[rul] xa[r]cL gvif CTUca[r]LsTOtfDnca[r]Iulc] jmul[jul] VcTOcul jmul",
"stackAllocation": true
}
},
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_pool","type":"address"},{"internalType":"address","name":"registry","type":"address"},{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"string","name":"name","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"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":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"RescueTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"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":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"burnFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"checkPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":"account","type":"address"}],"name":"getBalanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"uint256[]","name":"","type":"uint256[]"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155BatchReceived","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC1155Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"setApproval20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"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"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"}]