From 3a2377ed87243bfb0b57adc5a1a41be3c0b445d7 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Wed, 31 Jul 2024 16:29:19 +0530 Subject: [PATCH 1/8] feat: add DirectDonationStrategy (#589) * feat: add DirectDonationStrategy * update abit * fix * add strategy name * fix address(0) * add zero * format --------- Co-authored-by: 0xKurt --- .../allo-v2/v1/DirectAllocationStrategy.ts | 600 ++++++++++++++++++ src/indexer/abis/index.ts | 2 + src/indexer/allo/v2/handleEvent.ts | 66 +- src/indexer/allo/v2/strategy.ts | 8 + 4 files changed, 675 insertions(+), 1 deletion(-) create mode 100644 src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts diff --git a/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts b/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts new file mode 100644 index 00000000..81dbf190 --- /dev/null +++ b/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts @@ -0,0 +1,600 @@ +export default [ + { + inputs: [ + { + internalType: "address", + name: "_allo", + type: "address", + }, + { + internalType: "string", + name: "_name", + type: "string", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + inputs: [], + name: "ALLOCATION_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "ALLOCATION_NOT_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "ALLOCATION_NOT_ENDED", + type: "error", + }, + { + inputs: [], + name: "ALREADY_INITIALIZED", + type: "error", + }, + { + inputs: [], + name: "AMOUNT_MISMATCH", + type: "error", + }, + { + inputs: [], + name: "ANCHOR_ERROR", + type: "error", + }, + { + inputs: [], + name: "ARRAY_MISMATCH", + type: "error", + }, + { + inputs: [], + name: "INVALID", + type: "error", + }, + { + inputs: [], + name: "INVALID_ADDRESS", + type: "error", + }, + { + inputs: [], + name: "INVALID_FEE", + type: "error", + }, + { + inputs: [], + name: "INVALID_METADATA", + type: "error", + }, + { + inputs: [], + name: "INVALID_REGISTRATION", + type: "error", + }, + { + inputs: [], + name: "IS_APPROVED_STRATEGY", + type: "error", + }, + { + inputs: [], + name: "MISMATCH", + type: "error", + }, + { + inputs: [], + name: "NONCE_NOT_AVAILABLE", + type: "error", + }, + { + inputs: [], + name: "NON_ZERO_VALUE", + type: "error", + }, + { + inputs: [], + name: "NOT_APPROVED_STRATEGY", + type: "error", + }, + { + inputs: [], + name: "NOT_ENOUGH_FUNDS", + type: "error", + }, + { + inputs: [], + name: "NOT_IMPLEMENTED", + type: "error", + }, + { + inputs: [], + name: "NOT_INITIALIZED", + type: "error", + }, + { + inputs: [], + name: "NOT_PENDING_OWNER", + type: "error", + }, + { + inputs: [], + name: "POOL_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "POOL_INACTIVE", + type: "error", + }, + { + inputs: [], + name: "RECIPIENT_ALREADY_ACCEPTED", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "recipientId", + type: "address", + }, + ], + name: "RECIPIENT_ERROR", + type: "error", + }, + { + inputs: [], + name: "RECIPIENT_NOT_ACCEPTED", + type: "error", + }, + { + inputs: [], + name: "REGISTRATION_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "REGISTRATION_NOT_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "UNAUTHORIZED", + type: "error", + }, + { + inputs: [], + name: "ZERO_ADDRESS", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "recipientId", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "token", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "Allocated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "profileId", + type: "bytes32", + }, + { + indexed: false, + internalType: "address", + name: "profileOwner", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "token", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "DirectAllocated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "recipientId", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "recipientAddress", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "Distributed", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "poolId", + type: "uint256", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "Initialized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bool", + name: "active", + type: "bool", + }, + ], + name: "PoolActive", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "recipientId", + type: "address", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "Registered", + type: "event", + }, + { + inputs: [], + name: "NATIVE", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + { + internalType: "address", + name: "_sender", + type: "address", + }, + ], + name: "allocate", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address[]", + name: "_recipientIds", + type: "address[]", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + { + internalType: "address", + name: "_sender", + type: "address", + }, + ], + name: "distribute", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "getAllo", + outputs: [ + { + internalType: "contract IAllo", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address[]", + name: "_recipientIds", + type: "address[]", + }, + { + internalType: "bytes[]", + name: "_data", + type: "bytes[]", + }, + ], + name: "getPayouts", + outputs: [ + { + components: [ + { + internalType: "address", + name: "recipientAddress", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + internalType: "struct IStrategy.PayoutSummary[]", + name: "", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getPoolAmount", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getPoolId", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_recipientId", + type: "address", + }, + ], + name: "getRecipientStatus", + outputs: [ + { + internalType: "enum IStrategy.Status", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getStrategyId", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + ], + name: "increasePoolAmount", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_poolId", + type: "uint256", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "isPoolActive", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_allocator", + type: "address", + }, + ], + name: "isValidAllocator", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + { + internalType: "address", + name: "_sender", + type: "address", + }, + ], + name: "registerRecipient", + outputs: [ + { + internalType: "address", + name: "recipientId", + type: "address", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_token", + type: "address", + }, + { + internalType: "address", + name: "_recipient", + type: "address", + }, + ], + name: "withdraw", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + stateMutability: "payable", + type: "receive", + }, +] as const; diff --git a/src/indexer/abis/index.ts b/src/indexer/abis/index.ts index 1082fb03..87caba85 100644 --- a/src/indexer/abis/index.ts +++ b/src/indexer/abis/index.ts @@ -27,6 +27,7 @@ import AlloV2DirectGrantsSimpleStrategy from "./allo-v2/v1/DirectGrantsSimpleStr import AlloV1ToV2ProfileMigration from "./allo-v2/AlloV1ToV2ProfileMigration.js"; import AlloV2DirectGrantsLiteStrategy from "./allo-v2/v1/DirectGrantsLiteStrategy.js"; import AlloV2EasyRPGFStrategy from "./allo-v2/v1/EasyRPGFStrategy.js"; +import AlloV2DirectAllocationStrategy from "./allo-v2/v1/DirectAllocationStrategy.js"; const abis = { "AlloV1/ProjectRegistry/V1": ProjectRegistryV1, @@ -62,6 +63,7 @@ const abis = { "AlloV2/DirectGrantsSimpleStrategy/V1": AlloV2DirectGrantsSimpleStrategy, "AlloV2/DirectGrantsLiteStrategy/V1": AlloV2DirectGrantsLiteStrategy, "AlloV2/EasyRPGFStrategy/V1": AlloV2EasyRPGFStrategy, + "AlloV2/DirectAllocationStrategy/V1": AlloV2DirectAllocationStrategy, } as const; export default abis; diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index 071fde64..ceb89577 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -48,6 +48,8 @@ const ALLO_NATIVE_TOKEN = parseAddress( "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ); +const addressZero = "0x0000000000000000000000000000000000000000"; + enum ApplicationStatus { NONE = 0, PENDING, @@ -307,13 +309,18 @@ export async function handleEvent( address: strategyAddress, }); break; - case "allov2.EasyRPGFStrategy": subscribeToContract({ contract: "AlloV2/EasyRPGFStrategy/V1", address: strategyAddress, }); break; + case "allov2.DirectAllocationStrategy": + subscribeToContract({ + contract: "AlloV2/DirectAllocationStrategy/V1", + address: strategyAddress, + }); + break; } let applicationsStartTime: Date | null = null; @@ -1206,6 +1213,63 @@ export async function handleEvent( } } } + + case "DirectAllocated": { + const strategyAddress = parseAddress(event.address); + const round = await db.getRoundByStrategyAddress( + chainId, + strategyAddress + ); + + const profile = await db.getProjectById(chainId, event.params.profileId); + + if (profile === null || round === null) { + return []; + } + + const donationId = ethers.utils.solidityKeccak256( + ["string"], + [`${event.blockNumber}-${event.logIndex}`] + ); + + const amount = event.params.amount; + const token = parseAddress(event.params.token); + const sender = parseAddress(event.params.sender); + + const conversionToUSD = await convertToUSD( + priceProvider, + chainId, + token, + event.params.amount, + event.blockNumber + ); + + const amountInUsd = conversionToUSD.amount; + + const donation: Donation = { + id: donationId, + chainId, + roundId: round.id, + applicationId: parseAddress(addressZero), + donorAddress: sender, + recipientAddress: parseAddress(event.params.profileOwner), + projectId: event.params.profileId, + transactionHash: event.transactionHash, + blockNumber: event.blockNumber, + tokenAddress: token, + amount: amount, + amountInUsd, + amountInRoundMatchToken: 0n, + timestamp: conversionToUSD.timestamp, + }; + + return [ + { + type: "InsertDonation", + donation, + }, + ]; + } } return []; diff --git a/src/indexer/allo/v2/strategy.ts b/src/indexer/allo/v2/strategy.ts index f59fe3fc..23f0b961 100644 --- a/src/indexer/allo/v2/strategy.ts +++ b/src/indexer/allo/v2/strategy.ts @@ -115,6 +115,14 @@ export function extractStrategyFromId(_id: string): Strategy | null { name: "allov2.EasyRPGFStrategy", groups: ["allov2.EasyRPGFStrategy"], }; + + // DirectAllocationStrategyv1.1 + case "0x4cd0051913234cdd7d165b208851240d334786d6e5afbb4d0eec203515a9c6f3": + return { + id: id, + name: "allov2.DirectAllocationStrategy", + groups: ["allov2.DirectAllocationStrategy"], + }; } return null; From 248880c546219a6099a9b5a190f9cb97fc998a88 Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Wed, 31 Jul 2024 16:50:28 +0530 Subject: [PATCH 2/8] Update config.ts (#618) --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index a6252d2e..a5e7fdbe 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,7 +20,7 @@ type CoingeckoSupportedChainId = | 42220 | 1088; -const CHAIN_DATA_VERSION = "71"; +const CHAIN_DATA_VERSION = "72"; export type Token = { code: string; From 102128691fd57ccc825f9ce5a900b1bd6d819af0 Mon Sep 17 00:00:00 2001 From: Hussein Martinez Date: Thu, 1 Aug 2024 02:25:35 +0700 Subject: [PATCH 3/8] chore: bump version to 73 --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index a5e7fdbe..8fedfd6a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,7 +20,7 @@ type CoingeckoSupportedChainId = | 42220 | 1088; -const CHAIN_DATA_VERSION = "72"; +const CHAIN_DATA_VERSION = "73"; export type Token = { code: string; From 9930553f605f37afd8b94dfdfeeb12f7e0d8e260 Mon Sep 17 00:00:00 2001 From: Hussein Martinez Date: Thu, 1 Aug 2024 02:59:37 +0700 Subject: [PATCH 4/8] Revert "Merge pull request #619 from gitcoinco/chore/bump-version-73" This reverts commit eb1b97fe93fa7d926545e200f1862f5084a79462, reversing changes made to 248880c546219a6099a9b5a190f9cb97fc998a88. --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index 8fedfd6a..a5e7fdbe 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,7 +20,7 @@ type CoingeckoSupportedChainId = | 42220 | 1088; -const CHAIN_DATA_VERSION = "73"; +const CHAIN_DATA_VERSION = "72"; export type Token = { code: string; From 415156bbd2658ab1bbfc5e66f1967c3f8bacd35c Mon Sep 17 00:00:00 2001 From: Hussein Martinez Date: Thu, 1 Aug 2024 03:00:08 +0700 Subject: [PATCH 5/8] Revert "Update config.ts (#618)" This reverts commit 248880c546219a6099a9b5a190f9cb97fc998a88. --- src/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.ts b/src/config.ts index a5e7fdbe..a6252d2e 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,7 +20,7 @@ type CoingeckoSupportedChainId = | 42220 | 1088; -const CHAIN_DATA_VERSION = "72"; +const CHAIN_DATA_VERSION = "71"; export type Token = { code: string; From b88c6eefba44beef14c9f91a3b28fac722108c69 Mon Sep 17 00:00:00 2001 From: Hussein Martinez Date: Thu, 1 Aug 2024 03:00:20 +0700 Subject: [PATCH 6/8] Revert "feat: add DirectDonationStrategy (#589)" This reverts commit 3a2377ed87243bfb0b57adc5a1a41be3c0b445d7. --- .../allo-v2/v1/DirectAllocationStrategy.ts | 600 ------------------ src/indexer/abis/index.ts | 2 - src/indexer/allo/v2/handleEvent.ts | 66 +- src/indexer/allo/v2/strategy.ts | 8 - 4 files changed, 1 insertion(+), 675 deletions(-) delete mode 100644 src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts diff --git a/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts b/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts deleted file mode 100644 index 81dbf190..00000000 --- a/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts +++ /dev/null @@ -1,600 +0,0 @@ -export default [ - { - inputs: [ - { - internalType: "address", - name: "_allo", - type: "address", - }, - { - internalType: "string", - name: "_name", - type: "string", - }, - ], - stateMutability: "nonpayable", - type: "constructor", - }, - { - inputs: [], - name: "ALLOCATION_ACTIVE", - type: "error", - }, - { - inputs: [], - name: "ALLOCATION_NOT_ACTIVE", - type: "error", - }, - { - inputs: [], - name: "ALLOCATION_NOT_ENDED", - type: "error", - }, - { - inputs: [], - name: "ALREADY_INITIALIZED", - type: "error", - }, - { - inputs: [], - name: "AMOUNT_MISMATCH", - type: "error", - }, - { - inputs: [], - name: "ANCHOR_ERROR", - type: "error", - }, - { - inputs: [], - name: "ARRAY_MISMATCH", - type: "error", - }, - { - inputs: [], - name: "INVALID", - type: "error", - }, - { - inputs: [], - name: "INVALID_ADDRESS", - type: "error", - }, - { - inputs: [], - name: "INVALID_FEE", - type: "error", - }, - { - inputs: [], - name: "INVALID_METADATA", - type: "error", - }, - { - inputs: [], - name: "INVALID_REGISTRATION", - type: "error", - }, - { - inputs: [], - name: "IS_APPROVED_STRATEGY", - type: "error", - }, - { - inputs: [], - name: "MISMATCH", - type: "error", - }, - { - inputs: [], - name: "NONCE_NOT_AVAILABLE", - type: "error", - }, - { - inputs: [], - name: "NON_ZERO_VALUE", - type: "error", - }, - { - inputs: [], - name: "NOT_APPROVED_STRATEGY", - type: "error", - }, - { - inputs: [], - name: "NOT_ENOUGH_FUNDS", - type: "error", - }, - { - inputs: [], - name: "NOT_IMPLEMENTED", - type: "error", - }, - { - inputs: [], - name: "NOT_INITIALIZED", - type: "error", - }, - { - inputs: [], - name: "NOT_PENDING_OWNER", - type: "error", - }, - { - inputs: [], - name: "POOL_ACTIVE", - type: "error", - }, - { - inputs: [], - name: "POOL_INACTIVE", - type: "error", - }, - { - inputs: [], - name: "RECIPIENT_ALREADY_ACCEPTED", - type: "error", - }, - { - inputs: [ - { - internalType: "address", - name: "recipientId", - type: "address", - }, - ], - name: "RECIPIENT_ERROR", - type: "error", - }, - { - inputs: [], - name: "RECIPIENT_NOT_ACCEPTED", - type: "error", - }, - { - inputs: [], - name: "REGISTRATION_ACTIVE", - type: "error", - }, - { - inputs: [], - name: "REGISTRATION_NOT_ACTIVE", - type: "error", - }, - { - inputs: [], - name: "UNAUTHORIZED", - type: "error", - }, - { - inputs: [], - name: "ZERO_ADDRESS", - type: "error", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "recipientId", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - indexed: false, - internalType: "address", - name: "token", - type: "address", - }, - { - indexed: false, - internalType: "address", - name: "sender", - type: "address", - }, - ], - name: "Allocated", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "bytes32", - name: "profileId", - type: "bytes32", - }, - { - indexed: false, - internalType: "address", - name: "profileOwner", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - indexed: false, - internalType: "address", - name: "token", - type: "address", - }, - { - indexed: false, - internalType: "address", - name: "sender", - type: "address", - }, - ], - name: "DirectAllocated", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "recipientId", - type: "address", - }, - { - indexed: false, - internalType: "address", - name: "recipientAddress", - type: "address", - }, - { - indexed: false, - internalType: "uint256", - name: "amount", - type: "uint256", - }, - { - indexed: false, - internalType: "address", - name: "sender", - type: "address", - }, - ], - name: "Distributed", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "uint256", - name: "poolId", - type: "uint256", - }, - { - indexed: false, - internalType: "bytes", - name: "data", - type: "bytes", - }, - ], - name: "Initialized", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: false, - internalType: "bool", - name: "active", - type: "bool", - }, - ], - name: "PoolActive", - type: "event", - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "recipientId", - type: "address", - }, - { - indexed: false, - internalType: "bytes", - name: "data", - type: "bytes", - }, - { - indexed: false, - internalType: "address", - name: "sender", - type: "address", - }, - ], - name: "Registered", - type: "event", - }, - { - inputs: [], - name: "NATIVE", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "bytes", - name: "_data", - type: "bytes", - }, - { - internalType: "address", - name: "_sender", - type: "address", - }, - ], - name: "allocate", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - internalType: "address[]", - name: "_recipientIds", - type: "address[]", - }, - { - internalType: "bytes", - name: "_data", - type: "bytes", - }, - { - internalType: "address", - name: "_sender", - type: "address", - }, - ], - name: "distribute", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "getAllo", - outputs: [ - { - internalType: "contract IAllo", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address[]", - name: "_recipientIds", - type: "address[]", - }, - { - internalType: "bytes[]", - name: "_data", - type: "bytes[]", - }, - ], - name: "getPayouts", - outputs: [ - { - components: [ - { - internalType: "address", - name: "recipientAddress", - type: "address", - }, - { - internalType: "uint256", - name: "amount", - type: "uint256", - }, - ], - internalType: "struct IStrategy.PayoutSummary[]", - name: "", - type: "tuple[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getPoolAmount", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getPoolId", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_recipientId", - type: "address", - }, - ], - name: "getRecipientStatus", - outputs: [ - { - internalType: "enum IStrategy.Status", - name: "", - type: "uint8", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getStrategyId", - outputs: [ - { - internalType: "bytes32", - name: "", - type: "bytes32", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_amount", - type: "uint256", - }, - ], - name: "increasePoolAmount", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "_poolId", - type: "uint256", - }, - { - internalType: "bytes", - name: "_data", - type: "bytes", - }, - ], - name: "initialize", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "isPoolActive", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_allocator", - type: "address", - }, - ], - name: "isValidAllocator", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "bytes", - name: "_data", - type: "bytes", - }, - { - internalType: "address", - name: "_sender", - type: "address", - }, - ], - name: "registerRecipient", - outputs: [ - { - internalType: "address", - name: "recipientId", - type: "address", - }, - ], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "_token", - type: "address", - }, - { - internalType: "address", - name: "_recipient", - type: "address", - }, - ], - name: "withdraw", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - stateMutability: "payable", - type: "receive", - }, -] as const; diff --git a/src/indexer/abis/index.ts b/src/indexer/abis/index.ts index 87caba85..1082fb03 100644 --- a/src/indexer/abis/index.ts +++ b/src/indexer/abis/index.ts @@ -27,7 +27,6 @@ import AlloV2DirectGrantsSimpleStrategy from "./allo-v2/v1/DirectGrantsSimpleStr import AlloV1ToV2ProfileMigration from "./allo-v2/AlloV1ToV2ProfileMigration.js"; import AlloV2DirectGrantsLiteStrategy from "./allo-v2/v1/DirectGrantsLiteStrategy.js"; import AlloV2EasyRPGFStrategy from "./allo-v2/v1/EasyRPGFStrategy.js"; -import AlloV2DirectAllocationStrategy from "./allo-v2/v1/DirectAllocationStrategy.js"; const abis = { "AlloV1/ProjectRegistry/V1": ProjectRegistryV1, @@ -63,7 +62,6 @@ const abis = { "AlloV2/DirectGrantsSimpleStrategy/V1": AlloV2DirectGrantsSimpleStrategy, "AlloV2/DirectGrantsLiteStrategy/V1": AlloV2DirectGrantsLiteStrategy, "AlloV2/EasyRPGFStrategy/V1": AlloV2EasyRPGFStrategy, - "AlloV2/DirectAllocationStrategy/V1": AlloV2DirectAllocationStrategy, } as const; export default abis; diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index ceb89577..071fde64 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -48,8 +48,6 @@ const ALLO_NATIVE_TOKEN = parseAddress( "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ); -const addressZero = "0x0000000000000000000000000000000000000000"; - enum ApplicationStatus { NONE = 0, PENDING, @@ -309,18 +307,13 @@ export async function handleEvent( address: strategyAddress, }); break; + case "allov2.EasyRPGFStrategy": subscribeToContract({ contract: "AlloV2/EasyRPGFStrategy/V1", address: strategyAddress, }); break; - case "allov2.DirectAllocationStrategy": - subscribeToContract({ - contract: "AlloV2/DirectAllocationStrategy/V1", - address: strategyAddress, - }); - break; } let applicationsStartTime: Date | null = null; @@ -1213,63 +1206,6 @@ export async function handleEvent( } } } - - case "DirectAllocated": { - const strategyAddress = parseAddress(event.address); - const round = await db.getRoundByStrategyAddress( - chainId, - strategyAddress - ); - - const profile = await db.getProjectById(chainId, event.params.profileId); - - if (profile === null || round === null) { - return []; - } - - const donationId = ethers.utils.solidityKeccak256( - ["string"], - [`${event.blockNumber}-${event.logIndex}`] - ); - - const amount = event.params.amount; - const token = parseAddress(event.params.token); - const sender = parseAddress(event.params.sender); - - const conversionToUSD = await convertToUSD( - priceProvider, - chainId, - token, - event.params.amount, - event.blockNumber - ); - - const amountInUsd = conversionToUSD.amount; - - const donation: Donation = { - id: donationId, - chainId, - roundId: round.id, - applicationId: parseAddress(addressZero), - donorAddress: sender, - recipientAddress: parseAddress(event.params.profileOwner), - projectId: event.params.profileId, - transactionHash: event.transactionHash, - blockNumber: event.blockNumber, - tokenAddress: token, - amount: amount, - amountInUsd, - amountInRoundMatchToken: 0n, - timestamp: conversionToUSD.timestamp, - }; - - return [ - { - type: "InsertDonation", - donation, - }, - ]; - } } return []; diff --git a/src/indexer/allo/v2/strategy.ts b/src/indexer/allo/v2/strategy.ts index 23f0b961..f59fe3fc 100644 --- a/src/indexer/allo/v2/strategy.ts +++ b/src/indexer/allo/v2/strategy.ts @@ -115,14 +115,6 @@ export function extractStrategyFromId(_id: string): Strategy | null { name: "allov2.EasyRPGFStrategy", groups: ["allov2.EasyRPGFStrategy"], }; - - // DirectAllocationStrategyv1.1 - case "0x4cd0051913234cdd7d165b208851240d334786d6e5afbb4d0eec203515a9c6f3": - return { - id: id, - name: "allov2.DirectAllocationStrategy", - groups: ["allov2.DirectAllocationStrategy"], - }; } return null; From 8d2ece5e5a48356a83aed66ff529a84dab16c1cb Mon Sep 17 00:00:00 2001 From: Hussein Martinez Date: Thu, 1 Aug 2024 04:03:42 +0700 Subject: [PATCH 7/8] chore: add debug message with event name --- src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0be278aa..0a552cb3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -541,6 +541,14 @@ async function catchupAndWatchChain( try { // console.time(args.event.name); // do not await donation inserts as they are write only + indexerLogger.debug( + "DEBUG - event:", + args.event.name, + "- chainId:", + args.chainId, + "- event:", + event + ); if (args.event.name === "Voted") { handleAlloV1Event(args) .then((changesets) => db.applyChanges(changesets)) @@ -572,7 +580,7 @@ async function catchupAndWatchChain( } } catch (err) { indexerLogger.warn({ - msg: "skipping event due to error while processing", + msg: `skipping event due to error while processing - ${args.event.name}`, err, event: args.event, }); From e7b039c9f04c3b5f6306ba31a92cd03a32cd738b Mon Sep 17 00:00:00 2001 From: Aditya Anand M C Date: Thu, 1 Aug 2024 04:42:49 +0530 Subject: [PATCH 8/8] Revert "chore: revert to working version" --- src/config.ts | 2 +- .../allo-v2/v1/DirectAllocationStrategy.ts | 600 ++++++++++++++++++ src/indexer/abis/index.ts | 2 + src/indexer/allo/v2/handleEvent.ts | 66 +- src/indexer/allo/v2/strategy.ts | 8 + 5 files changed, 676 insertions(+), 2 deletions(-) create mode 100644 src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts diff --git a/src/config.ts b/src/config.ts index a6252d2e..8fedfd6a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,7 +20,7 @@ type CoingeckoSupportedChainId = | 42220 | 1088; -const CHAIN_DATA_VERSION = "71"; +const CHAIN_DATA_VERSION = "73"; export type Token = { code: string; diff --git a/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts b/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts new file mode 100644 index 00000000..81dbf190 --- /dev/null +++ b/src/indexer/abis/allo-v2/v1/DirectAllocationStrategy.ts @@ -0,0 +1,600 @@ +export default [ + { + inputs: [ + { + internalType: "address", + name: "_allo", + type: "address", + }, + { + internalType: "string", + name: "_name", + type: "string", + }, + ], + stateMutability: "nonpayable", + type: "constructor", + }, + { + inputs: [], + name: "ALLOCATION_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "ALLOCATION_NOT_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "ALLOCATION_NOT_ENDED", + type: "error", + }, + { + inputs: [], + name: "ALREADY_INITIALIZED", + type: "error", + }, + { + inputs: [], + name: "AMOUNT_MISMATCH", + type: "error", + }, + { + inputs: [], + name: "ANCHOR_ERROR", + type: "error", + }, + { + inputs: [], + name: "ARRAY_MISMATCH", + type: "error", + }, + { + inputs: [], + name: "INVALID", + type: "error", + }, + { + inputs: [], + name: "INVALID_ADDRESS", + type: "error", + }, + { + inputs: [], + name: "INVALID_FEE", + type: "error", + }, + { + inputs: [], + name: "INVALID_METADATA", + type: "error", + }, + { + inputs: [], + name: "INVALID_REGISTRATION", + type: "error", + }, + { + inputs: [], + name: "IS_APPROVED_STRATEGY", + type: "error", + }, + { + inputs: [], + name: "MISMATCH", + type: "error", + }, + { + inputs: [], + name: "NONCE_NOT_AVAILABLE", + type: "error", + }, + { + inputs: [], + name: "NON_ZERO_VALUE", + type: "error", + }, + { + inputs: [], + name: "NOT_APPROVED_STRATEGY", + type: "error", + }, + { + inputs: [], + name: "NOT_ENOUGH_FUNDS", + type: "error", + }, + { + inputs: [], + name: "NOT_IMPLEMENTED", + type: "error", + }, + { + inputs: [], + name: "NOT_INITIALIZED", + type: "error", + }, + { + inputs: [], + name: "NOT_PENDING_OWNER", + type: "error", + }, + { + inputs: [], + name: "POOL_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "POOL_INACTIVE", + type: "error", + }, + { + inputs: [], + name: "RECIPIENT_ALREADY_ACCEPTED", + type: "error", + }, + { + inputs: [ + { + internalType: "address", + name: "recipientId", + type: "address", + }, + ], + name: "RECIPIENT_ERROR", + type: "error", + }, + { + inputs: [], + name: "RECIPIENT_NOT_ACCEPTED", + type: "error", + }, + { + inputs: [], + name: "REGISTRATION_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "REGISTRATION_NOT_ACTIVE", + type: "error", + }, + { + inputs: [], + name: "UNAUTHORIZED", + type: "error", + }, + { + inputs: [], + name: "ZERO_ADDRESS", + type: "error", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "recipientId", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "token", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "Allocated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "bytes32", + name: "profileId", + type: "bytes32", + }, + { + indexed: false, + internalType: "address", + name: "profileOwner", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "token", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "DirectAllocated", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "recipientId", + type: "address", + }, + { + indexed: false, + internalType: "address", + name: "recipientAddress", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount", + type: "uint256", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "Distributed", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "poolId", + type: "uint256", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "Initialized", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "bool", + name: "active", + type: "bool", + }, + ], + name: "PoolActive", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "recipientId", + type: "address", + }, + { + indexed: false, + internalType: "bytes", + name: "data", + type: "bytes", + }, + { + indexed: false, + internalType: "address", + name: "sender", + type: "address", + }, + ], + name: "Registered", + type: "event", + }, + { + inputs: [], + name: "NATIVE", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + { + internalType: "address", + name: "_sender", + type: "address", + }, + ], + name: "allocate", + outputs: [], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address[]", + name: "_recipientIds", + type: "address[]", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + { + internalType: "address", + name: "_sender", + type: "address", + }, + ], + name: "distribute", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "getAllo", + outputs: [ + { + internalType: "contract IAllo", + name: "", + type: "address", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address[]", + name: "_recipientIds", + type: "address[]", + }, + { + internalType: "bytes[]", + name: "_data", + type: "bytes[]", + }, + ], + name: "getPayouts", + outputs: [ + { + components: [ + { + internalType: "address", + name: "recipientAddress", + type: "address", + }, + { + internalType: "uint256", + name: "amount", + type: "uint256", + }, + ], + internalType: "struct IStrategy.PayoutSummary[]", + name: "", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getPoolAmount", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getPoolId", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_recipientId", + type: "address", + }, + ], + name: "getRecipientStatus", + outputs: [ + { + internalType: "enum IStrategy.Status", + name: "", + type: "uint8", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getStrategyId", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_amount", + type: "uint256", + }, + ], + name: "increasePoolAmount", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [ + { + internalType: "uint256", + name: "_poolId", + type: "uint256", + }, + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + ], + name: "initialize", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + inputs: [], + name: "isPoolActive", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_allocator", + type: "address", + }, + ], + name: "isValidAllocator", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [ + { + internalType: "bytes", + name: "_data", + type: "bytes", + }, + { + internalType: "address", + name: "_sender", + type: "address", + }, + ], + name: "registerRecipient", + outputs: [ + { + internalType: "address", + name: "recipientId", + type: "address", + }, + ], + stateMutability: "payable", + type: "function", + }, + { + inputs: [ + { + internalType: "address", + name: "_token", + type: "address", + }, + { + internalType: "address", + name: "_recipient", + type: "address", + }, + ], + name: "withdraw", + outputs: [], + stateMutability: "nonpayable", + type: "function", + }, + { + stateMutability: "payable", + type: "receive", + }, +] as const; diff --git a/src/indexer/abis/index.ts b/src/indexer/abis/index.ts index 1082fb03..87caba85 100644 --- a/src/indexer/abis/index.ts +++ b/src/indexer/abis/index.ts @@ -27,6 +27,7 @@ import AlloV2DirectGrantsSimpleStrategy from "./allo-v2/v1/DirectGrantsSimpleStr import AlloV1ToV2ProfileMigration from "./allo-v2/AlloV1ToV2ProfileMigration.js"; import AlloV2DirectGrantsLiteStrategy from "./allo-v2/v1/DirectGrantsLiteStrategy.js"; import AlloV2EasyRPGFStrategy from "./allo-v2/v1/EasyRPGFStrategy.js"; +import AlloV2DirectAllocationStrategy from "./allo-v2/v1/DirectAllocationStrategy.js"; const abis = { "AlloV1/ProjectRegistry/V1": ProjectRegistryV1, @@ -62,6 +63,7 @@ const abis = { "AlloV2/DirectGrantsSimpleStrategy/V1": AlloV2DirectGrantsSimpleStrategy, "AlloV2/DirectGrantsLiteStrategy/V1": AlloV2DirectGrantsLiteStrategy, "AlloV2/EasyRPGFStrategy/V1": AlloV2EasyRPGFStrategy, + "AlloV2/DirectAllocationStrategy/V1": AlloV2DirectAllocationStrategy, } as const; export default abis; diff --git a/src/indexer/allo/v2/handleEvent.ts b/src/indexer/allo/v2/handleEvent.ts index 071fde64..ceb89577 100644 --- a/src/indexer/allo/v2/handleEvent.ts +++ b/src/indexer/allo/v2/handleEvent.ts @@ -48,6 +48,8 @@ const ALLO_NATIVE_TOKEN = parseAddress( "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" ); +const addressZero = "0x0000000000000000000000000000000000000000"; + enum ApplicationStatus { NONE = 0, PENDING, @@ -307,13 +309,18 @@ export async function handleEvent( address: strategyAddress, }); break; - case "allov2.EasyRPGFStrategy": subscribeToContract({ contract: "AlloV2/EasyRPGFStrategy/V1", address: strategyAddress, }); break; + case "allov2.DirectAllocationStrategy": + subscribeToContract({ + contract: "AlloV2/DirectAllocationStrategy/V1", + address: strategyAddress, + }); + break; } let applicationsStartTime: Date | null = null; @@ -1206,6 +1213,63 @@ export async function handleEvent( } } } + + case "DirectAllocated": { + const strategyAddress = parseAddress(event.address); + const round = await db.getRoundByStrategyAddress( + chainId, + strategyAddress + ); + + const profile = await db.getProjectById(chainId, event.params.profileId); + + if (profile === null || round === null) { + return []; + } + + const donationId = ethers.utils.solidityKeccak256( + ["string"], + [`${event.blockNumber}-${event.logIndex}`] + ); + + const amount = event.params.amount; + const token = parseAddress(event.params.token); + const sender = parseAddress(event.params.sender); + + const conversionToUSD = await convertToUSD( + priceProvider, + chainId, + token, + event.params.amount, + event.blockNumber + ); + + const amountInUsd = conversionToUSD.amount; + + const donation: Donation = { + id: donationId, + chainId, + roundId: round.id, + applicationId: parseAddress(addressZero), + donorAddress: sender, + recipientAddress: parseAddress(event.params.profileOwner), + projectId: event.params.profileId, + transactionHash: event.transactionHash, + blockNumber: event.blockNumber, + tokenAddress: token, + amount: amount, + amountInUsd, + amountInRoundMatchToken: 0n, + timestamp: conversionToUSD.timestamp, + }; + + return [ + { + type: "InsertDonation", + donation, + }, + ]; + } } return []; diff --git a/src/indexer/allo/v2/strategy.ts b/src/indexer/allo/v2/strategy.ts index f59fe3fc..23f0b961 100644 --- a/src/indexer/allo/v2/strategy.ts +++ b/src/indexer/allo/v2/strategy.ts @@ -115,6 +115,14 @@ export function extractStrategyFromId(_id: string): Strategy | null { name: "allov2.EasyRPGFStrategy", groups: ["allov2.EasyRPGFStrategy"], }; + + // DirectAllocationStrategyv1.1 + case "0x4cd0051913234cdd7d165b208851240d334786d6e5afbb4d0eec203515a9c6f3": + return { + id: id, + name: "allov2.DirectAllocationStrategy", + groups: ["allov2.DirectAllocationStrategy"], + }; } return null;