Skip to content

Commit 87a081d

Browse files
authored
Merge pull request #24 from webb-tools/drew-token-updates
Update tokens, contract names, tests
2 parents a06341c + e5a1057 commit 87a081d

24 files changed

+407
-529
lines changed

contracts/anchors/bridged/LinkableCompTokenAnchorPoseidon2.sol renamed to contracts/anchors/bridged/2/Anchor2.sol

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
pragma solidity ^0.8.0;
77

8-
import "../../tokens/TokenWrapper.sol";
9-
import "./LinkableAnchorPoseidon2.sol";
8+
import "../../../tokens/TokenWrapper.sol";
9+
import "../../../interfaces/IMintableERC20.sol";
10+
import "./LinkableAnchor2.sol";
1011
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
1112
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
1213

13-
contract LinkableCompTokenAnchorPoseidon2 is LinkableAnchorPoseidon2 {
14+
contract Anchor2 is LinkableAnchor2 {
1415
using SafeERC20 for IERC20;
1516
address public immutable token;
1617

@@ -20,22 +21,25 @@ contract LinkableCompTokenAnchorPoseidon2 is LinkableAnchorPoseidon2 {
2021
uint256 _denomination,
2122
uint32 _merkleTreeHeight,
2223
uint32 _chainID,
23-
TokenWrapper _token
24-
) LinkableAnchorPoseidon2(_verifier, _hasher, _denomination, _merkleTreeHeight, _chainID) {
24+
TokenWrapper _token,
25+
address _bridge,
26+
address _admin,
27+
address _handler
28+
) LinkableAnchor2(_verifier, _hasher, _denomination, _merkleTreeHeight, _chainID, _bridge, _admin, _handler) {
2529
token = address(_token);
2630
}
2731

2832
function wrap(address tokenAddress, uint256 amount) public {
29-
TokenWrapper(token).wrap(msg.sender, tokenAddress, amount);
33+
TokenWrapper(token).wrapFor(msg.sender, tokenAddress, amount);
3034
}
3135

3236
function unwrap(address tokenAddress, uint256 amount) public {
33-
TokenWrapper(token).unwrap(msg.sender, tokenAddress, amount);
37+
TokenWrapper(token).unwrapFor(msg.sender, tokenAddress, amount);
3438
}
3539

3640
function _processDeposit() internal override {
3741
require(msg.value == 0, "ETH value is supposed to be 0 for ERC20 instance");
38-
IMintableCompToken(token).transferFrom(msg.sender, address(this), denomination);
42+
IMintableERC20(token).transferFrom(msg.sender, address(this), denomination);
3943
}
4044

4145
function _processWithdraw(
@@ -46,15 +50,19 @@ contract LinkableCompTokenAnchorPoseidon2 is LinkableAnchorPoseidon2 {
4650
) internal override {
4751
require(msg.value == _refund, "Incorrect refund amount received by the contract");
4852

49-
if (IERC20(token).balanceOf(address(this)) == 0) {
50-
IMintableCompToken(token).mint(_recipient, denomination - _fee);
53+
uint balance = IERC20(token).balanceOf(address(this));
54+
55+
if (balance >= denomination) {
56+
// transfer tokens when balance exists
57+
IERC20(token).safeTransfer(_recipient, denomination - _fee);
5158
if (_fee > 0) {
52-
IMintableCompToken(token).mint(_relayer, _fee);
59+
IERC20(token).safeTransfer(_relayer, _fee);
5360
}
5461
} else {
55-
IERC20(token).safeTransfer(_recipient, denomination - _fee);
62+
// mint tokens when not enough balance exists
63+
IMintableERC20(token).mint(_recipient, denomination - _fee);
5664
if (_fee > 0) {
57-
IERC20(token).safeTransfer(_relayer, _fee);
65+
IMintableERC20(token).mint(_relayer, _fee);
5866
}
5967
}
6068

contracts/anchors/bridged/AnchorPoseidon2.sol renamed to contracts/anchors/bridged/2/AnchorBase2.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
pragma solidity ^0.8.0;
77

8-
import "../../trees/MerkleTreePoseidon.sol";
8+
import "../../../trees/MerkleTreePoseidon.sol";
99
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
1010

1111
interface IVerifier {
@@ -17,7 +17,7 @@ interface IVerifier {
1717
) external view returns (bool r);
1818
}
1919

20-
abstract contract AnchorPoseidon2 is MerkleTreePoseidon, ReentrancyGuard {
20+
abstract contract AnchorBase2 is MerkleTreePoseidon, ReentrancyGuard {
2121
address public bridge;
2222
address public admin;
2323
address public handler;

contracts/anchors/bridged/LinkableAnchorPoseidon2.sol renamed to contracts/anchors/bridged/2/LinkableAnchor2.sol

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55

66
pragma solidity ^0.8.0;
77

8-
import "./AnchorPoseidon2.sol";
9-
import "../../interfaces/ILinkableAnchor.sol";
8+
import "./AnchorBase2.sol";
9+
import "../../../interfaces/ILinkableAnchor.sol";
1010

11-
abstract contract LinkableAnchorPoseidon2 is AnchorPoseidon2, ILinkableAnchor {
11+
abstract contract LinkableAnchor2 is AnchorBase2, ILinkableAnchor {
1212
constructor(
1313
IVerifier _verifier,
1414
IPoseidonT3 _hasher,
1515
uint256 _denomination,
1616
uint32 _merkleTreeHeight,
17-
uint256 _chainID
18-
) AnchorPoseidon2(_verifier, _hasher, _denomination, _merkleTreeHeight, _chainID) {
19-
// set the sender as admin & bridge & handler address
20-
// TODO: Properly set addresses and permissions
21-
bridge = msg.sender;
22-
admin = msg.sender;
23-
handler = msg.sender;
17+
uint256 _chainID,
18+
address _bridge,
19+
address _admin,
20+
address _handler
21+
) AnchorBase2(_verifier, _hasher, _denomination, _merkleTreeHeight, _chainID) {
22+
bridge = _bridge;
23+
admin = _admin;
24+
handler = _handler;
2425
}
2526

2627
function setHandler(address _handler) onlyBridge override external {

contracts/anchors/bridged/AnchorFactoryPoseidon.sol

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
pragma solidity ^0.8.0;
77

8-
import "./LinkableERC20AnchorPoseidon2.sol";
8+
import "./2/Anchor2.sol";
99

1010
contract AnchorFactoryPoseidon {
1111
function createAnchor2(
@@ -14,15 +14,21 @@ contract AnchorFactoryPoseidon {
1414
uint256 _denomination,
1515
uint32 _merkleTreeHeight,
1616
uint32 _chainID,
17-
IERC20 _token
17+
TokenWrapper _token,
18+
address _bridge,
19+
address _admin,
20+
address _handler
1821
) external {
19-
new LinkableERC20AnchorPoseidon2(
22+
new Anchor2(
2023
_verifier,
2124
_hasher,
2225
_denomination,
2326
_merkleTreeHeight,
2427
_chainID,
25-
_token
28+
_token,
29+
_bridge,
30+
_admin,
31+
_handler
2632
);
2733
}
2834

@@ -33,15 +39,21 @@ contract AnchorFactoryPoseidon {
3339
uint256 _denomination,
3440
uint32 _merkleTreeHeight,
3541
uint32 _chainID,
36-
IERC20 _token
42+
TokenWrapper _token,
43+
address _bridge,
44+
address _admin,
45+
address _handler
3746
) external {
38-
new LinkableERC20AnchorPoseidon2{salt: _salt}(
47+
new Anchor2{salt: _salt}(
3948
_verifier,
4049
_hasher,
4150
_denomination,
4251
_merkleTreeHeight,
4352
_chainID,
44-
_token
53+
_token,
54+
_bridge,
55+
_admin,
56+
_handler
4557
);
4658
}
4759
}

contracts/anchors/bridged/LinkableERC20AnchorPoseidon2.sol

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

contracts/interfaces/IMintableCompToken.sol

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright 2021 Webb Technologies
3+
* SPDX-License-Identifier: GPL-3.0-or-later-only
4+
*/
5+
6+
pragma solidity ^0.8.0;
7+
8+
/**
9+
* @dev Interface of the ERC20 standard as defined in the EIP.
10+
*/
11+
interface IMintableERC20 {
12+
/**
13+
* @dev Mints `amount` tokens to account `to`.
14+
*
15+
* Emits a {Transfer} event.
16+
*/
17+
function mint(address to, uint256 amount) external;
18+
19+
/**
20+
* @dev Moves `amount` tokens from the caller's account to `recipient`.
21+
*
22+
* Returns a boolean value indicating whether the operation succeeded.
23+
*
24+
* Emits a {Transfer} event.
25+
*/
26+
function transfer(address recipient, uint256 amount) external returns (bool);
27+
28+
/**
29+
* @dev Moves `amount` tokens from `sender` to `recipient` using the
30+
* allowance mechanism. `amount` is then deducted from the caller's
31+
* allowance.
32+
*
33+
* Returns a boolean value indicating whether the operation succeeded.
34+
*
35+
* Emits a {Transfer} event.
36+
*/
37+
function transferFrom(
38+
address sender,
39+
address recipient,
40+
uint256 amount
41+
) external returns (bool);
42+
}

contracts/tokens/CompToken.sol

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
pragma solidity ^0.8.0;
77
pragma experimental ABIEncoderV2;
88

9-
import "../interfaces/IMintableCompToken.sol";
9+
import "../interfaces/IMintableERC20.sol";
1010
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
1111

12-
contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
12+
contract CompToken is ERC20PresetMinterPauser, IMintableERC20 {
1313
/// @notice A record of each accounts delegate
1414
mapping (address => address) public delegates;
1515

@@ -51,7 +51,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
5151
* @param rawAmount The number of tokens to transfer
5252
* @return Whether or not the transfer succeeded
5353
*/
54-
function transfer(address dst, uint rawAmount) override(ERC20, IMintableCompToken) public virtual returns (bool) {
54+
function transfer(address dst, uint rawAmount) override(ERC20, IMintableERC20) public virtual returns (bool) {
5555
_transfer(_msgSender(), dst, rawAmount);
5656
_transferDelegates(_msgSender(), dst, rawAmount);
5757
return true;
@@ -64,7 +64,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
6464
* @param rawAmount The number of tokens to transfer
6565
* @return Whether or not the transfer succeeded
6666
*/
67-
function transferFrom(address src, address dst, uint rawAmount) override(ERC20, IMintableCompToken) public virtual returns (bool) {
67+
function transferFrom(address src, address dst, uint rawAmount) override(ERC20, IMintableERC20) public virtual returns (bool) {
6868
_transfer(src, dst, rawAmount);
6969
_transferDelegates(src, dst, rawAmount);
7070

@@ -86,7 +86,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
8686
*
8787
* - the caller must have the `MINTER_ROLE`.
8888
*/
89-
function mint(address to, uint256 amount) override(ERC20PresetMinterPauser, IMintableCompToken) public virtual {
89+
function mint(address to, uint256 amount) override(ERC20PresetMinterPauser, IMintableERC20) public virtual {
9090
require(hasRole(MINTER_ROLE, _msgSender()), "ERC20PresetMinterPauser: must have minter role to mint");
9191
_mint(to, amount);
9292
}
@@ -95,7 +95,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
9595
* @notice Delegate votes from `msg.sender` to `delegatee`
9696
* @param delegatee The address to delegate votes to
9797
*/
98-
function delegate(address delegatee) override public {
98+
function delegate(address delegatee) public {
9999
return _delegate(msg.sender, delegatee);
100100
}
101101

@@ -108,7 +108,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
108108
* @param r Half of the ECDSA signature pair
109109
* @param s Half of the ECDSA signature pair
110110
*/
111-
function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) override public {
111+
function delegateBySig(address delegatee, uint nonce, uint expiry, uint8 v, bytes32 r, bytes32 s) public {
112112
bytes32 domainSeparator = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name())), getChainId(), address(this)));
113113
bytes32 structHash = keccak256(abi.encode(DELEGATION_TYPEHASH, delegatee, nonce, expiry));
114114
bytes32 digest = keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
@@ -124,7 +124,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
124124
* @param account The address to get votes balance
125125
* @return The number of current votes for `account`
126126
*/
127-
function getCurrentVotes(address account) override external view returns (uint256) {
127+
function getCurrentVotes(address account) external view returns (uint256) {
128128
uint32 nCheckpoints = numCheckpoints[account];
129129
return nCheckpoints > 0 ? checkpoints[account][nCheckpoints - 1].votes : 0;
130130
}
@@ -136,7 +136,7 @@ contract CompToken is ERC20PresetMinterPauser, IMintableCompToken {
136136
* @param blockNumber The block number to get the vote balance at
137137
* @return The number of votes the account had as of the given block
138138
*/
139-
function getPriorVotes(address account, uint blockNumber) override public view returns (uint256) {
139+
function getPriorVotes(address account, uint blockNumber) public view returns (uint256) {
140140
require(blockNumber < block.number, "Comp::getPriorVotes: not yet determined");
141141

142142
uint32 nCheckpoints = numCheckpoints[account];

0 commit comments

Comments
 (0)