-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cde0bad
commit 1a8ad55
Showing
6 changed files
with
569 additions
and
0 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,74 @@ | ||
# pragma version 0.3.10 | ||
|
||
""" | ||
@notice Mock ERC20 for testing | ||
""" | ||
|
||
|
||
event Transfer: | ||
_from: indexed(address) | ||
_to: indexed(address) | ||
_value: uint256 | ||
|
||
|
||
event Approval: | ||
_owner: indexed(address) | ||
_spender: indexed(address) | ||
_value: uint256 | ||
|
||
|
||
name: public(String[64]) | ||
symbol: public(String[32]) | ||
decimals: public(uint256) | ||
balanceOf: public(HashMap[address, uint256]) | ||
allowances: HashMap[address, HashMap[address, uint256]] | ||
totalSupply: public(uint256) | ||
|
||
# asset type | ||
asset_type: public(constant(uint8)) = 0 | ||
|
||
|
||
@external | ||
def __init__(_name: String[64], _symbol: String[32], _decimals: uint256): | ||
self.name = _name | ||
self.symbol = _symbol | ||
self.decimals = _decimals | ||
|
||
|
||
@external | ||
@view | ||
def allowance(_owner: address, _spender: address) -> uint256: | ||
return self.allowances[_owner][_spender] | ||
|
||
|
||
@external | ||
def transfer(_to: address, _value: uint256) -> bool: | ||
self.balanceOf[msg.sender] -= _value | ||
self.balanceOf[_to] += _value | ||
log Transfer(msg.sender, _to, _value) | ||
return True | ||
|
||
|
||
@external | ||
def transferFrom(_from: address, _to: address, _value: uint256) -> bool: | ||
self.balanceOf[_from] -= _value | ||
self.balanceOf[_to] += _value | ||
self.allowances[_from][msg.sender] -= _value | ||
log Transfer(_from, _to, _value) | ||
return True | ||
|
||
|
||
@external | ||
def approve(_spender: address, _value: uint256) -> bool: | ||
self.allowances[msg.sender][_spender] = _value | ||
log Approval(msg.sender, _spender, _value) | ||
return True | ||
|
||
|
||
@external | ||
def _mint_for_testing(_target: address, _value: uint256) -> bool: | ||
self.totalSupply += _value | ||
self.balanceOf[_target] += _value | ||
log Transfer(empty(address), _target, _value) | ||
|
||
return True |
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,99 @@ | ||
# pragma version 0.3.10 | ||
|
||
""" | ||
@notice Mock ERC20 with oracle | ||
@dev This is for testing only, it is NOT safe for use | ||
""" | ||
|
||
|
||
event Transfer: | ||
_from: indexed(address) | ||
_to: indexed(address) | ||
_value: uint256 | ||
|
||
|
||
event Approval: | ||
_owner: indexed(address) | ||
_spender: indexed(address) | ||
_value: uint256 | ||
|
||
|
||
name: public(String[64]) | ||
symbol: public(String[32]) | ||
decimals: public(uint256) | ||
balanceOf: public(HashMap[address, uint256]) | ||
allowances: HashMap[address, HashMap[address, uint256]] | ||
totalSupply: public(uint256) | ||
|
||
exchange_rate: public(uint256) | ||
|
||
# asset type | ||
asset_type: public(constant(uint8)) = 1 | ||
|
||
|
||
@external | ||
def __init__( | ||
_name: String[64], | ||
_symbol: String[32], | ||
_decimals: uint256, | ||
_exchange_rate: uint256 | ||
): | ||
|
||
self.name = _name | ||
self.symbol = _symbol | ||
|
||
assert _decimals == 18, "Decimals must be 18" | ||
self.decimals = _decimals | ||
self.exchange_rate = _exchange_rate | ||
|
||
|
||
@external | ||
@view | ||
def allowance(_owner: address, _spender: address) -> uint256: | ||
return self.allowances[_owner][_spender] | ||
|
||
|
||
@external | ||
def transfer(_to: address, _value: uint256) -> bool: | ||
self.balanceOf[msg.sender] -= _value | ||
self.balanceOf[_to] += _value | ||
log Transfer(msg.sender, _to, _value) | ||
return True | ||
|
||
|
||
@external | ||
def transferFrom(_from: address, _to: address, _value: uint256) -> bool: | ||
self.balanceOf[_from] -= _value | ||
self.balanceOf[_to] += _value | ||
self.allowances[_from][msg.sender] -= _value | ||
log Transfer(_from, _to, _value) | ||
return True | ||
|
||
|
||
@external | ||
def approve(_spender: address, _value: uint256) -> bool: | ||
self.allowances[msg.sender][_spender] = _value | ||
log Approval(msg.sender, _spender, _value) | ||
return True | ||
|
||
|
||
@external | ||
@view | ||
def exchangeRate() -> uint256: | ||
rate: uint256 = self.exchange_rate | ||
return rate | ||
|
||
|
||
@external | ||
def set_exchange_rate(rate: uint256) -> bool: | ||
self.exchange_rate = rate | ||
return True | ||
|
||
|
||
@external | ||
def _mint_for_testing(_target: address, _value: uint256) -> bool: | ||
self.totalSupply += _value | ||
self.balanceOf[_target] += _value | ||
log Transfer(empty(address), _target, _value) | ||
|
||
return True |
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,201 @@ | ||
import boa | ||
import pytest | ||
|
||
# ---- Stableswap NG ---- # | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_deployer(): | ||
return boa.load_partial("contracts/amms/stableswapng/CurveStableSwapNG.vy") | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_meta_deployer(): | ||
return boa.load_partial( | ||
"contracts/amms/stableswapng/CurveStableSwapMetaNG.vy" | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_implementation(stableswap_ng_deployer, deployer): | ||
with boa.env.prank(deployer): | ||
return stableswap_ng_deployer.deploy_as_blueprint() | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_meta_implementation(stableswap_ng_meta_deployer, deployer): | ||
with boa.env.prank(deployer): | ||
return stableswap_ng_meta_deployer.deploy_as_blueprint() | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_views_implementation(deployer): | ||
with boa.env.prank(deployer): | ||
return boa.load_partial( | ||
"contracts/amms/stableswapng/CurveStableSwapNGViews.vy" | ||
).deploy() | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_math_implementation(deployer): | ||
with boa.env.prank(deployer): | ||
return boa.load_partial( | ||
"contracts/amms/stableswapng/CurveStableSwapNGMath.vy" | ||
).deploy() | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_factory_empty( | ||
deployer, | ||
ng_fee_receiver, | ||
ng_owner, | ||
stableswap_ng_views_implementation, | ||
stableswap_ng_math_implementation, | ||
stableswap_ng_implementation, | ||
stableswap_ng_meta_implementation, | ||
): | ||
with boa.env.prank(deployer): | ||
factory = boa.load_partial( | ||
"contracts/amms/stableswapng/CurveStableSwapFactoryNG.vy" | ||
).deploy(ng_fee_receiver, ng_owner) | ||
|
||
with boa.env.prank(ng_owner): | ||
factory.set_views_implementation( | ||
stableswap_ng_views_implementation.address | ||
) | ||
factory.set_math_implementation( | ||
stableswap_ng_math_implementation.address | ||
) | ||
factory.set_pool_implementations( | ||
0, stableswap_ng_implementation.address | ||
) | ||
factory.set_metapool_implementations( | ||
0, stableswap_ng_meta_implementation.address | ||
) | ||
|
||
return factory | ||
|
||
|
||
@pytest.fixture() | ||
def stableswap_ng_factory( | ||
stableswap_ng_factory_empty, stableswap_ng_pool, base_pool_coins, ng_owner | ||
): | ||
stableswap_ng_factory_empty.add_base_pool( | ||
stableswap_ng_pool.address, | ||
stableswap_ng_pool.address, | ||
[0] * len(base_pool_coins), | ||
len(base_pool_coins), | ||
sender=ng_owner, | ||
) | ||
return stableswap_ng_factory_empty | ||
|
||
|
||
# ---- Twocrypto NG ---- # | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def twocrypto_ng_math_contract(deployer): | ||
with boa.env.prank(deployer): | ||
return boa.load( | ||
"contracts/amms/twocryptong/CurveCryptoMathOptimized2.vy" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def twocrypto_ng_amm_deployer(): | ||
return boa.load_partial( | ||
"contracts/amms/twocryptong/CurveTwocryptoOptimized.vy" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def twocrypto_ng_amm_implementation(deployer, twocrypto_ng_amm_deployer): | ||
with boa.env.prank(deployer): | ||
return twocrypto_ng_amm_deployer.deploy_as_blueprint() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def twocrypto_ng_views_contract(deployer): | ||
with boa.env.prank(deployer): | ||
return boa.load( | ||
"contracts/amms/twocryptong/CurveCryptoViews2Optimized.vy" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def twocrypto_ng_factory( | ||
deployer, | ||
ng_fee_receiver, | ||
ng_owner, | ||
twocrypto_ng_amm_implementation, | ||
twocrypto_ng_math_contract, | ||
twocrypto_ng_views_contract, | ||
): | ||
with boa.env.prank(deployer): | ||
factory = boa.load( | ||
"contracts/amms/twocryptong/CurveTwocryptoFactory.vy" | ||
) | ||
factory.initialise_ownership(ng_fee_receiver, ng_owner) | ||
|
||
with boa.env.prank(ng_owner): | ||
factory.set_pool_implementation(twocrypto_ng_amm_implementation, 0) | ||
factory.set_views_implementation(twocrypto_ng_views_contract) | ||
factory.set_math_implementation(twocrypto_ng_math_contract) | ||
|
||
return factory | ||
|
||
|
||
# ---- Tricrypto NG ---- # | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tricrypto_ng_math_contract(deployer): | ||
with boa.env.prank(deployer): | ||
return boa.load( | ||
"contracts/amms/tricryptong/CurveCryptoMathOptimized3.vy" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tricrypto_ng_amm_deployer(): | ||
return boa.load_partial( | ||
"contracts/amms/tricryptong/CurveTricryptoOptimized.vy" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tricrypto_ng_amm_implementation(deployer, tricrypto_ng_amm_deployer): | ||
with boa.env.prank(deployer): | ||
return tricrypto_ng_amm_deployer.deploy_as_blueprint() | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tricrypto_ng_views_contract(deployer): | ||
with boa.env.prank(deployer): | ||
return boa.load( | ||
"contracts/amms/tricryptong/CurveCryptoViews3Optimized.vy" | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def tricrypto_ng_factory( | ||
deployer, | ||
ng_fee_receiver, | ||
ng_owner, | ||
tricrypto_ng_amm_implementation, | ||
tricrypto_ng_math_contract, | ||
tricrypto_ng_views_contract, | ||
): | ||
with boa.env.prank(deployer): | ||
factory = boa.load( | ||
"contracts/amms/tricryptong/CurveTricryptoFactory.vy", | ||
ng_fee_receiver, | ||
ng_owner, | ||
) | ||
|
||
with boa.env.prank(ng_owner): | ||
factory.set_pool_implementation(tricrypto_ng_amm_implementation, 0) | ||
factory.set_views_implementation(tricrypto_ng_views_contract) | ||
factory.set_math_implementation(tricrypto_ng_math_contract) | ||
|
||
return factory |
Oops, something went wrong.