forked from decred/dcrdex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dex/{networks,testing}: Add simnet USDC
This adds the usdc.eth and usdc.polygon assets to simnet. This is useful for testing market making.
- Loading branch information
Showing
7 changed files
with
386 additions
and
12 deletions.
There are no files selected for viewing
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,204 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
// This is a simplified version of OpenZeppelin Contracts v4.4.0 (token/ERC20/ERC20.sol). | ||
|
||
pragma solidity = 0.8.18; | ||
|
||
contract TestUSDC { | ||
mapping(address => uint256) private _balances; | ||
|
||
mapping(address => mapping(address => uint256)) private _allowances; | ||
|
||
uint256 private _totalSupply; | ||
|
||
string private _name; | ||
string private _symbol; | ||
|
||
/** | ||
* @dev Sets the values for {name} and {symbol}. | ||
* | ||
* The default value of {decimals} is 18. To select a different value for | ||
* {decimals} you should overload it. | ||
* | ||
* All two of these values are immutable: they can only be set once during | ||
* construction. | ||
*/ | ||
constructor() { | ||
_name = "USD Coin"; | ||
_symbol = "USDC"; | ||
_totalSupply = 33000000000; | ||
_balances[0x18D65FB8d60c1199bb1Ad381bE47aA692b482605] = 11000000000; // alpha | ||
_balances[0x4F8eF3892B65ED7fc356fF473a2eF2aE5EC27A06] = 11000000000; // beta | ||
_balances[0xd12aB7cf72CCf1f3882eC99DDc53CD415635C3bE] = 11000000000; // delta | ||
} | ||
|
||
/** | ||
* @dev Returns the name of the token. | ||
*/ | ||
function name() public view virtual returns (string memory) { | ||
return _name; | ||
} | ||
|
||
/** | ||
* @dev Returns the symbol of the token, usually a shorter version of the | ||
* name. | ||
*/ | ||
function symbol() public view virtual returns (string memory) { | ||
return _symbol; | ||
} | ||
|
||
/** | ||
* @dev Returns the number of decimals used to get its user representation. | ||
* For example, if `decimals` equals `2`, a balance of `505` tokens should | ||
* be displayed to a user as `5.05` (`505 / 10 ** 2`). | ||
* | ||
* Tokens usually opt for a value of 18, imitating the relationship between | ||
* Ether and Wei. This is the value {ERC20} uses, unless this function is | ||
* overridden; | ||
* | ||
* NOTE: This information is only used for _display_ purposes: it in | ||
* no way affects any of the arithmetic of the contract, including | ||
* {IERC20-balanceOf} and {IERC20-transfer}. | ||
*/ | ||
function decimals() public view virtual returns (uint8) { | ||
return 6; | ||
} | ||
|
||
/** | ||
* @dev See {IERC20-totalSupply}. | ||
*/ | ||
function totalSupply() public view virtual returns (uint256) { | ||
return _totalSupply; | ||
} | ||
|
||
/** | ||
* @dev See {IERC20-balanceOf}. | ||
*/ | ||
function balanceOf(address account) public view virtual returns (uint256) { | ||
return _balances[account]; | ||
} | ||
|
||
/** | ||
* @dev See {IERC20-transfer}. | ||
* | ||
* Requirements: | ||
* | ||
* - `recipient` cannot be the zero address. | ||
* - the caller must have a balance of at least `amount`. | ||
*/ | ||
function transfer(address recipient, uint256 amount) public virtual returns (bool) { | ||
_transfer(msg.sender, recipient, amount); | ||
return true; | ||
} | ||
|
||
/** | ||
* @dev See {IERC20-allowance}. | ||
*/ | ||
function allowance(address owner, address spender) public view virtual returns (uint256) { | ||
return _allowances[owner][spender]; | ||
} | ||
|
||
/** | ||
* @dev See {IERC20-approve}. | ||
* | ||
* Requirements: | ||
* | ||
* - `spender` cannot be the zero address. | ||
*/ | ||
function approve(address spender, uint256 amount) public virtual returns (bool) { | ||
_approve(msg.sender, spender, amount); | ||
return true; | ||
} | ||
|
||
function testApprove(address user, address spender, uint256 amount) public returns (bool) { | ||
_approve(user, spender, amount); | ||
return true; | ||
} | ||
|
||
/** | ||
* @dev See {IERC20-transferFrom}. | ||
* | ||
* Emits an {Approval} event indicating the updated allowance. This is not | ||
* required by the EIP. See the note at the beginning of {ERC20}. | ||
* | ||
* Requirements: | ||
* | ||
* - `sender` and `recipient` cannot be the zero address. | ||
* - `sender` must have a balance of at least `amount`. | ||
* - the caller must have allowance for ``sender``'s tokens of at least | ||
* `amount`. | ||
*/ | ||
function transferFrom( | ||
address sender, | ||
address recipient, | ||
uint256 amount | ||
) public virtual returns (bool) { | ||
_transfer(sender, recipient, amount); | ||
|
||
uint256 currentAllowance = _allowances[sender][msg.sender]; | ||
require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); | ||
unchecked { | ||
_approve(sender, msg.sender, currentAllowance - amount); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Airdrop is used to mint new tokens and give them to a user. | ||
*/ | ||
function airdrop(address recipient, uint256 amount) public virtual { | ||
_totalSupply += amount; | ||
_balances[recipient] += amount; | ||
} | ||
|
||
/** | ||
* @dev Moves `amount` of tokens from `sender` to `recipient`. | ||
* | ||
* This internal function is equivalent to {transfer}, and can be used to | ||
* e.g. implement automatic token fees, slashing mechanisms, etc. | ||
* | ||
* Requirements: | ||
* | ||
* - `sender` cannot be the zero address. | ||
* - `recipient` cannot be the zero address. | ||
* - `sender` must have a balance of at least `amount`. | ||
*/ | ||
function _transfer( | ||
address sender, | ||
address recipient, | ||
uint256 amount | ||
) internal virtual { | ||
require(sender != address(0), "ERC20: transfer from the zero address"); | ||
require(recipient != address(0), "ERC20: transfer to the zero address"); | ||
|
||
uint256 senderBalance = _balances[sender]; | ||
require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); | ||
unchecked { | ||
_balances[sender] = senderBalance - amount; | ||
} | ||
_balances[recipient] += amount; | ||
} | ||
|
||
/** | ||
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. | ||
* | ||
* This internal function is equivalent to `approve`, and can be used to | ||
* e.g. set automatic allowances for certain subsystems, etc. | ||
* | ||
* Requirements: | ||
* | ||
* - `owner` cannot be the zero address. | ||
* - `spender` cannot be the zero address. | ||
*/ | ||
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; | ||
} | ||
} |
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
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
Oops, something went wrong.