Skip to content

Commit

Permalink
use DynArrays and save a bunch of gas while deploying pool
Browse files Browse the repository at this point in the history
  • Loading branch information
bout3fiddy committed Nov 22, 2023
1 parent d8021ec commit c81dbdc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions contracts/main/CurveTwocryptoFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ math_implementation: public(address)
# mapping of coins -> pools for trading
# a mapping key is generated for each pair of addresses via
# `bitwise_xor(convert(a, uint256), convert(b, uint256))`
markets: HashMap[uint256, address[4294967296]]
market_counts: HashMap[uint256, uint256]

pool_count: public(uint256) # actual length of pool_list
markets: HashMap[uint256, DynArray[address, 4294967296]]
pool_data: HashMap[address, PoolArray]
pool_list: public(address[4294967296]) # master list of pools
pool_list: public(DynArray[address, 4294967296]) # master list of pools


@external
Expand Down Expand Up @@ -203,9 +200,8 @@ def deploy_pool(
)

# populate pool data
length: uint256 = self.pool_count
self.pool_list[length] = pool
self.pool_count = length + 1
self.pool_list.append(pool)

self.pool_data[pool].decimals = decimals
self.pool_data[pool].coins = _coins
self.pool_data[pool].implementation = pool_implementation
Expand Down Expand Up @@ -237,10 +233,7 @@ def _add_coins_to_market(coin_a: address, coin_b: address, pool: address):
key: uint256 = (
convert(coin_a, uint256) ^ convert(coin_b, uint256)
)

length: uint256 = self.market_counts[key]
self.markets[key][length] = pool
self.market_counts[key] = length + 1
self.markets[key].append(pool)


@external
Expand Down Expand Up @@ -378,6 +371,16 @@ def find_pool_for_coins(_from: address, _to: address, i: uint256 = 0) -> address
# <--- Pool Getters --->


@view
@external
def pool_count() -> uint256:
"""
@notice Get number of pools deployed from the factory
@return Number of pools deployed from factory
"""
return len(self.pool_list)


@view
@external
def get_coins(_pool: address) -> address[N_COINS]:
Expand Down Expand Up @@ -460,4 +463,4 @@ def get_market_counts(coin_a: address, coin_b: address) -> uint256:
convert(coin_a, uint256) ^ convert(coin_b, uint256)
)

return self.market_counts[key]
return len(self.markets[key])
2 changes: 1 addition & 1 deletion tests/unitary/pool/test_admin_fee.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@given(ratio=st.floats(min_value=0.0001, max_value=0.1))
@settings(max_examples=1000, deadline=None)
@settings(max_examples=10, deadline=None)
def test_admin_fee_after_deposit(
swap, coins, fee_receiver, user, user_b, ratio
):
Expand Down

0 comments on commit c81dbdc

Please sign in to comment.