diff --git a/src/contextualizers/protocol/boombox/boombox.spec.ts b/src/contextualizers/protocol/boombox/boombox.spec.ts index aaab6bc7..227937e4 100644 --- a/src/contextualizers/protocol/boombox/boombox.spec.ts +++ b/src/contextualizers/protocol/boombox/boombox.spec.ts @@ -52,7 +52,7 @@ describe('Boombox', () => { ); expect(boombox3.context?.variables?.recipients['value'].length).toBe(798); expect(contextSummary(boombox3.context)).toBe( - '0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED 1050 for 06HL4z0CvFAxyc27GXpf02', + '0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED 4500000 for 06HL4z0CvFAxyc27GXpf02', ); expect(containsBigInt(boombox3.context)).toBe(false); @@ -63,7 +63,7 @@ describe('Boombox', () => { ); expect(boombox4.context?.variables?.recipients['value'].length).toBe(817); expect(contextSummary(boombox4.context)).toBe( - '0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED 1050 for 06HL4z0CvFAxyc27GXpf02', + '0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED 4500000 for 06HL4z0CvFAxyc27GXpf02', ); expect(containsBigInt(boombox4.context)).toBe(false); }); diff --git a/src/contextualizers/protocol/boombox/boombox.ts b/src/contextualizers/protocol/boombox/boombox.ts index f1097c95..e1239e6a 100644 --- a/src/contextualizers/protocol/boombox/boombox.ts +++ b/src/contextualizers/protocol/boombox/boombox.ts @@ -1,14 +1,15 @@ -import { Abi, Hex, hexToBigInt } from 'viem'; -import { BoomboxContextActionEnum, Transaction } from '../../../types'; +import { Abi, Hex } from 'viem'; +import { + BoomboxContextActionEnum, + EventLogTopics, + Transaction, +} from '../../../types'; import { BOOMBOX_ABI, BOOMBOX_ARTIST_SPOTIFY_LINK, - EVENT_DISTRIBUTE_TOPIC, + POINTS_ADDED_EVENT_ABI, } from './constants'; -import { - decodeEVMAddress, - decodeTransactionInput, -} from '../../../helpers/utils'; +import { decodeLog, decodeTransactionInput } from '../../../helpers/utils'; import { CHAIN_IDS } from '../../../helpers/constants'; export const contextualize = (transaction: Transaction): Transaction => { @@ -124,18 +125,35 @@ export const generate = (transaction: Transaction): Transaction => { const distributeArtistId = decoded.args && decoded.args.length > 0 ? decoded.args[0] : ''; // decode logs - const distributeLogs = transaction.logs - ? transaction.logs.filter( - (log) => log.topic0 === EVENT_DISTRIBUTE_TOPIC, - ) + const decodedLogs = transaction.logs + ? transaction.logs + .map((log) => { + const decoded = decodeLog( + POINTS_ADDED_EVENT_ABI as Abi, + log.data as Hex, + [ + log.topic0, + log.topic1, + log.topic2, + log.topic3, + ] as EventLogTopics, + ); + + if (decoded && decoded.eventName === 'PointsAdded') + return decoded; + return null; + }) + .filter((log) => log) : []; - const recipients = distributeLogs.map((log) => - decodeEVMAddress(log.topic2), - ); + const recipients = decodedLogs + .map((log) => + log?.args['user'] ? log?.args['user'].toLowerCase() : null, + ) + .filter((log) => log); const amount = - distributeLogs.length > 0 - ? hexToBigInt(distributeLogs[0].topic1 as Hex).toString() - : ''; + decodedLogs[0] && decodedLogs[0].args['points'] + ? decodedLogs[0].args['points'].toString() + : BigInt(0).toString(); transaction.context = { variables: { sender: { diff --git a/src/contextualizers/protocol/boombox/constants.ts b/src/contextualizers/protocol/boombox/constants.ts index d03ac491..c37aa6b2 100644 --- a/src/contextualizers/protocol/boombox/constants.ts +++ b/src/contextualizers/protocol/boombox/constants.ts @@ -2,5 +2,30 @@ import boomBoxAbi from './abis/Boombox'; export const EVENT_DISTRIBUTE_TOPIC = '0xa2283f96c6cf6736105c157e7e65bcdcb93a7d00384d129da2c964566b17c9a0'; +export const POINTS_ADDED_EVENT_ABI = [ + { + anonymous: false, + inputs: [ + { + indexed: true, + name: 'systemId', + type: 'uint256', + }, + { + indexed: true, + name: 'user', + type: 'address', + }, + { + indexed: false, + name: 'points', + type: 'uint256', + }, + ], + name: 'PointsAdded', + type: 'event', + }, +] as const; + export const BOOMBOX_ARTIST_SPOTIFY_LINK = 'https://open.spotify.com/artist'; export const BOOMBOX_ABI = boomBoxAbi;