-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deploy and proposal for USDT market on Goerli #801
Open
cwang25
wants to merge
32
commits into
main
Choose a base branch
from
hans/goerli-usdt-deploy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
a669690
add usdt deployment
22a4dc8
add run scenario entry
f0d1503
when deploy all suply cap should be zero
132d591
use the same usdt contract that compoundV2 is using, so easier to get…
83dcc49
clean up
6c6e5bf
change targetreserver to 5 usdt
e791775
USDT fork from mainnet for better consistent scenario cases
fe550f4
move sol files to deploy branch
1844dd8
add some usdt token fees scenario tests
c25386d
add liquidation scenario tests
b4a026e
port migration deploy script changes to here
eed10de
Update scenario/SupplyScenario.ts
cwang25 01ed6e0
Update contracts/Comet.sol
cwang25 c68fc7f
Update scenario/SupplyScenario.ts
cwang25 3b9eeee
Update scenario/SupplyScenario.ts
cwang25 59d101c
address comments
eff6e14
add docling
736aee5
add unit test for supply/ supply collateral / buy colalteral into uni…
e94e693
addressed comments
8ad9799
Update contracts/test/NonStandardFaucetFeeToken.sol
cwang25 ba090f0
address comments
cd3776f
fixed some tsc error complains
12e5e8f
fix re-entry tests, that since evilToken never transfer anything, wit…
4b0fc48
another test case that need to set it to 0 balance
63f4061
EviltToken with more realistic attack, and adjusted test cases, and a…
277b286
add extra line
c0f710e
Merge branch 'main' into hans/goerli-usdt-deploy
cwang25 49588d6
add and leveraged oz's re-entrancy guard
d0f016a
reentrancy guard in Comet, isntead of importing external contracts wi…
976c81f
Revert "reentrancy guard in Comet, isntead of importing external cont…
a13050a
Revert "add and leveraged oz's re-entrancy guard"
513f451
Address OZ's feedback on USDT comet support (#818)
cwang25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
cwang25 marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity 0.8.15; | ||
|
||
/** | ||
* @title Non-standard ERC20 token | ||
* @dev Implementation of the basic standard token. | ||
* See https://github.com/ethereum/EIPs/issues/20 | ||
* @dev With USDT fee token mechanism | ||
* @dev Note: `transfer` and `transferFrom` do not return a boolean | ||
*/ | ||
contract NonStandardFeeToken { | ||
cwang25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
string public name; | ||
string public symbol; | ||
uint8 public decimals; | ||
uint256 public totalSupply; | ||
mapping (address => mapping (address => uint256)) public allowance; | ||
cwang25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mapping(address => uint256) public balanceOf; | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Params(uint feeBasisPoints, uint maxFee); | ||
|
||
// additional variables for use if transaction fees ever became necessary | ||
uint public basisPointsRate = 0; | ||
uint public maximumFee = 0; | ||
|
||
constructor(uint256 _initialAmount, string memory _tokenName, uint8 _decimalUnits, string memory _tokenSymbol) { | ||
totalSupply = _initialAmount; | ||
balanceOf[msg.sender] = _initialAmount; | ||
name = _tokenName; | ||
symbol = _tokenSymbol; | ||
decimals = _decimalUnits; | ||
} | ||
|
||
function transfer(address dst, uint256 amount) external virtual { | ||
require(amount <= balanceOf[msg.sender], "ERC20: transfer amount exceeds balance"); | ||
uint256 fee = amount * basisPointsRate / 10000; | ||
uint256 sendAmount = amount - fee; | ||
if (fee > maximumFee) { | ||
fee = maximumFee; | ||
} | ||
|
||
// For testing purpose, just forward fee to contract itself | ||
if (fee > 0) { | ||
balanceOf[address(this)] = balanceOf[address(this)] + fee; | ||
} | ||
|
||
balanceOf[msg.sender] = balanceOf[msg.sender] - amount; | ||
balanceOf[dst] = balanceOf[dst] + sendAmount; | ||
emit Transfer(msg.sender, dst, sendAmount); | ||
} | ||
|
||
function transferFrom(address src, address dst, uint256 amount) external virtual { | ||
require(amount <= allowance[src][msg.sender], "ERC20: transfer amount exceeds allowance"); | ||
require(amount <= balanceOf[src], "ERC20: transfer amount exceeds balance"); | ||
uint256 fee = amount * basisPointsRate / 10000; | ||
uint256 sendAmount = amount - fee; | ||
if (fee > maximumFee) { | ||
fee = maximumFee; | ||
} | ||
|
||
// For testing purpose, just forward fee to contract itself | ||
if (fee > 0) { | ||
balanceOf[address(this)] = balanceOf[address(this)] + fee; | ||
} | ||
|
||
allowance[src][msg.sender] = allowance[src][msg.sender] - amount; | ||
balanceOf[src] = balanceOf[src] - amount; | ||
balanceOf[dst] = balanceOf[dst] + sendAmount; | ||
emit Transfer(src, dst, sendAmount); | ||
} | ||
|
||
function approve(address _spender, uint256 amount) external returns (bool) { | ||
cwang25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
allowance[msg.sender][_spender] = amount; | ||
emit Approval(msg.sender, _spender, amount); | ||
return true; | ||
} | ||
|
||
// For testing, just don't limit access on setting fees | ||
function setParams(uint256 newBasisPoints, uint256 newMaxFee) public { | ||
basisPointsRate = newBasisPoints; | ||
maximumFee = newMaxFee * (10**decimals); | ||
|
||
emit Params(basisPointsRate, maximumFee); | ||
} | ||
} | ||
|
||
/** | ||
* @title The Compound Faucet Test Token | ||
* @author Compound | ||
* @notice A simple test token that lets anyone get more of it. | ||
*/ | ||
contract NonStandardFaucetFeeToken is NonStandardFeeToken { | ||
constructor(uint256 _initialAmount, string memory _tokenName, uint8 _decimalUnits, string memory _tokenSymbol) | ||
NonStandardFeeToken(_initialAmount, _tokenName, _decimalUnits, _tokenSymbol) { | ||
} | ||
|
||
function allocateTo(address _owner, uint256 value) public { | ||
balanceOf[_owner] += value; | ||
totalSupply += value; | ||
emit Transfer(address(this), _owner, value); | ||
} | ||
} |
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,54 @@ | ||
{ | ||
"name": "Compound USDT", | ||
"symbol": "cUSDTv3", | ||
"baseToken": "USDT", | ||
"baseTokenPriceFeed": "0xAb5c49580294Aff77670F839ea425f5b78ab3Ae7", | ||
"borrowMin": "1e0", | ||
"governor": "0x8Fa336EB4bF58Cfc508dEA1B0aeC7336f55B1399", | ||
"pauseGuardian": "0x8Fa336EB4bF58Cfc508dEA1B0aeC7336f55B1399", | ||
"storeFrontPriceFactor": 0.5, | ||
"targetReserves": "5000000e6", | ||
"rates": { | ||
"supplyKink": 0.8, | ||
"supplySlopeLow": 0.0325, | ||
"supplySlopeHigh": 0.4, | ||
"supplyBase": 0, | ||
"borrowKink": 0.8, | ||
"borrowSlopeLow": 0.035, | ||
"borrowSlopeHigh": 0.25, | ||
"borrowBase": 0.015 | ||
}, | ||
"rewardToken": "COMP", | ||
"tracking": { | ||
"indexScale": "1e15", | ||
"baseSupplySpeed": "0", | ||
"baseBorrowSpeed": "0", | ||
"baseMinForRewards": "500e6" | ||
}, | ||
"assets": { | ||
"COMP": { | ||
"priceFeed": "0x54a06047087927D9B0fb21c1cf0ebd792764dDB8", | ||
"decimals": "18", | ||
"borrowCF": 0.65, | ||
"liquidateCF": 0.7, | ||
"liquidationFactor": 0.92, | ||
"supplyCap": "0e18" | ||
}, | ||
"WBTC": { | ||
"priceFeed": "0xA39434A63A52E749F02807ae27335515BA4b07F7", | ||
"decimals": "8", | ||
"borrowCF": 0.7, | ||
"liquidateCF": 0.75, | ||
"liquidationFactor": 0.93, | ||
"supplyCap": "0e8" | ||
}, | ||
"WETH": { | ||
"priceFeed": "0xD4a33860578De61DBAbDc8BFdb98FD742fA7028e", | ||
"decimals": "18", | ||
"borrowCF": 0.82, | ||
"liquidateCF": 0.85, | ||
"liquidationFactor": 0.93, | ||
"supplyCap": "0e18" | ||
} | ||
} | ||
} |
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,50 @@ | ||
import { Deployed, DeploymentManager } from '../../../plugins/deployment_manager'; | ||
import { debug, DeploySpec, deployComet, exp, sameAddress, wait } from '../../../src/deploy'; | ||
|
||
const clone = { | ||
usdt: '0xdAC17F958D2ee523a2206206994597C13D831ec7', | ||
}; | ||
|
||
export default async function deploy(deploymentManager: DeploymentManager, deploySpec: DeploySpec): Promise<Deployed> { | ||
const trace = deploymentManager.tracer(); | ||
const ethers = deploymentManager.hre.ethers; | ||
const signer = await deploymentManager.getSigner(); | ||
|
||
// Clone/fork USDT from mainnet which is non-standard erc20 to testnet | ||
const USDT = await deploymentManager.clone('USDT', clone.usdt, [100_000_000_000_000, 'Tether USD', 'USDT', 6]); | ||
|
||
// Declare existing assets as aliases | ||
const COMP = await deploymentManager.existing('COMP', '0x3587b2F7E0E2D6166d6C14230e7Fe160252B0ba4', 'goerli'); | ||
const WBTC = await deploymentManager.existing('WBTC', '0xAAD4992D949f9214458594dF92B44165Fb84dC19', 'goerli'); | ||
const WETH = await deploymentManager.existing('WETH', '0x42a71137C09AE83D8d05974960fd607d40033499', 'goerli'); | ||
|
||
// Import shared contracts from cUSDCv3 | ||
const cometAdmin = await deploymentManager.fromDep('cometAdmin', 'goerli', 'usdc'); | ||
// Purposely don't use the factory because Comet implementation changed. | ||
// const cometFactory = await deploymentManager.fromDep('cometFactory', 'goerli', 'usdc'); | ||
const $configuratorImpl = await deploymentManager.fromDep('configurator:implementation', 'goerli', 'usdc'); | ||
const configurator = await deploymentManager.fromDep('configurator', 'goerli', 'usdc'); | ||
const rewards = await deploymentManager.fromDep('rewards', 'goerli', 'usdc'); | ||
const fauceteer = await deploymentManager.fromDep('fauceteer', 'goerli', 'usdc'); | ||
const bulker = await deploymentManager.fromDep('bulker', 'goerli', 'usdc'); | ||
const timelock = await deploymentManager.fromDep('timelock', 'goerli', 'usdc'); | ||
|
||
|
||
// Send some forked USDT to timelock | ||
await deploymentManager.idempotent( | ||
async () => await USDT.connect(signer).balanceOf(timelock.address) == 0, | ||
async () => { | ||
trace(`Sending USDT to timelock`); | ||
await USDT.connect(signer).transfer( | ||
timelock.address, | ||
exp(50_000_000, 6), | ||
); | ||
trace(`Sent USDT to timelock completed`); | ||
} | ||
); | ||
|
||
// Deploy all Comet-related contracts | ||
const deployed = await deployComet(deploymentManager, deploySpec); | ||
|
||
return { ...deployed, bulker, fauceteer }; | ||
} |
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,5 @@ | ||
import baseRelationConfig from '../../relations'; | ||
|
||
export default { | ||
...baseRelationConfig | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contract size is approaching to limit, compiler will complain with
Warning: 2 contracts exceed the size limit for mainnet deployment.
But the actual size limit is 24.576 kb, so we should be fine :P