Skip to content

Commit

Permalink
Merge pull request #163 from bancorprotocol/quickfix
Browse files Browse the repository at this point in the history
Quickfix
  • Loading branch information
mikewcasale authored Sep 16, 2022
2 parents 23a776e + be02f14 commit cbe434d
Show file tree
Hide file tree
Showing 3 changed files with 4,731 additions and 51 deletions.
23 changes: 11 additions & 12 deletions bancor_research/bancor_simulator/v3/spec/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@ def deposit(
state = deposit_tkn(
state=state, tkn_name=tkn_name, tkn_amt=tkn_amt, user_name=user_name
)
self.next_transaction(state)
handle_logging(
state = handle_logging(
tkn_name=tkn_name,
tkn_amt=tkn_amt,
action_name=action_name,
user_name=user_name,
transaction_id=self.transaction_id,
state=state,
)
self.next_transaction(state)

def trade(
self,
Expand All @@ -240,15 +240,15 @@ def trade(
state = process_trade(
state, tkn_amt, source_token, target_token, user_name, timestamp
)
self.next_transaction(state)
handle_logging(
state = handle_logging(
source_token + "->" + target_token,
tkn_amt,
transaction_type,
user_name,
self.transaction_id,
state,
)
self.next_transaction(state)

def begin_cooldown_by_rtkn(
self,
Expand All @@ -269,10 +269,11 @@ def begin_cooldown_by_rtkn(
id_number = begin_withdrawal_cooldown_by_rtkn(
state, tkn_amt, tkn_name, user_name
)
self.next_transaction(state)
handle_logging(
state = handle_logging(
tkn_name, tkn_amt, action_name, user_name, self.transaction_id, state
)
self.next_transaction(state)

return id_number

def begin_cooldown_by_ptkn(
Expand Down Expand Up @@ -313,8 +314,6 @@ def withdraw(
state = self.get_state(copy_type="initial", timestamp=timestamp)
tkn_name = state.users[user_name].pending_withdrawals[id_number].tkn_name
state = process_withdrawal(state, user_name, id_number, timestamp)

self.next_transaction(state)
state = handle_logging(
tkn_name,
Decimal(0),
Expand All @@ -323,6 +322,7 @@ def withdraw(
self.transaction_id,
state,
)
self.next_transaction(state)

def enable_trading(
self,
Expand All @@ -342,15 +342,15 @@ def enable_trading(
if bnt_price:
state.price_feeds.at[state.timestamp, "bnt"] = bnt_price
state = enable_trading(state, tkn_name)
self.next_transaction(state)
handle_logging(
state = handle_logging(
tkn_name,
Decimal("0"),
transaction_type,
user_name,
state.transaction_id,
state,
)
self.next_transaction(state)

def describe(self, decimals: int = -1):
"""
Expand Down Expand Up @@ -430,8 +430,7 @@ 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.price_feeds[tkn_name] = state.price_feeds["bnt"].values
state.create_whitelisted_tkn(tkn_name)
handle_whitelisting_tokens(state)

Expand Down
78 changes: 39 additions & 39 deletions bancor_research/bancor_simulator/v3/spec/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,45 +471,45 @@ def handle_logging(
"""
state.iter_transaction_id = transaction_id
for tkn_name in state.whitelisted_tokens:
try:
state_variables = {
"timestamp": [state.timestamp],
"latest_action": [action_name],
"latest_amt": [tkn_amt],
"latest_user_name": [user_name],
"tkn_name": [tkn_name],
"master_vault_tkn": [get_master_vault_balance(state, tkn_name)],
"erc20contracts_bntkn": [get_pooltoken_balance(state, tkn_name)],
"staked_tkn": [get_staked_balance(state, tkn_name)],
"is_trading_enabled": [get_is_trading_enabled(state, tkn_name)],
"bnt_trading_liquidity": [get_bnt_trading_liquidity(state, tkn_name)],
"tkn_trading_liquidity": [get_tkn_trading_liquidity(state, tkn_name)],
"trading_fee": [get_trading_fee(state, tkn_name)],
"bnt_funding_limit": [get_bnt_funding_limit(state, tkn_name)],
"bnt_remaining_funding": [get_bnt_remaining_funding(state, tkn_name)],
"bnt_funding_amt": [get_bnt_funding_amt(state, tkn_name)],
"external_protection_vault": [
get_external_protection_vault_balance(state, tkn_name)
],
"spot_rate": [get_spot_rate(state, tkn_name)],
"ema_rate": [get_ema_rate(state, tkn_name)],
"inv_spot_rate": [get_inv_spot_rate(state, tkn_name)],
"inv_ema_rate": [get_inv_ema_rate(state, tkn_name)],
"ema_last_updated": [state.tokens[tkn_name].ema_last_updated],
"network_fee": [state.network_fee],
"withdrawal_fee": [state.withdrawal_fee],
"bnt_min_liquidity": [state.bnt_min_liquidity],
"cooldown_time": [state.cooldown_time],
"protocol_wallet_bnbnt": [get_protocol_wallet_balance(state, "bnt")],
"vortex_bnt": [get_vortex_balance(state, "bnt")],
"erc20contracts_bnbnt": [get_pooltoken_balance(state, "bnt")],
"master_vault_bnt": [get_master_vault_balance(state, "bnt")],
"staked_bnt": [get_staked_balance(state, "bnt")],
"bnbnt_rate": [state.bnbnt_rate],
}
state.history.append(DataFrame(state_variables))
except KeyError:
pass
# try:
state_variables = {
"timestamp": [state.timestamp],
"latest_action": [action_name],
"latest_amt": [tkn_amt],
"latest_user_name": [user_name],
"tkn_name": [tkn_name],
"master_vault_tkn": [get_master_vault_balance(state, tkn_name)],
"erc20contracts_bntkn": [get_pooltoken_balance(state, tkn_name)],
"staked_tkn": [get_staked_balance(state, tkn_name)],
"is_trading_enabled": [get_is_trading_enabled(state, tkn_name)],
"bnt_trading_liquidity": [get_bnt_trading_liquidity(state, tkn_name)],
"tkn_trading_liquidity": [get_tkn_trading_liquidity(state, tkn_name)],
"trading_fee": [get_trading_fee(state, tkn_name)],
"bnt_funding_limit": [get_bnt_funding_limit(state, tkn_name)],
"bnt_remaining_funding": [get_bnt_remaining_funding(state, tkn_name)],
"bnt_funding_amt": [get_bnt_funding_amt(state, tkn_name)],
"external_protection_vault": [
get_external_protection_vault_balance(state, tkn_name)
],
"spot_rate": [get_spot_rate(state, tkn_name)],
"ema_rate": [get_ema_rate(state, tkn_name)],
"inv_spot_rate": [get_inv_spot_rate(state, tkn_name)],
"inv_ema_rate": [get_inv_ema_rate(state, tkn_name)],
"ema_last_updated": [state.tokens[tkn_name].ema_last_updated],
"network_fee": [state.network_fee],
"withdrawal_fee": [state.withdrawal_fee],
"bnt_min_liquidity": [state.bnt_min_liquidity],
"cooldown_time": [state.cooldown_time],
"protocol_wallet_bnbnt": [get_protocol_wallet_balance(state, "bnt")],
"vortex_bnt": [get_vortex_balance(state, "bnt")],
"erc20contracts_bnbnt": [get_pooltoken_balance(state, "bnt")],
"master_vault_bnt": [get_master_vault_balance(state, "bnt")],
"staked_bnt": [get_staked_balance(state, "bnt")],
"bnbnt_rate": [state.bnbnt_rate],
}
state.history.append(DataFrame(state_variables))
# except KeyError:
# pass

return state

Expand Down
Loading

0 comments on commit cbe434d

Please sign in to comment.