Skip to content

Commit

Permalink
output total amount bridged and remaining in bridge events script (dy…
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Oct 5, 2023
1 parent 8ae40c2 commit 4228d1e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion protocol/scripts/bridge_events/bridge_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Usage:
go run scripts/bridge_events/bridge_events.go \
-denom <token_denom> \
-totalsupply <total_supply> \
-rpc <rpc_node_url> \
-address <bridge_contract_address> \
-toblock <last_block_inclusive>
Expand All @@ -42,10 +43,11 @@ func main() {
// ------------ FLAGS ------------

// Get flags.
var denom, rpcNode, bridgeAddress string
var denom, totalSupply, rpcNode, bridgeAddress string
var toBlock int64
var verbose bool
flag.StringVar(&denom, "denom", "adv4tnt", "token denom")
flag.StringVar(&totalSupply, "totalsupply", "1000000000000000000000000000", "token's total supply (base 10)")
flag.StringVar(&rpcNode, "rpc", "https://eth-sepolia.g.alchemy.com/v2/demo", "rpc node url")
flag.StringVar(&bridgeAddress, "address", "0xcca9D5f0a3c58b6f02BD0985fC7F9420EA24C1f0", "bridge address")
flag.Int64Var(&toBlock, "toblock", 100_000_000, "last block (inclusive)")
Expand All @@ -55,11 +57,19 @@ func main() {
// Print the flags used for the user
fmt.Println("Using the following configuration (modifiable via flags):")
fmt.Println("denom:", denom)
fmt.Println("totalsupply:", totalSupply)
fmt.Println("rpc:", rpcNode)
fmt.Println("address:", bridgeAddress)
fmt.Println("toblock:", toBlock)
fmt.Println()

// ------------ INPUT VALIDATION ------------
// Validate `-totalsupply`.
totalSupplyBigInt, ok := new(big.Int).SetString(totalSupply, 10)
if !ok {
log.Fatal("invalid total supply")
}

// ------------ LOGIC ------------

// Create client.
Expand Down Expand Up @@ -95,13 +105,17 @@ func main() {
EthBlockHeight: 0,
}
balances := make(map[string]*big.Int)
totalAmountBridged := big.NewInt(0)

// Iterate over each event and populate the above fields
for _, log := range logs {
event := libeth.BridgeLogToEvent(log, denom)
aei.NextId = lib.Max(aei.NextId, event.Id)
aei.EthBlockHeight = lib.Max(aei.EthBlockHeight, log.BlockNumber)

// Add amount to total bridged amount.
totalAmountBridged.Add(totalAmountBridged, event.Coin.Amount.BigInt())

// Get the current balance of the account.
v, exists := balances[event.Address]
if !exists {
Expand All @@ -116,6 +130,13 @@ func main() {

cdc := app.GetEncodingConfig().Codec

// Print total amount bridged.
fmt.Printf("Total amount bridged: %s\n", totalAmountBridged.String())

// Print bridge module account remaining balance.
bridgeModAccBalance := totalSupplyBigInt.Sub(totalSupplyBigInt, totalAmountBridged)
fmt.Printf("Remaining bridge module account balance: %s\n", bridgeModAccBalance.String())

// Print x/bridge event params.
eventParams := bridgetypes.EventParams{
Denom: denom,
Expand Down

0 comments on commit 4228d1e

Please sign in to comment.