Address Contract Verified
Address
0xB14F20982F2d1E5933362f5A796736D9ffa220E4
Balance
0 ETH
Nonce
1
Code Size
8009 bytes
Creator
0x6d228Fa4...E89A at tx 0x6d9b545d...bfeb4d
Indexed Transactions
0
Contract Bytecode
8009 bytes
0x608060405234801561001057600080fd5b506004361061014d5760003560e01c8063711ec9ac116100c3578063aaf5eb681161007c578063aaf5eb681461033c578063cbcbb50714610356578063cc69afec1461030d578063dde43cba1461037d578063f11b818814610385578063f5cf673b146103f757600080fd5b8063711ec9ac1461029b57806374d945ec146102a357806379f171b2146102e75780638b599f26146102fa578063919cd40f1461030d57806399248ea71461031557600080fd5b80633111e7b3116101155780633111e7b31461022957806331873e2e1461023c5780633373ee4c1461024f57806339ccbdd31461026257806341485304146102755780636d34b96e1461028857600080fd5b80630f1bf70d1461015257806311279b4a146101675780631652e7b714610181578063198fa81e146101ea5780632b6995dc14610221575b600080fd5b6101656101603660046119c5565b61040a565b005b604051630893cda560e11b81526020015b60405180910390f35b6101cf61018f366004611a10565b6001600160a01b0316600090815260208190526040902054600160681b81046001600160681b039081169290821691600160d01b900464ffffffffff1690565b60408051938452602084019290925290820152606001610178565b6102136101f8366004611a10565b6001600160a01b031660009081526002602052604090205490565b604051908152602001610178565b6101656105f6565b610213610237366004611a77565b610700565b61016561024a366004611ad4565b610742565b61021361025d366004611b07565b6107d9565b610165610270366004611b31565b610808565b610213610283366004611b4a565b61088c565b610213610296366004611b96565b6108a6565b61021361094d565b6102cf6102b1366004611a10565b6001600160a01b039081166000908152600360205260409020541690565b6040516001600160a01b039091168152602001610178565b6101656102f5366004611c04565b61095c565b610213610308366004611c70565b610bec565b600154610213565b6102cf7f0000000000000000000000006f80310ca7f2c654691d1383149fa1a57d8ab1f881565b610344601281565b60405160ff9091168152602001610178565b6102cf7f000000000000000000000000c04f84a02cc65f14f4e8c982a7a467ee88c5311e81565b610213600181565b6103ca610393366004611a10565b6000602081905290815260409020546001600160681b0380821691600160681b810490911690600160d01b900464ffffffffff1683565b604080516001600160681b03948516815293909216602084015264ffffffffff1690820152606001610178565b610165610405366004611b07565b610d75565b33600090815260208190526040902054600160d01b900464ffffffffff1615806104455750816001600160a01b0316836001600160a01b0316145b6105f0576000336001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610489573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ad9190611cc4565b90506001600160a01b0384166104c5578190036104d6565b6001600160a01b0383166104d65781015b6001600160a01b03841615610562576040516370a0823160e01b81526001600160a01b0385166004820152600090839033906370a0823190602401602060405180830381865afa15801561052e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105529190611cc4565b019050610560858383610742565b505b6001600160a01b038316156105ee576040516370a0823160e01b81526001600160a01b0384166004820152600090839033906370a0823190602401602060405180830381865afa1580156105ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105de9190611cc4565b0390506105ec848383610742565b505b505b50505050565b336001600160a01b037f000000000000000000000000c04f84a02cc65f14f4e8c982a7a467ee88c5311e161461063f57604051632f1907a960e21b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526106fe9033906001600160a01b037f0000000000000000000000006f80310ca7f2c654691d1383149fa1a57d8ab1f816906370a0823190602401602060405180830381865afa1580156106a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106cd9190611cc4565b6001600160a01b037f0000000000000000000000006f80310ca7f2c654691d1383149fa1a57d8ab1f8169190610e15565b565b60006001600160a01b03821661072957604051638aa3a72f60e01b815260040160405180910390fd5b610737858585333387610e6c565b90505b949350505050565b600061075084338486611108565b905080156105f0576001600160a01b03841660009081526002602052604090205461077c908290611cf3565b6001600160a01b038516600081815260026020526040908190209290925590517f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a76906107cb9084815260200190565b60405180910390a250505050565b6001600160a01b0380821660009081526020818152604080832093861683526001909301905220545b92915050565b336001600160a01b037f000000000000000000000000c04f84a02cc65f14f4e8c982a7a467ee88c5311e161461085157604051632f1907a960e21b815260040160405180910390fd5b60018190556040518181527f1cc1849a6602c3e91f2088cadea4381cc5717f2f28584197060ed2ebb434c16f9060200160405180910390a150565b600061089c848484333333610e6c565b90505b9392505050565b6001600160a01b038083166000908152600360205260408120549091339185911682146108e557604051620bb58b60e51b815260040160405180910390fd5b6001600160a01b03851661090c57604051630702b3d960e41b815260040160405180910390fd5b6001600160a01b03841661093357604051638aa3a72f60e01b815260040160405180910390fd5b610941888888338989610e6c565b98975050505050505050565b6109596012600a611def565b81565b336001600160a01b037f000000000000000000000000c04f84a02cc65f14f4e8c982a7a467ee88c5311e16146109a557604051632f1907a960e21b815260040160405180910390fd5b8281146109c55760405163c52a9bd360e01b815260040160405180910390fd5b60008367ffffffffffffffff8111156109e0576109e0611dfe565b604051908082528060200260200182016040528015610a2b57816020015b60408051606081018252600080825260208083018290529282015282526000199092019101816109fe5790505b50905060005b84811015610be257838382818110610a4b57610a4b611e14565b90506020020135848483818110610a6457610a64611e14565b905060200201356001600160681b031614610a9257604051634266136760e11b815260040160405180910390fd5b858582818110610aa457610aa4611e14565b9050602002016020810190610ab99190611a10565b828281518110610acb57610acb611e14565b6020026020010151604001906001600160a01b031690816001600160a01b031681525050838382818110610b0157610b01611e14565b90506020020135828281518110610b1a57610b1a611e14565b60209081029190910101516001600160681b039091169052858582818110610b4457610b44611e14565b9050602002016020810190610b599190611a10565b6001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610b96573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bba9190611cc4565b828281518110610bcc57610bcc611e14565b6020908102919091018101510152600101610a31565b506105ee816111c7565b6001600160a01b038116600090815260026020526040812054818467ffffffffffffffff811115610c1f57610c1f611dfe565b604051908082528060200260200182016040528015610c7d57816020015b610c6a604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815260200190600190039081610c3d5790505b50905060005b85811015610d5657868682818110610c9d57610c9d611e14565b9050602002016020810190610cb29190611a10565b828281518110610cc457610cc4611e14565b60209081029190910101516001600160a01b039091169052610d0c878783818110610cf157610cf1611e14565b9050602002016020810190610d069190611a10565b8661132b565b838381518110610d1e57610d1e611e14565b6020026020010151602001848481518110610d3b57610d3b611e14565b60209081029190910101516040019190915252600101610c83565b50610d618482611407565b610d6b9083611cf3565b9695505050505050565b336001600160a01b037f000000000000000000000000c04f84a02cc65f14f4e8c982a7a467ee88c5311e1614610dbe57604051632f1907a960e21b815260040160405180910390fd5b6001600160a01b0382811660008181526003602052604080822080546001600160a01b0319169486169485179055517f4925eafc82d0c4d67889898eeed64b18488ab19811e61620f387026dec126a289190a35050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663a9059cbb60e01b179052610e67908490611516565b505050565b600084600003610e7e57506000610d6b565b6001600160a01b038316600090815260026020526040902054808611156110595760008767ffffffffffffffff811115610eba57610eba611dfe565b604051908082528060200260200182016040528015610f1857816020015b610f05604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b815260200190600190039081610ed85790505b50905060005b88811015610ff157898982818110610f3857610f38611e14565b9050602002016020810190610f4d9190611a10565b828281518110610f5f57610f5f611e14565b60209081029190910101516001600160a01b039091169052610fa78a8a83818110610f8c57610f8c611e14565b9050602002016020810190610fa19190611a10565b8761132b565b838381518110610fb957610fb9611e14565b6020026020010151602001848481518110610fd657610fd6611e14565b60209081029190910101516040019190915252600101610f1e565b506000610ffe86836115ed565b90508015611056576110108184611cf3565b9250856001600160a01b03167f2468f9268c60ad90e2d49edb0032c8a001e733ae888b3ab8e982edf535be1a768260405161104d91815260200190565b60405180910390a25b50505b8060000361106b576000915050610d6b565b600081871161107a578661107c565b815b6001600160a01b0386166000908152600260205260409020818403905590506110a58482611672565b856001600160a01b0316846001600160a01b0316866001600160a01b03167f5637d7f962248a7f05a7ab69eec6446e31f3d0a299d997f135a65c62806e7891846040516110f491815260200190565b60405180910390a498975050505050505050565b6001600160a01b0380841660009081526020818152604080832093881683526001840190915281205490919082806111418885886116a6565b90508083146111bb57861561115e5761115b8782856117d7565b91505b6001600160a01b03808a1660008181526001870160205260409081902084905551918a16917fbb123b5c06d5408bbea3c4fef481578175cfb432e3b482c6186f02ed9086585b906111b29085815260200190565b60405180910390a35b50979650505050505050565b60005b81518110156113275760008060008484815181106111ea576111ea611e14565b6020026020010151604001516001600160a01b03166001600160a01b03168152602001908152602001600020905061125d83838151811061122d5761122d611e14565b6020026020010151604001518285858151811061124c5761124c611e14565b6020026020010151602001516116a6565b5082828151811061127057611270611e14565b60209081029190910101515181546cffffffffffffffffffffffffff19166001600160681b0390911617815582518390839081106112b0576112b0611e14565b6020026020010151604001516001600160a01b03167f87fa03892a0556cb6b8f97e6d533a150d4d55fcbf275fff5fa003fa636bcc7fa8484815181106112f8576112f8611e14565b602090810291909101810151516040516001600160681b0390911681520160405180910390a2506001016111ca565b5050565b6040516370a0823160e01b81526001600160a01b03828116600483015260009182918516906370a0823190602401602060405180830381865afa158015611376573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061139a9190611cc4565b9150836001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113fe9190611cc4565b90509250929050565b600080805b835181101561150e57600080600086848151811061142c5761142c611e14565b602090810291909101810151516001600160a01b031682528101919091526040016000908120805487519193506114a791600160681b82046001600160681b039081169290811691600160d01b90910464ffffffffff16908a908890811061149657611496611e14565b602002602001015160400151611800565b90506114f88684815181106114be576114be611e14565b602002602001015160200151828460010160008b6001600160a01b03166001600160a01b03168152602001908152602001600020546117d7565b6115029085611cf3565b9350505060010161140c565b509392505050565b600061156b826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166118ae9092919063ffffffff16565b805190915015610e6757808060200190518101906115899190611e2a565b610e675760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b600080805b835181101561150e5761165e8585838151811061161157611611611e14565b60200260200101516000015186848151811061162f5761162f611e14565b60200260200101516020015187858151811061164d5761164d611e14565b602002602001015160400151611108565b6116689083611cf3565b91506001016115f2565b6113276001600160a01b037f0000000000000000000000006f80310ca7f2c654691d1383149fa1a57d8ab1f8168383610e15565b81546000906001600160681b03600160681b82048116919081169064ffffffffff600160d01b90910416428190036116e35782935050505061089f565b60006116f184848489611800565b90508381146117ad5780816001600160681b03161461172357604051637decd25760e01b815260040160405180910390fd5b865471ffffffffffffffffffffffffffffffffffff60681b1916600160681b6001600160681b0383160264ffffffffff60d01b191617600160d01b4264ffffffffff16021787556040518181526001600160a01b038916907f5777ca300dfe5bead41006fbce4389794dbc0ed8d6cccebfaf94630aa04184bc9060200160405180910390a26117cc565b865464ffffffffff60d01b1916600160d01b4264ffffffffff16021787555b979650505050505050565b60006117e38284611e4c565b6117ed9085611e63565b670de0b6b3a76400009004949350505050565b600154600090841580611811575082155b80611824575042846001600160801b0316145b80611838575080846001600160801b031610155b15611846578591505061073a565b60008142116118555742611857565b815b9050600061186e6001600160801b03871683611e4c565b905061187c6012600a611def565b6118868289611e63565b6118909190611e63565b93508484816118a1576118a1611e82565b0493506109418885611cf3565b606061089c848460008585843b6119075760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016115e4565b600080866001600160a01b031685876040516119239190611ec4565b60006040518083038185875af1925050503d8060008114611960576040519150601f19603f3d011682016040523d82523d6000602084013e611965565b606091505b50915091506117cc8282866060831561197f57508161089f565b82511561198f5782518084602001fd5b8160405162461bcd60e51b81526004016115e49190611ee0565b80356001600160a01b03811681146119c057600080fd5b919050565b600080600080608085870312156119db57600080fd5b6119e4856119a9565b93506119f2602086016119a9565b9250611a00604086016119a9565b9396929550929360600135925050565b600060208284031215611a2257600080fd5b61089f826119a9565b60008083601f840112611a3d57600080fd5b50813567ffffffffffffffff811115611a5557600080fd5b6020830191508360208260051b8501011115611a7057600080fd5b9250929050565b60008060008060608587031215611a8d57600080fd5b843567ffffffffffffffff811115611aa457600080fd5b611ab087828801611a2b565b90955093505060208501359150611ac9604086016119a9565b905092959194509250565b600080600060608486031215611ae957600080fd5b611af2846119a9565b95602085013595506040909401359392505050565b60008060408385031215611b1a57600080fd5b611b23836119a9565b91506113fe602084016119a9565b600060208284031215611b4357600080fd5b5035919050565b600080600060408486031215611b5f57600080fd5b833567ffffffffffffffff811115611b7657600080fd5b611b8286828701611a2b565b909790965060209590950135949350505050565b600080600080600060808688031215611bae57600080fd5b853567ffffffffffffffff811115611bc557600080fd5b611bd188828901611a2b565b90965094505060208601359250611bea604087016119a9565b9150611bf8606087016119a9565b90509295509295909350565b60008060008060408587031215611c1a57600080fd5b843567ffffffffffffffff80821115611c3257600080fd5b611c3e88838901611a2b565b90965094506020870135915080821115611c5757600080fd5b50611c6487828801611a2b565b95989497509550505050565b600080600060408486031215611c8557600080fd5b833567ffffffffffffffff811115611c9c57600080fd5b611ca886828701611a2b565b9094509250611cbb9050602085016119a9565b90509250925092565b600060208284031215611cd657600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b60008219821115611d0657611d06611cdd565b500190565b600181815b80851115611d46578160001904821115611d2c57611d2c611cdd565b80851615611d3957918102915b93841c9390800290611d10565b509250929050565b600082611d5d57506001610802565b81611d6a57506000610802565b8160018114611d805760028114611d8a57611da6565b6001915050610802565b60ff841115611d9b57611d9b611cdd565b50506001821b610802565b5060208310610133831016604e8410600b8410161715611dc9575081810a610802565b611dd38383611d0b565b8060001904821115611de757611de7611cdd565b029392505050565b600061089f60ff841683611d4e565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052603260045260246000fd5b600060208284031215611e3c57600080fd5b8151801515811461089f57600080fd5b600082821015611e5e57611e5e611cdd565b500390565b6000816000190483118215151615611e7d57611e7d611cdd565b500290565b634e487b7160e01b600052601260045260246000fd5b60005b83811015611eb3578181015183820152602001611e9b565b838111156105f05750506000910152565b60008251611ed6818460208701611e98565b9190910192915050565b6020815260008251806020840152611eff816040850160208701611e98565b601f01601f1916919091016040019291505056fea264697066735822122048c07c1993317222bfa2febad60a082970d9d98a3e77a186b874b4797ef7759d64736f6c634300080d0033
Verified Source Code Full Match
Compiler: v0.8.13+commit.abaa5c0e
EVM: london
Optimization: Yes (200 runs)
Address.sol 217 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @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
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 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://diligence.consensys.net/posts/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 functionCall(target, data, "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");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(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) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(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) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason 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 {
// 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
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
IERC20.sol 82 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @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);
/**
* @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);
/**
* @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);
}
INotificationReceiver.sol 16 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.13;
/// @title Common interface for Silo Incentive Contract
interface INotificationReceiver {
/// @dev Informs the contract about token transfer
/// @param _token address of the token that was transferred
/// @param _from sender
/// @param _to receiver
/// @param _amount amount that was transferred
function onAfterTransfer(address _token, address _from, address _to, uint256 _amount) external;
/// @dev Sanity check function
/// @return always true
function notificationReceiverPing() external pure returns (bytes4);
}
DistributionTypes.sol 16 lines
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.13;
library DistributionTypes {
struct AssetConfigInput {
uint104 emissionPerSecond;
uint256 totalStaked;
address underlyingAsset;
}
struct UserStakeInput {
address underlyingAsset;
uint256 stakedByUser;
uint256 totalStaked;
}
}
SiloIncentivesController.sol 89 lines
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.13;
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {BaseIncentivesController} from "../external/aave/incentives/base/BaseIncentivesController.sol";
import "../interfaces/INotificationReceiver.sol";
/**
* @title SiloIncentivesController
* @notice Distributor contract for rewards to the Aave protocol, using a staked token as rewards asset.
* The contract stakes the rewards before redistributing them to the Aave protocol participants.
* The reference staked token implementation is at https://github.com/aave/aave-stake-v2
* @author Aave
*/
contract SiloIncentivesController is BaseIncentivesController, INotificationReceiver {
using SafeERC20 for IERC20;
constructor(IERC20 rewardToken, address emissionManager) BaseIncentivesController(rewardToken, emissionManager) {}
/**
* @dev Silo share token event handler
*/
function onAfterTransfer(address /* _token */, address _from, address _to, uint256 _amount) external {
if (assets[msg.sender].lastUpdateTimestamp == 0 || _from == _to) {
// optimisation check, if we never configured rewards distribution, then no need for updating any data
return;
}
uint256 totalSupplyBefore = IERC20(msg.sender).totalSupply();
if (_from == address(0x0)) {
// we minting tokens, so supply before was less
// we safe, because this amount came from token, if token handle them we can handle as well
unchecked { totalSupplyBefore -= _amount; }
} else if (_to == address(0x0)) {
// we burning, so supply before was more
// we safe, because this amount came from token, if token handle them we can handle as well
unchecked { totalSupplyBefore += _amount; }
}
// here user either transferring token to someone else or burning tokens
// user state will be new, because this event is `onAfterTransfer`
// we need to recreate status before event in order to automatically calculate rewards
if (_from != address(0x0)) {
uint256 balanceBefore;
// we safe, because this amount came from token, if token handle them we can handle as well
unchecked { balanceBefore = IERC20(msg.sender).balanceOf(_from) + _amount; }
handleAction(_from, totalSupplyBefore, balanceBefore);
}
// we have to checkout also user `_to`
if (_to != address(0x0)) {
uint256 balanceBefore;
// we safe, because this amount came from token, if token handle them we can handle as well
unchecked { balanceBefore = IERC20(msg.sender).balanceOf(_to) - _amount; }
handleAction(_to, totalSupplyBefore, balanceBefore);
}
}
/// @dev it will transfer all balance of reward token to emission manager wallet
function rescueRewards() external onlyEmissionManager {
IERC20(REWARD_TOKEN).safeTransfer(msg.sender, IERC20(REWARD_TOKEN).balanceOf(address(this)));
}
function notificationReceiverPing() external pure returns (bytes4) {
return this.notificationReceiverPing.selector;
}
function _transferRewards(address to, uint256 amount) internal override {
IERC20(REWARD_TOKEN).safeTransfer(to, amount);
}
/**
* @dev in Silo, there is no scale, we simply using balance and total supply. Original method name is used here
* to keep as much of original code.
*/
function _getScaledUserBalanceAndSupply(address _asset, address _user)
internal
virtual
view
override
returns (uint256 userBalance, uint256 totalSupply)
{
userBalance = IERC20(_asset).balanceOf(_user);
totalSupply = IERC20(_asset).totalSupply();
}
}
SafeERC20.sol 99 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.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 IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
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));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
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'
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));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @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. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}
DistributionManager.sol 267 lines
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.13;
import {IAaveDistributionManager} from "../../interfaces/IAaveDistributionManager.sol";
import {DistributionTypes} from "../../lib/DistributionTypes.sol";
/**
* @title DistributionManager
* @notice Accounting contract to manage multiple staking distributions
* @author Aave
*/
contract DistributionManager is IAaveDistributionManager {
struct AssetData {
uint104 emissionPerSecond;
uint104 index;
uint40 lastUpdateTimestamp;
mapping(address => uint256) users;
}
address public immutable EMISSION_MANAGER; // solhint-disable-line var-name-mixedcase
uint8 public constant PRECISION = 18;
uint256 public constant TEN_POW_PRECISION = 10 ** PRECISION;
mapping(address => AssetData) public assets;
uint256 internal _distributionEnd;
error OnlyEmissionManager();
error IndexOverflow();
modifier onlyEmissionManager() {
if (msg.sender != EMISSION_MANAGER) revert OnlyEmissionManager();
_;
}
constructor(address emissionManager) {
EMISSION_MANAGER = emissionManager;
}
/// @inheritdoc IAaveDistributionManager
function setDistributionEnd(uint256 distributionEnd) external override onlyEmissionManager {
_distributionEnd = distributionEnd;
emit DistributionEndUpdated(distributionEnd);
}
/// @inheritdoc IAaveDistributionManager
function getDistributionEnd() external view override returns (uint256) {
return _distributionEnd;
}
/// @inheritdoc IAaveDistributionManager
function DISTRIBUTION_END() external view override returns (uint256) { // solhint-disable-line func-name-mixedcase
return _distributionEnd;
}
/// @inheritdoc IAaveDistributionManager
function getUserAssetData(address user, address asset) public view override returns (uint256) {
return assets[asset].users[user];
}
/// @inheritdoc IAaveDistributionManager
function getAssetData(address asset) public view override returns (uint256, uint256, uint256) {
return (assets[asset].index, assets[asset].emissionPerSecond, assets[asset].lastUpdateTimestamp);
}
/**
* @dev Configure the assets for a specific emission
* @param assetsConfigInput The array of each asset configuration
*/
function _configureAssets(DistributionTypes.AssetConfigInput[] memory assetsConfigInput) internal {
for (uint256 i = 0; i < assetsConfigInput.length;) {
AssetData storage assetConfig = assets[assetsConfigInput[i].underlyingAsset];
_updateAssetStateInternal(
assetsConfigInput[i].underlyingAsset,
assetConfig,
assetsConfigInput[i].totalStaked
);
assetConfig.emissionPerSecond = assetsConfigInput[i].emissionPerSecond;
emit AssetConfigUpdated(
assetsConfigInput[i].underlyingAsset,
assetsConfigInput[i].emissionPerSecond
);
unchecked { i++; }
}
}
/**
* @dev Updates the state of one distribution, mainly rewards index and timestamp
* @param asset The address of the asset being updated
* @param assetConfig Storage pointer to the distribution's config
* @param totalStaked Current total of staked assets for this distribution
* @return The new distribution index
*/
function _updateAssetStateInternal(
address asset,
AssetData storage assetConfig,
uint256 totalStaked
) internal returns (uint256) {
uint256 oldIndex = assetConfig.index;
uint256 emissionPerSecond = assetConfig.emissionPerSecond;
uint128 lastUpdateTimestamp = assetConfig.lastUpdateTimestamp;
if (block.timestamp == lastUpdateTimestamp) {
return oldIndex;
}
uint256 newIndex = _getAssetIndex(oldIndex, emissionPerSecond, lastUpdateTimestamp, totalStaked);
if (newIndex != oldIndex) {
if (uint104(newIndex) != newIndex) revert IndexOverflow();
//optimization: storing one after another saves one SSTORE
assetConfig.index = uint104(newIndex);
assetConfig.lastUpdateTimestamp = uint40(block.timestamp);
emit AssetIndexUpdated(asset, newIndex);
} else {
assetConfig.lastUpdateTimestamp = uint40(block.timestamp);
}
return newIndex;
}
/**
* @dev Updates the state of an user in a distribution
* @param user The user's address
* @param asset The address of the reference asset of the distribution
* @param stakedByUser Amount of tokens staked by the user in the distribution at the moment
* @param totalStaked Total tokens staked in the distribution
* @return The accrued rewards for the user until the moment
*/
function _updateUserAssetInternal(
address user,
address asset,
uint256 stakedByUser,
uint256 totalStaked
) internal returns (uint256) {
AssetData storage assetData = assets[asset];
uint256 userIndex = assetData.users[user];
uint256 accruedRewards = 0;
uint256 newIndex = _updateAssetStateInternal(asset, assetData, totalStaked);
if (userIndex != newIndex) {
if (stakedByUser != 0) {
accruedRewards = _getRewards(stakedByUser, newIndex, userIndex);
}
assetData.users[user] = newIndex;
emit UserIndexUpdated(user, asset, newIndex);
}
return accruedRewards;
}
/**
* @dev Used by "frontend" stake contracts to update the data of an user when claiming rewards from there
* @param user The address of the user
* @param stakes List of structs of the user data related with his stake
* @return The accrued rewards for the user until the moment
*/
function _claimRewards(address user, DistributionTypes.UserStakeInput[] memory stakes)
internal
returns (uint256)
{
uint256 accruedRewards = 0;
for (uint256 i = 0; i < stakes.length;) {
accruedRewards = accruedRewards + _updateUserAssetInternal(
user,
stakes[i].underlyingAsset,
stakes[i].stakedByUser,
stakes[i].totalStaked
);
unchecked { i++; }
}
return accruedRewards;
}
/**
* @dev Return the accrued rewards for an user over a list of distribution
* @param user The address of the user
* @param stakes List of structs of the user data related with his stake
* @return The accrued rewards for the user until the moment
*/
function _getUnclaimedRewards(address user, DistributionTypes.UserStakeInput[] memory stakes)
internal
view
returns (uint256)
{
uint256 accruedRewards = 0;
for (uint256 i = 0; i < stakes.length;) {
AssetData storage assetConfig = assets[stakes[i].underlyingAsset];
uint256 assetIndex = _getAssetIndex(
assetConfig.index,
assetConfig.emissionPerSecond,
assetConfig.lastUpdateTimestamp,
stakes[i].totalStaked
);
accruedRewards = accruedRewards + _getRewards(stakes[i].stakedByUser, assetIndex, assetConfig.users[user]);
unchecked { i++; }
}
return accruedRewards;
}
/**
* @dev Internal function for the calculation of user's rewards on a distribution
* @param principalUserBalance Amount staked by the user on a distribution
* @param reserveIndex Current index of the distribution
* @param userIndex Index stored for the user, representation his staking moment
* @return rewards The rewards
*/
function _getRewards(
uint256 principalUserBalance,
uint256 reserveIndex,
uint256 userIndex
) internal pure returns (uint256 rewards) {
rewards = principalUserBalance * (reserveIndex - userIndex);
unchecked { rewards /= TEN_POW_PRECISION; }
}
/**
* @dev Calculates the next value of an specific distribution index, with validations
* @param currentIndex Current index of the distribution
* @param emissionPerSecond Representing the total rewards distributed per second per asset unit,
* on the distribution
* @param lastUpdateTimestamp Last moment this distribution was updated
* @param totalBalance of tokens considered for the distribution
* @return newIndex The new index.
*/
function _getAssetIndex(
uint256 currentIndex,
uint256 emissionPerSecond,
uint128 lastUpdateTimestamp,
uint256 totalBalance
) internal view returns (uint256 newIndex) {
uint256 distributionEnd = _distributionEnd;
if (
emissionPerSecond == 0 ||
totalBalance == 0 ||
lastUpdateTimestamp == block.timestamp ||
lastUpdateTimestamp >= distributionEnd
) {
return currentIndex;
}
uint256 currentTimestamp = block.timestamp > distributionEnd ? distributionEnd : block.timestamp;
uint256 timeDelta = currentTimestamp - lastUpdateTimestamp;
newIndex = emissionPerSecond * timeDelta * TEN_POW_PRECISION;
unchecked { newIndex /= totalBalance; }
newIndex += currentIndex;
}
}
IAaveDistributionManager.sol 45 lines
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.13;
import {DistributionTypes} from "../lib/DistributionTypes.sol";
interface IAaveDistributionManager {
event AssetConfigUpdated(address indexed asset, uint256 emission);
event AssetIndexUpdated(address indexed asset, uint256 index);
event UserIndexUpdated(address indexed user, address indexed asset, uint256 index);
event DistributionEndUpdated(uint256 newDistributionEnd);
/**
* @dev Sets the end date for the distribution
* @param distributionEnd The end date timestamp
*/
function setDistributionEnd(uint256 distributionEnd) external;
/**
* @dev Gets the end date for the distribution
* @return The end of the distribution
*/
function getDistributionEnd() external view returns (uint256);
/**
* @dev for backwards compatibility with the previous DistributionManager used
* @return The end of the distribution
*/
function DISTRIBUTION_END() external view returns(uint256); // solhint-disable-line func-name-mixedcase
/**
* @dev Returns the data of an user on a distribution
* @param user Address of the user
* @param asset The address of the reference asset of the distribution
* @return The new index
*/
function getUserAssetData(address user, address asset) external view returns (uint256);
/**
* @dev Returns the configuration of the distribution for a certain asset
* @param asset The address of the reference asset of the distribution
* @return The asset index, the emission per second and the last updated timestamp
*/
function getAssetData(address asset) external view returns (uint256, uint256, uint256);
}
IAaveIncentivesController.sol 104 lines
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.13;
import {IAaveDistributionManager} from "../interfaces/IAaveDistributionManager.sol";
interface IAaveIncentivesController is IAaveDistributionManager {
event RewardsAccrued(address indexed user, uint256 amount);
event RewardsClaimed(
address indexed user,
address indexed to,
address indexed claimer,
uint256 amount
);
event ClaimerSet(address indexed user, address indexed claimer);
/**
* @dev Whitelists an address to claim the rewards on behalf of another address
* @param user The address of the user
* @param claimer The address of the claimer
*/
function setClaimer(address user, address claimer) external;
/**
* @dev Configure assets for a certain rewards emission
* @param assets The assets to incentivize
* @param emissionsPerSecond The emission for each asset
*/
function configureAssets(address[] calldata assets, uint256[] calldata emissionsPerSecond) external;
/**
* @dev Called by the corresponding asset on any update that affects the rewards distribution
* @param asset The address of the user
* @param userBalance The balance of the user of the asset in the lending pool
* @param totalSupply The total supply of the asset in the lending pool
*/
function handleAction(
address asset,
uint256 userBalance,
uint256 totalSupply
) external;
/**
* @dev Claims reward for an user to the desired address, on all the assets of the lending pool,
* accumulating the pending rewards
* @param amount Amount of rewards to claim
* @param to Address that will be receiving the rewards
* @return Rewards claimed
*/
function claimRewards(
address[] calldata assets,
uint256 amount,
address to
) external returns (uint256);
/**
* @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating the pending
* rewards. The caller must be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
* @param amount Amount of rewards to claim
* @param user Address to check and claim rewards
* @param to Address that will be receiving the rewards
* @return Rewards claimed
*/
function claimRewardsOnBehalf(
address[] calldata assets,
uint256 amount,
address user,
address to
) external returns (uint256);
/**
* @dev Claims reward for msg.sender, on all the assets of the lending pool, accumulating the pending rewards
* @param amount Amount of rewards to claim
* @return Rewards claimed
*/
function claimRewardsToSelf(address[] calldata assets, uint256 amount) external returns (uint256);
/**
* @dev Returns the whitelisted claimer for a certain address (0x0 if not set)
* @param user The address of the user
* @return The claimer address
*/
function getClaimer(address user) external view returns (address);
/**
* @dev Returns the total of rewards of an user, already accrued + not yet accrued
* @param user The address of the user
* @return The rewards
*/
function getRewardsBalance(address[] calldata assets, address user) external view returns (uint256);
/**
* @dev returns the unclaimed rewards of the user
* @param user the address of the user
* @return the unclaimed user rewards
*/
function getUserUnclaimedRewards(address user) external view returns (uint256);
/**
* @dev for backward compatibility with previous implementation of the Incentives controller
*/
function REWARD_TOKEN() external view returns (address); // solhint-disable-line func-name-mixedcase
}
BaseIncentivesController.sol 214 lines
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.13;
import {DistributionTypes} from "../../lib/DistributionTypes.sol";
import {DistributionManager} from "./DistributionManager.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IAaveIncentivesController} from "../../interfaces/IAaveIncentivesController.sol";
/**
* @title BaseIncentivesController
* @notice Abstract contract template to build Distributors contracts for ERC20 rewards to protocol participants
* @author Aave
*/
abstract contract BaseIncentivesController is IAaveIncentivesController, DistributionManager {
uint256 public constant REVISION = 1;
address public immutable override REWARD_TOKEN; // solhint-disable-line var-name-mixedcase
mapping(address => uint256) internal _usersUnclaimedRewards;
// this mapping allows whitelisted addresses to claim on behalf of others
// useful for contracts that hold tokens to be rewarded but don't have any native logic to claim Liquidity Mining
// rewards
mapping(address => address) internal _authorizedClaimers;
modifier onlyAuthorizedClaimers(address claimer, address user) {
if (_authorizedClaimers[user] != claimer) revert ClaimerUnauthorized();
_;
}
error InvalidConfiguration();
error IndexOverflowAtEmissionsPerSecond();
error InvalidToAddress();
error InvalidUserAddress();
error ClaimerUnauthorized();
constructor(IERC20 rewardToken, address emissionManager) DistributionManager(emissionManager) {
REWARD_TOKEN = address(rewardToken);
}
/// @inheritdoc IAaveIncentivesController
function configureAssets(address[] calldata assets, uint256[] calldata emissionsPerSecond)
external
override
onlyEmissionManager
{
if (assets.length != emissionsPerSecond.length) revert InvalidConfiguration();
DistributionTypes.AssetConfigInput[] memory assetsConfig =
new DistributionTypes.AssetConfigInput[](assets.length);
for (uint256 i = 0; i < assets.length;) {
if (uint104(emissionsPerSecond[i]) != emissionsPerSecond[i]) revert IndexOverflowAtEmissionsPerSecond();
assetsConfig[i].underlyingAsset = assets[i];
assetsConfig[i].emissionPerSecond = uint104(emissionsPerSecond[i]);
assetsConfig[i].totalStaked = IERC20(assets[i]).totalSupply();
unchecked { i++; }
}
_configureAssets(assetsConfig);
}
/// @inheritdoc IAaveIncentivesController
function handleAction(
address user,
uint256 totalSupply,
uint256 userBalance
) public override {
uint256 accruedRewards = _updateUserAssetInternal(user, msg.sender, userBalance, totalSupply);
if (accruedRewards != 0) {
_usersUnclaimedRewards[user] = _usersUnclaimedRewards[user] + accruedRewards;
emit RewardsAccrued(user, accruedRewards);
}
}
/// @inheritdoc IAaveIncentivesController
function getRewardsBalance(address[] calldata assets, address user)
external
view
override
returns (uint256)
{
uint256 unclaimedRewards = _usersUnclaimedRewards[user];
DistributionTypes.UserStakeInput[] memory userState = new DistributionTypes.UserStakeInput[](assets.length);
for (uint256 i = 0; i < assets.length;) {
userState[i].underlyingAsset = assets[i];
(userState[i].stakedByUser, userState[i].totalStaked) = _getScaledUserBalanceAndSupply(assets[i], user);
unchecked { i++; }
}
unclaimedRewards = unclaimedRewards + _getUnclaimedRewards(user, userState);
return unclaimedRewards;
}
/// @inheritdoc IAaveIncentivesController
function claimRewards(
address[] calldata assets,
uint256 amount,
address to
) external override returns (uint256) {
if (to == address(0)) revert InvalidToAddress();
return _claimRewards(assets, amount, msg.sender, msg.sender, to);
}
/// @inheritdoc IAaveIncentivesController
function claimRewardsOnBehalf(
address[] calldata assets,
uint256 amount,
address user,
address to
) external override onlyAuthorizedClaimers(msg.sender, user) returns (uint256) {
if (user == address(0)) revert InvalidUserAddress();
if (to == address(0)) revert InvalidToAddress();
return _claimRewards(assets, amount, msg.sender, user, to);
}
/// @inheritdoc IAaveIncentivesController
function claimRewardsToSelf(address[] calldata assets, uint256 amount)
external
override
returns (uint256)
{
return _claimRewards(assets, amount, msg.sender, msg.sender, msg.sender);
}
/// @inheritdoc IAaveIncentivesController
function setClaimer(address user, address caller) external override onlyEmissionManager {
_authorizedClaimers[user] = caller;
emit ClaimerSet(user, caller);
}
/// @inheritdoc IAaveIncentivesController
function getClaimer(address user) external view override returns (address) {
return _authorizedClaimers[user];
}
/// @inheritdoc IAaveIncentivesController
function getUserUnclaimedRewards(address _user) external view override returns (uint256) {
return _usersUnclaimedRewards[_user];
}
/**
* @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating the pending rewards
* @param amount Amount of rewards to claim
* @param user Address to check and claim rewards
* @param to Address that will be receiving the rewards
* @return Rewards claimed
*/
function _claimRewards(
address[] calldata assets,
uint256 amount,
address claimer,
address user,
address to
) internal returns (uint256) {
if (amount == 0) {
return 0;
}
uint256 unclaimedRewards = _usersUnclaimedRewards[user];
if (amount > unclaimedRewards) {
DistributionTypes.UserStakeInput[] memory userState = new DistributionTypes.UserStakeInput[](assets.length);
for (uint256 i = 0; i < assets.length;) {
userState[i].underlyingAsset = assets[i];
(userState[i].stakedByUser, userState[i].totalStaked) = _getScaledUserBalanceAndSupply(assets[i], user);
unchecked { i++; }
}
uint256 accruedRewards = _claimRewards(user, userState);
if (accruedRewards != 0) {
unclaimedRewards = unclaimedRewards + accruedRewards;
emit RewardsAccrued(user, accruedRewards);
}
}
if (unclaimedRewards == 0) {
return 0;
}
uint256 amountToClaim = amount > unclaimedRewards ? unclaimedRewards : amount;
unchecked { _usersUnclaimedRewards[user] = unclaimedRewards - amountToClaim; } // Safe due to the previous line
_transferRewards(to, amountToClaim);
emit RewardsClaimed(user, to, claimer, amountToClaim);
return amountToClaim;
}
/**
* @dev Abstract function to transfer rewards to the desired account
* @param to Account address to send the rewards
* @param amount Amount of rewards to transfer
*/
function _transferRewards(address to, uint256 amount) internal virtual;
function _getScaledUserBalanceAndSupply(address _asset, address _user)
internal
view
virtual
returns (uint256 userBalance, uint256 totalSupply);
}
Read Contract
DISTRIBUTION_END 0x919cd40f → uint256
EMISSION_MANAGER 0xcbcbb507 → address
PRECISION 0xaaf5eb68 → uint8
REVISION 0xdde43cba → uint256
REWARD_TOKEN 0x99248ea7 → address
TEN_POW_PRECISION 0x711ec9ac → uint256
assets 0xf11b8188 → uint104, uint104, uint40
getAssetData 0x1652e7b7 → uint256, uint256, uint256
getClaimer 0x74d945ec → address
getDistributionEnd 0xcc69afec → uint256
getRewardsBalance 0x8b599f26 → uint256
getUserAssetData 0x3373ee4c → uint256
getUserUnclaimedRewards 0x198fa81e → uint256
notificationReceiverPing 0x11279b4a → bytes4
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
claimRewards 0x3111e7b3
address[] assets
uint256 amount
address to
returns: uint256
claimRewardsOnBehalf 0x6d34b96e
address[] assets
uint256 amount
address user
address to
returns: uint256
claimRewardsToSelf 0x41485304
address[] assets
uint256 amount
returns: uint256
configureAssets 0x79f171b2
address[] assets
uint256[] emissionsPerSecond
handleAction 0x31873e2e
address user
uint256 totalSupply
uint256 userBalance
onAfterTransfer 0x0f1bf70d
address
address _from
address _to
uint256 _amount
rescueRewards 0x2b6995dc
No parameters
setClaimer 0xf5cf673b
address user
address caller
setDistributionEnd 0x39ccbdd3
uint256 distributionEnd
Recent Transactions
No transactions found for this address