-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1018 from statechannels/badtokens
Allow Adjudicator to accepts "bad" ERC20 tokens (such as USDT)
- Loading branch information
Showing
9 changed files
with
204 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
./contracts/test/BadToken.sol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// SPDX-License-Identifier: MIT | ||
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) | ||
|
||
pragma solidity 0.8.17; | ||
|
||
/** | ||
* @dev Copy-pasted from Openzeppelin ERC20 contract, but with the inheritance from IERC20 interface removed and no return value for transferFrom. | ||
*/ | ||
contract BadToken { | ||
function transferFrom( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) public virtual { | ||
address spender = msg.sender; | ||
_spendAllowance(from, spender, amount); | ||
_transfer(from, to, amount); | ||
// return true; // purposefully ommitted because bad token | ||
} | ||
|
||
constructor(address owner) { | ||
_mint(owner, 10_000_000_000); | ||
} | ||
|
||
// The rest of the file is as it is in the Openzeppelin ERC20 contract. | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
mapping(address => uint256) private _balances; | ||
mapping(address => mapping(address => uint256)) private _allowances; | ||
uint256 private _totalSupply; | ||
string private _name; | ||
string private _symbol; | ||
|
||
function balanceOf(address account) public view virtual returns (uint256) { | ||
return _balances[account]; | ||
} | ||
|
||
function transfer(address to, uint256 amount) public virtual returns (bool) { | ||
address owner = msg.sender; | ||
_transfer(owner, to, amount); | ||
return true; | ||
} | ||
|
||
function allowance(address owner, address spender) public view virtual returns (uint256) { | ||
return _allowances[owner][spender]; | ||
} | ||
|
||
function approve(address spender, uint256 amount) public virtual returns (bool) { | ||
address owner = msg.sender; | ||
_approve(owner, spender, amount); | ||
return true; | ||
} | ||
|
||
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { | ||
address owner = msg.sender; | ||
_approve(owner, spender, allowance(owner, spender) + addedValue); | ||
return true; | ||
} | ||
|
||
function _transfer( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) internal virtual { | ||
require(from != address(0), 'ERC20: transfer from the zero address'); | ||
require(to != address(0), 'ERC20: transfer to the zero address'); | ||
_beforeTokenTransfer(from, to, amount); | ||
uint256 fromBalance = _balances[from]; | ||
require(fromBalance >= amount, 'ERC20: transfer amount exceeds balance'); | ||
unchecked { | ||
_balances[from] = fromBalance - amount; | ||
} | ||
_balances[to] += amount; | ||
emit Transfer(from, to, amount); | ||
_afterTokenTransfer(from, to, amount); | ||
} | ||
|
||
function _mint(address account, uint256 amount) internal virtual { | ||
require(account != address(0), 'ERC20: mint to the zero address'); | ||
_beforeTokenTransfer(address(0), account, amount); | ||
_totalSupply += amount; | ||
_balances[account] += amount; | ||
emit Transfer(address(0), account, amount); | ||
_afterTokenTransfer(address(0), account, amount); | ||
} | ||
|
||
function _approve( | ||
address owner, | ||
address spender, | ||
uint256 amount | ||
) internal virtual { | ||
require(owner != address(0), 'ERC20: approve from the zero address'); | ||
require(spender != address(0), 'ERC20: approve to the zero address'); | ||
_allowances[owner][spender] = amount; | ||
emit Approval(owner, spender, amount); | ||
} | ||
|
||
function _spendAllowance( | ||
address owner, | ||
address spender, | ||
uint256 amount | ||
) internal virtual { | ||
uint256 currentAllowance = allowance(owner, spender); | ||
if (currentAllowance != type(uint256).max) { | ||
require(currentAllowance >= amount, 'ERC20: insufficient allowance'); | ||
unchecked { | ||
_approve(owner, spender, currentAllowance - amount); | ||
} | ||
} | ||
} | ||
|
||
function _beforeTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) internal virtual {} | ||
|
||
function _afterTokenTransfer( | ||
address from, | ||
address to, | ||
uint256 amount | ||
) internal virtual {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
{ | ||
"deployInfrastructureContracts": { | ||
"satp": { | ||
"NitroAdjudicator": 3316515 | ||
"NitroAdjudicator": 3363358 | ||
} | ||
}, | ||
"directlyFundAChannelWithETHFirst": { | ||
"satp": 47318 | ||
"satp": 47279 | ||
}, | ||
"directlyFundAChannelWithETHSecond": { | ||
"satp": 30230 | ||
"satp": 30191 | ||
}, | ||
"directlyFundAChannelWithERC20First": { | ||
"satp": { | ||
"approve": 46218, | ||
"deposit": 70026 | ||
"deposit": 70595 | ||
} | ||
}, | ||
"directlyFundAChannelWithERC20Second": { | ||
"satp": { | ||
"approve": 46218, | ||
"deposit": 52938 | ||
"deposit": 53507 | ||
} | ||
}, | ||
"ETHexit": { | ||
"satp": 110949 | ||
}, | ||
"ERC20exit": { | ||
"satp": 112231 | ||
"satp": 112233 | ||
}, | ||
"ETHexitSad": { | ||
"satp": { | ||
"challenge": 113232, | ||
"challenge": 113241, | ||
"transferAllAssets": 80967, | ||
"total": 194199 | ||
"total": 194208 | ||
} | ||
}, | ||
"ETHexitSadLedgerFunded": { | ||
"satp": { | ||
"challengeX": 113232, | ||
"challengeL": 106643, | ||
"challengeX": 113241, | ||
"challengeL": 106652, | ||
"transferAllAssetsL": 61079, | ||
"transferAllAssetsX": 80967, | ||
"total": 361921 | ||
"total": 361939 | ||
} | ||
}, | ||
"ETHexitSadVirtualFunded": { | ||
"satp": { | ||
"challengeL": 122187, | ||
"challengeV": 172745, | ||
"challengeL": 122196, | ||
"challengeV": 172754, | ||
"reclaimL": 60323, | ||
"transferAllAssetsL": 112667, | ||
"total": 467922 | ||
"total": 467940 | ||
} | ||
} | ||
} |
Oops, something went wrong.