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

update tricrypto-ng #23

Merged
merged 56 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
0ad0764
feat: no more weth; no more public claim_admin_fees; wip: working on …
bout3fiddy Aug 1, 2023
3d0a62c
remove claiming fees from remove_liquidity
bout3fiddy Aug 1, 2023
b8e6393
amend docstring
bout3fiddy Aug 1, 2023
247920a
move fee collection to the top of liquidity methods
bout3fiddy Aug 1, 2023
3373977
raise fees while pool is ramping and only allow claiming admin fees w…
bout3fiddy Aug 2, 2023
b3b86d5
add MIN_GULP_INTERVAL logic
bout3fiddy Aug 2, 2023
5652a3d
convert some methods to pure to facilitate easier handling of state
bout3fiddy Aug 2, 2023
0c19f16
bye bye exchange_extended. you were good, but nobody used you
bout3fiddy Aug 2, 2023
1b5095e
Merge branch 'main' into remove_eth_transfers
bout3fiddy Aug 2, 2023
ed15aa1
simplify claim admin fees a bit
bout3fiddy Aug 2, 2023
19cd912
remove unneeded args from _exchange method
bout3fiddy Aug 2, 2023
184eeb8
adjust tests
bout3fiddy Aug 3, 2023
956311b
goodbye gulp. you were a feature too many
bout3fiddy Aug 3, 2023
2a90f9f
remove balances update
bout3fiddy Aug 3, 2023
1a6e898
wip: admin fee in individual tokens proposal
bout3fiddy Aug 4, 2023
b76e267
some ironing out of var names and remove updating D in storage since …
bout3fiddy Aug 4, 2023
d961100
remove stored_balances and use balances instead
bout3fiddy Aug 4, 2023
b98f895
update boa and start fixing tests
bout3fiddy Aug 4, 2023
033bd42
fix test: use _immutables since packed precisions are immutables
bout3fiddy Aug 4, 2023
7eebe94
fix tests: remove stored_balances
bout3fiddy Aug 4, 2023
8d1b609
fix: fee was waaaayyyy too high
bout3fiddy Aug 6, 2023
7acfc14
update tests and fix admin fee claiming logic
bout3fiddy Aug 7, 2023
96a09b9
add tests for exchange_received
bout3fiddy Aug 8, 2023
5b6bc95
test donation does not account in self.balances; add comments explain…
bout3fiddy Aug 8, 2023
958ffd5
fix: must adjust virtual price and D anyway
bout3fiddy Aug 8, 2023
7a21ea5
remove TODO in contract
bout3fiddy Aug 8, 2023
e55ae53
fix test_get_p test
bout3fiddy Aug 8, 2023
7467292
cei
bout3fiddy Aug 9, 2023
10507c9
set default receiver in exchange received to msg.sender
bout3fiddy Aug 14, 2023
178d8e4
add getter for gauge_implementaiton in l2 factory that points to zero
bout3fiddy Aug 14, 2023
043705a
revert changes to L2 factory
bout3fiddy Aug 14, 2023
9eab58c
add tvl oracle
bout3fiddy Aug 14, 2023
ae3e5cd
update tvl oracle
bout3fiddy Aug 14, 2023
73b5224
docstrings
bout3fiddy Aug 14, 2023
52ae070
optimise D oracle and rename to match stableswap-ng
bout3fiddy Aug 23, 2023
29940df
add tests; change name to xcp_oracle
bout3fiddy Aug 23, 2023
e6d616c
add clarity in comment
bout3fiddy Aug 27, 2023
2eea2a5
fix: precisions is not longer stored packed
bout3fiddy Aug 28, 2023
991db54
fix: use cached last_xcp insteadgit add .
bout3fiddy Sep 4, 2023
73a3398
remove raising fees
bout3fiddy Sep 4, 2023
b67ad80
reduce number of reads of coin balance
bout3fiddy Sep 4, 2023
7ea427f
remove invariant for fee check during ramp (in test)
bout3fiddy Sep 4, 2023
ab7a8f0
clean up _transfer_in
bout3fiddy Sep 5, 2023
b7cc65f
remove increaseAllowance and decreaseAllowance since we don't use it …
bout3fiddy Sep 8, 2023
8bbd3d8
break cei but use dx received for calcs instead
bout3fiddy Sep 12, 2023
a2b126c
fix test since we now acknowledge what goes in
bout3fiddy Sep 13, 2023
4630a27
add xcp time for oracle; make commit and apply for parameters a singl…
bout3fiddy Sep 13, 2023
de7d4cd
fix: set rebalancing params to the right var
bout3fiddy Sep 13, 2023
b30f59f
remove test that is no longer necessary'
bout3fiddy Sep 13, 2023
e925470
fix: add checks for applying xcp_ma_time
bout3fiddy Sep 13, 2023
59b387f
add exchange received note
bout3fiddy Sep 13, 2023
22b14b0
Merge branch 'main' into remove_eth_transfers
bout3fiddy Sep 14, 2023
6ed527d
remove unused local var
bout3fiddy Sep 14, 2023
1bc9337
Merge branch 'remove_eth_transfers' of https://github.com/bout3fiddy/…
bout3fiddy Sep 14, 2023
de23ace
reduce one redundant for-loop
bout3fiddy Sep 14, 2023
7ab6023
deploy new tricrypto implementations
bout3fiddy Sep 14, 2023
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
823 changes: 355 additions & 468 deletions contracts/main/CurveTricryptoOptimizedWETH.vy

