Skip to content
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

snekmate-erc20-mocks #22

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,040 changes: 0 additions & 2,040 deletions contracts/mocks/CurveTricryptoOptimizedWETH.vy

This file was deleted.

71 changes: 0 additions & 71 deletions contracts/mocks/ERC20Mock.vy

This file was deleted.

82 changes: 0 additions & 82 deletions contracts/mocks/WETH.vy

This file was deleted.

18 changes: 6 additions & 12 deletions tests/fixtures/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,40 @@
import pytest


@pytest.fixture(scope="module")
def weth(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/WETH.vy")


@pytest.fixture(scope="module")
def usd(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/ERC20Mock.vy", "USD", "USD", 18)
return boa.load("tests/mocks/MockERC20.vy", "USD", "USD", 18)


@pytest.fixture(scope="module")
def btc(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/ERC20Mock.vy", "BTC", "BTC", 18)
return boa.load("tests/mocks/MockERC20.vy", "BTC", "BTC", 18)


@pytest.fixture(scope="module")
def stg(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/ERC20Mock.vy", "STG", "STG", 18)
return boa.load("tests/mocks/MockERC20.vy", "STG", "STG", 18)


@pytest.fixture(scope="module")
def usdt(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/ERC20Mock.vy", "USDT", "USDT", 6)
return boa.load("tests/mocks/MockERC20.vy", "USDT", "USDT", 6)


@pytest.fixture(scope="module")
def usdc(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/ERC20Mock.vy", "USDC", "USDC", 6)
return boa.load("tests/mocks/MockERC20.vy", "USDC", "USDC", 6)


@pytest.fixture(scope="module")
def dai(deployer):
with boa.env.prank(deployer):
return boa.load("contracts/mocks/ERC20Mock.vy", "DAI", "DAI", 18)
return boa.load("tests/mocks/MockERC20.vy", "DAI", "DAI", 18)


@pytest.fixture(scope="module")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_create2_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def factory(

@pytest.fixture(scope="module")
def coins():
erc20_mock = boa.load_partial("./contracts/mocks/ERC20Mock.vy")
erc20_mock = boa.load_partial("./tests/mocks/MockERC20.vy")
return [
erc20_mock.at("0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E"),
erc20_mock.at("0xD533a949740bb3306d119CC777fa900bA034cd52"),
Expand Down
15 changes: 15 additions & 0 deletions tests/mocks/MockERC20.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# pragma version ~=0.4.0

from snekmate.tokens import erc20
from snekmate.auth import ownable

initializes: ownable
initializes: erc20[ownable := ownable]

exports: erc20.__interface__


@deploy
def __init__(decimals: uint8):
ownable.__init__()
erc20.__init__("mock", "mock", decimals, "mock", "mock")
49 changes: 49 additions & 0 deletions tests/mocks/MockERC20Fee.vy
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# pragma version ~=0.4.0

from snekmate.tokens import erc20
from snekmate.auth import ownable

from ethereum.ercs import IERC20

initializes: ownable
initializes: erc20[ownable := ownable]

exports: (erc20.approve, erc20.transferFrom)

MAX_FEE: constant(uint256) = 10_000
FEE_PERCENTAGE: public(immutable(uint256))

@deploy
def __init__(decimals: uint8, fee: uint256):
ownable.__init__()
erc20.__init__("mock", "mock", decimals, "mock", "mock")
assert fee <= MAX_FEE, "fee must be less than or equal to 100%"
FEE_PERCENTAGE = fee


@internal
def _transfer(owner: address, to: address, amount: uint256):
# Adapted from snekmate to have fee on transfer

assert owner != empty(address), "erc20: transfer from the zero address"
assert to != empty(address), "erc20: transfer to the zero address"

fee: uint256 = amount * FEE_PERCENTAGE // MAX_FEE
amount -= fee

erc20._burn(owner, fee)

owner_balance: uint256 = erc20.balanceOf[owner]
assert owner_balance >= amount, "erc20: transfer amount exceeds balance"
# Deduct full amount from sender
erc20.balanceOf[owner] = unsafe_sub(owner_balance, amount)
# Credit recipient with full amount first
erc20.balanceOf[to] = unsafe_add(erc20.balanceOf[to], amount)
log IERC20.Transfer(owner, to, amount)


@external
def transfer(to: address, amount: uint256) -> bool:
# Adapted from snekmate to have fee on transfer
self._transfer(msg.sender, to, amount)
return True
Loading
Loading