Address Contract Verified
Address
0xF87D6Eb8fb00FFF65Ac6784c68be56Fb5aFb97A6
Balance
0 ETH
Nonce
1
Code Size
7161 bytes
Creator
0xA87710c7...B363 at tx 0xbcb807b4...bd47f4
Indexed Transactions
0
Contract Bytecode
7161 bytes
0x608060405234801561000f575f5ffd5b5060043610610249575f3560e01c806380faa57d11610140578063cd3daf9d116100bf578063e4d2620e11610084578063e4d2620e14610508578063e9fad8ee1461052d578063ebe2b12b14610535578063f2fde38b1461053e578063f43edbc714610551578063f520e7e514610564575f5ffd5b8063cd3daf9d146104aa578063ce2f3543146104b2578063d38fe43f146104c5578063d98db465146104d8578063df136d65146104ff575f5ffd5b8063b6d4c6cb11610105578063b6d4c6cb14610449578063bc42d1781461045c578063bc58d7951461047b578063c0ed00c91461048e578063c8f33c91146104a1575f5ffd5b806380faa57d146104015780638456cb59146104095780638b876347146104115780638da5cb5b14610430578063ae79e86114610440575f5ffd5b80634cdcd8d3116101cc578063605779811161019157806360577981146103a25780636386c1c7146103aa5780636946a235146103e8578063715018a6146103f05780637b0a47ee146103f8575f5ffd5b80634cdcd8d314610322578063503690d11461034157806351ec8d1e14610354578063564442f7146103845780635c975abb14610397575f5ffd5b8063372500ab11610212578063372500ab146102d95780633f4ba83a146102e157806347d62809146102e957806348a9c640146102f257806349e297231461030f575f5ffd5b80628cc2621461024d5780630700037d146102735780630c6b8fe214610292578063168b5df9146102a75780631ab9db25146102c6575b5f5ffd5b61026061025b366004611a24565b61056d565b6040519081526020015b60405180910390f35b610260610281366004611a24565b600d6020525f908152604090205481565b6102a56102a0366004611a44565b6105ee565b005b6102606102b5366004611a24565b600a6020525f908152604090205481565b6102606102d4366004611a63565b61063e565b6102a561069c565b6102a56106b7565b61026060095481565b600e546102ff9060ff1681565b604051901515815260200161026a565b6102a561031d366004611a24565b6106c7565b610260610330366004611a99565b600f6020525f908152604090205481565b6102a561034f366004611ab4565b610876565b60025461036c9061010090046001600160a01b031681565b6040516001600160a01b03909116815260200161026a565b6102a5610392366004611aee565b610a1f565b60025460ff166102ff565b610260610bb4565b6103bd6103b8366004611a24565b610c39565b6040805195865260208601949094529284019190915260ff166060830152608082015260a00161026a565b610260610ca6565b6102a5610cd6565b61026060045481565b610260610ce7565b6102a5610cfd565b61026061041f366004611a24565b600c6020525f908152604090205481565b5f546001600160a01b031661036c565b61026060085481565b6102a5610457366004611aee565b610d0d565b61026061046a366004611a24565b600b6020525f908152604090205481565b6102a5610489366004611aee565b610d27565b6102a561049c366004611aee565b610f69565b61026060065481565b61026061100e565b6102606104c0366004611a24565b61106d565b6102a56104d3366004611a24565b611090565b61036c7f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a81565b61026060075481565b61051b610516366004611a24565b6110e9565b60405160ff909116815260200161026a565b6102a5611193565b61026060035481565b6102a561054c366004611a24565b6111b3565b6102a561055f366004611b05565b6111f2565b61026060055481565b6001600160a01b0381165f908152600b6020908152604080832054600c909252822054829061059a61100e565b6105a49190611b35565b6001600160a01b0385165f908152600d6020526040902054909150670de0b6b3a76400006105d28385611b48565b6105dc9190611b5f565b6105e69190611b7e565b949350505050565b6105f661129f565b600e805460ff19168215159081179091556040519081527ff21c676006857a7e28f8cf2035c6723b5d5e0b0c60bf6f1bd93a0a4a6ca4d8a3906020015b60405180910390a150565b600e545f9060ff161580610650575081155b1561065c575080610696565b5f610666846110e9565b60ff81165f908152600f602052604090205490915060646106878286611b48565b6106919190611b5f565b925050505b92915050565b6106a46112cb565b6106ac6112f5565b6106b560018055565b565b6106bf61129f565b6106b56113e6565b6106cf6112cb565b806106d861100e565b6007556106e3610ce7565b6006556001600160a01b03811615610731576106fe8161056d565b6001600160a01b0382165f908152600d6020908152604080832093909355600754600c9091529190205561073181611438565b6001600160a01b0382165f908152600a6020526040812054908190036107575750610869565b6001600160a01b0383165f908152600b602052604090205460095461077c8282611b35565b90505f610789868561063e565b6001600160a01b0387165f908152600b6020526040902081905590506107af8183611b7e565b6009558281111561080d576001600160a01b0386167f77fd1e5d2f34ad7d60b6774cd1c2aa21573f5fd769af5c4ac0525a1cdbf55ccc5f6107f08685611b35565b6040805192835260208301919091520160405180910390a2610864565b82811015610864576001600160a01b0386167ff55056edc4d39311cb0997e7c655e9f1954c9aa034628ff8799934ee7c836c115f61084b8487611b35565b6040805192835260208301919091520160405180910390a25b505050505b5061087360018055565b50565b61087e61129f565b6001600160a01b0382166108a557604051634e46966960e11b815260040160405180910390fd5b805f036108c557604051632e11316f60e11b815260040160405180910390fd5b7f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a6001600160a01b0316836001600160a01b031603610a06576040516370a0823160e01b81523060048201525f907f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a6001600160a01b0316906370a0823190602401602060405180830381865afa158015610962573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109869190611b91565b90505f6003544210610998575f6109b3565b426003546109a69190611b35565b6004546109b39190611b48565b90505f816008546109c49190611b7e565b90505f8184116109d4575f6109de565b6109de8285611b35565b905080851115610a015760405163fc46380360e01b815260040160405180910390fd5b505050505b610a1a6001600160a01b038416838361156f565b505050565b610a276112cb565b610a2f6115ce565b33610a3861100e565b600755610a43610ce7565b6006556001600160a01b03811615610a9157610a5e8161056d565b6001600160a01b0382165f908152600d6020908152604080832093909355600754600c90915291902055610a9181611438565b815f03610ab157604051636a76ff9f60e01b815260040160405180910390fd5b335f908152600b6020908152604080832054600a90925290912054600954600854610adc8483611b35565b91505f610ae98785611b7e565b335f908152600a602052604090208190559050610b068783611b7e565b6008555f610b14338361063e565b335f908152600b602052604090208190559050610b318185611b7e565b600955610b5f7f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a338a6115f2565b337f77fd1e5d2f34ad7d60b6774cd1c2aa21573f5fd769af5c4ac0525a1cdbf55ccc89610b8c8985611b35565b6040805192835260208301919091520160405180910390a25050505050505061087360018055565b5f6009545f1480610bc757506003544210155b15610bd157505f90565b5f42600354610be09190611b35565b600454610bed9190611b48565b90505f42600354610bfe9190611b35565b610c0c836301e13380611b48565b610c169190611b5f565b600954909150610c2882612710611b48565b610c329190611b5f565b9250505090565b6001600160a01b0381165f908152600a6020908152604080832054600b90925282205490918080610c698661056d565b9250610c74866110e9565b600e5490925060ff16610c88576064610c9b565b60ff82165f908152600f60205260409020545b905091939590929450565b5f6003544210610cb6575f610cc4565b42600354610cc49190611b35565b600454610cd19190611b48565b905090565b610cde61129f565b6106b55f61170e565b5f6003544210610cf8575060035490565b504290565b610d0561129f565b6106b561175d565b610d156112cb565b610d1e8161179a565b61087360018055565b610d2f61129f565b5f610d3861100e565b600755610d43610ce7565b6006556001600160a01b03811615610d9157610d5e8161056d565b6001600160a01b0382165f908152600d6020908152604080832093909355600754600c90915291902055610d9181611438565b815f03610db15760405163fb93c7c760e01b815260040160405180910390fd5b60035460055460045442929190828410610dd657610dcf8287611b5f565b9050610e0a565b5f610de18585611b35565b90505f610dee8383611b48565b905083610dfb828a611b7e565b610e059190611b5f565b925050505b805f03610e2a57604051630639c74d60e41b815260040160405180910390fd5b60048190556006849055610e3e8285611b7e565b600355610e6c7f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a33886115f2565b6008546040516370a0823160e01b81523060048201527f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a6001600160a01b0316906370a0823190602401602060405180830381865afa158015610ed1573d5f5f3e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610ef59190611b91565b610eff9190611b35565b610f098383611b48565b1115610f28576040516307899f1560e31b815260040160405180910390fd5b60408051878152602081018490527f6c07ee05dcf262f13abf9d87b846ee789d2f90fe991d495acd7d7fc109ee1f55910160405180910390a1505050505050565b610f7161129f565b600354421015610f9457604051630224d35d60e51b815260040160405180910390fd5b805f03610fb4576040516334cc7c9360e21b815260040160405180910390fd5b6301e13380811115610fd957604051634a94fa8360e11b815260040160405180910390fd5b60058190556040518181527ffeece2f615b2fecca6c26deadea49416a6ba6b52b2cd2613065fd6a787cf124090602001610633565b5f6009545f0361101f575060075490565b600954600454600654611030610ce7565b61103a9190611b35565b6110449190611b48565b61105690670de0b6b3a7640000611b48565b6110609190611b5f565b600754610cd19190611b7e565b6001600160a01b0381165f908152600a602052604081205461069690839061063e565b61109861129f565b60028054610100600160a81b0319166101006001600160a01b038416908102919091179091556040517fe9bbf5b6182b0e736e0f2ea3ebd067b5e1b08c6e58200d8c703a9767ec5c3e37905f90a250565b6002545f9061010090046001600160a01b0316158061110b5750600e5460ff16155b1561111757505f919050565b600254604051637269310760e11b81526001600160a01b0384811660048301526101009092049091169063e4d2620e90602401602060405180830381865afa925050508015611183575060408051601f3d908101601f1916820190925261118091810190611ba8565b60015b61069657505f919050565b919050565b61119b6112cb565b335f908152600a60205260409020546106a49061179a565b6111bb61129f565b6001600160a01b0381166111e957604051631e4fbdf760e01b81525f60048201526024015b60405180910390fd5b6108738161170e565b6111fa61129f565b60038260ff16111561121f5760405163e142361760e01b815260040160405180910390fd5b606481108061122f57506103e881115b1561124d576040516331cbc0d360e11b815260040160405180910390fd5b60ff82165f818152600f602052604090819020839055517f8c1e7653d00c679f327201461ca64989e5d77ba3f2a800ccfa7680f716e07cb6906112939084815260200190565b60405180910390a25050565b5f546001600160a01b031633146106b55760405163118cdaa760e01b81523360048201526024016111e0565b6002600154036112ee57604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b336112fe61100e565b600755611309610ce7565b6006556001600160a01b03811615611357576113248161056d565b6001600160a01b0382165f908152600d6020908152604080832093909355600754600c9091529190205561135781611438565b335f908152600d602052604090205480156113e257335f818152600d60205260408120556113b0907f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a6001600160a01b0316908361156f565b60405181815233907fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e048690602001611293565b5050565b6113ee611946565b6002805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b6001600160a01b0381165f908152600a60205260408120549081900361145c575050565b5f611467838361063e565b6001600160a01b0384165f908152600b60205260409020549091508082146115695781816009546114989190611b35565b6114a29190611b7e565b6009556001600160a01b0384165f908152600b602052604090208290558082111561151a576001600160a01b0384167f77fd1e5d2f34ad7d60b6774cd1c2aa21573f5fd769af5c4ac0525a1cdbf55ccc5f6114fd8486611b35565b6040805192835260208301919091520160405180910390a2611569565b6001600160a01b0384167ff55056edc4d39311cb0997e7c655e9f1954c9aa034628ff8799934ee7c836c115f6115508585611b35565b6040805192835260208301919091520160405180910390a25b50505050565b6040516001600160a01b03838116602483015260448201839052610a1a91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611969565b60025460ff16156106b55760405163d93c066560e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201525f906001600160a01b038516906370a0823190602401602060405180830381865afa158015611636573d5f5f3e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061165a9190611b91565b90506116716001600160a01b0385168430856119d5565b6040516370a0823160e01b81523060048201525f9082906001600160a01b038716906370a0823190602401602060405180830381865afa1580156116b7573d5f5f3e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116db9190611b91565b6116e59190611b35565b9050828114611707576040516388cf528960e01b815260040160405180910390fd5b5050505050565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6117656115ce565b6002805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861141b3390565b336117a361100e565b6007556117ae610ce7565b6006556001600160a01b038116156117fc576117c98161056d565b6001600160a01b0382165f908152600d6020908152604080832093909355600754600c909152919020556117fc81611438565b815f0361181c5760405163061bb89b60e51b815260040160405180910390fd5b335f908152600a60205260409020548281101561184c576040516378de4a6960e11b815260040160405180910390fd5b335f908152600b602052604090205460095460085461186b8383611b35565b91505f6118788786611b35565b335f908152600a6020526040902081905590506118958783611b35565b6008555f6118a3338361063e565b335f908152600b6020526040902081905590506118c08185611b7e565b6009556118f76001600160a01b037f00000000000000000000000039903a1a6f289a67e0de94096915c4ccd506ab2a16338a61156f565b337ff55056edc4d39311cb0997e7c655e9f1954c9aa034628ff8799934ee7c836c11896119248489611b35565b6040805192835260208301919091520160405180910390a25050505050505050565b60025460ff166106b557604051638dfc202b60e01b815260040160405180910390fd5b5f5f60205f8451602086015f885af180611988576040513d5f823e3d81fd5b50505f513d9150811561199f5780600114156119ac565b6001600160a01b0384163b155b1561156957604051635274afe760e01b81526001600160a01b03851660048201526024016111e0565b6040516001600160a01b0384811660248301528381166044830152606482018390526115699186918216906323b872dd9060840161159c565b80356001600160a01b038116811461118e575f5ffd5b5f60208284031215611a34575f5ffd5b611a3d82611a0e565b9392505050565b5f60208284031215611a54575f5ffd5b81358015158114611a3d575f5ffd5b5f5f60408385031215611a74575f5ffd5b611a7d83611a0e565b946020939093013593505050565b60ff81168114610873575f5ffd5b5f60208284031215611aa9575f5ffd5b8135611a3d81611a8b565b5f5f5f60608486031215611ac6575f5ffd5b611acf84611a0e565b9250611add60208501611a0e565b929592945050506040919091013590565b5f60208284031215611afe575f5ffd5b5035919050565b5f5f60408385031215611b16575f5ffd5b8235611a7d81611a8b565b634e487b7160e01b5f52601160045260245ffd5b8181038181111561069657610696611b21565b808202811582820484141761069657610696611b21565b5f82611b7957634e487b7160e01b5f52601260045260245ffd5b500490565b8082018082111561069657610696611b21565b5f60208284031215611ba1575f5ffd5b5051919050565b5f60208284031215611bb8575f5ffd5b8151611a3d81611a8b56fea2646970667358221220115a3d4fcff421c849af19235815cb35a63675fc7e3b922e6663a1b2b00b6b0c64736f6c634300081c0033
Verified Source Code Full Match
Compiler: v0.8.28+commit.7893614a
EVM: cancun
Optimization: Yes (200 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
SafeERC20.sol 212 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
Pausable.sol 112 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
bool private _paused;
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
ReentrancyGuard.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
MAIVStaking.sol 536 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/Pausable.sol";
/**
* @notice Interface for Membership contract
*/
interface IMembership {
function getUserTier(address user) external view returns (uint8);
}
/**
* @notice Custom errors for gas optimization
*/
error InvalidTokenAddress();
error TransferFeeNotSupported();
error CannotStakeZero();
error CannotWithdrawZero();
error InsufficientStake();
error RewardMustBePositive();
error RewardRateTooLow();
error InsufficientBalanceForRewards();
error PeriodNotFinished();
error DurationMustBePositive();
error DurationTooLong();
error InvalidTier();
error InvalidMultiplierRange();
error InvalidRecipient();
error AmountMustBePositive();
error CannotSweepLockedTokens();
/**
* @title MAIVStaking
* @notice Flexible staking with tier-based reward multipliers
* @dev Synthetix-style reward distribution with automatic membership tier integration
*
* Key Features:
* - No lock periods - stake and withdraw anytime
* - Linear reward distribution over admin-configured duration
* - Tier multipliers: 1x (none), 1.25x (T1), 1.5x (T2), 2x (T3)
* - Automatic tier sync when membership changes
* - Fair expiration handling - no boosted rewards after membership expires
*/
contract MAIVStaking is Ownable, ReentrancyGuard, Pausable {
using SafeERC20 for IERC20;
IERC20 public immutable maivToken;
IMembership public membershipContract;
uint256 public periodFinish;
uint256 public rewardRate;
uint256 public rewardDuration = 30 days;
uint256 public lastUpdateTime;
uint256 public rewardPerTokenStored;
uint256 public totalFlexStaked;
uint256 public totalEffectiveStaked; // Adjusted for multipliers
mapping(address => uint256) public flexStakes;
mapping(address => uint256) public userEffectiveStake; // Snapshot: prevents retroactive multiplier exploit
mapping(address => uint256) public userRewardPerTokenPaid;
mapping(address => uint256) public rewards;
// Tier multiplier settings (in basis points: 100 = 1x, 150 = 1.5x, 200 = 2x)
bool public tierMultipliersEnabled;
mapping(uint8 => uint256) public tierMultipliers; // tier => multiplier in basis points
event FlexStaked(address indexed user, uint256 amount, uint256 effectiveAmount);
event FlexWithdrawn(address indexed user, uint256 amount, uint256 effectiveAmount);
event RewardPaid(address indexed user, uint256 reward);
event RewardAdded(uint256 reward, uint256 duration);
event RewardDurationUpdated(uint256 newDuration);
event MembershipContractUpdated(address indexed newMembership);
event TierMultipliersToggled(bool enabled);
event TierMultiplierUpdated(uint8 indexed tier, uint256 multiplier);
constructor(address _maivToken, address _membershipContract) Ownable(msg.sender) {
if (_maivToken == address(0)) revert InvalidTokenAddress();
maivToken = IERC20(_maivToken);
membershipContract = IMembership(_membershipContract);
// Default multipliers (in basis points)
tierMultipliers[0] = 100; // No tier: 1x
tierMultipliers[1] = 125; // Tier 1: 1.25x
tierMultipliers[2] = 150; // Tier 2: 1.5x
tierMultipliers[3] = 200; // Tier 3: 2x
tierMultipliersEnabled = true; // Enabled by default
}
/**
* @dev Prevents fee-on-transfer token exploits by verifying exact amount received
* @param token The ERC20 token to transfer
* @param from Address to transfer from
* @param amount Expected amount to receive
*/
function _pullExact(IERC20 token, address from, uint256 amount) internal {
uint256 balanceBefore = token.balanceOf(address(this));
token.safeTransferFrom(from, address(this), amount);
uint256 received = token.balanceOf(address(this)) - balanceBefore;
if (received != amount) revert TransferFeeNotSupported();
}
/**
* @dev Updates global and user reward state, then auto-syncs tier if changed
* @param account User address to update (address(0) for global only)
*/
modifier updateReward(address account) {
rewardPerTokenStored = rewardPerToken();
lastUpdateTime = lastTimeRewardApplicable();
if (account != address(0)) {
rewards[account] = earned(account);
userRewardPerTokenPaid[account] = rewardPerTokenStored;
_autoSyncTierIfChanged(account);
}
_;
}
/**
* @dev Auto-syncs tier multiplier if it changed (e.g. membership expired)
* @param account User address to check and sync
*
* This function ensures fair rewards by:
* - Checking if user's current tier differs from snapshotted tier
* - Updating effective stake if tier changed
* - Handling membership expiration automatically
*/
function _autoSyncTierIfChanged(address account) internal {
uint256 stakeAmount = flexStakes[account];
if (stakeAmount == 0) return;
uint256 currentEffectiveStake = getEffectiveStake(account, stakeAmount);
uint256 snapshotEffectiveStake = userEffectiveStake[account];
if (currentEffectiveStake != snapshotEffectiveStake) {
totalEffectiveStaked = totalEffectiveStaked - snapshotEffectiveStake + currentEffectiveStake;
userEffectiveStake[account] = currentEffectiveStake;
if (currentEffectiveStake > snapshotEffectiveStake) {
emit FlexStaked(account, 0, currentEffectiveStake - snapshotEffectiveStake);
} else {
emit FlexWithdrawn(account, 0, snapshotEffectiveStake - currentEffectiveStake);
}
}
}
/**
* @notice Query user's current membership tier
* @param user Address to check
* @return tier 0 (none), 1, 2, or 3
*/
function getUserTier(address user) public view returns (uint8) {
if (address(membershipContract) == address(0) || !tierMultipliersEnabled) {
return 0;
}
try membershipContract.getUserTier(user) returns (uint8 tier) {
return tier;
} catch {
return 0;
}
}
/**
* @notice Calculate effective stake with current tier multiplier
* @param user Address to calculate for
* @param amount Actual staked amount
* @return Effective amount after applying multiplier
*/
function getEffectiveStake(address user, uint256 amount) public view returns (uint256) {
if (!tierMultipliersEnabled || amount == 0) {
return amount;
}
uint8 tier = getUserTier(user);
uint256 multiplier = tierMultipliers[tier];
return (amount * multiplier) / 100;
}
/**
* @notice Get user's effective stake (convenience function)
* @param user Address to query
* @return User's current effective stake
*/
function getEffectiveStakeForUser(address user) public view returns (uint256) {
return getEffectiveStake(user, flexStakes[user]);
}
/**
* @notice Get the last applicable reward time
* @return Current time or period end, whichever is earlier
*/
function lastTimeRewardApplicable() public view returns (uint256) {
return block.timestamp < periodFinish ? block.timestamp : periodFinish;
}
/**
* @notice Calculate accumulated reward per effective token
* @return Reward per token (scaled by 1e18)
*/
function rewardPerToken() public view returns (uint256) {
if (totalEffectiveStaked == 0) {
return rewardPerTokenStored;
}
return rewardPerTokenStored +
((lastTimeRewardApplicable() - lastUpdateTime) * rewardRate * 1e18) / totalEffectiveStaked;
}
/**
* @notice Calculate user's earned rewards
* @param account User address
* @return Total earned rewards (claimable amount)
*
* @dev CRITICAL: Uses snapshot effective stake to ensure rewards are calculated
* with the multiplier that was active during the earning period. This prevents:
* - Gaming via tier upgrades (can't earn past rewards with new higher multiplier)
* - Loss of earned rewards on membership expiry (preserves boosted rewards)
* - The snapshot is updated via _autoSyncTierIfChanged() after rewards are calculated
*/
function earned(address account) public view returns (uint256) {
uint256 effectiveStake = userEffectiveStake[account];
uint256 rewardDelta = rewardPerToken() - userRewardPerTokenPaid[account];
return (effectiveStake * rewardDelta) / 1e18 + rewards[account];
}
/**
* @notice Calculate current APR based on effective staking
* @return APR in basis points (e.g., 5000 = 50% APR)
*
* @dev APR = (annualized rewards / total effective stake) * 10000
* Returns 0 if no one is staking or reward period ended
*/
function currentAPR() external view returns (uint256) {
if (totalEffectiveStaked == 0 || block.timestamp >= periodFinish) {
return 0;
}
uint256 remainingRewards = rewardRate * (periodFinish - block.timestamp);
uint256 annualRewards = (remainingRewards * 365 days) / (periodFinish - block.timestamp);
// APR relative to effective stake (accounts for multipliers)
return (annualRewards * 10000) / totalEffectiveStaked;
}
/**
* @notice Get remaining rewards for current period
* @return Remaining reward tokens until periodFinish
*/
function rewardForDuration() external view returns (uint256) {
return rewardRate * (block.timestamp < periodFinish ? (periodFinish - block.timestamp) : 0);
}
/**
* @notice Stake MAIV tokens to earn rewards
* @param amount Amount of MAIV to stake
*
* @dev Applies current tier multiplier and updates effective stake.
* No lock period - can withdraw anytime.
*/
function stakeFlex(uint256 amount) external nonReentrant whenNotPaused updateReward(msg.sender) {
if (amount == 0) revert CannotStakeZero();
// Cache storage reads
uint256 oldEffectiveStake = userEffectiveStake[msg.sender];
uint256 currentStake = flexStakes[msg.sender];
uint256 totalEffective = totalEffectiveStaked;
uint256 totalFlex = totalFlexStaked;
totalEffective -= oldEffectiveStake;
uint256 newStake = currentStake + amount;
flexStakes[msg.sender] = newStake;
totalFlexStaked = totalFlex + amount;
uint256 newEffectiveStake = getEffectiveStake(msg.sender, newStake);
userEffectiveStake[msg.sender] = newEffectiveStake;
totalEffectiveStaked = totalEffective + newEffectiveStake;
_pullExact(maivToken, msg.sender, amount);
emit FlexStaked(msg.sender, amount, newEffectiveStake - oldEffectiveStake);
}
/**
* @dev Internal withdraw logic - called by withdrawFlex() and exit()
* @param amount Amount to withdraw
*/
function _withdrawFlex(uint256 amount) internal updateReward(msg.sender) {
if (amount == 0) revert CannotWithdrawZero();
// Cache storage reads
uint256 currentStake = flexStakes[msg.sender];
if (currentStake < amount) revert InsufficientStake();
uint256 oldEffectiveStake = userEffectiveStake[msg.sender];
uint256 totalEffective = totalEffectiveStaked;
uint256 totalFlex = totalFlexStaked;
totalEffective -= oldEffectiveStake;
// Update stake amount
uint256 newStake = currentStake - amount;
flexStakes[msg.sender] = newStake;
totalFlexStaked = totalFlex - amount;
// Calculate and store new effective stake
uint256 newEffectiveStake = getEffectiveStake(msg.sender, newStake);
userEffectiveStake[msg.sender] = newEffectiveStake;
totalEffectiveStaked = totalEffective + newEffectiveStake;
maivToken.safeTransfer(msg.sender, amount);
emit FlexWithdrawn(msg.sender, amount, oldEffectiveStake - newEffectiveStake);
}
/**
* @notice Withdraw staked MAIV tokens
* @param amount Amount to withdraw (must be <= staked balance)
*/
function withdrawFlex(uint256 amount) public nonReentrant {
_withdrawFlex(amount);
}
/**
* @dev Internal claim logic - called by claimRewards() and exit()
*/
function _claimRewards() internal updateReward(msg.sender) {
uint256 reward = rewards[msg.sender];
if (reward > 0) {
rewards[msg.sender] = 0;
maivToken.safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, reward);
}
}
/**
* @notice Claim earned rewards
*/
function claimRewards() public nonReentrant {
_claimRewards();
}
/**
* @notice Withdraw all stake and claim rewards
*/
function exit() external nonReentrant {
_withdrawFlex(flexStakes[msg.sender]);
_claimRewards();
}
/**
* @notice Manually sync user's tier multiplier
* @param user Address to sync
*
* @dev Called automatically by Membership contract when tier changes.
* Can also be called manually if needed (permissionless).
* Returns silently if user has no stake.
*/
function syncTierMultiplierFor(address user) external nonReentrant updateReward(user) {
// Cache storage reads
uint256 stakeAmount = flexStakes[user];
if (stakeAmount == 0) return;
uint256 oldEffectiveStake = userEffectiveStake[user];
uint256 totalEffective = totalEffectiveStaked;
totalEffective -= oldEffectiveStake;
uint256 newEffectiveStake = getEffectiveStake(user, stakeAmount);
userEffectiveStake[user] = newEffectiveStake;
totalEffectiveStaked = totalEffective + newEffectiveStake;
if (newEffectiveStake > oldEffectiveStake) {
emit FlexStaked(user, 0, newEffectiveStake - oldEffectiveStake);
} else if (newEffectiveStake < oldEffectiveStake) {
emit FlexWithdrawn(user, 0, oldEffectiveStake - newEffectiveStake);
}
}
/**
* @notice Fund reward pool for distribution
* @param reward Amount of MAIV tokens to add to reward pool
*
* @dev Distributes linearly over rewardDuration (default 30 days).
* If adding during active period, combines with remaining rewards.
* Requires sufficient contract balance to cover distribution.
*/
function topUpRewards(uint256 reward) external onlyOwner updateReward(address(0)) {
if (reward == 0) revert RewardMustBePositive();
// Cache storage reads
uint256 currentTime = block.timestamp;
uint256 periodEnd = periodFinish;
uint256 duration = rewardDuration;
uint256 rate = rewardRate;
if (currentTime >= periodEnd) {
// Starting new period
rate = reward / duration;
} else {
// Adding to existing period
uint256 remaining = periodEnd - currentTime;
uint256 leftover = remaining * rate;
rate = (reward + leftover) / duration;
}
if (rate == 0) revert RewardRateTooLow();
rewardRate = rate;
lastUpdateTime = currentTime;
periodFinish = currentTime + duration;
_pullExact(maivToken, msg.sender, reward);
// Verify sufficient balance after transfer
if (rate * duration > maivToken.balanceOf(address(this)) - totalFlexStaked) {
revert InsufficientBalanceForRewards();
}
emit RewardAdded(reward, duration);
}
/**
* @notice Set reward distribution duration
* @param newDuration Duration in seconds (max 365 days)
*
* @dev Can only be changed when no active reward period.
* Affects next topUpRewards() call.
*/
function setRewardDuration(uint256 newDuration) external onlyOwner {
if (block.timestamp < periodFinish) revert PeriodNotFinished();
if (newDuration == 0) revert DurationMustBePositive();
if (newDuration > 365 days) revert DurationTooLong();
rewardDuration = newDuration;
emit RewardDurationUpdated(newDuration);
}
/**
* @notice Update Membership contract address
* @param newMembershipContract Address of new Membership contract
*/
function setMembershipContract(address newMembershipContract) external onlyOwner {
membershipContract = IMembership(newMembershipContract);
emit MembershipContractUpdated(newMembershipContract);
}
/**
* @notice Enable or disable tier multiplier system
* @param enabled True to enable multipliers, false for all 1x
*/
function setTierMultipliersEnabled(bool enabled) external onlyOwner {
tierMultipliersEnabled = enabled;
emit TierMultipliersToggled(enabled);
}
/**
* @notice Configure tier multiplier
* @param tier Tier level (0=none, 1-3=tiers)
* @param multiplier Basis points (100=1x, 125=1.25x, 150=1.5x, 200=2x)
*
* @dev Multiplier must be between 100 (1x) and 1000 (10x)
*/
function setTierMultiplier(uint8 tier, uint256 multiplier) external onlyOwner {
if (tier > 3) revert InvalidTier();
if (multiplier < 100 || multiplier > 1000) revert InvalidMultiplierRange();
tierMultipliers[tier] = multiplier;
emit TierMultiplierUpdated(tier, multiplier);
}
/**
* @notice Recover accidentally sent tokens
* @param token Token address to recover
* @param to Recipient address
* @param amount Amount to recover
*
* @dev MAIV safety: Cannot sweep staked tokens or active reward pool
*/
function sweepERC20(address token, address to, uint256 amount) external onlyOwner {
if (to == address(0)) revert InvalidRecipient();
if (amount == 0) revert AmountMustBePositive();
if (token == address(maivToken)) {
uint256 contractBalance = maivToken.balanceOf(address(this));
uint256 remainingRewards = block.timestamp < periodFinish
? rewardRate * (periodFinish - block.timestamp)
: 0;
uint256 lockedAmount = totalFlexStaked + remainingRewards;
uint256 sweepableAmount = contractBalance > lockedAmount ? contractBalance - lockedAmount : 0;
if (amount > sweepableAmount) revert CannotSweepLockedTokens();
}
IERC20(token).safeTransfer(to, amount);
}
/**
* @notice Get complete user staking info
* @param user Address to query
* @return staked Actual staked amount
* @return effectiveStake Snapshot effective stake (with multiplier)
* @return earnedRewards Current claimable rewards
* @return membershipTier Current tier (0-3)
* @return appliedMultiplier Current multiplier in basis points
*/
function getUserInfo(address user) external view returns (
uint256 staked,
uint256 effectiveStake,
uint256 earnedRewards,
uint8 membershipTier,
uint256 appliedMultiplier
) {
staked = flexStakes[user];
effectiveStake = userEffectiveStake[user]; // Use snapshot
earnedRewards = earned(user);
membershipTier = getUserTier(user);
appliedMultiplier = tierMultipliersEnabled ? tierMultipliers[membershipTier] : 100;
}
function pause() external onlyOwner {
_pause();
}
function unpause() external onlyOwner {
_unpause();
}
}
Read Contract
currentAPR 0x60577981 → uint256
earned 0x008cc262 → uint256
flexStakes 0x168b5df9 → uint256
getEffectiveStake 0x1ab9db25 → uint256
getEffectiveStakeForUser 0xce2f3543 → uint256
getUserInfo 0x6386c1c7 → uint256, uint256, uint256, uint8, uint256
getUserTier 0xe4d2620e → uint8
lastTimeRewardApplicable 0x80faa57d → uint256
lastUpdateTime 0xc8f33c91 → uint256
maivToken 0xd98db465 → address
membershipContract 0x51ec8d1e → address
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
periodFinish 0xebe2b12b → uint256
rewardDuration 0xf520e7e5 → uint256
rewardForDuration 0x6946a235 → uint256
rewardPerToken 0xcd3daf9d → uint256
rewardPerTokenStored 0xdf136d65 → uint256
rewardRate 0x7b0a47ee → uint256
rewards 0x0700037d → uint256
tierMultipliers 0x4cdcd8d3 → uint256
tierMultipliersEnabled 0x48a9c640 → bool
totalEffectiveStaked 0x47d62809 → uint256
totalFlexStaked 0xae79e861 → uint256
userEffectiveStake 0xbc42d178 → uint256
userRewardPerTokenPaid 0x8b876347 → uint256
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
claimRewards 0x372500ab
No parameters
exit 0xe9fad8ee
No parameters
pause 0x8456cb59
No parameters
renounceOwnership 0x715018a6
No parameters
setMembershipContract 0xd38fe43f
address newMembershipContract
setRewardDuration 0xc0ed00c9
uint256 newDuration
setTierMultiplier 0xf43edbc7
uint8 tier
uint256 multiplier
setTierMultipliersEnabled 0x0c6b8fe2
bool enabled
stakeFlex 0x564442f7
uint256 amount
sweepERC20 0x503690d1
address token
address to
uint256 amount
syncTierMultiplierFor 0x49e29723
address user
topUpRewards 0xbc58d795
uint256 reward
transferOwnership 0xf2fde38b
address newOwner
unpause 0x3f4ba83a
No parameters
withdrawFlex 0xb6d4c6cb
uint256 amount
Recent Transactions
No transactions found for this address