Skip to content

Commit 3831ef8

Browse files
authored
Merge pull request #9 from oplabs/nonRebasingSupply
attempt to track nonRebasingSupply
2 parents 7955639 + 4b863ae commit 3831ef8

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

db/migrations/1695855931552-Data.js renamed to db/migrations/1696284606457-Data.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module.exports = class Data1695855931552 {
2-
name = 'Data1695855931552'
1+
module.exports = class Data1696284606457 {
2+
name = 'Data1696284606457'
33

44
async up(db) {
5-
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"))`)
5+
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"))`)
66
await db.query(`CREATE INDEX "IDX_5b81a67229bac2d68e0dc92cc4" ON "oeth" ("timestamp") `)
77
await db.query(`CREATE INDEX "IDX_408e5f79f83093aa5cf2b0ea32" ON "oeth" ("block_number") `)
88
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"))`)

schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ type OETH @entity {
33
timestamp: DateTime! @index
44
blockNumber: Int! @index
55
totalSupply: BigInt!
6+
rebasingSupply: BigInt!
7+
nonRebasingSupply: BigInt!
68
}
79

810
enum RebasingOption {

src/model/generated/oeth.model.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ export class OETH {
2020

2121
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
2222
totalSupply!: bigint
23+
24+
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
25+
rebasingSupply!: bigint
26+
27+
@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
28+
nonRebasingSupply!: bigint
2329
}

src/processors/oeth/oeth.ts

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const from = 16933090 // https://etherscan.io/tx/0x3b4ece4f5fef04bf7ceaec
2727

2828
export const setup = (processor: EvmBatchProcessor) => {
2929
processor.addTrace({
30-
type: ['call', 'delegatecall'],
30+
type: ['call'],
3131
callSighash: [
3232
oeth.functions.rebaseOptOut.sighash,
3333
oeth.functions.rebaseOptIn.sighash,
@@ -121,12 +121,10 @@ const processTransfer = async (
121121
value: dataRaw.value,
122122
}
123123

124+
const oethObject = await getLatestOETHObject(ctx, result, block)
124125
if (data.from === ADDRESS_ZERO) {
125-
const oethObject = await getLatestOETHObject(ctx, result, block)
126126
oethObject.totalSupply += data.value
127-
}
128-
if (data.to === ADDRESS_ZERO) {
129-
const oethObject = await getLatestOETHObject(ctx, result, block)
127+
} else if (data.to === ADDRESS_ZERO) {
130128
oethObject.totalSupply -= data.value
131129
}
132130

@@ -155,12 +153,13 @@ const processTransfer = async (
155153
[addressSub, addressAdd].map(async (address) => {
156154
const credits = await token.creditsBalanceOfHighres(address.id)
157155
const newBalance = (credits[0] * DECIMALS_18) / credits[1]
156+
const change = newBalance - address.balance
158157
result.history.push(
159158
new History({
160159
// we can't use {t.id} because it's not unique
161160
id: uuidv4(),
162161
address: address,
163-
value: newBalance - address.balance,
162+
value: change,
164163
balance: newBalance,
165164
timestamp: new Date(block.header.timestamp),
166165
blockNumber: block.header.height,
@@ -176,6 +175,40 @@ const processTransfer = async (
176175
address.balance = newBalance // token balance
177176
}),
178177
)
178+
179+
if (
180+
addressAdd.rebasingOption === RebasingOption.OptOut &&
181+
data.from === ADDRESS_ZERO
182+
) {
183+
// If it's a mint and minter has opted out of rebasing,
184+
// add to non-rebasing supply
185+
oethObject.nonRebasingSupply += data.value
186+
} else if (
187+
data.to === ADDRESS_ZERO &&
188+
addressSub.rebasingOption === RebasingOption.OptOut
189+
) {
190+
// If it's a redeem and redeemer has opted out of rebasing,
191+
// subtract non-rebasing supply
192+
oethObject.nonRebasingSupply -= data.value
193+
} else if (
194+
addressAdd.rebasingOption === RebasingOption.OptOut &&
195+
addressSub.rebasingOption === RebasingOption.OptIn
196+
) {
197+
// If receiver has opted out but sender hasn't,
198+
// Add to non-rebasing supply
199+
oethObject.nonRebasingSupply += data.value
200+
} else if (
201+
addressAdd.rebasingOption === RebasingOption.OptIn &&
202+
addressSub.rebasingOption === RebasingOption.OptOut
203+
) {
204+
// If sender has opted out but receiver hasn't,
205+
// Subtract non-rebasing supply
206+
oethObject.nonRebasingSupply -= data.value
207+
}
208+
209+
// Update rebasing supply in all cases
210+
oethObject.rebasingSupply =
211+
oethObject.totalSupply - oethObject.nonRebasingSupply
179212
}
180213
}
181214

@@ -194,6 +227,8 @@ const processTotalSupplyUpdatedHighres = async (
194227
// OETH Object
195228
const oethObject = await getLatestOETHObject(ctx, result, block)
196229
oethObject.totalSupply = data.totalSupply
230+
oethObject.rebasingSupply =
231+
oethObject.totalSupply - oethObject.nonRebasingSupply
197232

198233
if (!result.lastYieldDistributionEvent) {
199234
throw new Error('lastYieldDistributionEvent is not set')
@@ -266,7 +301,8 @@ const processRebaseOpt = async (
266301
await result.initialize()
267302
const timestamp = new Date(block.header.timestamp)
268303
const blockNumber = block.header.height
269-
const address = trace.transaction!.from.toLowerCase()
304+
const address = trace.action.from.toLowerCase()
305+
const oethObject = await getLatestOETHObject(ctx, result, block)
270306
let owner = result.owners.get(address)
271307
if (!owner) {
272308
owner = await createAddress(ctx, address, timestamp)
@@ -285,10 +321,16 @@ const processRebaseOpt = async (
285321
if (trace.action.sighash === oeth.functions.rebaseOptIn.sighash) {
286322
owner.rebasingOption = RebasingOption.OptIn
287323
rebaseOption.status = RebasingOption.OptIn
324+
oethObject.nonRebasingSupply -= owner.balance
325+
oethObject.rebasingSupply =
326+
oethObject.totalSupply - oethObject.nonRebasingSupply
288327
}
289328
if (trace.action.sighash === oeth.functions.rebaseOptOut.sighash) {
290329
owner.rebasingOption = RebasingOption.OptOut
291330
rebaseOption.status = RebasingOption.OptOut
331+
oethObject.nonRebasingSupply += owner.balance
332+
oethObject.rebasingSupply =
333+
oethObject.totalSupply - oethObject.nonRebasingSupply
292334
}
293335
}
294336
}
@@ -313,6 +355,8 @@ const getLatestOETHObject = async (
313355
timestamp: new Date(block.header.timestamp),
314356
blockNumber: block.header.height,
315357
totalSupply: latest?.totalSupply ?? 0n,
358+
rebasingSupply: latest?.rebasingSupply ?? 0n,
359+
nonRebasingSupply: latest?.nonRebasingSupply ?? 0n,
316360
})
317361
result.oeths.push(oethObject)
318362
}

0 commit comments

Comments
 (0)