Skip to content

Commit c81dbdc

Browse files
committed
use DynArrays and save a bunch of gas while deploying pool
1 parent d8021ec commit c81dbdc

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

contracts/main/CurveTwocryptoFactory.vy

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,9 @@ math_implementation: public(address)
8686
# mapping of coins -> pools for trading
8787
# a mapping key is generated for each pair of addresses via
8888
# `bitwise_xor(convert(a, uint256), convert(b, uint256))`
89-
markets: HashMap[uint256, address[4294967296]]
90-
market_counts: HashMap[uint256, uint256]
91-
92-
pool_count: public(uint256) # actual length of pool_list
89+
markets: HashMap[uint256, DynArray[address, 4294967296]]
9390
pool_data: HashMap[address, PoolArray]
94-
pool_list: public(address[4294967296]) # master list of pools
91+
pool_list: public(DynArray[address, 4294967296]) # master list of pools
9592

9693

9794
@external
@@ -203,9 +200,8 @@ def deploy_pool(
203200
)
204201

205202
# populate pool data
206-
length: uint256 = self.pool_count
207-
self.pool_list[length] = pool
208-
self.pool_count = length + 1
203+
self.pool_list.append(pool)
204+
209205
self.pool_data[pool].decimals = decimals
210206
self.pool_data[pool].coins = _coins
211207
self.pool_data[pool].implementation = pool_implementation
@@ -237,10 +233,7 @@ def _add_coins_to_market(coin_a: address, coin_b: address, pool: address):
237233
key: uint256 = (
238234
convert(coin_a, uint256) ^ convert(coin_b, uint256)
239235
)
240-
241-
length: uint256 = self.market_counts[key]
242-
self.markets[key][length] = pool
243-
self.market_counts[key] = length + 1
236+
self.markets[key].append(pool)
244237

245238

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

380373

374+
@view
375+
@external
376+
def pool_count() -> uint256:
377+
"""
378+
@notice Get number of pools deployed from the factory
379+
@return Number of pools deployed from factory
380+
"""
381+
return len(self.pool_list)
382+
383+
381384
@view
382385
@external
383386
def get_coins(_pool: address) -> address[N_COINS]:
@@ -460,4 +463,4 @@ def get_market_counts(coin_a: address, coin_b: address) -> uint256:
460463
convert(coin_a, uint256) ^ convert(coin_b, uint256)
461464
)
462465

463-
return self.market_counts[key]
466+
return len(self.markets[key])

tests/unitary/pool/test_admin_fee.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
@given(ratio=st.floats(min_value=0.0001, max_value=0.1))
10-
@settings(max_examples=1000, deadline=None)
10+
@settings(max_examples=10, deadline=None)
1111
def test_admin_fee_after_deposit(
1212
swap, coins, fee_receiver, user, user_b, ratio
1313
):

0 commit comments

Comments
 (0)