From 23acf07d9227daa0726d824f33ea2a45aef53e6c Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Mon, 2 Oct 2023 19:13:27 -0700 Subject: [PATCH 1/4] attempt to track nonRebasingSupply --- ...55931552-Data.js => 1696284606457-Data.js} | 6 +-- schema.graphql | 2 + src/main.ts | 2 +- src/model/generated/oeth.model.ts | 6 +++ src/processors/oeth/oeth.ts | 49 +++++++++++++++++-- 5 files changed, 56 insertions(+), 9 deletions(-) rename db/migrations/{1695855931552-Data.js => 1696284606457-Data.js} (97%) diff --git a/db/migrations/1695855931552-Data.js b/db/migrations/1696284606457-Data.js similarity index 97% rename from db/migrations/1695855931552-Data.js rename to db/migrations/1696284606457-Data.js index f27d4e4f..b7f35b73 100644 --- a/db/migrations/1695855931552-Data.js +++ b/db/migrations/1696284606457-Data.js @@ -1,8 +1,8 @@ -module.exports = class Data1695855931552 { - name = 'Data1695855931552' +module.exports = class Data1696284606457 { + name = 'Data1696284606457' async up(db) { - await db.query(`CREATE TABLE "oeth" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "total_supply" numeric NOT NULL, CONSTRAINT "PK_de1d885501070dbd1ab6f8577ba" PRIMARY KEY ("id"))`) + await db.query(`CREATE TABLE "oeth" ("id" character varying NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "total_supply" numeric NOT NULL, "rebasing_supply" numeric NOT NULL, "non_rebasing_supply" numeric NOT NULL, CONSTRAINT "PK_de1d885501070dbd1ab6f8577ba" PRIMARY KEY ("id"))`) await db.query(`CREATE INDEX "IDX_5b81a67229bac2d68e0dc92cc4" ON "oeth" ("timestamp") `) await db.query(`CREATE INDEX "IDX_408e5f79f83093aa5cf2b0ea32" ON "oeth" ("block_number") `) await db.query(`CREATE TABLE "history" ("id" character varying NOT NULL, "value" numeric NOT NULL, "balance" numeric NOT NULL, "timestamp" TIMESTAMP WITH TIME ZONE NOT NULL, "block_number" integer NOT NULL, "tx_hash" text NOT NULL, "type" character varying(8) NOT NULL, "address_id" character varying, CONSTRAINT "PK_9384942edf4804b38ca0ee51416" PRIMARY KEY ("id"))`) diff --git a/schema.graphql b/schema.graphql index d8dcea65..443e60d8 100644 --- a/schema.graphql +++ b/schema.graphql @@ -3,6 +3,8 @@ type OETH @entity { timestamp: DateTime! @index blockNumber: Int! @index totalSupply: BigInt! + rebasingSupply: BigInt! + nonRebasingSupply: BigInt! } enum RebasingOption { diff --git a/src/main.ts b/src/main.ts index bf711675..43cb915f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ import * as vault from './processors/vault' run({ // The idea is that these processors have zero dependencies on one another and can be processed asynchronously. - processors: [oeth, vault, fraxStaking, morphoAave, dripper, curveLp], + processors: [oeth], //, vault, fraxStaking, morphoAave, dripper, curveLp], // For processors which depend on results from other processors, post processors run after all processors have finished. postProcessors: [], }) diff --git a/src/model/generated/oeth.model.ts b/src/model/generated/oeth.model.ts index ee84fcf1..4f2d1ace 100644 --- a/src/model/generated/oeth.model.ts +++ b/src/model/generated/oeth.model.ts @@ -20,4 +20,10 @@ export class OETH { @Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) totalSupply!: bigint + + @Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) + rebasingSupply!: bigint + + @Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false}) + nonRebasingSupply!: bigint } diff --git a/src/processors/oeth/oeth.ts b/src/processors/oeth/oeth.ts index 4a503d76..de283c30 100644 --- a/src/processors/oeth/oeth.ts +++ b/src/processors/oeth/oeth.ts @@ -121,12 +121,10 @@ const processTransfer = async ( value: dataRaw.value, } + const oethObject = await getLatestOETHObject(ctx, result, block) if (data.from === ADDRESS_ZERO) { - const oethObject = await getLatestOETHObject(ctx, result, block) oethObject.totalSupply += data.value - } - if (data.to === ADDRESS_ZERO) { - const oethObject = await getLatestOETHObject(ctx, result, block) + } else if (data.to === ADDRESS_ZERO) { oethObject.totalSupply -= data.value } @@ -155,12 +153,13 @@ const processTransfer = async ( [addressSub, addressAdd].map(async (address) => { const credits = await token.creditsBalanceOfHighres(address.id) const newBalance = (credits[0] * DECIMALS_18) / credits[1] + const change = newBalance - address.balance result.history.push( new History({ // we can't use {t.id} because it's not unique id: uuidv4(), address: address, - value: newBalance - address.balance, + value: change, balance: newBalance, timestamp: new Date(block.header.timestamp), blockNumber: block.header.height, @@ -176,6 +175,36 @@ const processTransfer = async ( address.balance = newBalance // token balance }), ) + + if ( + addressAdd.rebasingOption === RebasingOption.OptOut && + addressSub.id === ADDRESS_ZERO + ) { + oethObject.nonRebasingSupply += data.value + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply + } else if ( + addressAdd.id === ADDRESS_ZERO && + addressSub.rebasingOption === RebasingOption.OptOut + ) { + oethObject.nonRebasingSupply -= data.value + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply + } else if ( + addressAdd.rebasingOption === RebasingOption.OptOut && + addressSub.rebasingOption === RebasingOption.OptIn + ) { + oethObject.nonRebasingSupply += data.value + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply + } else if ( + addressAdd.rebasingOption === RebasingOption.OptIn && + addressSub.rebasingOption === RebasingOption.OptOut + ) { + oethObject.nonRebasingSupply -= data.value + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply + } } } @@ -231,6 +260,7 @@ const processTotalSupplyUpdatedHighres = async ( ) address.balance = newBalance + oethObject.rebasingSupply += earned address.earned += earned } const entity = await rebase @@ -267,6 +297,7 @@ const processRebaseOpt = async ( const timestamp = new Date(block.header.timestamp) const blockNumber = block.header.height const address = trace.transaction!.from.toLowerCase() + const oethObject = await getLatestOETHObject(ctx, result, block) let owner = result.owners.get(address) if (!owner) { owner = await createAddress(ctx, address, timestamp) @@ -285,10 +316,16 @@ const processRebaseOpt = async ( if (trace.action.sighash === oeth.functions.rebaseOptIn.sighash) { owner.rebasingOption = RebasingOption.OptIn rebaseOption.status = RebasingOption.OptIn + oethObject.nonRebasingSupply -= owner.balance + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply } if (trace.action.sighash === oeth.functions.rebaseOptOut.sighash) { owner.rebasingOption = RebasingOption.OptOut rebaseOption.status = RebasingOption.OptOut + oethObject.nonRebasingSupply += owner.balance + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply } } } @@ -313,6 +350,8 @@ const getLatestOETHObject = async ( timestamp: new Date(block.header.timestamp), blockNumber: block.header.height, totalSupply: latest?.totalSupply ?? 0n, + rebasingSupply: latest?.rebasingSupply ?? 0n, + nonRebasingSupply: latest?.nonRebasingSupply ?? 0n, }) result.oeths.push(oethObject) } From 811817094c7ff7f88410cdb9914cc97a3c747ea4 Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:07:38 +0530 Subject: [PATCH 2/4] Update rebasing-supply for all cases --- src/processors/oeth/oeth.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/processors/oeth/oeth.ts b/src/processors/oeth/oeth.ts index de283c30..303d07c6 100644 --- a/src/processors/oeth/oeth.ts +++ b/src/processors/oeth/oeth.ts @@ -180,31 +180,36 @@ const processTransfer = async ( addressAdd.rebasingOption === RebasingOption.OptOut && addressSub.id === ADDRESS_ZERO ) { + // If it's a mint and minter has opted out of rebasing, + // add to non-rebasing supply oethObject.nonRebasingSupply += data.value - oethObject.rebasingSupply = - oethObject.totalSupply - oethObject.nonRebasingSupply } else if ( addressAdd.id === ADDRESS_ZERO && addressSub.rebasingOption === RebasingOption.OptOut ) { + // If it's a redeem and redeemer has opted out of rebasing, + // subtract non-rebasing supply oethObject.nonRebasingSupply -= data.value - oethObject.rebasingSupply = - oethObject.totalSupply - oethObject.nonRebasingSupply } else if ( addressAdd.rebasingOption === RebasingOption.OptOut && addressSub.rebasingOption === RebasingOption.OptIn ) { + // If receiver has opted out but sender hasn't, + // Add to non-rebasing supply oethObject.nonRebasingSupply += data.value - oethObject.rebasingSupply = - oethObject.totalSupply - oethObject.nonRebasingSupply } else if ( addressAdd.rebasingOption === RebasingOption.OptIn && addressSub.rebasingOption === RebasingOption.OptOut ) { + // If sender has opted out but receiver hasn't, + // Subtract non-rebasing supply oethObject.nonRebasingSupply -= data.value - oethObject.rebasingSupply = - oethObject.totalSupply - oethObject.nonRebasingSupply } + + // Update rebasing supply in all cases + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply + } } From c9fd077978ad3deae31cbbe30d613ec531c8689c Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Tue, 3 Oct 2023 09:47:22 -0700 Subject: [PATCH 3/4] fix tracking nonRebasingSupply --- src/processors/oeth/oeth.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/processors/oeth/oeth.ts b/src/processors/oeth/oeth.ts index 303d07c6..65014643 100644 --- a/src/processors/oeth/oeth.ts +++ b/src/processors/oeth/oeth.ts @@ -27,7 +27,7 @@ export const from = 16933090 // https://etherscan.io/tx/0x3b4ece4f5fef04bf7ceaec export const setup = (processor: EvmBatchProcessor) => { processor.addTrace({ - type: ['call', 'delegatecall'], + type: ['call'], callSighash: [ oeth.functions.rebaseOptOut.sighash, oeth.functions.rebaseOptIn.sighash, @@ -178,16 +178,16 @@ const processTransfer = async ( if ( addressAdd.rebasingOption === RebasingOption.OptOut && - addressSub.id === ADDRESS_ZERO + data.from === ADDRESS_ZERO ) { - // If it's a mint and minter has opted out of rebasing, + // If it's a mint and minter has opted out of rebasing, // add to non-rebasing supply oethObject.nonRebasingSupply += data.value } else if ( - addressAdd.id === ADDRESS_ZERO && + data.to === ADDRESS_ZERO && addressSub.rebasingOption === RebasingOption.OptOut ) { - // If it's a redeem and redeemer has opted out of rebasing, + // If it's a redeem and redeemer has opted out of rebasing, // subtract non-rebasing supply oethObject.nonRebasingSupply -= data.value } else if ( @@ -209,7 +209,6 @@ const processTransfer = async ( // Update rebasing supply in all cases oethObject.rebasingSupply = oethObject.totalSupply - oethObject.nonRebasingSupply - } } @@ -228,6 +227,8 @@ const processTotalSupplyUpdatedHighres = async ( // OETH Object const oethObject = await getLatestOETHObject(ctx, result, block) oethObject.totalSupply = data.totalSupply + oethObject.rebasingSupply = + oethObject.totalSupply - oethObject.nonRebasingSupply if (!result.lastYieldDistributionEvent) { throw new Error('lastYieldDistributionEvent is not set') @@ -265,7 +266,6 @@ const processTotalSupplyUpdatedHighres = async ( ) address.balance = newBalance - oethObject.rebasingSupply += earned address.earned += earned } const entity = await rebase @@ -301,7 +301,7 @@ const processRebaseOpt = async ( await result.initialize() const timestamp = new Date(block.header.timestamp) const blockNumber = block.header.height - const address = trace.transaction!.from.toLowerCase() + const address = trace.action.from.toLowerCase() const oethObject = await getLatestOETHObject(ctx, result, block) let owner = result.owners.get(address) if (!owner) { From 4b863ae1b907fbbab75ec6b110b330ee75f2411a Mon Sep 17 00:00:00 2001 From: Chris Jacobs Date: Tue, 3 Oct 2023 09:48:36 -0700 Subject: [PATCH 4/4] fix tracking nonRebasingSupply --- src/main.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 43cb915f..bf711675 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ import * as vault from './processors/vault' run({ // The idea is that these processors have zero dependencies on one another and can be processed asynchronously. - processors: [oeth], //, vault, fraxStaking, morphoAave, dripper, curveLp], + processors: [oeth, vault, fraxStaking, morphoAave, dripper, curveLp], // For processors which depend on results from other processors, post processors run after all processors have finished. postProcessors: [], })