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
22 changes: 14 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

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_ZERO since this is a global const?

Copy link
Contributor Author

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


interface RawTransfer {
id: string;
value: bigint;
Expand All @@ -27,14 +29,16 @@ interface RawRebase {
txHash: string;
}

type RawLog = RawTransfer | RawRebase;
Copy link
Contributor

Choose a reason for hiding this comment

The 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 (
Expand Down Expand Up @@ -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 &&
Expand All @@ -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 &&
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
Expand Down
18 changes: 5 additions & 13 deletions src/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Store } from '@subsquid/typeorm-store';
import * as oeth from './abi/oeth';

export const OETH_ADDRESS =
'0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3'.toLocaleLowerCase();
'0x856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3'.toLowerCase();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice 👍


export const processor = new EvmBatchProcessor()
.setDataSource({
Expand All @@ -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: [
Expand Down