17 releases

0.4.1 Feb 26, 2024
0.3.25 Feb 16, 2024
0.3.17 Dec 6, 2023
0.3.13 Nov 30, 2023
0.2.0 Sep 29, 2023

#2244 in Magic Beans

Download history 101/week @ 2024-02-13 180/week @ 2024-02-20 138/week @ 2024-02-27 78/week @ 2024-03-05 40/week @ 2024-03-12 5/week @ 2024-03-19 19/week @ 2024-03-26 87/week @ 2024-04-02

157 downloads per month

MIT license

530KB
5.5K SLoC

Rust 2K SLoC // 0.0% comments TSX 1.5K SLoC // 0.0% comments Solidity 802 SLoC // 0.5% comments JavaScript 317 SLoC // 0.4% comments Python 297 SLoC // 0.0% comments TypeScript 189 SLoC Shell 53 SLoC // 0.1% comments Batch 6 SLoC

rust_erc20_payment

Notes

  • all addresses/txs in database are in hex/lowercase format.

Frontend

Link to frontend repo: https://github.com/scx1332/erc20_driver_frontend

Sample environment setup

ETH_PRIVATE_KEY=0000000000000000000000000000000000000000000000000000000000000000 PROVIDER_URL=https://rpc-mumbai.matic.today RUST_LOG=debug,sqlx::query=info,web=warn

Sample runs

cargo run -- transfer --plain-eth --amounts=1,2,3,4 --receivers=0xA000000000000000000000000000000000050001,0xA000000000000000000000000000000000050002,0xa000000000000000000000000000000000050003,0xa000000000000000000000000000000000050004
cargo run -- transfer --token-addr=0x2036807b0b3aaf5b1858ee822d0e111fddac7018 --amounts=1,2,3,4 --receivers=0xA000000000000000000000000000000000050001,0xA000000000000000000000000000000000050002,0xa000000000000000000000000000000000050003,0xa000000000000000000000000000000000050004
cargo run --example generate_transfers -- --chain-name dev --address-pool-size 10000 --amounts-pool-size 10000 --generate-count 100

prepare test transfers into db, it generates 100 random GLM transfers to 10 unique addresses

cargo run --example generate_transfers -- --generate-count 100 --address-pool-size 10 --amounts-pool-size=100

dry run without processing transactions

cargo run -- process --generate-tx-only=1

Useful command to see transactions being processed

SELECT id,
       (CAST((julianday(broadcast_date) - 2440587.5)*86400000 AS INTEGER) - CAST((julianday(created_date) - 2440587.5)*86400000 AS INTEGER)) / 1000.0 as broadcast_delay,
       broadcast_count,
       (CAST((julianday(confirm_date) - 2440587.5)*86400000 AS INTEGER) - CAST((julianday(broadcast_date) - 2440587.5)*86400000 AS INTEGER)) / 1000.0 as confirm_delay,
       tx_hash,
       *
FROM tx
order by created_date desc

Clean all transactions and transfers

DELETE FROM token_transfer;
DELETE FROM tx;

TODO

  • Add error handling in gather_transactions, now SQL will loop forever, when hit error in gather

Example get balance

Get balance running 4 tasks in parallel

cargo run -- account-balance --tasks 4 -c polygon -a 0x75be52afd54a13b6c98490b4db495aa79b609d58,0x7caac644722316101807e0d55f838f7851a97031,0x52a258ed593c793251a89bfd36cae158ee9fc4f8,0x04e2dc96afecdf72221882e1cee039cab4d443e0,0xa32a0edc623d86e623f58e7c4174023a80a67ddf,0x7cb53b925a79fb15c348fcfd9abcf2287854d33a,0x8cf88c473b6cb40b8d37cdd93e6c8118c14a6e60,0xa96d3f3e177687fb0b5f990d5c4000923b49430b,0x92fb36230b50a87a39ba3237c996caf5a39b230b,0x0c4d7a995aa9846ef25e1a347a8711c8b534b5a6,0x698076ae39e7e44bcd2bbe15f0486c8d44bb4e6f

Be nicer to endpoint one by one

cargo run -- account-balance --tasks 1 -c polygon -a 0x75be52afd54a13b6c98490b4db495aa79b609d58,0x7caac644722316101807e0d55f838f7851a97031,0x52a258ed593c793251a89bfd36cae158ee9fc4f8,0x04e2dc96afecdf72221882e1cee039cab4d443e0,0xa32a0edc623d86e623f58e7c4174023a80a67ddf,0x7cb53b925a79fb15c348fcfd9abcf2287854d33a,0x8cf88c473b6cb40b8d37cdd93e6c8118c14a6e60,0xa96d3f3e177687fb0b5f990d5c4000923b49430b,0x92fb36230b50a87a39ba3237c996caf5a39b230b,0x0c4d7a995aa9846ef25e1a347a8711c8b534b5a6,0x698076ae39e7e44bcd2bbe15f0486c8d44bb4e6f

Be nicer to endpoint rate limit every 2 seconds

cargo run -- account-balance --interval 2.0 -c polygon -a 0x75be52afd54a13b6c98490b4db495aa79b609d58,0x7caac644722316101807e0d55f838f7851a97031,0x52a258ed593c793251a89bfd36cae158ee9fc4f8,0x04e2dc96afecdf72221882e1cee039cab4d443e0,0xa32a0edc623d86e623f58e7c4174023a80a67ddf,0x7cb53b925a79fb15c348fcfd9abcf2287854d33a,0x8cf88c473b6cb40b8d37cdd93e6c8118c14a6e60,0xa96d3f3e177687fb0b5f990d5c4000923b49430b,0x92fb36230b50a87a39ba3237c996caf5a39b230b,0x0c4d7a995aa9846ef25e1a347a8711c8b534b5a6,0x698076ae39e7e44bcd2bbe15f0486c8d44bb4e6f

Dependencies

~86MB
~1.5M SLoC