Conversation
|
Building works, but then I tried to run get-tokenomics-history: tsconfig.json might need some tweaking because that |
|
I guess I was using old version of node |
mnaamani
left a comment
There was a problem hiding this comment.
Works, as long as you connect to an archival node.
Left a few tips and suggestions. If you just need a quick and dirty script, I would say just update the trarget in tsconfig.json to es2019 to make it work with node LTS (v12.x)
| } | ||
|
|
||
|
|
||
| export async function getPoolStart(api: ApiPromise, burnAddress:string, firstBlock:number, topUps:PoolTopup[], allExchanges: ExchangeInfo[]): Promise<PoolStatus> { |
There was a problem hiding this comment.
I was gonna suggest a better name would be getPoolStatus()
But I see the other getPoolEnd() which also returns the same type.
After understanding more what you are computing at the start and end, it makes more sense to actually rename PoolStatus to something more appropriate but its difficult to pick a name because it contains both status values and delta values, which suggests you need two separate types, one for each category.
But I think its overkill so carry on :)
| feesPaid: feesPaid, | ||
| slashAmount: slashAmount, | ||
| proposalsAddedInRange: proposalsAddedInRange, | ||
| proposalsFinalizedInRange: proposalsFinalizedInRange, |
There was a problem hiding this comment.
a nice shorthand way of writing this when the key and value names are identical is:
const proposalData: OverviewProposal = {
activeProposalsAtStart,
activeProposalsAtEnd,
fundingCosts,
feesPaid,
slashAmount,
proposalsAddedInRange,
proposalsFinalizedInRange,
}|
|
||
|
|
||
| export async function getPoolStart(api: ApiPromise, burnAddress:string, firstBlock:number, topUps:PoolTopup[], allExchanges: ExchangeInfo[]): Promise<PoolStatus> { | ||
| let totalAddedToPool = 0 |
There was a problem hiding this comment.
The code is fragile because you are using a plain javascript number for the Balance type which in the runtime is u128.
This is fine as long as the values we are dealing with are not larger than
| export async function getGeneralOverview(api: ApiPromise, firstBlockHash:Hash,lastBlockHash:Hash): Promise<OverviewGeneral> { | ||
| const forumCategoriesAtStart = await api.query.forum.nextCategoryId.at(firstBlockHash) as CategoryId; | ||
| const forumCategoriesAtEnd = await api.query.forum.nextCategoryId.at(lastBlockHash) as CategoryId; | ||
| const newCategories = forumCategoriesAtEnd.toNumber()-forumCategoriesAtStart.toNumber() |
There was a problem hiding this comment.
| const newCategories = forumCategoriesAtEnd.toNumber()-forumCategoriesAtStart.toNumber() | |
| const newCategories = forumCategoriesAtEnd.sub(forumCategoriesAtStart).toNumber() |
Easier on the eyes :)
| proposals[index].executedAt = blockHeight | ||
| } | ||
| } else { | ||
| if (decision.type === "Canceled" ||decision.type === "Cancelled") { |
There was a problem hiding this comment.
why are we checking for two different spellings ?
There was a problem hiding this comment.
I thought Canceled was incorrect (one "l"), so I figured it may be changed in the future :)
A quick search uncovered that it's one of the US/British English differences, so it makes less sense!
| } | ||
| } else { | ||
| if (decision.type === "Canceled" ||decision.type === "Cancelled") { | ||
| proposals[index].feePaid = 10000 |
There was a problem hiding this comment.
wondering where this number comes from?
There was a problem hiding this comment.
I didn't know how to find them with the API, so I used manual inputs. From memory, they're hardcoded in pioneer even.
If I'm wrong, I'd be happy to correct it!
| } | ||
| // Get tokens burned from tx fees | ||
| if ( | ||
| sectionName === "actors" || sectionName ==="contentWorkingGroup" || sectionName === "councilElection" || |
There was a problem hiding this comment.
a pattern like this could work well here:
let sectionNames = ['actors', 'contentWorkingGroup', ....]
if ( sectionNamesToLookFor.contains(sectionName) && otherChecks ...){
}| (sectionName === "members" && methodName !== "buyMembership") || | ||
| (sectionName === "session" && methodName=== "setKeys") | ||
| ) { | ||
| transactionFees ++ |
There was a problem hiding this comment.
assumption that transaction fee is always 1 token is okay, but we will miss this when that changes.
in network integration tests there are some examples on how tx fees are calculated. It could get more complicated in future if weights of transactions also affect the transaction fee (like gas).
To keep it very simple I would have some function at the top function getFeePerTransaction() { return 1 },
and instead of transactionFees++ do transactionFees += getFeePerTransaction() so it will be easy to update later
|
Closing, as it's pretty much outdated... |
Made a very rough version in #6 , but will replace with this now.
Not exactly clean code, as I am both not the best coder, and have had to do it in patches. Not sure we can have this in a public repo w/o cleaning it up...?