Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ workspace
.idea/
# build output
/hive

hiveview
2 changes: 1 addition & 1 deletion simulators/ethereum/engine/debug.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ENV GO111MODULE=on
RUN go install github.com/go-delve/delve/cmd/dlv@latest
ADD . $GOPATH/src/github.com/gnosischain/hive/simulators/ethereum/engine
WORKDIR $GOPATH/src/github.com/gnosischain/hive/simulators/ethereum/engine
RUN go build -gcflags="all=-N -l" -v .
RUN go build -gcflags="all=-N -l" -v .

# Build the simulator run container.
FROM alpine:latest
Expand Down
25 changes: 22 additions & 3 deletions simulators/ethereum/engine/libgno/gno.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TransferData(recipient common.Address, amount *big.Int) ([]byte, error) {
// `From` = deposit contract address
// `To` = all addresses from addresses argument
//
// for specific block range and returns map { withdrawalAddress: transferAmount }
// for specific block range and returns accumulated map { withdrawalAddress: Sum(transferAmounts) }
func GetWithdrawalsTransferEvents(client *ethclient.Client, addresses []common.Address, fromBlock, toBlock uint64) (map[string]*big.Int, error) {
transfersList := make(map[string]*big.Int, 0)
token, err := NewGnoToken(GNOTokenAddress, client)
Expand All @@ -122,14 +122,27 @@ func GetWithdrawalsTransferEvents(client *ethclient.Client, addresses []common.A
}

for eventsIterator.Next() {

addr := eventsIterator.Event.To.Hex()
amount := eventsIterator.Event.Value

transfersList[addr] = amount
if _, ok := transfersList[addr]; ok {
transfersList[addr].Add(transfersList[addr], amount)
} else {
transfersList[addr] = amount
}
}
return transfersList, nil
}

func GetBalanceOf(client *ethclient.Client, account common.Address, block *big.Int) (*big.Int, error) {
opts := &bind.CallOpts{Pending: false, BlockNumber: block}
token, err := NewGnoToken(GNOTokenAddress, client)
if err != nil {
return nil, fmt.Errorf("can't bind token contract: %w", err)
}
return token.BalanceOf(opts, account)
}

// GetGNOTokenABI return the GNO token ABI.
func GetGNOTokenABI() (*abi.ABI, error) {
gnoTokenABI, err := abi.JSON(strings.NewReader(GNOTokenContractABI))
Expand All @@ -147,3 +160,9 @@ func GetWithdrawalsABI() (*abi.ABI, error) {
}
return &withdrawalsABI, nil
}

// UnwrapToGNO takes mGNO wrapped token amount and returns GNO (32 mGNO == 1 GNO) amount
// see https://docs.gnosischain.com/node/faq/#what-is-mgno for rationale
func UnwrapToGNO(amount *big.Int) *big.Int {
return amount.Div(amount, big.NewInt(32))
}
Loading