Skip to content

Commit

Permalink
Merge pull request #494 from oasisprotocol/andrew7234/total-supply-bu…
Browse files Browse the repository at this point in the history
…gfix

update total_supply to accept negative updates
  • Loading branch information
Andrew7234 authored Aug 1, 2023
2 parents 82c10f7 + a04760f commit ce3b751
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ var (
VALUES ($1, $2, $3, $4)
ON CONFLICT (runtime, token_address) DO NOTHING`

RuntimeEVMTokenAnalysisMutateInsert = `
RuntimeEVMTokenAnalysisMutateUpsert = `
INSERT INTO analysis.evm_tokens (runtime, token_address, total_supply, last_mutate_round)
VALUES ($1, $2, $3, $4)
ON CONFLICT (runtime, token_address) DO
Expand Down
2 changes: 1 addition & 1 deletion analyzer/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (m *processor) queueDbUpdates(batch *storage.QueryBatch, data *BlockData) {
totalSupply = possibleToken.TotalSupplyChange.String()
}
if possibleToken.Mutated {
batch.Queue(queries.RuntimeEVMTokenAnalysisMutateInsert, m.runtime, addr, totalSupply, data.Header.Round)
batch.Queue(queries.RuntimeEVMTokenAnalysisMutateUpsert, m.runtime, addr, totalSupply, data.Header.Round)
} else {
batch.Queue(queries.RuntimeEVMTokenAnalysisInsert, m.runtime, addr, totalSupply, data.Header.Round)
}
Expand Down
9 changes: 7 additions & 2 deletions storage/migrations/02_runtimes.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,19 @@ CREATE TABLE chain.evm_tokens
token_name TEXT,
symbol TEXT,
decimals INTEGER,
total_supply uint_numeric
-- NOT an uint because a non-conforming token contract could issue a fake burn event,
-- causing a negative dead-reckoned total_supply.
total_supply uint_numeric -- changed to NUMERIC(1000,0) in 09_evm_token_total_supply.up.sql
);

CREATE TABLE chain.evm_token_analysis -- Moved to analysis.evm_tokens in 06_analysis_schema.up.sql
(
runtime runtime NOT NULL,
token_address oasis_addr NOT NULL,
total_supply uint_numeric, -- Dead reckons total_supply before token is downloaded.
-- Dead-reckoned total_supply before token metadata is downloaded.
-- NOT an uint because a non-conforming token contract could issue a fake burn event,
-- causing a negative dead-reckoned total_supply.
total_supply uint_numeric, -- changed to NUMERIC(1000,0) in 09_evm_token_total_supply.up.sql
PRIMARY KEY (runtime, token_address),
-- Block analyzer bumps this when it sees the mutable fields of the token
-- change (e.g. total supply) based on dead reckoning.
Expand Down
6 changes: 6 additions & 0 deletions storage/migrations/09_evm_token_total_supply.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

ALTER TABLE analysis.evm_tokens ALTER COLUMN total_supply type NUMERIC(1000,0);
ALTER TABLE chain.evm_tokens ALTER COLUMN total_supply type NUMERIC(1000,0);

COMMIT;

0 comments on commit ce3b751

Please sign in to comment.