[HOWTO] Get usage statistics from tokenbridge.cash (SmartBCH bridge to/from ETH and BSC)

0 66
Avatar for norphine
2 years ago

If you're a SmartBCH fan, maybe you already know what tokenbridge.cash is. It's a bridge based on RSK token bridge that allows moving assets from/to SmartBCH and Ethereum/Binance Smart Chain. KoingFu's bridge is also based on RSK token bridge.

Bridges are going to be one of the keys for SmartBCH success, so there's interesting to get usage statistics of them. Sadly, RSK didn't build any tool for that.

Introducing tokenbridge_stats

Recently, @ClearSky write here about Web3py, a tool for interacting with EVM-compatible blockchains, like SmartBCH, using Python. Despite I'm not a developer, Python makes building apps very easy, so I developed tokenbridge_stats.

This small tool allows to get basic usage data about tokenbridge.cash and can be easily used for other RSK bridges, like KoingFu's. The code is available here.

How does it works?

Using Web3py, this script request data from a Ethereum RPC node and reads events from the bridge smart contract. Two kind of events are stored in a JSON file, called ETH_tokenbridge_events.json:

  • Cross: this event means an asset crossed from Ethereum to SmartBCH. Contains information like date, token type or amount.

  • AcceptedCrossTransfer: this event signals for an asset crossing from SmartBCH to Ethereum. Like the former one, it also contains useful information about the swap.

The next step is to request the same data but from a Binance Smart Chain (BSC) RPC node, so we can know cross-transactions between SmartBCH and BSC. The events stored follow the same structure as the Ethereum bridge, and the data is stored in a file called BSC_tokenbridge_events.json.

The final step is to process the data stored in those 2 files. Anybody is free to play with the data, the script I wrote is very easy and just gives the amount of assets that crossed from and to SmartBCH and the number of transactions for each asset.

Running it

You need Python3 install in your computer. Then, install the dependencies if needed:

pip3 install web3
pip3 install tqdm

Next, make the shell script executable and run it:

chmod +x get_stats.sh
./get_stats.sh

Actual tokenbridge.cash stats

This is the output of running tokenbridge_stats:

These are the tokens moved from Ethereum to SmartBCH:

{'AAVE': {'Amount': 0.10978,
          'No. of txs': 1,
          'Price': 303.5505,
          'Value': 33.32377389},
 'BCH': {'Amount': 1.30476524,
         'No. of txs': 2,
         'Price': 631.7703430538077,
         'Value': 824.3119832794837},
 'BTC': {'Amount': 0.00079681,
         'No. of txs': 2,
         'Price': 61589.7997,
         'Value': 49.075368298957},
 'DAI': {'Amount': 19.96,
         'No. of txs': 1,
         'Price': 1.0020257994852833,
         'Value': 20.000434957726256},
 'ETH': {'Amount': 0.0050898,
         'No. of txs': 1,
         'Price': 3882.8844,
         'Value': 19.76310501912},
 'LINK': {'Amount': 1.00798,
          'No. of txs': 1,
          'Price': 27.0711,
          'Value': 27.287127378000005},
 'SUSHI': {'Amount': 1.00798,
           'No. of txs': 1,
           'Price': 11.1215,
           'Value': 11.21024957},
 'UNI': {'Amount': 1.00798,
         'No. of txs': 1,
         'Price': 25.9846,
         'Value': 26.191957108000004},
 'USDC': {'Amount': 19.96, 'No. of txs': 1, 'Price': 1, 'Value': 19.96},
 'USDT': {'Amount': 58.688694999999996,
          'No. of txs': 3,
          'Price': 1,
          'Value': 58.688694999999996}}
Total value moved:  1866.80

These are the tokens moved from SmartBCH to Ethereum:

{'BCH': {'Amount': 1.30738,
         'No. of txs': 2,
         'Price': 632.1466753272995,
         'Value': 826.4559203894048},
 'BTC': {'Amount': 0.00039840000000000003,
         'No. of txs': 1,
         'Price': 61589.7997,
         'Value': 24.537376200480004},
 'ETH': {'Amount': 0.0050796204,
         'No. of txs': 1,
         'Price': 3885.598,
         'Value': 19.7373628669992},
 'USDT': {'Amount': 38.806307000000004,
          'No. of txs': 2,
          'Price': 1,
          'Value': 38.806307000000004}}
Total value moved:  1685.56

These are the tokens moved from BSC to SmartBCH:

{'BCH': {'Amount': 0.50676444,
         'No. of txs': 3,
         'Price': 631.7703430538077,
         'Value': 320.1587441062707},
 'BNB': {'Amount': 0.32802571032879646,
         'No. of txs': 3,
         'Price': 473.8507,
         'Value': 155.43521245729744},
 'BUSD': {'Amount': 72.72257103287966,
          'No. of txs': 6,
          'Price': 0.9986526694055778,
          'Value': 72.62458968802201},
 'CAKE': {'Amount': 3.280257103287965,
          'No. of txs': 3,
          'Price': 19.8767,
          'Value': 65.2006863649239}}
Total value moved:  1286.74

These are the tokens moved from SmartBCH to BSC:

{'BCH': {'Amount': 0.5089800000000001,
         'No. of txs': 4,
         'Price': 632.0216,
         'Value': 321.6863539680001},
 'BNB': {'Amount': 0.21868307648176,
         'No. of txs': 2,
         'Price': 473.8507,
         'Value': 103.62312886903551},
 'BUSD': {'Amount': 61.70846764817601,
          'No. of txs': 4,
          'Price': 0.9994514583791084,
          'Value': 61.674617985309546},
 'CAKE': {'Amount': 2.1868307648176,
          'No. of txs': 2,
          'Price': 19.8767,
          'Value': 43.46697906304999}}
Total value moved:  1085.10

As you can see, those are no big amounts because the bridges are still centralized. We are working on decentralization, until then, we recommend to wait.

Further steps

One further step could be getting the price of the assets in order to know the value that the bridges are moving, and make a web front-end to easily view this information. I try to make it, to evaluate the success of the bridges and the SmartBCH ecosystem overall.

Update (15/10/21):

Price added for every asset using Coincodex.com API.

2
$ 0.66
$ 0.56 from @TheRandomRewarder
$ 0.10 from @ClearSky
Avatar for norphine
2 years ago

Comments