Skip to content

Commit

Permalink
Merge pull request #162 from bancorprotocol/quickfix
Browse files Browse the repository at this point in the history
Quickfix
  • Loading branch information
mikewcasale authored Sep 14, 2022
2 parents df642d6 + 05a54cd commit 23a776e
Show file tree
Hide file tree
Showing 3 changed files with 693 additions and 41 deletions.
3 changes: 3 additions & 0 deletions bancor_research/bancor_simulator/v3/spec/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ def whitelist_token(self, tkn_name: str, timestamp: int = 0):
state = self.get_state(copy_type="initial", timestamp=timestamp)
tkn_name = tkn_name.lower()
state.price_feeds[tkn_name] = [0 for _ in range(len(state.price_feeds))]

state.create_whitelisted_tkn(tkn_name)
handle_whitelisting_tokens(state)

self.next_transaction(state)
handle_logging(
tkn_name,
Expand Down
43 changes: 43 additions & 0 deletions bancor_research/bancor_simulator/v3/spec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,49 @@ def swap_fee_collection(
return b * d * x * (1 - e) / (a + x)


def handle_whitelisting_tokens(state):
whitelisted_tokens = state.whitelisted_tokens
bnt_min_liquidity = state.bnt_min_liquidity
withdrawal_fee = state.withdrawal_fee
network_fee = state.network_fee
cooldown_time = state.cooldown_time

for tkn_name in whitelisted_tokens:

# Get tokens not yet initialized.
if tkn_name not in state.tokens:

decimals = whitelisted_tokens[tkn_name]["decimals"]
trading_fee = whitelisted_tokens[tkn_name]["trading_fee"]
bnt_funding_limit = whitelisted_tokens[tkn_name]["bnt_funding_limit"]
ep_vault_balance = whitelisted_tokens[tkn_name]["ep_vault_balance"]

# initialize tokens
state.tokens[tkn_name] = Tokens(
tkn_name=tkn_name,
decimals=decimals,
trading_fee=trading_fee,
bnt_min_liquidity=bnt_min_liquidity,
network_fee=network_fee,
bnt_funding_limit=bnt_funding_limit,
withdrawal_fee=withdrawal_fee,
cooldown_time=cooldown_time,
external_protection_vault=Token(balance=ep_vault_balance),
)

# initialize pooltoken
pooltkn_name = get_pooltoken_name(tkn_name)
state.tokens[pooltkn_name] = Tokens(
tkn_name=pooltkn_name,
trading_fee=trading_fee,
bnt_min_liquidity=bnt_min_liquidity,
network_fee=network_fee,
bnt_funding_limit=bnt_funding_limit,
withdrawal_fee=withdrawal_fee,
cooldown_time=cooldown_time,
)


def init_protocol(
state: State,
whitelisted_tokens: dict,
Expand Down
Loading

0 comments on commit 23a776e

Please sign in to comment.