Large diffs are not rendered by default.

14 changes: 0 additions & 14 deletions scripts/deployment_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,6 @@ def test_deployment(pool, coins, fee_receiver, account):
assert coin_contract.balanceOf(account) == coin_balance + dy_coin
logger.info(f"Removed {dy_coin} of {coin_name}.")

logger.info("------------------------------ Claim admin fees")
logger.info("(should not claim since pool hasn't accrued enough profits)")

fees_claimed = pool.balanceOf(fee_receiver)
pool.claim_admin_fees(sender=account, gas_limit=400000, **_get_tx_params())
if pool.totalSupply() < 10**18:
assert pool.balanceOf(fee_receiver) == fees_claimed
logger.info("No fees claimed.")
else:
assert pool.balanceOf(fee_receiver) > fees_claimed
logger.info(
f"{pool.balanceOf(fee_receiver) - fees_claimed} LP tokens of admin fees claimed!" # noqa: E501
)

logger.info(
"------------------------------ Remove liquidity proportionally"
)
Expand Down
8 changes: 7 additions & 1 deletion scripts/experiments/sim_dydx.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ def _get_dydx(swap, i, j):
A = ANN / 10**4 / 3**3
gamma = swap.gamma() / 10**18

xp = swap.internal.xp()
balances = []
for i in range(3):
balances.append(swap.balances(i))

xp = swap.internal.xp(
balances, swap._storage.price_scale_packed.get(), swap.precisions()
)

