From eb3c82eda43618b95cdd2fe9ff7165cf99f130ca Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Mon, 6 Jan 2025 15:40:59 -0300 Subject: [PATCH 1/5] fix: Add a new allowed selector (sponserdCallV2) for committee txn inputs --- src/handlers/collection.ts | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/handlers/collection.ts b/src/handlers/collection.ts index 6e485a4..4fc6094 100644 --- a/src/handlers/collection.ts +++ b/src/handlers/collection.ts @@ -212,8 +212,7 @@ export function handleRescueItem(event: RescueItem): void { if ((isNewContent && event.block.number.gt(block)) || event.block.number.equals(block)) { // Create curation let txInput = event.transaction.input.toHexString() - // forwardMetaTx(address _target, bytes calldata _data) or manageCollection(address,address,address,bytes[]) selector - if (txInput.startsWith('0x07bd3522') || txInput.startsWith('0x81c9308e')) { + if (isAllowedCommitteeTxInput(txInput)) { let curationId = getCurationId(collectionAddress, event.transaction.hash.toHexString(), event.logIndex.toString()) let curation = new Curation(curationId) let curator = '' @@ -517,8 +516,7 @@ export function handleSetApproved(event: SetApproved): void { if (event.block.number.lt(block)) { // Create curation let txInput = event.transaction.input.toHexString() - // forwardMetaTx(address _target, bytes calldata _data) or manageCollection(address,address,address,bytes[]) selector - if (txInput.startsWith('0x07bd3522') || txInput.startsWith('0x81c9308e')) { + if (isAllowedCommitteeTxInput(txInput)) { let curationId = getCurationId(collectionAddress, event.transaction.hash.toHexString(), event.logIndex.toString()) let curation = new Curation(curationId) let curator = '' @@ -592,3 +590,18 @@ export function handleTransferOwnership(event: OwnershipTransferred): void { collection.save() } } + +// List of allowed committee function selectors +// 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data) +// 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs) +// 0x81c9308e: manageCollection(address,address,address,bytes[]) selector +const ALLOWED_SELECTORS = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] + +/** + * Verify if it's an allowed committee transaction input. + * @param txInput - The transaction input data as a hexadecimal string. + * @returns True if the input starts with an allowed selector, false otherwise. + */ +function isAllowedCommitteeTxInput(txInput: string): boolean { + return ALLOWED_SELECTORS.some(selector => txInput.startsWith(selector)) +} From edb3ea665f061973c7bbc35e7cba971d6fb9deb1 Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Mon, 6 Jan 2025 16:12:28 -0300 Subject: [PATCH 2/5] chore: Updates node-version --- .github/workflows/node.js.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/node.js.yaml b/.github/workflows/node.js.yaml index 9266e3c..259c3e5 100644 --- a/.github/workflows/node.js.yaml +++ b/.github/workflows/node.js.yaml @@ -2,20 +2,20 @@ name: Node.js CI on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: build: - runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - name: Use Node.js 20.x + uses: actions/setup-node@v3 with: - node-version: 16.x + node-version: 20.x # Cache dependencies as `npm ci` takes like 6 minutes to run. # https://github.com/actions/cache/blob/main/examples.md#node---npm - id: npm-cache-dir From 5490b0024bd784f701f0fbac407246cd6fefad8b Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Mon, 6 Jan 2025 17:07:27 -0300 Subject: [PATCH 3/5] fix: AssemblyScript method --- src/handlers/collection.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/handlers/collection.ts b/src/handlers/collection.ts index 4fc6094..744cef7 100644 --- a/src/handlers/collection.ts +++ b/src/handlers/collection.ts @@ -595,7 +595,7 @@ export function handleTransferOwnership(event: OwnershipTransferred): void { // 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data) // 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs) // 0x81c9308e: manageCollection(address,address,address,bytes[]) selector -const ALLOWED_SELECTORS = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] +const ALLOWED_SELECTORS: string[] = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] /** * Verify if it's an allowed committee transaction input. @@ -603,5 +603,10 @@ const ALLOWED_SELECTORS = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] * @returns True if the input starts with an allowed selector, false otherwise. */ function isAllowedCommitteeTxInput(txInput: string): boolean { - return ALLOWED_SELECTORS.some(selector => txInput.startsWith(selector)) + for (let i = 0; i < ALLOWED_SELECTORS.length; i++) { + if (txInput.startsWith(ALLOWED_SELECTORS[i])) { + return true + } + } + return false } From 63c26c68cb52b150d5848bb2a69164044e33ea1d Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Tue, 7 Jan 2025 09:35:05 -0300 Subject: [PATCH 4/5] refactor: Move isAllowedCommitteeTxInput to utils --- src/handlers/collection.ts | 22 +--------------------- src/utils/index.ts | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/handlers/collection.ts b/src/handlers/collection.ts index 744cef7..99651cf 100644 --- a/src/handlers/collection.ts +++ b/src/handlers/collection.ts @@ -31,7 +31,7 @@ import { getURNForWearableV2, getURNForCollectionV2 } from '../modules/metadata/ import { getStoreAddress } from '../modules/store' import { getOrCreateAnalyticsDayData } from '../modules/analytics' import { getCurationId, getBlockWhereRescueItemsStarted } from '../modules/curation' -import { toLowerCase } from '../utils' +import { toLowerCase, isAllowedCommitteeTxInput } from '../utils' import { getRaritiesWithOracleAddress } from '../modules/rarity' export function handleInitializeWearablesV1(_: OwnershipTransferred): void { @@ -590,23 +590,3 @@ export function handleTransferOwnership(event: OwnershipTransferred): void { collection.save() } } - -// List of allowed committee function selectors -// 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data) -// 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs) -// 0x81c9308e: manageCollection(address,address,address,bytes[]) selector -const ALLOWED_SELECTORS: string[] = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] - -/** - * Verify if it's an allowed committee transaction input. - * @param txInput - The transaction input data as a hexadecimal string. - * @returns True if the input starts with an allowed selector, false otherwise. - */ -function isAllowedCommitteeTxInput(txInput: string): boolean { - for (let i = 0; i < ALLOWED_SELECTORS.length; i++) { - if (txInput.startsWith(ALLOWED_SELECTORS[i])) { - return true - } - } - return false -} diff --git a/src/utils/index.ts b/src/utils/index.ts index 5400ace..4ec69af 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -12,4 +12,24 @@ export function toLowerCase(str: string): string { } return result -} \ No newline at end of file +} + +// List of allowed committee function selectors +// 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data) +// 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs) +// 0x81c9308e: manageCollection(address,address,address,bytes[]) selector +export const ALLOWED_SELECTORS: string[] = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] + +/** + * Verify if it's an allowed committee transaction input. + * @param txInput - The transaction input data as a hexadecimal string. + * @returns True if the input starts with an allowed selector, false otherwise. + */ +export function isAllowedCommitteeTxInput(txInput: string): boolean { + for (let i = 0; i < ALLOWED_SELECTORS.length; i++) { + if (txInput.startsWith(ALLOWED_SELECTORS[i])) { + return true + } + } + return false +} From 22110253c82955f235692fc3c67c0c6ae847a63f Mon Sep 17 00:00:00 2001 From: Gabriel Diaz Date: Tue, 7 Jan 2025 10:38:21 -0300 Subject: [PATCH 5/5] fix: Move method to a properly module --- src/handlers/collection.ts | 4 ++-- src/modules/curation/index.ts | 20 ++++++++++++++++++++ src/utils/index.ts | 20 -------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/handlers/collection.ts b/src/handlers/collection.ts index 99651cf..851a3de 100644 --- a/src/handlers/collection.ts +++ b/src/handlers/collection.ts @@ -30,8 +30,8 @@ import { RaritiesWithOracle } from '../entities/RaritiesWithOracle/RaritiesWithO import { getURNForWearableV2, getURNForCollectionV2 } from '../modules/metadata/wearable' import { getStoreAddress } from '../modules/store' import { getOrCreateAnalyticsDayData } from '../modules/analytics' -import { getCurationId, getBlockWhereRescueItemsStarted } from '../modules/curation' -import { toLowerCase, isAllowedCommitteeTxInput } from '../utils' +import { getCurationId, getBlockWhereRescueItemsStarted, isAllowedCommitteeTxInput } from '../modules/curation' +import { toLowerCase } from '../utils' import { getRaritiesWithOracleAddress } from '../modules/rarity' export function handleInitializeWearablesV1(_: OwnershipTransferred): void { diff --git a/src/modules/curation/index.ts b/src/modules/curation/index.ts index feeb128..f481f10 100644 --- a/src/modules/curation/index.ts +++ b/src/modules/curation/index.ts @@ -22,3 +22,23 @@ export function getBlockWhereRescueItemsStarted(): BigInt { return BigInt.fromI32(I32.MAX_VALUE) } + +// List of allowed committee function selectors +// 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data) +// 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs) +// 0x81c9308e: manageCollection(address,address,address,bytes[]) selector +export const ALLOWED_SELECTORS: string[] = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] + +/** + * Verify if it's an allowed committee transaction input. + * @param txInput - The transaction input data as a hexadecimal string. + * @returns True if the input starts with an allowed selector, false otherwise. + */ +export function isAllowedCommitteeTxInput(txInput: string): boolean { + for (let i = 0; i < ALLOWED_SELECTORS.length; i++) { + if (txInput.startsWith(ALLOWED_SELECTORS[i])) { + return true + } + } + return false +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 4ec69af..113d252 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -13,23 +13,3 @@ export function toLowerCase(str: string): string { return result } - -// List of allowed committee function selectors -// 0x07bd3522: forwardMetaTx(address _target, bytes calldata _data) -// 0xad718d2a: sponsoredCallV2(address _target,bytes _data,bytes32 _correlationId,bytes32 _r,bytes32 _vs) -// 0x81c9308e: manageCollection(address,address,address,bytes[]) selector -export const ALLOWED_SELECTORS: string[] = ['0x07bd3522', '0xad718d2a', '0x81c9308e'] - -/** - * Verify if it's an allowed committee transaction input. - * @param txInput - The transaction input data as a hexadecimal string. - * @returns True if the input starts with an allowed selector, false otherwise. - */ -export function isAllowedCommitteeTxInput(txInput: string): boolean { - for (let i = 0; i < ALLOWED_SELECTORS.length; i++) { - if (txInput.startsWith(ALLOWED_SELECTORS[i])) { - return true - } - } - return false -}