Address Contract Verified
Address
0xa1B56E42137D06280E34B3E1352d80Ac3BECAF79
Balance
0.735678 ETH
Nonce
1
Code Size
5598 bytes
Creator
0xE05430D4...aE11 at tx 0x8d85c734...15d1f2
Indexed Transactions
0
Contract Bytecode
5598 bytes
0x6080604052600436106101d15760003560e01c8063817b1cd2116100f7578063d2a5276b11610095578063e6f0d1e911610064578063e6f0d1e9146105ba578063eded3fda146105d0578063ef3b9dd1146105e6578063feedab00146105fb57600080fd5b8063d2a5276b14610531578063e07335aa14610565578063e0b006951461057a578063e2bbb1581461059a57600080fd5b806393f1a40b116100d157806393f1a40b1461049d5780639dbc2d90146104dc578063c8ffb873146104f1578063cf3090121461050757600080fd5b8063817b1cd214610451578063841d9ac214610467578063900cf0cf1461048757600080fd5b80633f791deb1161016f5780635312ea8e1161013e5780635312ea8e146103f05780635d577c1814610410578063608c8d3a14610426578063630b5ba11461043c57600080fd5b80633f791deb1461033957806349c5468d1461038d5780634cf5fbf5146103a35780634dc47d34146103c357600080fd5b806317caf6f1116101ab57806317caf6f1146102a157806331b703db146102b757806333cfcd3b1461030357806335c62bc21461032357600080fd5b806303dec009146101e55780630ff350851461020d5780631526fe271461022357600080fd5b366101e0576101de610612565b005b600080fd5b3480156101f157600080fd5b506101fa610665565b6040519081526020015b60405180910390f35b34801561021957600080fd5b506101fa60085481565b34801561022f57600080fd5b5061027561023e3660046113d1565b600160208190526000918252604090912080549181015460028201546003909201546001600160a01b039093169290919060ff1684565b604080516001600160a01b03909516855260208501939093529183015215156060820152608001610204565b3480156102ad57600080fd5b506101fa60035481565b3480156102c357600080fd5b506102eb7f00000000000000000000000070536d44820fe3ddd4a2e3eedbc937b8b9d566c781565b6040516001600160a01b039091168152602001610204565b34801561030f57600080fd5b506101de61031e3660046113f8565b610687565b34801561032f57600080fd5b506101fa60005481565b34801561034557600080fd5b5061037861035436600461144d565b60046020908152600092835260408084209091529082529020805460019091015482565b60408051928352602083019190915201610204565b34801561039957600080fd5b506101fa600a5481565b3480156103af57600080fd5b506101de6103be366004611479565b6106d4565b3480156103cf57600080fd5b506101fa6103de3660046113d1565b600f6020526000908152604090205481565b3480156103fc57600080fd5b506101de61040b3660046113d1565b610808565b34801561041c57600080fd5b506101fa600b5481565b34801561043257600080fd5b506101fa600d5481565b34801561044857600080fd5b506101de6108f5565b34801561045d57600080fd5b506101fa60095481565b34801561047357600080fd5b506101de6104823660046113d1565b61093f565b34801561049357600080fd5b506101fa600e5481565b3480156104a957600080fd5b506103786104b836600461144d565b60026020908152600092835260408084209091529082529020805460019091015482565b3480156104e857600080fd5b506101fa610a14565b3480156104fd57600080fd5b506101fa600c5481565b34801561051357600080fd5b506007546105219060ff1681565b6040519015158152602001610204565b34801561053d57600080fd5b506102eb7f000000000000000000000000e05430d42842c7b757e5633d19ca65350e01ae1181565b34801561057157600080fd5b506101de610612565b34801561058657600080fd5b506101fa61059536600461144d565b610a3e565b3480156105a657600080fd5b506101de6105b53660046114ac565b610aa8565b3480156105c657600080fd5b506101fa60065481565b3480156105dc57600080fd5b506101fa60055481565b3480156105f257600080fd5b506101de610bc9565b34801561060757600080fd5b506101fa6201518081565b61061a610bc9565b60006006544761062a91906114e4565b9050801561066257476006556005546106449082906114f7565b60058190555080600d600082825461065c91906114f7565b90915550505b50565b6000600b544361067591906114e4565b600d54610682919061150a565b905090565b60075460ff16156106ab576040516303cb96db60e21b815260040160405180910390fd5b6007805460ff191660011790556106c58383338085610c30565b50506007805460ff1916905550565b60075460ff16156106f8576040516303cb96db60e21b815260040160405180910390fd5b6007805460ff19166001908117909155600083815260209182526040808220600284528183206001600160a01b038816845290935290206107376108f5565b6107418486610f8c565b821561079157815461075e906001600160a01b0316333086611095565b8281600001600082825461077291906114f7565b92505081905550826009600082825461078b91906114f7565b90915550505b6002820154815464e8d4a51000916107a89161152c565b6107b2919061150a565b600182015560405183815284906001600160a01b038716907f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a159060200160405180910390a350506007805460ff19169055505050565b60075460ff161561082c576040516303cb96db60e21b815260040160405180910390fd5b6007805460ff19166001908117909155600082815260209190915260409020600381015460ff16610870576040516337ae717b60e01b815260040160405180910390fd5b60008281526002602090815260408083203380855292529091208054835491926108a3926001600160a01b031691611102565b8054604051908152839033907fbb757047c2b5f3974fe26b7c10f732e7bce710b0952a71082702781e62ae05959060200160405180910390a3600080825560019091015550506007805460ff19169055565b6000805490805b828110156109295761090d81611138565b61091790836114f7565b915061092281611543565b90506108fc565b508060055461093891906114e4565b6005555050565b60008181526001602081815260408084206004835281852033865290925290922090810154158061096f57508054155b1561098d576040516333ff64eb60e21b815260040160405180910390fd5b80600101544210156109b25760405163b0782df760e01b815260040160405180910390fd5b8054600060018301819055825582546109d5906001600160a01b03163383611102565b8154604051908152849033907ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5689060200160405180910390a350505050565b6000600a5443610a2491906114e4565b600d54600c54610a3491906114f7565b610682919061150a565b600082815260016020818152604080842060028084528286206001600160a01b03881687529093529084209181015492820154825491939164e8d4a5100090610a8890849061152c565b610a92919061150a565b610a9c91906114e4565b93505050505b92915050565b60075460ff1615610acc576040516303cb96db60e21b815260040160405180910390fd5b6007805460ff19166001908117909155600083815260209182526040808220600284528183203384529093529020610b026108f5565b610b0c8433610f8c565b8215610b5c578154610b29906001600160a01b0316333086611095565b82816000016000828254610b3d91906114f7565b925050819055508260096000828254610b5691906114f7565b90915550505b6002820154815464e8d4a5100091610b739161152c565b610b7d919061150a565b6001820155604051838152849033907f90890809c654f11d6e72a28fa60149770a0d11ec6c92319d6ceb2bb0a4ea1a159060200160405180910390a350506007805460ff191690555050565b43600b5461c350610bda91906114f7565b1015610c2e57600d54600e546000908152600f60205260408120829055600c8054909190610c099084906114f7565b90915550506000600d81905543600b55600e8054909190610c2990611543565b909155505b565b6000858152600160205260409020600381015460ff16610c63576040516337ae717b60e01b815260040160405180910390fd5b60008681526002602090815260408083206001600160a01b038816845290915290208054861115610ca75760405163caccb6d960e01b815260040160405180910390fd5b85610cb06108f5565b610cba8887610f8c565b600088815260046020908152604080832033845290915290208715610f1a5780600101544210158015610cf05750600181015415155b15610cfe57610cfe8961093f565b8254610d0b9089906114e4565b835560098054899190600090610d229084906114e4565b90915550508415610d4d57612710610d3c89611d4c61152c565b610d46919061150a565b9150610e2e565b8060010154600003610e15576000610d6862015180426114f7565b6040805180820182528b8152602080820184815260008f8152600483528481203382529092529290209051815590516001909101556002860154855491925064e8d4a5100091610db8919061152c565b610dc2919061150a565b6001850155604080518a8152602081018390526001600160a01b038a16917fd72eb5d043f24a0168ae744d5c44f9596fd673a26bf74d9646bff4b844882d14910160405180910390a25050505050610f85565b60405163b0782df760e01b815260040160405180910390fd5b8354610e44906001600160a01b03168784611102565b87821015610f1a576000610e58838a6114e4565b60405163a9059cbb60e01b815273deadbeefdeadbeefdeadbeefdeadbeefdeadbeef6004820152602481018290529091507f00000000000000000000000070536d44820fe3ddd4a2e3eedbc937b8b9d566c76001600160a01b03169063a9059cbb906044016020604051808303816000875af1158015610edc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f00919061155c565b508060086000828254610f1391906114f7565b9091555050505b6002840154835464e8d4a5100091610f319161152c565b610f3b919061150a565b600184015560405188815289906001600160a01b038816907ff279e6a1f5e320cca91135676d9cb6e44ca8a08c0b88342bcdb1144f6511b5689060200160405180910390a3505050505b5050505050565b6000610f988383610a3e565b90508015610faa57610faa82826111b5565b7f000000000000000000000000e05430d42842c7b757e5633d19ca65350e01ae116001600160a01b031663c87965726040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561100557600080fd5b505af1158015611019573d6000803e3d6000fd5b505050507f000000000000000000000000e05430d42842c7b757e5633d19ca65350e01ae116001600160a01b031663930ffbe36040518163ffffffff1660e01b8152600401600060405180830381600087803b15801561107857600080fd5b505af115801561108c573d6000803e3d6000fd5b50505050505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526110fc9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611232565b50505050565b6040516001600160a01b0383811660248301526044820183905261113391859182169063a9059cbb906064016110ca565b505050565b600081815260016020526040812060095482036111585750600092915050565b600354816001015460055461116d919061152c565b611177919061150a565b60095490925061118c8364e8d4a5100061152c565b611196919061150a565b8160020160008282546111a991906114f7565b90915550919392505050565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611202576040519150601f19603f3d011682016040523d82523d6000602084013e611207565b606091505b5050905080611229576040516350490ba960e01b815260040160405180910390fd5b50504760065550565b60006112476001600160a01b0384168361129a565b9050805160001415801561126c57508080602001905181019061126a919061155c565b155b1561113357604051635274afe760e01b81526001600160a01b03841660048201526024015b60405180910390fd5b60606112a8838360006112af565b9392505050565b6060814710156112d45760405163cd78605960e01b8152306004820152602401611291565b600080856001600160a01b031684866040516112f09190611579565b60006040518083038185875af1925050503d806000811461132d576040519150601f19603f3d011682016040523d82523d6000602084013e611332565b606091505b509150915061134286838361134c565b9695505050505050565b6060826113615761135c826113a8565b6112a8565b815115801561137857506001600160a01b0384163b155b156113a157604051639996b31560e01b81526001600160a01b0385166004820152602401611291565b50806112a8565b8051156113b85780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b6000602082840312156113e357600080fd5b5035919050565b801515811461066257600080fd5b60008060006060848603121561140d57600080fd5b83359250602084013591506040840135611426816113ea565b809150509250925092565b80356001600160a01b038116811461144857600080fd5b919050565b6000806040838503121561146057600080fd5b8235915061147060208401611431565b90509250929050565b60008060006060848603121561148e57600080fd5b61149784611431565b95602085013595506040909401359392505050565b600080604083850312156114bf57600080fd5b50508035926020909101359150565b634e487b7160e01b600052601160045260246000fd5b81810381811115610aa257610aa26114ce565b80820180821115610aa257610aa26114ce565b60008261152757634e487b7160e01b600052601260045260246000fd5b500490565b8082028115828204841417610aa257610aa26114ce565b600060018201611555576115556114ce565b5060010190565b60006020828403121561156e57600080fd5b81516112a8816113ea565b6000825160005b8181101561159a5760208186018101518583015201611580565b50600092019182525091905056fea2646970667358221220f135a5b16279139ce9c2124f2e1290083f264d8df3c60a063f7f32b1d25d71d464736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
NXDStakingVault.sol 384 lines
pragma solidity >=0.8.0;
import "./interfaces/INXDProtocol.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract NXDStakingVault {
using SafeERC20 for IERC20;
error PoolAlreadyAdded();
error InvalidAmount();
error SendETHFail();
error NoRequest();
error Cooldown();
error Underflow();
error Locked();
error WithdrawDisabled();
event Add(address indexed token, uint256 indexed pid, uint256 allocPoint, bool withdrawable);
event Deposit(address indexed user, uint256 indexed pid, uint256 amount);
event Withdraw(address indexed user, uint256 indexed pid, uint256 amount);
event EmergencyWithdraw(address indexed user, uint256 indexed pid, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 _pid, uint256 value);
event WithdrawRequested(address indexed user, uint256 amount, uint256 canWithdrawAfterTimestamp);
// Info of each user.
struct UserInfo {
uint256 amount; // How many tokens the user has provided.
uint256 rewardDebt; // Reward debt. See explanation below.
//
// We do some fancy math here. Basically, any point in time, the amount of ETHs
// entitled to a user but is pending to be distributed is:
//
// pending reward = (user.amount * pool.accEthPerShare) - user.rewardDebt
//
// Whenever a user deposits or withdraws tokens to a pool. Here's what happens:
// 1. The pool's `accEthPerShare` (and `lastRewardBlock`) gets updated.
// 2. User receives the pending reward sent to his/her address.
// 3. User's `amount` gets updated.
// 4. User's `rewardDebt` gets updated.
}
// Info of each pool.
struct PoolInfo {
IERC20 token; // Address of token contract.
uint256 allocPoint; // How many allocation points assigned to this pool. ETHs to distribute per block.
uint256 accEthPerShare; // Accumulated ETHs per share, times 1e12. See below.
bool withdrawable; // Is this pool withdrawable?
}
// Info of each pool.
uint256 public numPools;
mapping(uint256 => PoolInfo) public poolInfo;
mapping(uint256 => mapping(address => UserInfo)) public userInfo;
// Total allocation poitns. Must be the sum of all allocation points in all pools.
uint256 public totalAllocPoint;
// pid => owner => timestamp
// mapping(uint256 => mapping(address => uint256)) public canWithdrawAfter;
struct WithdrawalRequest {
uint256 amount;
uint256 canWithdrawAfterTimestamp;
}
// pid => owner => WithdrawalRequest
mapping(uint256 => mapping(address => WithdrawalRequest)) public withdrawalRequests;
uint256 public constant WITHDRAWAL_COOLDOWN = 1 days;
//// pending rewards awaiting anyone to massUpdate
uint256 public pendingRewards;
// The NXD TOKEN!
IERC20 public immutable nxd;
INXDProtocol public immutable nxdProtocol;
// keep track of latest known eth balance. used to determine new rewards
uint256 public ourETHBalance;
bool public locked;
uint256 public nxdPenaltyBurned;
uint256 public totalStaked;
// variables used to calculate rewards apy
uint256 public contractStartBlock;
uint256 public epochCalculationStartBlock;
uint256 public cumulativeRewardsSinceStart;
uint256 public rewardsInThisEpoch;
uint256 public epoch;
// Returns fees generated since start of this contract
function averageFeesPerBlockSinceStart() external view returns (uint256 averagePerBlock) {
averagePerBlock = (cumulativeRewardsSinceStart + rewardsInThisEpoch) / (block.number - (contractStartBlock));
}
// Returns averge fees in this epoch
function averageFeesPerBlockEpoch() external view returns (uint256 averagePerBlock) {
averagePerBlock = rewardsInThisEpoch / (block.number - epochCalculationStartBlock);
}
// For easy graphing historical epoch rewards
mapping(uint256 => uint256) public epochRewards;
//Starts a new calculation epoch
// Because averge since start will not be accurate
function startNewEpochIfReady() public {
if (epochCalculationStartBlock + 50000 < block.number) {
epochRewards[epoch] = rewardsInThisEpoch;
cumulativeRewardsSinceStart += rewardsInThisEpoch;
rewardsInThisEpoch = 0;
epochCalculationStartBlock = block.number;
++epoch;
}
}
// Reentrancy lock
modifier lock() {
if (locked) {
revert Locked();
}
locked = true;
_;
locked = false;
}
constructor(IERC20 _nxd) {
nxd = _nxd;
nxdProtocol = INXDProtocol(msg.sender);
_add(100, _nxd, false, true);
contractStartBlock = block.number;
startNewEpochIfReady();
}
// Add a new token pool. Can only be when contract is deployed.
function _add(uint256 _allocPoint, IERC20 _token, bool _withUpdate, bool _withdrawable) internal {
if (_withUpdate) {
massUpdatePools();
}
uint256 length = numPools;
for (uint256 pid = 0; pid < length; ++pid) {
if (poolInfo[pid].token == _token) {
revert PoolAlreadyAdded();
}
}
totalAllocPoint = totalAllocPoint + _allocPoint;
PoolInfo storage _poolInfo = poolInfo[length];
_poolInfo.token = _token;
_poolInfo.allocPoint = _allocPoint;
_poolInfo.accEthPerShare = 0;
_poolInfo.withdrawable = _withdrawable;
numPools += 1;
emit Add(address(_token), length, _allocPoint, _withdrawable);
}
// View function to see pending ETHs on frontend.
function pendingETH(uint256 _pid, address _user) public view returns (uint256) {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_user];
uint256 accEthPerShare = pool.accEthPerShare;
return ((user.amount * accEthPerShare) / 1e12) - user.rewardDebt;
}
// Update reward vairables for all pools. Be careful of gas spending!
function massUpdatePools() public {
uint256 length = numPools;
uint256 allRewards;
for (uint256 pid = 0; pid < length; ++pid) {
allRewards = allRewards + updatePool(pid);
}
pendingRewards = pendingRewards - allRewards;
}
function addPendingRewards() public {
startNewEpochIfReady();
uint256 newRewards = address(this).balance - ourETHBalance;
if (newRewards > 0) {
ourETHBalance = address(this).balance; // If there is no change the balance didn't change
pendingRewards = pendingRewards + newRewards;
rewardsInThisEpoch += newRewards;
}
}
// Update reward variables of the given pool to be up-to-date.
function updatePool(uint256 _pid) internal returns (uint256 ethReward) {
PoolInfo storage pool = poolInfo[_pid];
if (totalStaked == 0) {
// avoids division by 0 errors
return 0;
}
ethReward = (pendingRewards * pool.allocPoint) // Multiplies pending rewards by allocation point of this pool and then total allocation
// getting the percent of total pending rewards this pool should get
/ totalAllocPoint; // we can do this because pools are only mass updated
pool.accEthPerShare += ((ethReward * 1e12) / totalStaked);
}
// Deposit NXD tokens to NXDStakingVault for ETH allocation.
function deposit(uint256 _pid, uint256 _amount) public lock {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][msg.sender];
massUpdatePools();
// Transfer pending tokens
// to user
updateAndPayOutPending(_pid, msg.sender);
//Transfer in the amounts from user
// save gas
if (_amount > 0) {
pool.token.safeTransferFrom(address(msg.sender), address(this), _amount);
user.amount += _amount;
totalStaked += _amount;
}
user.rewardDebt = (user.amount * pool.accEthPerShare) / 1e12;
emit Deposit(msg.sender, _pid, _amount);
}
// Test coverage
// [x] Does user get the deposited amounts?
// [x] Does user that its deposited for update correcty?
// [x] Does the depositor get their tokens decreased
function depositFor(address _depositFor, uint256 _pid, uint256 _amount) public lock {
PoolInfo storage pool = poolInfo[_pid];
UserInfo storage user = userInfo[_pid][_depositFor];
massUpdatePools();
// Transfer pending tokens
// to user
updateAndPayOutPending(_pid, _depositFor); // Update the balances of person that amount is being deposited for
if (_amount > 0) {
pool.token.safeTransferFrom(address(msg.sender), address(this), _amount);
user.amount += _amount; // This is depositedFor address
totalStaked += _amount;
}
user.rewardDebt = (user.amount * pool.accEthPerShare) / 1e12;
/// This is deposited for address
emit Deposit(_depositFor, _pid, _amount);
}
// Withdraw tokens from NXDStakingVault.
function withdraw(uint256 _pid, uint256 _amount, bool acceptsPenalty) public lock {
_withdraw(_pid, _amount, msg.sender, msg.sender, acceptsPenalty);
}
// Low level withdraw function
function _withdraw(uint256 _pid, uint256 _amount, address from, address to, bool acceptsPenalty) internal {
PoolInfo storage pool = poolInfo[_pid];
if (!pool.withdrawable) {
revert WithdrawDisabled();
}
UserInfo storage user = userInfo[_pid][from];
if (user.amount < _amount) {
revert Underflow();
}
uint256 userGetsAfterPenalty = _amount;
massUpdatePools();
updateAndPayOutPending(_pid, from); // Update balances of from. This is not withdrawal but claiming ETH farmed
WithdrawalRequest storage request = withdrawalRequests[_pid][msg.sender];
if (_amount > 0) {
if (block.timestamp >= request.canWithdrawAfterTimestamp && request.canWithdrawAfterTimestamp != 0) {
withdrawCooldown(_pid);
}
// Stop receiving rewards for this amount NOW
user.amount = user.amount - _amount;
totalStaked -= _amount;
if (acceptsPenalty) {
userGetsAfterPenalty = (_amount * 7500) / 10000;
} else {
// 0 means Needs to wait 24 hours
if (request.canWithdrawAfterTimestamp == 0) {
uint256 timestamp = block.timestamp + WITHDRAWAL_COOLDOWN;
withdrawalRequests[_pid][msg.sender] = WithdrawalRequest(_amount, timestamp);
user.rewardDebt = (user.amount * pool.accEthPerShare) / 1e12;
emit WithdrawRequested(from, _amount, timestamp);
return;
} else {
revert Cooldown();
}
}
// If we are here we can withdraw
pool.token.safeTransfer(address(to), userGetsAfterPenalty);
// Burn penalty amount
if (userGetsAfterPenalty < _amount) {
uint256 amountToBurn = _amount - userGetsAfterPenalty;
nxd.transfer(0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF, amountToBurn);
nxdPenaltyBurned += amountToBurn;
}
}
user.rewardDebt = (user.amount * pool.accEthPerShare) / 1e12;
emit Withdraw(to, _pid, _amount);
}
/**
* @notice Withdraws the amount requested if the cooldown period has passed. If the user has not requested a withdrawal or the cooldown period has not passed, the function reverts.
* @param _pid The pool id.
*/
function withdrawCooldown(uint256 _pid) public {
PoolInfo storage pool = poolInfo[_pid];
WithdrawalRequest storage request = withdrawalRequests[_pid][msg.sender];
if (request.canWithdrawAfterTimestamp == 0 || request.amount == 0) {
revert NoRequest();
}
if (block.timestamp < request.canWithdrawAfterTimestamp) {
revert Cooldown();
}
uint256 amount = request.amount;
request.canWithdrawAfterTimestamp = 0;
request.amount = 0;
pool.token.safeTransfer(msg.sender, amount);
emit Withdraw(msg.sender, _pid, request.amount);
}
function updateAndPayOutPending(uint256 _pid, address from) internal {
uint256 pending = pendingETH(_pid, from);
if (pending > 0) {
safeETHTransfer(from, pending);
}
nxdProtocol.collectFees();
nxdProtocol.stakeOurDXN();
}
// Withdraw without caring about rewards. EMERGENCY ONLY.
// !Caution this will remove all your pending rewards!
function emergencyWithdraw(uint256 _pid) public lock {
PoolInfo storage pool = poolInfo[_pid];
if (!pool.withdrawable) {
revert WithdrawDisabled();
}
UserInfo storage user = userInfo[_pid][msg.sender];
pool.token.safeTransfer(address(msg.sender), user.amount);
emit EmergencyWithdraw(msg.sender, _pid, user.amount);
user.amount = 0;
user.rewardDebt = 0;
// No mass update dont update pending rewards
}
// Safe eth transfer function
function safeETHTransfer(address _to, uint256 _amount) internal {
(bool sent,) = _to.call{value: _amount}("");
if (!sent) {
revert SendETHFail();
}
ourETHBalance = address(this).balance;
//Avoids possible recursion loop
// proxy?
}
/**
* @dev Receives ETH from NXDProtocol and updates pending rewards.
*/
receive() external payable {
addPendingRewards();
}
}
INXDProtocol.sol 7 lines
pragma solidity ^0.8.13;
interface INXDProtocol {
function depositNoMint(uint256 _amount) external;
function collectFees() external;
function stakeOurDXN() external;
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @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);
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
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);
}
SafeERC20.sol 173 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.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 {
using Address for address;
/**
* @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 Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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.
*/
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.
*/
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).
*/
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);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
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 silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// 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 cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @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);
}
Read Contract
WITHDRAWAL_COOLDOWN 0xfeedab00 → uint256
averageFeesPerBlockEpoch 0x03dec009 → uint256
averageFeesPerBlockSinceStart 0x9dbc2d90 → uint256
contractStartBlock 0x49c5468d → uint256
cumulativeRewardsSinceStart 0xc8ffb873 → uint256
epoch 0x900cf0cf → uint256
epochCalculationStartBlock 0x5d577c18 → uint256
epochRewards 0x4dc47d34 → uint256
locked 0xcf309012 → bool
numPools 0x35c62bc2 → uint256
nxd 0x31b703db → address
nxdPenaltyBurned 0x0ff35085 → uint256
nxdProtocol 0xd2a5276b → address
ourETHBalance 0xe6f0d1e9 → uint256
pendingETH 0xe0b00695 → uint256
pendingRewards 0xeded3fda → uint256
poolInfo 0x1526fe27 → address, uint256, uint256, bool
rewardsInThisEpoch 0x608c8d3a → uint256
totalAllocPoint 0x17caf6f1 → uint256
totalStaked 0x817b1cd2 → uint256
userInfo 0x93f1a40b → uint256, uint256
withdrawalRequests 0x3f791deb → uint256, uint256
Write Contract 8 functions
These functions modify contract state and require a wallet transaction to execute.
addPendingRewards 0xe07335aa
No parameters
deposit 0xe2bbb158
uint256 _pid
uint256 _amount
depositFor 0x4cf5fbf5
address _depositFor
uint256 _pid
uint256 _amount
emergencyWithdraw 0x5312ea8e
uint256 _pid
massUpdatePools 0x630b5ba1
No parameters
startNewEpochIfReady 0xef3b9dd1
No parameters
withdraw 0x33cfcd3b
uint256 _pid
uint256 _amount
bool acceptsPenalty
withdrawCooldown 0x841d9ac2
uint256 _pid
Recent Transactions
No transactions found for this address