From 32c21f22395656368fce1e217b028fe8436ba79e Mon Sep 17 00:00:00 2001 From: mikewcasale Date: Mon, 19 Sep 2022 04:40:39 -0700 Subject: [PATCH 1/3] Update network.py - fixed timestamp logging issue --- bancor_research/bancor_simulator/v3/spec/network.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bancor_research/bancor_simulator/v3/spec/network.py b/bancor_research/bancor_simulator/v3/spec/network.py index 9c3dd62..ecc297b 100644 --- a/bancor_research/bancor_simulator/v3/spec/network.py +++ b/bancor_research/bancor_simulator/v3/spec/network.py @@ -134,21 +134,22 @@ def copy_state(self, copy_type: str, state: State = None, timestamp: int = 0): ts = s.timestamp else: ts = timestamp + s.timestamp = timestamp self._backup_states[f"{copy_type}_{ts}"] = s.copy() return s - def update_state(self, state: State): + def update_state(self, state: State, timestamp: int = 0): """ Updates the global state at the end of each action. """ - self.global_state = self.copy_state("end", state) + self.global_state = self.copy_state("end", state, timestamp) - def next_transaction(self, state: State): + def next_transaction(self, state: State, timestamp: int = 0): """ Increments a new id and state for each action """ if self.log_state: - self.update_state(state) + self.update_state(state, timestamp) self.transaction_id += 1 def get_state( From 19118400c9dc34783ec92d9985aa10d11ec5628b Mon Sep 17 00:00:00 2001 From: mikewcasale Date: Mon, 19 Sep 2022 11:41:17 +0000 Subject: [PATCH 2/3] fixup: Format Python code with Black --- bancor_research/bancor_simulator/v3/spec/network.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bancor_research/bancor_simulator/v3/spec/network.py b/bancor_research/bancor_simulator/v3/spec/network.py index ecc297b..740dff6 100644 --- a/bancor_research/bancor_simulator/v3/spec/network.py +++ b/bancor_research/bancor_simulator/v3/spec/network.py @@ -218,7 +218,6 @@ def deposit( ) self.next_transaction(state) - def trade( self, tkn_amt: str, @@ -252,7 +251,6 @@ def trade( ) self.next_transaction(state) - def begin_cooldown_by_rtkn( self, tkn_amt: str, @@ -327,7 +325,6 @@ def withdraw( ) self.next_transaction(state) - def enable_trading( self, tkn_name: str, @@ -356,7 +353,6 @@ def enable_trading( ) self.next_transaction(state) - def describe(self, decimals: int = -1): """ Describes the state ledger in a format similar to BIP15 documentation. @@ -435,7 +431,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]=state.price_feeds['bnt'].values + state.price_feeds[tkn_name] = state.price_feeds["bnt"].values state.create_whitelisted_tkn(tkn_name) handle_whitelisting_tokens(state) From fbfc436f1ae558ea50c5297f33e354d9825eceab Mon Sep 17 00:00:00 2001 From: mikewcasale Date: Mon, 19 Sep 2022 04:42:33 -0700 Subject: [PATCH 3/3] Create User Actions and State Transition Functions - (pt 2 of 4).ipynb --- ...e Transition Functions - (pt 2 of 4).ipynb | 213 ++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 examples/artifacts/User Actions and State Transition Functions - (pt 2 of 4).ipynb diff --git a/examples/artifacts/User Actions and State Transition Functions - (pt 2 of 4).ipynb b/examples/artifacts/User Actions and State Transition Functions - (pt 2 of 4).ipynb new file mode 100644 index 0000000..78db6b6 --- /dev/null +++ b/examples/artifacts/User Actions and State Transition Functions - (pt 2 of 4).ipynb @@ -0,0 +1,213 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "source": [ + "# User Actions and State Transition FUnctions - (pt 2 of 4)" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from bancor_research.bancor_simulator.v3.spec.state import *\n", + "from bancor_research.bancor_simulator.v3.spec.network import BancorDapp" + ] + }, + { + "cell_type": "markdown", + "source": [ + "#### Review from last session\n", + "\n", + "Configure the system state.\n" + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [ + { + "data": { + "text/plain": " bnt eth link tkn wbtc \\\n1 Account Alice 1000000 1000000 1000000 0 0 \n Bob 1000000 1000000 1000000 0 0 \n2 Pool a: TKN Staked Balance 0 0 0 0 0 \n b: TKN Trading Liquidity 0 0 0 0 0 \n c: BNT Trading Liquidity 0 0 0 0 0 \n d: BNT Current Funding 0 0 0 0 0 \n e: Spot Rate 0 0 0 0 0 \n f: Average Rate 0 0 0 0 0 \n g: Average Inverse Rate 0 0 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 \n Master Vault 0 0 0 0 0 \n Protection Vault 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 \n Rewards Vault 0 0 0 0 0 \n\n usdc usdt dai bnbnt bneth \\\n1 Account Alice 1000000 1000000 1000000 0 0 \n Bob 1000000 1000000 1000000 0 0 \n2 Pool a: TKN Staked Balance 0 0 0 0 0 \n b: TKN Trading Liquidity 0 0 0 0 0 \n c: BNT Trading Liquidity 0 0 0 0 0 \n d: BNT Current Funding 0 0 0 0 0 \n e: Spot Rate 0 0 0 0 0 \n f: Average Rate 0 0 0 0 0 \n g: Average Inverse Rate 0 0 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 \n Master Vault 0 0 0 0 0 \n Protection Vault 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 \n Rewards Vault 0 0 0 0 0 \n\n bnlink bntkn bnwbtc bnusdc bnusdt bndai \\\n1 Account Alice 0 0 0 0 0 0 \n Bob 0 0 0 0 0 0 \n2 Pool a: TKN Staked Balance 0 0 0 0 0 0 \n b: TKN Trading Liquidity 0 0 0 0 0 0 \n c: BNT Trading Liquidity 0 0 0 0 0 0 \n d: BNT Current Funding 0 0 0 0 0 0 \n e: Spot Rate 0 0 0 0 0 0 \n f: Average Rate 0 0 0 0 0 0 \n g: Average Inverse Rate 0 0 0 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 0 \n Master Vault 0 0 0 0 0 0 \n Protection Vault 0 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 0 \n Rewards Vault 0 0 0 0 0 0 \n\n vbnt \n1 Account Alice 0 \n Bob 0 \n2 Pool a: TKN Staked Balance 0 \n b: TKN Trading Liquidity 0 \n c: BNT Trading Liquidity 0 \n d: BNT Current Funding 0 \n e: Spot Rate 0 \n f: Average Rate 0 \n g: Average Inverse Rate 0 \n3 Network BNT Staked Balance 0 \n Master Vault 0 \n Protection Vault 0 \n Protocol Equity 0 \n Rewards Vault 0 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
bntethlinktknwbtcusdcusdtdaibnbntbnethbnlinkbntknbnwbtcbnusdcbnusdtbndaivbnt
1AccountAlice10000001000000100000000100000010000001000000000000000
Bob10000001000000100000000100000010000001000000000000000
2Poola: TKN Staked Balance00000000000000000
b: TKN Trading Liquidity00000000000000000
c: BNT Trading Liquidity00000000000000000
d: BNT Current Funding00000000000000000
e: Spot Rate00000000000000000
f: Average Rate00000000000000000
g: Average Inverse Rate00000000000000000
3NetworkBNT Staked Balance00000000000000000
Master Vault00000000000000000
Protection Vault00000000000000000
Protocol Equity00000000000000000
Rewards Vault00000000000000000
\n
" + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Initialize the main simulator class\n", + "v3 = BancorDapp()\n", + "\n", + "# whitelist tokens\n", + "v3.whitelist_token('usdc')\n", + "v3.whitelist_token('usdt')\n", + "v3.whitelist_token('dai')\n", + "\n", + "# Create the users\n", + "v3.create_user('Alice')\n", + "\n", + "# Set the initial starting balances\n", + "v3.set_user_balance(user_name='Alice', tkn_name='eth',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Alice', tkn_name='link',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Alice', tkn_name='bnt',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Alice', tkn_name='usdc',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Alice', tkn_name='usdt',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Alice', tkn_name='dai',tkn_amt=1000000)\n", + "\n", + "v3.create_user('Bob')\n", + "\n", + "# Set the initial starting balances\n", + "v3.set_user_balance(user_name='Bob', tkn_name='eth',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Bob', tkn_name='link',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Bob', tkn_name='bnt',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Bob', tkn_name='usdc',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Bob', tkn_name='usdt',tkn_amt=1000000)\n", + "v3.set_user_balance(user_name='Bob', tkn_name='dai',tkn_amt=1000000)\n", + "\n", + "v3.describe()" + ] + }, + { + "cell_type": "markdown", + "source": [ + "#### Review from last session\n", + "\n", + "Create some deposits to bootstrap the pools." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [ + { + "data": { + "text/plain": " bnt eth \\\n1 Account Alice 1000000 950000 \n Bob 1000000 1000000 \n2 Pool a: TKN Staked Balance 0 50000 \n b: TKN Trading Liquidity 0 20.000 \n c: BNT Trading Liquidity 0 20000 \n d: BNT Current Funding 0 20000 \n e: Spot Rate 0 1E+3 \n f: Average Rate 0 1E+3 \n g: Average Inverse Rate 0 0.001 \n3 Network BNT Staked Balance 60000 0 \n Master Vault 60000 50000 \n Protection Vault 0 0 \n Protocol Equity 0 0 \n Rewards Vault 0 0 \n\n link \\\n1 Account Alice 1000000 \n Bob 450000 \n2 Pool a: TKN Staked Balance 550000 \n b: TKN Trading Liquidity 3333.33333333333333333333333333333333333333333... \n c: BNT Trading Liquidity 20000 \n d: BNT Current Funding 20000 \n e: Spot Rate 6.00000000000000000000000000000000000000000000... \n f: Average Rate 6.00000000000000000000000000000000000000000000... \n g: Average Inverse Rate 0.16666666666666666666666666666666666666666666... \n3 Network BNT Staked Balance 0 \n Master Vault 550000 \n Protection Vault 0 \n Protocol Equity 0 \n Rewards Vault 0 \n\n tkn wbtc usdc usdt dai bnbnt \\\n1 Account Alice 0 0 500000 1000000 1000000 0 \n Bob 0 0 1000000 1000000 1000000 0 \n2 Pool a: TKN Staked Balance 0 0 500000 0 0 0 \n b: TKN Trading Liquidity 0 0 20000 0 0 0 \n c: BNT Trading Liquidity 0 0 20000 0 0 0 \n d: BNT Current Funding 0 0 20000 0 0 0 \n e: Spot Rate 0 0 1 0 0 0 \n f: Average Rate 0 0 1 0 0 0 \n g: Average Inverse Rate 0 0 1 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 0 \n Master Vault 0 0 500000 0 0 0 \n Protection Vault 0 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 60000 \n Rewards Vault 0 0 0 0 0 0 \n\n bneth bnlink bntkn bnwbtc bnusdc bnusdt \\\n1 Account Alice 50000 0 0 0 500000 0 \n Bob 0 550000 0 0 0 0 \n2 Pool a: TKN Staked Balance 0 0 0 0 0 0 \n b: TKN Trading Liquidity 0 0 0 0 0 0 \n c: BNT Trading Liquidity 0 0 0 0 0 0 \n d: BNT Current Funding 0 0 0 0 0 0 \n e: Spot Rate 0 0 0 0 0 0 \n f: Average Rate 0 0 0 0 0 0 \n g: Average Inverse Rate 0 0 0 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 0 \n Master Vault 0 0 0 0 0 0 \n Protection Vault 0 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 0 \n Rewards Vault 0 0 0 0 0 0 \n\n bndai vbnt \n1 Account Alice 0 0 \n Bob 0 0 \n2 Pool a: TKN Staked Balance 0 0 \n b: TKN Trading Liquidity 0 0 \n c: BNT Trading Liquidity 0 0 \n d: BNT Current Funding 0 0 \n e: Spot Rate 0 0 \n f: Average Rate 0 0 \n g: Average Inverse Rate 0 0 \n3 Network BNT Staked Balance 0 0 \n Master Vault 0 0 \n Protection Vault 0 0 \n Protocol Equity 0 0 \n Rewards Vault 0 0 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
bntethlinktknwbtcusdcusdtdaibnbntbnethbnlinkbntknbnwbtcbnusdcbnusdtbndaivbnt
1AccountAlice100000095000010000000050000010000001000000050000000500000000
Bob100000010000004500000010000001000000100000000550000000000
2Poola: TKN Staked Balance0500005500000050000000000000000
b: TKN Trading Liquidity020.0003333.33333333333333333333333333333333333333333...002000000000000000
c: BNT Trading Liquidity02000020000002000000000000000
d: BNT Current Funding02000020000002000000000000000
e: Spot Rate01E+36.00000000000000000000000000000000000000000000...00100000000000
f: Average Rate01E+36.00000000000000000000000000000000000000000000...00100000000000
g: Average Inverse Rate00.0010.16666666666666666666666666666666666666666666...00100000000000
3NetworkBNT Staked Balance600000000000000000000
Master Vault60000500005500000050000000000000000
Protection Vault00000000000000000
Protocol Equity000000006000000000000
Rewards Vault00000000000000000
\n
" + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create deposits\n", + "timestamp = 0\n", + "v3.deposit('usdc', '500000', 'Alice', timestamp=timestamp)\n", + "v3.deposit('eth', '50000', 'Alice', timestamp=timestamp)\n", + "v3.deposit('link', '500000', 'Bob', timestamp=timestamp)\n", + "\n", + "# Iterate timestamp\n", + "timestamp = 1\n", + "v3.deposit('link', '50000', 'Bob', timestamp=timestamp)\n", + "\n", + "# Enable trading\n", + "v3.enable_trading('link', timestamp=timestamp)\n", + "v3.enable_trading('eth', timestamp=timestamp)\n", + "v3.enable_trading('usdc', timestamp=timestamp)\n", + "v3.describe()" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [ + { + "data": { + "text/plain": " timestamp latest_action latest_amt latest_user_name tkn_name \\\n0 0 deposit 500000 Alice eth \n0 0 deposit 500000 Alice link \n0 0 deposit 500000 Alice tkn \n0 0 deposit 500000 Alice wbtc \n0 0 deposit 500000 Alice usdc \n0 0 deposit 500000 Alice usdt \n0 0 deposit 500000 Alice dai \n0 0 deposit 50000 Alice eth \n0 0 deposit 50000 Alice link \n0 0 deposit 50000 Alice tkn \n0 0 deposit 50000 Alice wbtc \n0 0 deposit 50000 Alice usdc \n0 0 deposit 50000 Alice usdt \n0 0 deposit 50000 Alice dai \n0 0 deposit 500000 Bob eth \n0 0 deposit 500000 Bob link \n0 0 deposit 500000 Bob tkn \n0 0 deposit 500000 Bob wbtc \n0 0 deposit 500000 Bob usdc \n0 0 deposit 500000 Bob usdt \n0 0 deposit 500000 Bob dai \n0 1 deposit 50000 Bob eth \n0 1 deposit 50000 Bob link \n0 1 deposit 50000 Bob tkn \n0 1 deposit 50000 Bob wbtc \n0 1 deposit 50000 Bob usdc \n0 1 deposit 50000 Bob usdt \n0 1 deposit 50000 Bob dai \n0 1 enableTrading 0 protocol eth \n0 1 enableTrading 0 protocol link \n0 1 enableTrading 0 protocol tkn \n0 1 enableTrading 0 protocol wbtc \n0 1 enableTrading 0 protocol usdc \n0 1 enableTrading 0 protocol usdt \n0 1 enableTrading 0 protocol dai \n0 1 enableTrading 0 protocol eth \n0 1 enableTrading 0 protocol link \n0 1 enableTrading 0 protocol tkn \n0 1 enableTrading 0 protocol wbtc \n0 1 enableTrading 0 protocol usdc \n0 1 enableTrading 0 protocol usdt \n0 1 enableTrading 0 protocol dai \n0 1 enableTrading 0 protocol eth \n0 1 enableTrading 0 protocol link \n0 1 enableTrading 0 protocol tkn \n0 1 enableTrading 0 protocol wbtc \n0 1 enableTrading 0 protocol usdc \n0 1 enableTrading 0 protocol usdt \n0 1 enableTrading 0 protocol dai \n\n master_vault_tkn erc20contracts_bntkn staked_tkn is_trading_enabled \\\n0 0 0 0 False \n0 0 0 0 False \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 50000 50000 50000 False \n0 0 0 0 False \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 50000 50000 50000 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 50000 50000 50000 False \n0 550000 550000 550000 False \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 50000 50000 50000 False \n0 550000 550000 550000 True \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 50000 50000 50000 True \n0 550000 550000 550000 True \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 False \n0 0 0 0 False \n0 0 0 0 False \n0 50000 50000 50000 True \n0 550000 550000 550000 True \n0 0 0 0 False \n0 0 0 0 False \n0 500000 500000 500000 True \n0 0 0 0 False \n0 0 0 0 False \n\n bnt_trading_liquidity ... network_fee withdrawal_fee bnt_min_liquidity \\\n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 20000 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 20000 ... 0.2 0.0025 10000 \n0 20000 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 20000 ... 0.2 0.0025 10000 \n0 20000 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 20000 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n0 0 ... 0.2 0.0025 10000 \n\n cooldown_time protocol_wallet_bnbnt vortex_bnt erc20contracts_bnbnt \\\n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 0 0 0 \n0 604800 20000 0 20000 \n0 604800 20000 0 20000 \n0 604800 20000 0 20000 \n0 604800 20000 0 20000 \n0 604800 20000 0 20000 \n0 604800 20000 0 20000 \n0 604800 20000 0 20000 \n0 604800 40000 0 40000 \n0 604800 40000 0 40000 \n0 604800 40000 0 40000 \n0 604800 40000 0 40000 \n0 604800 40000 0 40000 \n0 604800 40000 0 40000 \n0 604800 40000 0 40000 \n0 604800 60000 0 60000 \n0 604800 60000 0 60000 \n0 604800 60000 0 60000 \n0 604800 60000 0 60000 \n0 604800 60000 0 60000 \n0 604800 60000 0 60000 \n0 604800 60000 0 60000 \n\n master_vault_bnt staked_bnt bnbnt_rate \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 0 0 1 \n0 20000 20000 1 \n0 20000 20000 1 \n0 20000 20000 1 \n0 20000 20000 1 \n0 20000 20000 1 \n0 20000 20000 1 \n0 20000 20000 1 \n0 40000 40000 1 \n0 40000 40000 1 \n0 40000 40000 1 \n0 40000 40000 1 \n0 40000 40000 1 \n0 40000 40000 1 \n0 40000 40000 1 \n0 60000 60000 1 \n0 60000 60000 1 \n0 60000 60000 1 \n0 60000 60000 1 \n0 60000 60000 1 \n0 60000 60000 1 \n0 60000 60000 1 \n\n[49 rows x 31 columns]", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
timestamplatest_actionlatest_amtlatest_user_nametkn_namemaster_vault_tknerc20contracts_bntknstaked_tknis_trading_enabledbnt_trading_liquidity...network_feewithdrawal_feebnt_min_liquiditycooldown_timeprotocol_wallet_bnbntvortex_bnterc20contracts_bnbntmaster_vault_bntstaked_bntbnbnt_rate
00deposit500000Aliceeth000False0...0.20.002510000604800000001
00deposit500000Alicelink000False0...0.20.002510000604800000001
00deposit500000Alicetkn000False0...0.20.002510000604800000001
00deposit500000Alicewbtc000False0...0.20.002510000604800000001
00deposit500000Aliceusdc500000500000500000False0...0.20.002510000604800000001
00deposit500000Aliceusdt000False0...0.20.002510000604800000001
00deposit500000Alicedai000False0...0.20.002510000604800000001
00deposit50000Aliceeth500005000050000False0...0.20.002510000604800000001
00deposit50000Alicelink000False0...0.20.002510000604800000001
00deposit50000Alicetkn000False0...0.20.002510000604800000001
00deposit50000Alicewbtc000False0...0.20.002510000604800000001
00deposit50000Aliceusdc500000500000500000False0...0.20.002510000604800000001
00deposit50000Aliceusdt000False0...0.20.002510000604800000001
00deposit50000Alicedai000False0...0.20.002510000604800000001
00deposit500000Bobeth500005000050000False0...0.20.002510000604800000001
00deposit500000Boblink500000500000500000False0...0.20.002510000604800000001
00deposit500000Bobtkn000False0...0.20.002510000604800000001
00deposit500000Bobwbtc000False0...0.20.002510000604800000001
00deposit500000Bobusdc500000500000500000False0...0.20.002510000604800000001
00deposit500000Bobusdt000False0...0.20.002510000604800000001
00deposit500000Bobdai000False0...0.20.002510000604800000001
01deposit50000Bobeth500005000050000False0...0.20.002510000604800000001
01deposit50000Boblink550000550000550000False0...0.20.002510000604800000001
01deposit50000Bobtkn000False0...0.20.002510000604800000001
01deposit50000Bobwbtc000False0...0.20.002510000604800000001
01deposit50000Bobusdc500000500000500000False0...0.20.002510000604800000001
01deposit50000Bobusdt000False0...0.20.002510000604800000001
01deposit50000Bobdai000False0...0.20.002510000604800000001
01enableTrading0protocoleth500005000050000False0...0.20.0025100006048002000002000020000200001
01enableTrading0protocollink550000550000550000True20000...0.20.0025100006048002000002000020000200001
01enableTrading0protocoltkn000False0...0.20.0025100006048002000002000020000200001
01enableTrading0protocolwbtc000False0...0.20.0025100006048002000002000020000200001
01enableTrading0protocolusdc500000500000500000False0...0.20.0025100006048002000002000020000200001
01enableTrading0protocolusdt000False0...0.20.0025100006048002000002000020000200001
01enableTrading0protocoldai000False0...0.20.0025100006048002000002000020000200001
01enableTrading0protocoleth500005000050000True20000...0.20.0025100006048004000004000040000400001
01enableTrading0protocollink550000550000550000True20000...0.20.0025100006048004000004000040000400001
01enableTrading0protocoltkn000False0...0.20.0025100006048004000004000040000400001
01enableTrading0protocolwbtc000False0...0.20.0025100006048004000004000040000400001
01enableTrading0protocolusdc500000500000500000False0...0.20.0025100006048004000004000040000400001
01enableTrading0protocolusdt000False0...0.20.0025100006048004000004000040000400001
01enableTrading0protocoldai000False0...0.20.0025100006048004000004000040000400001
01enableTrading0protocoleth500005000050000True20000...0.20.0025100006048006000006000060000600001
01enableTrading0protocollink550000550000550000True20000...0.20.0025100006048006000006000060000600001
01enableTrading0protocoltkn000False0...0.20.0025100006048006000006000060000600001
01enableTrading0protocolwbtc000False0...0.20.0025100006048006000006000060000600001
01enableTrading0protocolusdc500000500000500000True20000...0.20.0025100006048006000006000060000600001
01enableTrading0protocolusdt000False0...0.20.0025100006048006000006000060000600001
01enableTrading0protocoldai000False0...0.20.0025100006048006000006000060000600001
\n

49 rows × 31 columns

\n
" + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the historical system state per user action.\n", + "v3.show_history()" + ] + }, + { + "cell_type": "markdown", + "source": [ + "#### Create new Trades." + ], + "metadata": { + "collapsed": false + } + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [ + { + "data": { + "text/plain": " bnt \\\n1 Account Alice 1000000 \n Bob 1000000 \n2 Pool a: TKN Staked Balance 0 \n b: TKN Trading Liquidity 0 \n c: BNT Trading Liquidity 0 \n d: BNT Current Funding 0 \n e: Spot Rate 0 \n f: Average Rate 0 \n g: Average Inverse Rate 0 \n3 Network BNT Staked Balance 60114.2857142857142857142857142857142857142857... \n Master Vault 60000.0000000000000000000000000000000000000000... \n Protection Vault 0 \n Protocol Equity 0 \n Rewards Vault 0 \n\n eth \\\n1 Account Alice 949950 \n Bob 1000000 \n2 Pool a: TKN Staked Balance 50000 \n b: TKN Trading Liquidity 70.000 \n c: BNT Trading Liquidity 5828.57142857142857142857142857142857142857142... \n d: BNT Current Funding 20114.2857142857142857142857142857142857142857... \n e: Spot Rate 83.2653061224489795918367346938775510204081632... \n f: Average Rate 1.0E+3 \n g: Average Inverse Rate 0.0010 \n3 Network BNT Staked Balance 0 \n Master Vault 50050 \n Protection Vault 0 \n Protocol Equity 0 \n Rewards Vault 0 \n\n link \\\n1 Account Alice 1001366.94560669456066945606694560669456066945... \n Bob 450000 \n2 Pool a: TKN Staked Balance 550011.046025104602510460251046025104602510460... \n b: TKN Trading Liquidity 1966.38772663877266387726638772663877266387726... \n c: BNT Trading Liquidity 34094.9084534870760844234140212578399683868156... \n d: BNT Current Funding 20000 \n e: Spot Rate 17.3388533663027403025261279900999157793697048... \n f: Average Rate 6.00000000000000000000000000000000000000000000... \n g: Average Inverse Rate 0.16666666666666666666666666666666666666666666... \n3 Network BNT Staked Balance 0 \n Master Vault 548633.054393305439330543933054393305439330543... \n Protection Vault 0 \n Protocol Equity 0 \n Rewards Vault 0 \n\n tkn wbtc usdc usdt dai bnbnt \\\n1 Account Alice 0 0 500000 1000000 1000000 0 \n Bob 0 0 1000000 1000000 1000000 0 \n2 Pool a: TKN Staked Balance 0 0 500000 0 0 0 \n b: TKN Trading Liquidity 0 0 20000 0 0 0 \n c: BNT Trading Liquidity 0 0 20000 0 0 0 \n d: BNT Current Funding 0 0 20000 0 0 0 \n e: Spot Rate 0 0 1 0 0 0 \n f: Average Rate 0 0 1 0 0 0 \n g: Average Inverse Rate 0 0 1 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 0 \n Master Vault 0 0 500000 0 0 0 \n Protection Vault 0 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 60000 \n Rewards Vault 0 0 0 0 0 0 \n\n bneth bnlink bntkn bnwbtc bnusdc bnusdt \\\n1 Account Alice 50000 0 0 0 500000 0 \n Bob 0 550000 0 0 0 0 \n2 Pool a: TKN Staked Balance 0 0 0 0 0 0 \n b: TKN Trading Liquidity 0 0 0 0 0 0 \n c: BNT Trading Liquidity 0 0 0 0 0 0 \n d: BNT Current Funding 0 0 0 0 0 0 \n e: Spot Rate 0 0 0 0 0 0 \n f: Average Rate 0 0 0 0 0 0 \n g: Average Inverse Rate 0 0 0 0 0 0 \n3 Network BNT Staked Balance 0 0 0 0 0 0 \n Master Vault 0 0 0 0 0 0 \n Protection Vault 0 0 0 0 0 0 \n Protocol Equity 0 0 0 0 0 0 \n Rewards Vault 0 0 0 0 0 0 \n\n bndai vbnt \n1 Account Alice 0 0 \n Bob 0 0 \n2 Pool a: TKN Staked Balance 0 0 \n b: TKN Trading Liquidity 0 0 \n c: BNT Trading Liquidity 0 0 \n d: BNT Current Funding 0 0 \n e: Spot Rate 0 0 \n f: Average Rate 0 0 \n g: Average Inverse Rate 0 0 \n3 Network BNT Staked Balance 0 0 \n Master Vault 0 0 \n Protection Vault 0 0 \n Protocol Equity 0 0 \n Rewards Vault 0 0 ", + "text/html": "
\n\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
bntethlinktknwbtcusdcusdtdaibnbntbnethbnlinkbntknbnwbtcbnusdcbnusdtbndaivbnt
1AccountAlice10000009499501001366.94560669456066945606694560669456066945...0050000010000001000000050000000500000000
Bob100000010000004500000010000001000000100000000550000000000
2Poola: TKN Staked Balance050000550011.046025104602510460251046025104602510460...0050000000000000000
b: TKN Trading Liquidity070.0001966.38772663877266387726638772663877266387726...002000000000000000
c: BNT Trading Liquidity05828.57142857142857142857142857142857142857142...34094.9084534870760844234140212578399683868156...002000000000000000
d: BNT Current Funding020114.2857142857142857142857142857142857142857...20000002000000000000000
e: Spot Rate083.2653061224489795918367346938775510204081632...17.3388533663027403025261279900999157793697048...00100000000000
f: Average Rate01.0E+36.00000000000000000000000000000000000000000000...00100000000000
g: Average Inverse Rate00.00100.16666666666666666666666666666666666666666666...00100000000000
3NetworkBNT Staked Balance60114.2857142857142857142857142857142857142857...0000000000000000
Master Vault60000.0000000000000000000000000000000000000000...50050548633.054393305439330543933054393305439330543...0050000000000000000
Protection Vault00000000000000000
Protocol Equity000000006000000000000
Rewards Vault00000000000000000
\n
" + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "timestamp = 2\n", + "v3.trade('50', 'eth','link', 'Alice', timestamp=timestamp)\n", + "v3.describe()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.13" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} \ No newline at end of file