forked from ciaranmcveigh5/ethernaut-x-foundry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Denial.sol
39 lines (32 loc) · 1.38 KB
/
Denial.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
import "openzeppelin-contracts/contracts/utils/math/SafeMath.sol";
contract Denial {
using SafeMath for uint256;
address public partner; // withdrawal partner - pay the gas, split the withdraw
// Foundry: wrapped address in "payable" to avoid error
address payable public constant owner = payable(address(0xA9E));
uint256 timeLastWithdrawn;
mapping(address => uint256) withdrawPartnerBalances; // keep track of partners balances
function setWithdrawPartner(address _partner) public {
partner = _partner;
}
// withdraw 1% to recipient and 1% to owner
function withdraw() public {
uint256 amountToSend = address(this).balance.div(100);
// perform a call without checking return
// The recipient can revert, the owner will still get their share
partner.call{ value: amountToSend }("");
owner.transfer(amountToSend);
// keep track of last withdrawal time
// Foundry: changed from "now" as it is deprecated
timeLastWithdrawn = block.timestamp;
withdrawPartnerBalances[partner] = withdrawPartnerBalances[partner].add(amountToSend);
}
// allow deposit of funds
receive() external payable { }
// convenience function
function contractBalance() public view returns (uint256) {
return address(this).balance;
}
}