Skip to content

Commit b94583c

Browse files
committed
save work before resetting computer
1 parent b06b9a7 commit b94583c

File tree

4 files changed

+126
-19
lines changed

4 files changed

+126
-19
lines changed

remappings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
ds-test/=lib/forge-std/lib/ds-test/src/
22
forge-std/=lib/forge-std/src/
33
solmate/=lib/solmate/src/
4+
openzeppelin/=lib/openzeppelin-contracts/contracts
5+

src/Safu.sol

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,97 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.13;
33

4+
import "openzeppelin/token/ERC20/IERC20.sol";
5+
46
interface SafuLike {
57
// Record that white-hat has deposited funds.
68
function deposit(address erc20, uint256 wad) external;
79

810
// all eligible bounties for msg.sender are transfered
9-
function withdraw() external;
11+
function claim() external;
12+
13+
function bounty(uint16 id) external returns (uint256 amt, bool approved);
14+
15+
function approveBounty(uint16 id) external;
1016
}
1117

1218
contract SimpleSafu {
13-
struct Deposit {
14-
IERC20 token
15-
19+
struct Receipt {
20+
uint16 id;
21+
IERC20 token;
22+
uint256 amt;
23+
uint256 blockTime;
24+
bool rewardApproved;
1625
}
1726

1827
address[] public depositors;
19-
mapping(address => )
28+
mapping(address => Receipt[]) depositorToReceipts;
29+
mapping(IERC20 => uint256) public tokenToBountyCap;
30+
mapping(IERC20 => uint256) public tokenToTotalDeposited;
31+
mapping(IERC20 => uint256) public tokenToBountyWithdrawn;
32+
uint256 public immutable defaultBountyCap;
33+
uint256 public immutable minDelay;
34+
uint256 public immutable maxDelay;
35+
uint8 public immutable bountyPercent;
36+
37+
bool public rewardsClaimable;
38+
bool public autoApprove;
39+
40+
constructor(
41+
uint256 _defaultBountyCap,
42+
uint256 _minDelay,
43+
uint256 _maxDelay,
44+
uint8 _bountyPercent,
45+
bool _rewardsClaimable,
46+
bool _autoApprove
47+
) {
48+
defaultBountyCap = _defaultBountyCap;
49+
minDelay = _minDelay;
50+
maxDelay = _maxDelay;
51+
bountyPercent = _bountyPercent;
52+
rewardsClaimable = _rewardsClaimable;
53+
autoApprove = _autoApprove;
54+
}
55+
56+
function deposit(address _erc20, uint256 wad) external {
57+
require(wad > 0, "Safu/zero-deposit");
58+
depositors.push(msg.sender);
59+
IERC20 erc20 = IERC20(_erc20);
60+
61+
uint256 prevTotalBounty = tokenToTotalDeposited[erc20] -
62+
tokenToBountyWithdrawn[erc20];
63+
// if (prevTotalBounty + )
64+
}
65+
66+
function bounty(address guy, uint16 id) public view returns (uint256 amt, bool approved) {
67+
Receipt memory receipt = getReceipt(guy, id);
68+
approved = receipt.rewardApproved;
69+
if ()
70+
}
71+
72+
function bounty(uint16 id) public view returns (uint256 amt, bool approved) {
73+
return bounty(msg.sender, id);
74+
}
75+
76+
function getReceipt(address depositor, uint16 id)
77+
public
78+
view
79+
returns (Receipt memory)
80+
{
81+
Receipt[] storage deposits = depositorToReceipts[depositor];
82+
for (uint256 i = 0; i < deposits.length; ++i) {
83+
if (deposits[i].id == id) {
84+
return deposits[i];
85+
}
86+
}
87+
revert("Safu/deposit-not-found-for-id-address-pair");
88+
}
2089
}
2190

2291
/*
2392
pro rata with cap per token
2493
mapping : token -> cap
25-
mapping : token -> percentOfDepositWithdrawable
94+
mapping : token -> percentOfReceiptWithdrawable
2695
2796
depositor delay
2897
@@ -33,4 +102,4 @@ sender
33102
34103
each deposit keyed by (sender addr, blocktime)
35104
36-
*/
105+
*/

test/Safu.sol

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/Safu.t.sol

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import "forge-std/Test.sol";
5+
import "openzeppelin/token/ERC20/IERC20.sol";
6+
import "openzeppelin/token/ERC20/ERC20.sol";
7+
import "../src/Safu.sol";
8+
9+
contract DummyERC20 is ERC20 {
10+
constructor(string memory name_, string memory symbol_)
11+
ERC20(name_, symbol_)
12+
{}
13+
14+
function mint(address account, uint256 amount) external {
15+
_mint(account, amount);
16+
}
17+
}
18+
19+
contract SimpleSafuTest is Test {
20+
SimpleSafu safu;
21+
IERC20 erc20;
22+
23+
function setUp() public {
24+
DummyERC20 _erc20 = new DummyERC20("testERC20", "TBD");
25+
_erc20.mint(address(this), 1_000_000);
26+
erc20 = _erc20;
27+
}
28+
29+
function defaultSafu() SimpleSafu internal {
30+
uint256 defaultBountyCap = 10;
31+
uint256 minDelay = 10;
32+
uint256 maxDelay = 20;
33+
uint8 bountyPercent = 50;
34+
safu = new SimpleSafu(
35+
defaultBountyCap,
36+
minDelay,
37+
maxDelay,
38+
bountyPercent
39+
);
40+
}
41+
42+
function testDepositSuccess() public {
43+
44+
erc20.approve(address(this), 2_000);
45+
safu.deposit(address(erc20), 2_000);
46+
assertEq(safu.tokenToBountyCap(erc20), defaultBountyCap);
47+
}
48+
}

0 commit comments

Comments
 (0)