Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add gas used and transactions fee #1

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

alexandre-abrioux
Copy link

@alexandre-abrioux alexandre-abrioux commented Mar 2, 2022

This PR adds new properties to the following entities:

  • gasUsed and transactionFee to Block, with transactionFee = gasUsed x gasPrice
  • totalTransactionFee to User
  • totalTransactionFee to Summary

This change was made possible thanks to graphprotocol/graph-node#3218 and the new TransactionReceipt that is now available in the AssemblyScript API version 0.0.7: https://thegraph.com/docs/en/developer/assemblyscript-api/#versions

Mics

A Dockerfile was added for convenience to test the subgraph without the need to download matchstick binary. It is based on the one found in the documentation.

})

test("stake(1000) while maturing", () => {
let address = "0x0000000000000000000000000000000000000000"

// create a user with 500 maturing
let user = new User(address)
let user = loadOrCreate(Address.fromString(address))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since graphprotocol/graph-tooling@629176c the code generation of graph-cli does not assign default values for entities, so we need to initialize ourselves all properties.

@alexandre-abrioux alexandre-abrioux marked this pull request as ready for review May 31, 2022 01:29
@alexandre-abrioux alexandre-abrioux changed the title (WIP) feat: add gas used and transactions fee feat: add gas used and transactions fee May 31, 2022
@@ -0,0 +1 @@
.gitignore
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a symlink to .gitignore


export function handleRewarded(event: Rewarded): void {
let reward = event.params.userReward.plus(event.params.beneficiaryReward)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refacto: similar code from block.ts and block-1.0.ts have been moved to block-common.ts

Comment on lines +70 to +72
user.totalTransactionFee = user.totalTransactionFee.plus(
block.transactionFee
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this big code block that was moved, those 3 lines were added

let s = summary.loadOrCreate()
s.totalBlocks++
s.totalReward = s.totalReward.plus(reward)
s.totalTransactionFee = s.totalTransactionFee.plus(block.transactionFee)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this big code block that was moved, this line was also added

@@ -90,6 +90,7 @@ dataSources:
handler: handleNewChain
- event: "Rewarded(indexed uint256,indexed address,indexed address,uint256)"
handler: handleRewarded
receipt: true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we ask the Graph Node to fetch the receipt and pass it down to the Subgraph event

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant