-
Notifications
You must be signed in to change notification settings - Fork 0
Differentiate Sent/Received/Swap events #2
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ import * as oeth from './abi/oeth'; | |
| import { APY, Address, History, Rebase } from './model'; | ||
| import { Context, OETH_ADDRESS, processor } from './processor'; | ||
|
|
||
| const addressZero = "0x0000000000000000000000000000000000000000" | ||
|
|
||
| interface RawTransfer { | ||
| id: string; | ||
| value: bigint; | ||
|
|
@@ -27,14 +29,16 @@ interface RawRebase { | |
| txHash: string; | ||
| } | ||
|
|
||
| type RawLog = RawTransfer | RawRebase; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
|
|
||
| /** | ||
| * Aggregate Transfer and Rebase events from the logs | ||
| * | ||
| * @param {Context} ctx subsquid context | ||
| * @returns {(RawTransfer|RawRebase)[]} array of Transfer and Rebase events | ||
| * @returns {(RawLog)[]} array of Transfer and Rebase events | ||
| */ | ||
| function getRawLogs(ctx: Context): (RawTransfer | RawRebase)[] { | ||
| let logs: (RawTransfer | RawRebase)[] = []; | ||
| function getRawLogs(ctx: Context): (RawLog)[] { | ||
| let logs: (RawLog)[] = []; | ||
| for (let block of ctx.blocks) { | ||
| for (let log of block.logs) { | ||
| if ( | ||
|
|
@@ -78,10 +82,10 @@ function getRawLogs(ctx: Context): (RawTransfer | RawRebase)[] { | |
| /** | ||
| * Verify if the log is a Transfer event | ||
| * | ||
| * @param {(RawTransfer|RawRebase)} log | ||
| * @param {(RawLog)} log | ||
| * @returns {boolean} true if the log is a Transfer event | ||
| */ | ||
| function isRawTransfer(log: RawTransfer | RawRebase): log is RawTransfer { | ||
| function isRawTransfer(log: RawLog): log is RawTransfer { | ||
| return ( | ||
| (log as RawTransfer).value !== undefined && | ||
| (log as RawTransfer).from !== undefined && | ||
|
|
@@ -92,10 +96,10 @@ function isRawTransfer(log: RawTransfer | RawRebase): log is RawTransfer { | |
| /** | ||
| * Verify if the log is a Rebase event | ||
| * | ||
| * @param {(RawTransfer|RawRebase)} log | ||
| * @param {(RawLog)} log | ||
| * @returns {boolean} true if the log is a Rebase event | ||
| */ | ||
| function isRawRebase(log: RawTransfer | RawRebase): log is RawRebase { | ||
| function isRawRebase(log: RawLog): log is RawRebase { | ||
| return ( | ||
| (log as RawRebase).totalSupply !== undefined && | ||
| (log as RawRebase).rebasingCredits !== undefined && | ||
|
|
@@ -276,6 +280,8 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { | |
| addressSub.lastUpdated = t.timestamp; | ||
| addressAdd.lastUpdated = t.timestamp; | ||
|
|
||
| const isSwap = [t.from, t.to].includes(addressZero); | ||
|
|
||
| // update the address balance | ||
| await Promise.all( | ||
| [addressSub, addressAdd].map(async (address) => { | ||
|
|
@@ -291,7 +297,7 @@ processor.run(new TypeormDatabase({ supportHotBlocks: true }), async (ctx) => { | |
| timestamp: t.timestamp, | ||
| blockNumber: t.blockNumber, | ||
| txHash: t.txHash, | ||
| type: 'Swap', | ||
| type: isSwap ? 'Swap' : (addressSub === address ? 'Sent' : 'Received'), | ||
| }), | ||
| ); | ||
| address.credits = BigInt(credits[0]); // token credits | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ import { Store } from '@subsquid/typeorm-store'; | |
| import * as oeth from './abi/oeth'; | ||
|
|
||
| export const OETH_ADDRESS = | ||
| '0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3'.toLocaleLowerCase(); | ||
| '0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3'.toLowerCase(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice 👍 |
||
|
|
||
| export const processor = new EvmBatchProcessor() | ||
| .setDataSource({ | ||
|
|
@@ -32,28 +32,20 @@ export const processor = new EvmBatchProcessor() | |
| .setFields({ | ||
| transaction: { | ||
| from: true, | ||
| value: true, | ||
| hash: true, | ||
| gasUsed: true, | ||
| gas: true, | ||
| value: true, | ||
| }, | ||
| log: { | ||
| transactionHash: true, | ||
| topics: true, | ||
| data: true, | ||
| }, | ||
| }) | ||
| .setBlockRange({ | ||
| from: 16933090, // https://etherscan.io/tx/0x3b4ece4f5fef04bf7ceaec4f6c6edf700540d7597589f8da0e3a8c94264a3b50 | ||
| }) | ||
| .setFields({ | ||
| log: { | ||
| transactionHash: true, | ||
| }, | ||
| transaction: { | ||
| hash: true, | ||
| gasUsed: true, | ||
| gas: true, | ||
| value: true, | ||
| }, | ||
| }) | ||
| .addLog({ | ||
| address: [OETH_ADDRESS], | ||
| topic0: [ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shahthepro what do you think about using
ADDRESS_ZEROsince this is a global const?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. We can clean up a few things. Like having addresses and constants in different files. Breaking down the processor file to keep it short and clean. Will work on that