for k in range(3):
if k != i and k != j:
Expand Down
4 changes: 2 additions & 2 deletions tests/boa/fixtures/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def _crypto_swap_with_deposit(
@pytest.fixture(scope="module")
def params():

ma_time = 866 # 600 seconds / ln(2)
return {
"A": 135 * 3**3 * 10000,
"gamma": int(7e-5 * 1e18),
Expand All @@ -55,7 +54,8 @@ def params():
"allowed_extra_profit": 2 * 10**12,
"fee_gamma": int(0.01 * 1e18),
"adjustment_step": int(0.0015 * 1e18),
"ma_time": ma_time,
"ma_time": 866, # # 600 seconds//math.log(2)
"xcp_ma_time": 62324, # 12 hours//math.log(2)
"initial_prices": INITIAL_PRICES[1:],
}

Expand Down
46 changes: 7 additions & 39 deletions tests/boa/profiling/test_boa_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ def _random_exchange(swap):
i, j = _choose_indices()
amount = int(swap.balances(i) * 0.01)

use_eth = i == 2
value = 0
if use_eth:
value = amount

swap.exchange(i, j, amount, 0, use_eth, value=value)
swap.exchange(i, j, amount, 0)
boa.env.time_travel(random.randint(12, 600))


Expand All @@ -34,7 +29,7 @@ def _random_deposit(swap):
c = random.uniform(0, 0.05)
amounts = [int(c * i * random.uniform(0, 0.8)) for i in balances]

swap.add_liquidity(amounts, 0, True, value=amounts[2])
swap.add_liquidity(amounts, 0)

boa.env.time_travel(random.randint(12, 600))

Expand All @@ -44,42 +39,20 @@ def _random_deposit_weth(swap):
balances = [swap.balances(i) for i in range(3)]
c = random.uniform(0, 0.05)
amounts = [int(c * i * random.uniform(0, 0.8)) for i in balances]
swap.add_liquidity(amounts, 0, False)
swap.add_liquidity(amounts, 0)
boa.env.time_travel(random.randint(12, 600))


def _random_deposit_one(swap):
balances = [swap.balances(i) for i in range(3)]
c = random.uniform(0, 0.05)
i = random.randint(0, 2)
use_eth = i == 2
amounts = [0, 0, 0]
value = 0
for j in range(3):
if i == j:
amounts[i] = int(balances[i] * c)
if use_eth:
value = amounts[i]

swap.add_liquidity(amounts, 0, use_eth, value=value)

boa.env.time_travel(random.randint(12, 600))


def _random_deposit_eth(swap):
balances = [swap.balances(i) for i in range(3)]
c = random.uniform(0, 0.05)
i = 2
use_eth = True
amounts = [0, 0, 0]
value = 0
for j in range(3):
if i == j:
amounts[i] = int(balances[i] * c)
if use_eth:
value = amounts[i]

swap.add_liquidity(amounts, 0, use_eth, value=value)
swap.add_liquidity(amounts, 0)

boa.env.time_travel(random.randint(12, 600))

Expand All @@ -88,7 +61,7 @@ def _random_proportional_withdraw(swap):

amount = int(swap.totalSupply() * random.uniform(0, 0.01))

swap.remove_liquidity(amount, [0, 0, 0], True)
swap.remove_liquidity(amount, [0, 0, 0])

boa.env.time_travel(random.randint(12, 600))

Expand All @@ -97,13 +70,11 @@ def _random_withdraw_one(swap):

i = random.randint(0, 2)
amount = int(swap.totalSupply() * 0.01)
use_eth = i == 2

swap.remove_liquidity_one_coin(amount, i, 0, use_eth)
swap.remove_liquidity_one_coin(amount, i, 0)


@pytest.mark.profile
def test_profile_amms(swap_with_deposit, coins, user, math_contract):
def test_profile_amms(swap_with_deposit, coins, user):

swap = swap_with_deposit

Expand All @@ -126,9 +97,6 @@ def test_profile_amms(swap_with_deposit, coins, user, math_contract):
# deposit single token:
_random_deposit_one(swap)

# deposit only eth:
_random_deposit_eth(swap)

# swap:
_random_exchange(swap)

Expand Down
4 changes: 1 addition & 3 deletions tests/boa/unitary/factory/test_deploy_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def empty_factory(deployer, fee_receiver, owner, weth):
def test_check_packed_params_on_deployment(swap, params, coins):

# check packed precisions
unpacked_precisions = swap.internal._unpack(
swap._storage.packed_precisions.get()
)
unpacked_precisions = swap.precisions()
for i in range(len(coins)):
assert unpacked_precisions[i] == 10 ** (18 - coins[i].decimals())

Expand Down
15 changes: 5 additions & 10 deletions tests/boa/unitary/math/test_get_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ def get_p(

def _get_dydx_vyper(swap, i, j, price_calc):

# ANN = swap.A()
# A = ANN // 10**4 // 3**3
A = swap.A()
gamma = swap.gamma()

xp = swap.internal.xp()
xp = swap.internal.xp(
swap._storage.balances.get(),
swap._storage.price_scale_packed.get(),
)

for k in range(3):
if k != i and k != j:
Expand All @@ -67,10 +65,7 @@ def _get_dydx_vyper(swap, i, j, price_calc):
x2 = xp[j]
x3 = xp[k]

D = swap.D()

dxdy = price_calc.get_p(x1, x2, x3, D, A, gamma)
return dxdy
return price_calc.get_p(x1, x2, x3, swap.D(), swap.A(), swap.gamma())


def _get_prices_vyper(swap, price_calc):
Expand Down
12 changes: 9 additions & 3 deletions tests/boa/unitary/math/test_get_p_expt.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ def _get_prices_vyper(swap, price_calc):

A = swap.A()
gamma = swap.gamma()
xp = swap.internal.xp()
balances = []
for i in range(3):
balances.append(swap.balances(i))

xp = swap.internal.xp(balances, swap._storage.price_scale_packed.get())

D = swap.D()

p = price_calc.get_p(xp, D, [A, gamma])
Expand Down Expand Up @@ -224,11 +229,12 @@ def test_against_expt(dydx_optimised_math):
def _imbalance_swap(swap, coins, imbalance_frac, user, dollar_amount, i, j):

# make swap imbalanced:
mint_for_testing(coins[0], user, int(swap.balances(0) * imbalance_frac))
imbalance_amount = int(swap.balances(i) * imbalance_frac)
mint_for_testing(coins[i], user, imbalance_amount)

try:
with boa.env.prank(user):
swap.exchange(i, j, coins[0].balanceOf(user), 0)
swap.exchange(i, j, imbalance_amount, 0)
except boa.BoaError as b_error:
assert_string_contains(
b_error.stack_trace.last_frame.pretty_vm_reason,
Expand Down
33 changes: 21 additions & 12 deletions tests/boa/unitary/pool/admin/test_commit_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import boa


def _commit_apply_new_params(swap, params):
swap.commit_new_parameters(
def _apply_new_params(swap, params):
swap.apply_new_parameters(
params["mid_fee"],
params["out_fee"],
params["fee_gamma"],
params["allowed_extra_profit"],
params["adjustment_step"],
params["ma_time"],
params["xcp_ma_time"],
)
boa.env.time_travel(7 * 24 * 60 * 60)
swap.apply_new_parameters()


def test_commit_accept_mid_fee(swap, factory_admin, params):

p = copy.deepcopy(params)
p["mid_fee"] = p["mid_fee"] + 1
with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

mid_fee = swap.internal._unpack(swap._storage.packed_fee_params.get())[0]
assert mid_fee == p["mid_fee"]
Expand All @@ -32,7 +31,7 @@ def test_commit_accept_out_fee(swap, factory_admin, params):
p = copy.deepcopy(params)
p["out_fee"] = p["out_fee"] + 1
with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

out_fee = swap.internal._unpack(swap._storage.packed_fee_params.get())[1]
assert out_fee == p["out_fee"]
Expand All @@ -43,7 +42,7 @@ def test_commit_accept_fee_gamma(swap, factory_admin, params):
p = copy.deepcopy(params)
p["fee_gamma"] = 10**17
with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

fee_gamma = swap.internal._unpack(swap._storage.packed_fee_params.get())[2]
assert fee_gamma == p["fee_gamma"]
Expand All @@ -57,7 +56,7 @@ def test_commit_accept_fee_params(swap, factory_admin, params):
p["fee_gamma"] = 10**17

with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

fee_params = swap.internal._unpack(swap._storage.packed_fee_params.get())
assert fee_params[0] == p["mid_fee"]
Expand All @@ -70,7 +69,7 @@ def test_commit_accept_allowed_extra_profit(swap, factory_admin, params):
p = copy.deepcopy(params)
p["allowed_extra_profit"] = 10**17
with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

allowed_extra_profit = swap.internal._unpack(
swap._storage.packed_rebalancing_params.get()
Expand All @@ -83,7 +82,7 @@ def test_commit_accept_adjustment_step(swap, factory_admin, params):
p = copy.deepcopy(params)
p["adjustment_step"] = 10**17
with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

adjustment_step = swap.internal._unpack(
swap._storage.packed_rebalancing_params.get()
Expand All @@ -96,14 +95,24 @@ def test_commit_accept_ma_time(swap, factory_admin, params):
p = copy.deepcopy(params)
p["ma_time"] = 872
with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

ma_time = swap.internal._unpack(
swap._storage.packed_rebalancing_params.get()
)[2]
assert ma_time == p["ma_time"]


def test_commit_accept_xcp_ma_time(swap, factory_admin, params):

p = copy.deepcopy(params)
p["xcp_ma_time"] = 872541
with boa.env.prank(factory_admin):
_apply_new_params(swap, p)

assert swap.xcp_ma_time() == p["xcp_ma_time"]


def test_commit_accept_rebalancing_params(swap, factory_admin, params):

p = copy.deepcopy(params)
Expand All @@ -112,7 +121,7 @@ def test_commit_accept_rebalancing_params(swap, factory_admin, params):
p["ma_time"] = 1000

with boa.env.prank(factory_admin):
_commit_apply_new_params(swap, p)
_apply_new_params(swap, p)

rebalancing_params = swap.internal._unpack(
swap._storage.packed_rebalancing_params.get()
Expand Down
Loading
Loading