From 8e8f5aff26e061953d08e09b902d5c7bb08be994 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Jul 2023 04:55:02 +0000 Subject: [PATCH 01/17] Bump word-wrap from 1.2.3 to 1.2.4 Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4. - [Release notes](https://github.com/jonschlinkert/word-wrap/releases) - [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4) --- updated-dependencies: - dependency-name: word-wrap dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 0b1b574..a7e91d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5675,9 +5675,9 @@ window-size@^0.2.0: integrity sha512-UD7d8HFA2+PZsbKyaOCEy8gMh1oDtHgJh1LfgjQ4zVXmYjAT/kvz3PueITKuqDiIXQe7yzpPnxX3lNc+AhQMyw== word-wrap@^1.2.3, word-wrap@~1.2.3: - version "1.2.3" - resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" - integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== + version "1.2.4" + resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f" + integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA== wrap-ansi@^2.0.0: version "2.1.0" From 01067af14208b4dbf8443955a74cd0f681df5c86 Mon Sep 17 00:00:00 2001 From: Adam Goth Date: Thu, 25 Apr 2024 10:18:04 +0200 Subject: [PATCH 02/17] Add sepolia contract, starting block --- config.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.js b/config.js index ca131e3..7cb6ca6 100644 --- a/config.js +++ b/config.js @@ -45,9 +45,9 @@ const VOTE_DELEGATE_FACTORY_GOERLI_ADDRESS = //Arbitrum mainnet const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; -// arbitrum testnet +// arbitrum testnet (sepolia) const ARB_TESTNET_POLLING_ADDRESS = - '0x4d196378e636D22766d6A9C6C6f4F32AD3ECB050'; + '0xceaB5Bb248A9237128943BbC9d38fd02A4440B10'; const CHAIN_HOST_L1 = process.env.VL_CHAIN_HOST; const CHAIN_HOST_L2 = process.env.VL_CHAIN_HOST_L2; @@ -157,7 +157,7 @@ const mainnet = { }, onStart: (services) => console.log( - `Starting Mainnet config with these services: ${Object.keys(services)}` + `Starting Mainnet config with these services: ${Object.keys(services)}`, ), }; @@ -202,7 +202,7 @@ const arbitrumTestnet = { host: CHAIN_HOST_L2, retries: 15, }, - startingBlock: 154800, + startingBlock: 37261050, extractors: [...makeRawLogExtractors([ARB_TESTNET_POLLING_ADDRESS])], transformers: [arbitrumPollingTransformer(ARB_TESTNET_POLLING_ADDRESS)], migrations: { From 0d9922b50a50ede86486dbc4ba62c805cb1b7bdf Mon Sep 17 00:00:00 2001 From: tyler17 Date: Thu, 9 May 2024 18:50:07 -0700 Subject: [PATCH 03/17] new sepolia contract --- config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.js b/config.js index 7cb6ca6..2e59f9d 100644 --- a/config.js +++ b/config.js @@ -47,7 +47,7 @@ const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; // arbitrum testnet (sepolia) const ARB_TESTNET_POLLING_ADDRESS = - '0xceaB5Bb248A9237128943BbC9d38fd02A4440B10'; + '0x849637EabC4b87363717fb3bD7457358F64F925C'; const CHAIN_HOST_L1 = process.env.VL_CHAIN_HOST; const CHAIN_HOST_L2 = process.env.VL_CHAIN_HOST_L2; From 8bee7d3c6e80884b6a2cbd459843fb6fc1a42d8b Mon Sep 17 00:00:00 2001 From: tyler17 Date: Fri, 10 May 2024 15:24:00 -0700 Subject: [PATCH 04/17] replace multi_goerli with multi_tenderly --- config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config.js b/config.js index 2e59f9d..14aee88 100644 --- a/config.js +++ b/config.js @@ -227,9 +227,9 @@ let config; if (process.env.VL_CONFIG_NAME === 'multi') { console.log('Using Mainnet multi-chain config'); config = [mainnet, arbitrum]; -} else if (process.env.VL_CONFIG_NAME === 'multi_goerli') { - console.log('Using Goerli multi-chain config'); - config = [goerli, arbitrumTestnet]; +} else if (process.env.VL_CONFIG_NAME === 'multi_tenderly') { + console.log('Using Tenderly multi-chain config'); + config = [mainnet, arbitrumTestnet]; } module.exports.default = config; From b2e68d3516e932bfc46a774eed0f99a0e6c54a78 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Tue, 24 Sep 2024 11:42:26 -0700 Subject: [PATCH 05/17] delete goerli and kovan config & references --- config.js | 63 ------------------------------ transformers/PollingTransformer.js | 22 ++--------- 2 files changed, 3 insertions(+), 82 deletions(-) diff --git a/config.js b/config.js index 14aee88..75a24fc 100644 --- a/config.js +++ b/config.js @@ -29,19 +29,6 @@ const VOTE_PROXY_FACTORY_12_ADDRESS = const VOTE_DELEGATE_FACTORY_ADDRESS = '0xD897F108670903D1d6070fcf818f9db3615AF272'; -//goerli -// note: there is no v1 of DSCHIEF or VOTE_PROXY_FACTORY deployed to goerli, only the newer versions -const MKR_GOERLI_ADDRESS = '0xc5E4eaB513A7CD12b2335e8a0D57273e13D499f7'; -const BATCH_VOTING_CONTRACT_GOERLI_ADDRESS = - '0xdbE5d00b2D8C13a77Fb03Ee50C87317dbC1B15fb'; -const ESM_ADDRESS_GOERLI = '0x105BF37e7D81917b6fEACd6171335B4838e53D5e'; -const ESM_V2_ADDRESS_GOERLI = '0x023A960cb9BE7eDE35B433256f4AfE9013334b55'; -const DSCHIEF_12_GOERLI_ADDRESS = '0x33Ed584fc655b08b2bca45E1C5b5f07c98053bC1'; -const VOTE_PROXY_FACTORY_12_GOERLI_ADDRESS = - '0x1a7c1ee5eE2A3B67778ff1eA8c719A3fA1b02b6f'; -const VOTE_DELEGATE_FACTORY_GOERLI_ADDRESS = - '0xE2d249AE3c156b132C40D07bd4d34e73c1712947'; - //Arbitrum mainnet const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; @@ -52,56 +39,6 @@ const ARB_TESTNET_POLLING_ADDRESS = const CHAIN_HOST_L1 = process.env.VL_CHAIN_HOST; const CHAIN_HOST_L2 = process.env.VL_CHAIN_HOST_L2; -const goerli = { - name: 'goerli', - processorSchema: 'vulcan2x', - extractedSchema: 'extracted', - chain: { - name: 'goerli', - host: CHAIN_HOST_L1, - retries: 15, - }, - startingBlock: 5273000, - extractors: [ - ...makeRawLogExtractors([ - BATCH_VOTING_CONTRACT_GOERLI_ADDRESS, - MKR_GOERLI_ADDRESS, - ESM_ADDRESS_GOERLI, - ESM_V2_ADDRESS_GOERLI, - DSCHIEF_12_GOERLI_ADDRESS, - VOTE_PROXY_FACTORY_12_GOERLI_ADDRESS, - VOTE_DELEGATE_FACTORY_GOERLI_ADDRESS, - ]), - ], - transformers: [ - pollingTransformer(BATCH_VOTING_CONTRACT_GOERLI_ADDRESS), - mkrTransformer(MKR_GOERLI_ADDRESS), - mkrBalanceTransformer(MKR_GOERLI_ADDRESS), - esmTransformer(ESM_ADDRESS_GOERLI), - esmV2Transformer(ESM_V2_ADDRESS_GOERLI), - dsChiefTransformer(DSCHIEF_12_GOERLI_ADDRESS, '_v1.2'), - chiefBalanceTransformer(DSCHIEF_12_GOERLI_ADDRESS, '_v1.2'), - voteProxyFactoryTransformer(VOTE_PROXY_FACTORY_12_GOERLI_ADDRESS, '_v1.2'), - voteDelegateFactoryTransformer(VOTE_DELEGATE_FACTORY_GOERLI_ADDRESS), - ], - migrations: { - mkr: './migrations', - }, - api: { - whitelisting: { - enabled: true, - whitelistedQueriesDir: './queries', - bypassSecret: process.env.BYPASS_SECRET, - }, - responseCaching: { - enabled: false, - duration: '15 seconds', - }, - }, - onStart: (services) => - console.log(`Starting with these services: ${Object.keys(services)}`), -}; - const mainnet = { name: 'mainnet', processorSchema: 'vulcan2x', diff --git a/transformers/PollingTransformer.js b/transformers/PollingTransformer.js index eba52b8..5c19bad 100644 --- a/transformers/PollingTransformer.js +++ b/transformers/PollingTransformer.js @@ -19,18 +19,12 @@ const authorizedCreators = process.env.AUTHORIZED_CREATORS : []; // TODO -module.exports.VOTING_CONTRACT_GOERLI_ADDRESS = - '0xdbE5d00b2D8C13a77Fb03Ee50C87317dbC1B15fb'; -module.exports.VOTING_CONTRACT_KOVAN_ADDRESS = - '0x518a0702701BF98b5242E73b2368ae07562BEEA3'; module.exports.VOTING_CONTRACT_ADDRESS = '0xF9be8F0945acDdeeDaA64DFCA5Fe9629D0CF8E5D'; module.exports.default = (address) => ({ name: - address === module.exports.VOTING_CONTRACT_ADDRESS || - address === module.exports.VOTING_CONTRACT_KOVAN_ADDRESS || - address === module.exports.VOTING_CONTRACT_GOERLI_ADDRESS + address === module.exports.VOTING_CONTRACT_ADDRESS ? `Polling_Transformer` : `Polling_Transformer_${address}`, dependencies: [getExtractorName(address)], @@ -43,12 +37,7 @@ const handlers = { async PollCreated(services, info) { if ( info.event.address.toLowerCase() !== - module.exports.VOTING_CONTRACT_KOVAN_ADDRESS.toLowerCase() && - info.event.address.toLowerCase() !== - module.exports.VOTING_CONTRACT_ADDRESS.toLowerCase() && - // goerli uses batch polling contract for creating polls - info.event.address.toLowerCase() !== - module.exports.VOTING_CONTRACT_GOERLI_ADDRESS.toLowerCase() + module.exports.VOTING_CONTRACT_ADDRESS.toLowerCase() ) { logger.info( `Ignoring PollCreated event because ${info.event.address} is not the primary voting contract` @@ -100,12 +89,7 @@ const handlers = { async PollWithdrawn(services, info) { if ( info.event.address.toLowerCase() !== - module.exports.VOTING_CONTRACT_KOVAN_ADDRESS.toLowerCase() && - info.event.address.toLowerCase() !== - module.exports.VOTING_CONTRACT_ADDRESS.toLowerCase() && - // goerli uses batch polling contract for withdrawing polls - info.event.address.toLowerCase() !== - module.exports.VOTING_CONTRACT_GOERLI_ADDRESS.toLowerCase() + module.exports.VOTING_CONTRACT_ADDRESS.toLowerCase() ) { logger.info( `Ignoring PollWithdrawn event because ${info.event.address} is not the primary voting contract` From 4ba2e109acf4c703d17b2aaefb352da9798ed1cc Mon Sep 17 00:00:00 2001 From: tyler17 Date: Tue, 24 Sep 2024 14:23:03 -0700 Subject: [PATCH 06/17] Add second transformer --- config.js | 8 ++++- migrations/074-delegate-version-row.sql | 3 ++ .../V2VoteDelegateFactoryTransformer.js | 35 +++++++++++++++++++ .../VoteDelegateFactoryTransformer.js | 6 ++-- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 migrations/074-delegate-version-row.sql create mode 100644 transformers/V2VoteDelegateFactoryTransformer.js diff --git a/config.js b/config.js index 75a24fc..8da7fb8 100644 --- a/config.js +++ b/config.js @@ -12,6 +12,7 @@ const voteProxyFactoryTransformer = require('./transformers/VoteProxyFactoryTran const esmTransformer = require('./transformers/EsmTransformer'); const esmV2Transformer = require('./transformers/EsmV2Transformer'); const voteDelegateFactoryTransformer = require('./transformers/VoteDelegateFactoryTransformer'); +const v2VoteDelegateFactoryTransformer = require('./transformers/V2VoteDelegateFactoryTransformer'); //mainnet const MKR_ADDRESS = '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2'; @@ -29,6 +30,9 @@ const VOTE_PROXY_FACTORY_12_ADDRESS = const VOTE_DELEGATE_FACTORY_ADDRESS = '0xD897F108670903D1d6070fcf818f9db3615AF272'; +const USE_TENDERLY_CONFIG = process.env.USE_TENDERLY_CONFIG; +const V2_VOTE_DELEGATE_FACTORY_ADDRESS = USE_TENDERLY_CONFIG ? '0xc1dc7a8379885676a6ea08e67b7defd9a235de71' : ''; //TODO: add mainnet address + //Arbitrum mainnet const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; @@ -43,7 +47,7 @@ const mainnet = { name: 'mainnet', processorSchema: 'vulcan2x', extractedSchema: 'extracted', - startingBlock: 4620855, + startingBlock: USE_TENDERLY_CONFIG ? 20627170 : 4620855, //TODO: update tenderly starting block once done testing chain: { name: 'mainnet', host: CHAIN_HOST_L1, @@ -61,6 +65,7 @@ const mainnet = { ESM_ADDRESS, ESM_V2_ADDRESS, VOTE_DELEGATE_FACTORY_ADDRESS, + V2_VOTE_DELEGATE_FACTORY_ADDRESS, ]), ], transformers: [ @@ -77,6 +82,7 @@ const mainnet = { esmTransformer(ESM_ADDRESS), esmV2Transformer(ESM_V2_ADDRESS), voteDelegateFactoryTransformer(VOTE_DELEGATE_FACTORY_ADDRESS), + v2VoteDelegateFactoryTransformer(V2_VOTE_DELEGATE_FACTORY_ADDRESS), ], migrations: { mkr: './migrations', diff --git a/migrations/074-delegate-version-row.sql b/migrations/074-delegate-version-row.sql new file mode 100644 index 0000000..6283e12 --- /dev/null +++ b/migrations/074-delegate-version-row.sql @@ -0,0 +1,3 @@ +-- Add optional version column as a number to dschief.vote_delegate_created_event table +ALTER TABLE dschief.vote_delegate_created_event +ADD COLUMN version INTEGER NULL; \ No newline at end of file diff --git a/transformers/V2VoteDelegateFactoryTransformer.js b/transformers/V2VoteDelegateFactoryTransformer.js new file mode 100644 index 0000000..471df16 --- /dev/null +++ b/transformers/V2VoteDelegateFactoryTransformer.js @@ -0,0 +1,35 @@ +const { + getExtractorName, +} = require('@makerdao-dux/spock-utils/dist/extractors/rawEventDataExtractor'); + +const { + handleEvents, +} = require('@makerdao-dux/spock-utils/dist/transformers/common'); + +// @ts-ignore +const abi = require('../abis/vote_delegate_factory.json'); + +module.exports = (voteDelegateFactoryAddress, nameSuffix = '') => ({ + name: `V2_vote_delegate_factory_transformer${nameSuffix}`, + dependencies: [getExtractorName(voteDelegateFactoryAddress)], + transform: async (services, logs) => { + await handleEvents(services, abi, logs[0], handlers); + }, +}); + +const handlers = { + async CreateVoteDelegate(services, info) { + const sql = `INSERT INTO dschief.vote_delegate_created_event + (delegate, vote_delegate, log_index, tx_id, block_id, version) + VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${version});`; + + await services.tx.none(sql, { + delegate: info.event.params.delegate.toLowerCase(), + vote_delegate: info.event.params.voteDelegate.toLowerCase(), + log_index: info.log.log_index, + tx_id: info.log.tx_id, + block_id: info.log.block_id, + version: 2, + }); + }, +}; diff --git a/transformers/VoteDelegateFactoryTransformer.js b/transformers/VoteDelegateFactoryTransformer.js index 087f5f0..7815e77 100644 --- a/transformers/VoteDelegateFactoryTransformer.js +++ b/transformers/VoteDelegateFactoryTransformer.js @@ -20,16 +20,16 @@ module.exports = (voteDelegateFactoryAddress, nameSuffix = '') => ({ const handlers = { async CreateVoteDelegate(services, info) { const sql = `INSERT INTO dschief.vote_delegate_created_event - (delegate,vote_delegate,log_index,tx_id,block_id) - VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id});`; + (delegate, vote_delegate, log_index, tx_id, block_id, version) + VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${version});`; await services.tx.none(sql, { delegate: info.event.params.delegate.toLowerCase(), vote_delegate: info.event.params.voteDelegate.toLowerCase(), - log_index: info.log.log_index, tx_id: info.log.tx_id, block_id: info.log.block_id, + version: 1, }); }, }; From f0d49a59ee343acf089f7c224c9f07d0a11e1942 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 25 Sep 2024 13:25:07 -0700 Subject: [PATCH 07/17] arbitrum transformer - handle case where one address has v1 and v2 delegates --- transformers/ArbitrumPollingTransformer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transformers/ArbitrumPollingTransformer.js b/transformers/ArbitrumPollingTransformer.js index 64ab4c4..42e4b83 100644 --- a/transformers/ArbitrumPollingTransformer.js +++ b/transformers/ArbitrumPollingTransformer.js @@ -45,7 +45,9 @@ const handlers = { const vdQuery = `SELECT ce.vote_delegate as voter, (SELECT now() >= b.timestamp + interval '1 year') as expired FROM dschief.vote_delegate_created_event ce JOIN vulcan2x.block b ON b.id = ce.block_id - WHERE ce.delegate = $1`; + WHERE ce.delegate = $1 + ORDER BY ce.version DESC + LIMIT 1`; //get latest version if there are multiple const row = await services.db.oneOrNone(vdQuery, [voter]); From af9e897482986576434729437965456bdfe9e5c9 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 25 Sep 2024 13:40:22 -0700 Subject: [PATCH 08/17] handle usr in CreateVoteDelegate event --- transformers/V2VoteDelegateFactoryTransformer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transformers/V2VoteDelegateFactoryTransformer.js b/transformers/V2VoteDelegateFactoryTransformer.js index 471df16..c711bec 100644 --- a/transformers/V2VoteDelegateFactoryTransformer.js +++ b/transformers/V2VoteDelegateFactoryTransformer.js @@ -23,8 +23,10 @@ const handlers = { (delegate, vote_delegate, log_index, tx_id, block_id, version) VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${version});`; + const delegate = info.event.params.usr || info.event.params.delegate; //TODO: why isn't it just usr? + await services.tx.none(sql, { - delegate: info.event.params.delegate.toLowerCase(), + delegate: delegate.toLowerCase(), vote_delegate: info.event.params.voteDelegate.toLowerCase(), log_index: info.log.log_index, tx_id: info.log.tx_id, From c6a668981b908182416415bf7b8b477c1d9fcc76 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 25 Sep 2024 14:03:14 -0700 Subject: [PATCH 09/17] require USE_TENDERLY_CONFIG=true --- config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config.js b/config.js index 8da7fb8..703cee0 100644 --- a/config.js +++ b/config.js @@ -30,7 +30,7 @@ const VOTE_PROXY_FACTORY_12_ADDRESS = const VOTE_DELEGATE_FACTORY_ADDRESS = '0xD897F108670903D1d6070fcf818f9db3615AF272'; -const USE_TENDERLY_CONFIG = process.env.USE_TENDERLY_CONFIG; +const USE_TENDERLY_CONFIG = process.env.USE_TENDERLY_CONFIG === 'true'; const V2_VOTE_DELEGATE_FACTORY_ADDRESS = USE_TENDERLY_CONFIG ? '0xc1dc7a8379885676a6ea08e67b7defd9a235de71' : ''; //TODO: add mainnet address //Arbitrum mainnet @@ -47,7 +47,7 @@ const mainnet = { name: 'mainnet', processorSchema: 'vulcan2x', extractedSchema: 'extracted', - startingBlock: USE_TENDERLY_CONFIG ? 20627170 : 4620855, //TODO: update tenderly starting block once done testing + startingBlock: USE_TENDERLY_CONFIG ? 20628384 : 4620855, //TODO: update tenderly starting block once done testing chain: { name: 'mainnet', host: CHAIN_HOST_L1, From c1200dd5df743fbbd67cc817777fecb79af8e915 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Thu, 26 Sep 2024 15:52:36 -0700 Subject: [PATCH 10/17] delete USE_TENDERLY_CONFIG --- config.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/config.js b/config.js index 703cee0..da46dc5 100644 --- a/config.js +++ b/config.js @@ -29,9 +29,7 @@ const VOTE_PROXY_FACTORY_12_ADDRESS = '0x6FCD258af181B3221073A96dD90D1f7AE7eEc408'; const VOTE_DELEGATE_FACTORY_ADDRESS = '0xD897F108670903D1d6070fcf818f9db3615AF272'; - -const USE_TENDERLY_CONFIG = process.env.USE_TENDERLY_CONFIG === 'true'; -const V2_VOTE_DELEGATE_FACTORY_ADDRESS = USE_TENDERLY_CONFIG ? '0xc1dc7a8379885676a6ea08e67b7defd9a235de71' : ''; //TODO: add mainnet address +const V2_VOTE_DELEGATE_FACTORY_ADDRESS = '0xc1dc7a8379885676a6ea08e67b7defd9a235de71'; //Arbitrum mainnet const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; @@ -47,7 +45,7 @@ const mainnet = { name: 'mainnet', processorSchema: 'vulcan2x', extractedSchema: 'extracted', - startingBlock: USE_TENDERLY_CONFIG ? 20628384 : 4620855, //TODO: update tenderly starting block once done testing + startingBlock: 4620855, chain: { name: 'mainnet', host: CHAIN_HOST_L1, From cdd31116253a145bd877856dcd4ff286c5cc2c1f Mon Sep 17 00:00:00 2001 From: tyler17 Date: Mon, 30 Sep 2024 14:34:26 -0700 Subject: [PATCH 11/17] add version to delegates query, change name to delegate_version --- migrations/074-delegate-version-row.sql | 2 +- migrations/075-add-delegate-version.sql | 102 +++++++++++++++++++++ queries/delegates.graphql | 1 + transformers/ArbitrumPollingTransformer.js | 2 +- 4 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 migrations/075-add-delegate-version.sql diff --git a/migrations/074-delegate-version-row.sql b/migrations/074-delegate-version-row.sql index 6283e12..7496b4c 100644 --- a/migrations/074-delegate-version-row.sql +++ b/migrations/074-delegate-version-row.sql @@ -1,3 +1,3 @@ -- Add optional version column as a number to dschief.vote_delegate_created_event table ALTER TABLE dschief.vote_delegate_created_event -ADD COLUMN version INTEGER NULL; \ No newline at end of file +ADD COLUMN delegate_version INTEGER NULL; \ No newline at end of file diff --git a/migrations/075-add-delegate-version.sql b/migrations/075-add-delegate-version.sql new file mode 100644 index 0000000..1439773 --- /dev/null +++ b/migrations/075-add-delegate-version.sql @@ -0,0 +1,102 @@ +-- Dropping function as the return type changed +drop function if exists api.delegates; + +drop type delegate_entry; + +create type delegate_entry as ( + delegate character varying(66), + vote_delegate character varying(66), + creation_date timestamp with time zone, + expiration_date timestamp with time zone, + expired boolean, + last_voted timestamp with time zone, + delegator_count int, + total_mkr numeric(78,18), + delegate_version int +); + +-- Same function, but also return the delegate version +create or replace function api.delegates(_first int, order_by delegate_order_by_type default 'DATE', order_direction order_direction_type default 'DESC', include_expired boolean default false, seed double precision default random(), constitutional_delegates char[] default '{}') +returns setof delegate_entry as $$ +declare + max_page_size_value int := (select api.max_page_size()); +begin + if _first > max_page_size_value then + raise exception 'Parameter FIRST cannot be greater than %.', max_page_size_value; + elsif seed > 1 or seed < -1 then + raise exception 'Parameter SEED must have a value between -1 and 1'; + else + return query + -- Merge poll votes from Mainnet and Arbitrum and attach the timestamp to them + with merged_vote_events as ( + select voter, vote_timestamp + from ( + select voter, timestamp as vote_timestamp + from polling.voted_event A + left join vulcan2x.block B + on A.block_id = B.id + ) AB + union all + select voter, vote_timestamp + from ( + select voter, timestamp as vote_timestamp + from polling.voted_event_arbitrum C + left join vulcan2xarbitrum.block D + on C.block_id = D.id + ) CD + ), + delegates_table as ( + select E.delegate, E.vote_delegate, F.timestamp as creation_date, F.timestamp + '1 year' as expiration_date, now() > F.timestamp + '1 year' as expired, E.delegate_version + from dschief.vote_delegate_created_event E + left join vulcan2x.block F + on E.block_id = F.id + -- Filter out expired delegates if include_expired is false + where include_expired or now() < F.timestamp + '1 year' + ), + -- Merge delegates with their last votes + delegates_with_last_vote as ( + select G.*, max(H.vote_timestamp) as last_voted + from delegates_table G + left join merged_vote_events H + on G.vote_delegate = H.voter + group by G.vote_delegate, G.delegate, G.creation_date, G.expiration_date, G.expired, G.delegate_version + ), + delegations_table as ( + select contract_address, count(immediate_caller) as delegators, sum(delegations) as delegations + from ( + select immediate_caller, sum(lock) as delegations, contract_address + from dschief.delegate_lock + group by contract_address, immediate_caller + ) as I + where delegations > 0 + group by contract_address + ) + select delegate::character varying(66), vote_delegate::character varying(66), creation_date, expiration_date, expired, last_voted, coalesce(delegators, 0)::int as delegator_count, coalesce(delegations, 0)::numeric(78,18) as total_mkr, delegate_version + from ( + -- We call setseed here to make sure it's executed before the main select statement and the order by random clause. + -- By appending it to the delegates_with_last_vote table and then removing the row with offset 1, we make sure the table remains unmodified. + select setseed(seed), null delegate, null vote_delegate, null creation_date, null expiration_date, null expired, null last_voted, null delegate_version + union all + select null, delegate, vote_delegate, creation_date, expiration_date, expired, last_voted, delegate_version from delegates_with_last_vote + offset 1 + ) sd + left join delegations_table + on sd.vote_delegate::character varying(66) = delegations_table.contract_address + order by + -- Ordering first by expiration: expired at the end, second by delegate type: constitutional delegates first + -- and third by the sorting criterion selected. + case when expired then 1 else 0 end, + case when vote_delegate = ANY (constitutional_delegates) then 0 else 1 end, + case + when order_by = 'DELEGATORS' then + case when order_direction = 'ASC' then coalesce(delegators, 0)::int else -coalesce(delegators, 0)::int end + when order_by = 'MKR' then + case when order_direction = 'ASC' then coalesce(delegations, 0)::numeric(78,18) else -coalesce(delegations, 0)::numeric(78,18) end + when order_by = 'DATE' then + case when order_direction = 'ASC' then extract(epoch from creation_date) else -extract(epoch from creation_date) end + else + random() + end; + end if; +end; +$$ language plpgsql stable strict; \ No newline at end of file diff --git a/queries/delegates.graphql b/queries/delegates.graphql index 20aa7c9..e117c23 100644 --- a/queries/delegates.graphql +++ b/queries/delegates.graphql @@ -36,6 +36,7 @@ query delegates( lastVoted delegatorCount totalMkr + delegateVersion } } } diff --git a/transformers/ArbitrumPollingTransformer.js b/transformers/ArbitrumPollingTransformer.js index 42e4b83..a349710 100644 --- a/transformers/ArbitrumPollingTransformer.js +++ b/transformers/ArbitrumPollingTransformer.js @@ -46,7 +46,7 @@ const handlers = { FROM dschief.vote_delegate_created_event ce JOIN vulcan2x.block b ON b.id = ce.block_id WHERE ce.delegate = $1 - ORDER BY ce.version DESC + ORDER BY ce.delegate_version DESC LIMIT 1`; //get latest version if there are multiple const row = await services.db.oneOrNone(vdQuery, [voter]); From b20a3749ca0eae4c2abd506b3d36e013fe1253b6 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Mon, 30 Sep 2024 16:46:34 -0700 Subject: [PATCH 12/17] fix transformer --- transformers/V2VoteDelegateFactoryTransformer.js | 6 +++--- transformers/VoteDelegateFactoryTransformer.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/transformers/V2VoteDelegateFactoryTransformer.js b/transformers/V2VoteDelegateFactoryTransformer.js index c711bec..c0a4ed7 100644 --- a/transformers/V2VoteDelegateFactoryTransformer.js +++ b/transformers/V2VoteDelegateFactoryTransformer.js @@ -20,8 +20,8 @@ module.exports = (voteDelegateFactoryAddress, nameSuffix = '') => ({ const handlers = { async CreateVoteDelegate(services, info) { const sql = `INSERT INTO dschief.vote_delegate_created_event - (delegate, vote_delegate, log_index, tx_id, block_id, version) - VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${version});`; + (delegate, vote_delegate, log_index, tx_id, block_id, delegate_version) + VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${delegate_version});`; const delegate = info.event.params.usr || info.event.params.delegate; //TODO: why isn't it just usr? @@ -31,7 +31,7 @@ const handlers = { log_index: info.log.log_index, tx_id: info.log.tx_id, block_id: info.log.block_id, - version: 2, + delegate_version: 2, }); }, }; diff --git a/transformers/VoteDelegateFactoryTransformer.js b/transformers/VoteDelegateFactoryTransformer.js index 7815e77..3bed7c6 100644 --- a/transformers/VoteDelegateFactoryTransformer.js +++ b/transformers/VoteDelegateFactoryTransformer.js @@ -20,8 +20,8 @@ module.exports = (voteDelegateFactoryAddress, nameSuffix = '') => ({ const handlers = { async CreateVoteDelegate(services, info) { const sql = `INSERT INTO dschief.vote_delegate_created_event - (delegate, vote_delegate, log_index, tx_id, block_id, version) - VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${version});`; + (delegate, vote_delegate, log_index, tx_id, block_id, delegate_version) + VALUES(\${delegate}, \${vote_delegate}, \${log_index}, \${tx_id}, \${block_id}, \${delegate_version});`; await services.tx.none(sql, { delegate: info.event.params.delegate.toLowerCase(), @@ -29,7 +29,7 @@ const handlers = { log_index: info.log.log_index, tx_id: info.log.tx_id, block_id: info.log.block_id, - version: 1, + delegate_version: 1, }); }, }; From ae6906ca5f3337dc325b7989f303245344f20b24 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Mon, 30 Sep 2024 16:48:08 -0700 Subject: [PATCH 13/17] update arbitrum sepolia polling address --- config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.js b/config.js index da46dc5..cf1881f 100644 --- a/config.js +++ b/config.js @@ -36,7 +36,7 @@ const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; // arbitrum testnet (sepolia) const ARB_TESTNET_POLLING_ADDRESS = - '0x849637EabC4b87363717fb3bD7457358F64F925C'; + '0xE63329692fA90B3efd5eB675c601abeDB2DF715a'; const CHAIN_HOST_L1 = process.env.VL_CHAIN_HOST; const CHAIN_HOST_L2 = process.env.VL_CHAIN_HOST_L2; From 3b12093d7c182bf1a8a6c888bd0006a6df510243 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 2 Oct 2024 13:50:36 -0700 Subject: [PATCH 14/17] update v2 factory address --- config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.js b/config.js index cf1881f..6e83652 100644 --- a/config.js +++ b/config.js @@ -29,7 +29,7 @@ const VOTE_PROXY_FACTORY_12_ADDRESS = '0x6FCD258af181B3221073A96dD90D1f7AE7eEc408'; const VOTE_DELEGATE_FACTORY_ADDRESS = '0xD897F108670903D1d6070fcf818f9db3615AF272'; -const V2_VOTE_DELEGATE_FACTORY_ADDRESS = '0xc1dc7a8379885676a6ea08e67b7defd9a235de71'; +const V2_VOTE_DELEGATE_FACTORY_ADDRESS = '0x093d305366218d6d09ba10448922f10814b031dd'; //Arbitrum mainnet const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC'; From fa9daf23928ea2e29ebd8634214ec48d4cdb239f Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 2 Oct 2024 17:14:29 -0700 Subject: [PATCH 15/17] add delegateVersion to allDelegates query in whitelist --- queries/allDelegates.graphql | 1 + 1 file changed, 1 insertion(+) diff --git a/queries/allDelegates.graphql b/queries/allDelegates.graphql index 55848eb..e52cd2b 100644 --- a/queries/allDelegates.graphql +++ b/queries/allDelegates.graphql @@ -4,6 +4,7 @@ query allDelegates { delegate voteDelegate blockTimestamp + delegateVersion } } } From ba565d189de39d4a656e7cba284aa8b677e84dcd Mon Sep 17 00:00:00 2001 From: tyler17 Date: Wed, 2 Oct 2024 18:22:01 -0700 Subject: [PATCH 16/17] update allDelegates query to include version --- migrations/076-new-all-delegates.sql | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 migrations/076-new-all-delegates.sql diff --git a/migrations/076-new-all-delegates.sql b/migrations/076-new-all-delegates.sql new file mode 100644 index 0000000..c3f4172 --- /dev/null +++ b/migrations/076-new-all-delegates.sql @@ -0,0 +1,28 @@ +-- Drop existing functions +DROP FUNCTION IF EXISTS dschief.all_delegates(); +DROP FUNCTION IF EXISTS api.all_delegates(); + +CREATE OR REPLACE FUNCTION dschief.all_delegates() +RETURNS TABLE ( + delegate character varying(66), + vote_delegate character varying(66), + delegate_version int +) AS $$ +SELECT delegate, vote_delegate, delegate_version +FROM dschief.vote_delegate_created_event +$$ LANGUAGE sql STABLE STRICT; + + +--This query would be called by allDelegates() in the sdk +CREATE OR REPLACE FUNCTION api.all_delegates() +RETURNS TABLE ( + delegate character varying(66), + vote_delegate character varying(66), + delegate_version int, + block_timestamp TIMESTAMP WITH TIME ZONE +) AS $$ +SELECT delegate, vote_delegate, delegate_version, b.timestamp +FROM dschief.vote_delegate_created_event d +LEFT JOIN vulcan2x.block b +ON d.block_id = b.id; +$$ LANGUAGE sql STABLE STRICT; \ No newline at end of file From 382d3424eaa38663caa641f279e505163b672fe5 Mon Sep 17 00:00:00 2001 From: tyler17 Date: Thu, 17 Oct 2024 15:39:19 -0700 Subject: [PATCH 17/17] add mainnet v2 delegate factory contract --- config.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index 6e83652..8058189 100644 --- a/config.js +++ b/config.js @@ -29,7 +29,10 @@ const VOTE_PROXY_FACTORY_12_ADDRESS = '0x6FCD258af181B3221073A96dD90D1f7AE7eEc408'; const VOTE_DELEGATE_FACTORY_ADDRESS = '0xD897F108670903D1d6070fcf818f9db3615AF272'; -const V2_VOTE_DELEGATE_FACTORY_ADDRESS = '0x093d305366218d6d09ba10448922f10814b031dd'; +const V2_VOTE_DELEGATE_FACTORY_ADDRESS = + process.env.VL_CONFIG_NAME === 'multi_tenderly' + ? '0x093d305366218d6d09ba10448922f10814b031dd' + : '0xC3D809E87A2C9da4F6d98fECea9135d834d6F5A0'; //Arbitrum mainnet const ARB_POLLING_ADDRESS = '0x4f4e551b4920a5417F8d4e7f8f099660dAdadcEC';