From f58ea35a599d86dae24abd750e84a8db506531d8 Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 4 Sep 2024 09:43:35 -0500 Subject: [PATCH 1/4] add new chains --- libs/shared/src/commonProtocol/chainConfig.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/shared/src/commonProtocol/chainConfig.ts b/libs/shared/src/commonProtocol/chainConfig.ts index 05a07eb3fe1..514c676f331 100644 --- a/libs/shared/src/commonProtocol/chainConfig.ts +++ b/libs/shared/src/commonProtocol/chainConfig.ts @@ -4,6 +4,10 @@ export enum ValidChains { SepoliaBase = 84532, Sepolia = 11155111, Blast = 81457, + Linea = 59144, + Optimism = 10, + Mainnet = 1, + Arbitrum = 42161, } export const STAKE_ID = 2; @@ -39,4 +43,24 @@ export const factoryContracts: { communityStake: '0xcc752fd15A7Dd0d5301b6A626316E7211352Cf62', chainId: 8453, }, + [ValidChains.Linea]: { + factory: '0xe3ae9569f4523161742414480f87967e991741bd', + communityStake: '0xcc752fd15a7dd0d5301b6a626316e7211352cf62', + chainId: 59144, + }, + [ValidChains.Optimism]: { + factory: '0xe3ae9569f4523161742414480f87967e991741bd', + communityStake: '0xcc752fd15a7dd0d5301b6a626316e7211352cf62', + chainId: 10, + }, + [ValidChains.Mainnet]: { + factory: '0x90aa47bf6e754f69ee53f05b5187b320e3118b0f', + communityStake: '0x9ed281e62db1b1d98af90106974891a4c1ca3a47', + chainId: 1, + }, + [ValidChains.Arbitrum]: { + factory: '0xE3AE9569f4523161742414480f87967e991741bd', + communityStake: '0xcc752fd15A7Dd0d5301b6A626316E7211352Cf62', + chainId: 42161, + }, }; From abda1710e339b7aecb36d1e342dbb85c221c523c Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 4 Sep 2024 14:53:21 -0500 Subject: [PATCH 2/4] add evm event source migration --- .../20240904153821-new-chain-event-sources.js | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js diff --git a/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js b/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js new file mode 100644 index 00000000000..28abdf82bda --- /dev/null +++ b/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js @@ -0,0 +1,134 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.transaction(async (transaction) => { + const specificEvmChainIds = [59144, 10, 42161, 1]; + + const chainNodes = await queryInterface.sequelize.query( + 'SELECT id, eth_chain_id FROM "ChainNodes" WHERE eth_chain_id IN (:evmChainIds)', + { + replacements: { evmChainIds: specificEvmChainIds }, + type: Sequelize.QueryTypes.SELECT, + transaction, + }, + ); + + // Define three sets of hard-coded values + const hardCodedValueSetsL2 = [ + { + contract_address: '0xedf43C919f59900C82d963E99d822dA3F95575EA', + event_signature: + '0x8870ba2202802ce285ce6bead5ac915b6dc2d35c8a9d6f96fa56de9de12829d5', + kind: 'DeployedNamespace', + abi_id: 53, + active: true, + }, + { + contract_address: '0xcc752fd15A7Dd0d5301b6A626316E7211352Cf62', + event_signature: + '0xfc13c9a8a9a619ac78b803aecb26abdd009182411d51a986090f82519d88a89e', + kind: 'Trade', + abi_id: 52, + active: true, + }, + { + contract_address: '0xedf43C919f59900C82d963E99d822dA3F95575EA', + event_signature: + '0x990f533044dbc89b838acde9cd2c72c400999871cf8f792d731edcae15ead693', + kind: 'NewContest', + abi_id: 53, + active: true, + }, + ]; + + const hardCodedValueSetsETH = [ + { + contract_address: '0x90aa47bf6e754f69ee53f05b5187b320e3118b0f', + event_signature: + '0x8870ba2202802ce285ce6bead5ac915b6dc2d35c8a9d6f96fa56de9de12829d5', + kind: 'DeployedNamespace', + abi_id: 53, + active: true, + }, + { + contract_address: '0x9ed281e62db1b1d98af90106974891a4c1ca3a47', + event_signature: + '0xfc13c9a8a9a619ac78b803aecb26abdd009182411d51a986090f82519d88a89e', + kind: 'Trade', + abi_id: 52, + active: true, + }, + { + contract_address: '0x90aa47bf6e754f69ee53f05b5187b320e3118b0f', + event_signature: + '0x990f533044dbc89b838acde9cd2c72c400999871cf8f792d731edcae15ead693', + kind: 'NewContest', + abi_id: 53, + active: true, + }, + ]; + + // Prepare records for insertion + const records = chainNodes.flatMap((node) => { + if (node.eth_chain_id == 1) { + return hardCodedValueSetsETH.map((valueSet) => ({ + chain_node_id: node.id, + ...valueSet, + })); + } else { + return hardCodedValueSetsL2.map((valueSet) => ({ + chain_node_id: node.id, + ...valueSet, + })); + } + }); + // Insert records into EvmEventSource table + await queryInterface.bulkInsert('EvmEventSources', records, { + transaction, + }); + }); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.sequelize.transaction(async (transaction) => { + // Fetch the chain_node_ids that were inserted + const chainNodes = await queryInterface.sequelize.query( + 'SELECT id, eth_chain_id FROM "ChainNodes" WHERE eth_chain_id IN (:evmChainIds)', + { + replacements: { evmChainIds: [59144, 10, 42161, 1] }, + type: Sequelize.QueryTypes.SELECT, + transaction, + }, + ); + + const chainNodeIds = chainNodes.map((node) => node.id); + + const contractAddressesL2 = [ + '0xedf43C919f59900C82d963E99d822dA3F95575EA', + '0xcc752fd15A7Dd0d5301b6A626316E7211352Cf62', + '0xedf43C919f59900C82d963E99d822dA3F95575EA', + ]; + + const contractAddressesETH = [ + '0x90aa47bf6e754f69ee53f05b5187b320e3118b0f', + '0x9ed281e62db1b1d98af90106974891a4c1ca3a47', + '0x90aa47bf6e754f69ee53f05b5187b320e3118b0f', + ]; + + // Remove inserted records + await queryInterface.bulkDelete( + 'EvmEventSources', + { + chain_node_id: chainNodeIds, + [Sequelize.Op.or]: [ + { contract_address: contractAddressesL2 }, + { contract_address: contractAddressesETH }, + ], + }, + { transaction }, + ); + }); + }, +}; From 56671940665c0acd2210f36f623ba0a0a5eb9cba Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 4 Sep 2024 14:54:29 -0500 Subject: [PATCH 3/4] fix comments --- .../migrations/20240904153821-new-chain-event-sources.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js b/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js index 28abdf82bda..01d42d151ff 100644 --- a/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js +++ b/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js @@ -15,7 +15,6 @@ module.exports = { }, ); - // Define three sets of hard-coded values const hardCodedValueSetsL2 = [ { contract_address: '0xedf43C919f59900C82d963E99d822dA3F95575EA', @@ -70,7 +69,6 @@ module.exports = { }, ]; - // Prepare records for insertion const records = chainNodes.flatMap((node) => { if (node.eth_chain_id == 1) { return hardCodedValueSetsETH.map((valueSet) => ({ @@ -84,7 +82,7 @@ module.exports = { })); } }); - // Insert records into EvmEventSource table + await queryInterface.bulkInsert('EvmEventSources', records, { transaction, }); @@ -93,7 +91,6 @@ module.exports = { down: async (queryInterface, Sequelize) => { await queryInterface.sequelize.transaction(async (transaction) => { - // Fetch the chain_node_ids that were inserted const chainNodes = await queryInterface.sequelize.query( 'SELECT id, eth_chain_id FROM "ChainNodes" WHERE eth_chain_id IN (:evmChainIds)', { @@ -117,7 +114,6 @@ module.exports = { '0x90aa47bf6e754f69ee53f05b5187b320e3118b0f', ]; - // Remove inserted records await queryInterface.bulkDelete( 'EvmEventSources', { From bc57d0d8210541a28e204dd3b7432c69c09d494f Mon Sep 17 00:00:00 2001 From: ianrowan Date: Wed, 4 Sep 2024 15:09:43 -0500 Subject: [PATCH 4/4] dynamic ABI --- .../20240904153821-new-chain-event-sources.js | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js b/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js index 01d42d151ff..bfecb2dbdfc 100644 --- a/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js +++ b/packages/commonwealth/server/migrations/20240904153821-new-chain-event-sources.js @@ -15,13 +15,31 @@ module.exports = { }, ); + const contractAbis = await queryInterface.sequelize.query( + 'SELECT id, nickname FROM "ContractAbis" WHERE nickname IN (:nicknames)', + { + replacements: { nicknames: ['NamespaceFactory', 'CommunityStakes'] }, + type: Sequelize.QueryTypes.SELECT, + transaction, + }, + ); + + const abiIds = { + NamespaceFactory: contractAbis.find( + (abi) => abi.nickname === 'NamespaceFactory', + ).id, + CommunityStakes: contractAbis.find( + (abi) => abi.nickname === 'CommunityStakes', + ).id, + }; + const hardCodedValueSetsL2 = [ { contract_address: '0xedf43C919f59900C82d963E99d822dA3F95575EA', event_signature: '0x8870ba2202802ce285ce6bead5ac915b6dc2d35c8a9d6f96fa56de9de12829d5', kind: 'DeployedNamespace', - abi_id: 53, + abi_id: abiIds.NamespaceFactory, active: true, }, { @@ -29,7 +47,7 @@ module.exports = { event_signature: '0xfc13c9a8a9a619ac78b803aecb26abdd009182411d51a986090f82519d88a89e', kind: 'Trade', - abi_id: 52, + abi_id: abiIds.CommunityStakes, active: true, }, { @@ -37,7 +55,7 @@ module.exports = { event_signature: '0x990f533044dbc89b838acde9cd2c72c400999871cf8f792d731edcae15ead693', kind: 'NewContest', - abi_id: 53, + abi_id: abiIds.NamespaceFactory, active: true, }, ]; @@ -48,7 +66,7 @@ module.exports = { event_signature: '0x8870ba2202802ce285ce6bead5ac915b6dc2d35c8a9d6f96fa56de9de12829d5', kind: 'DeployedNamespace', - abi_id: 53, + abi_id: abiIds.NamespaceFactory, active: true, }, { @@ -56,7 +74,7 @@ module.exports = { event_signature: '0xfc13c9a8a9a619ac78b803aecb26abdd009182411d51a986090f82519d88a89e', kind: 'Trade', - abi_id: 52, + abi_id: abiIds.CommunityStakes, active: true, }, { @@ -64,7 +82,7 @@ module.exports = { event_signature: '0x990f533044dbc89b838acde9cd2c72c400999871cf8f792d731edcae15ead693', kind: 'NewContest', - abi_id: 53, + abi_id: abiIds.NamespaceFactory, active: true, }, ];