Skip to content

Commit

Permalink
feat: update parsing distribution points
Browse files Browse the repository at this point in the history
  • Loading branch information
ponyjackal committed May 1, 2024
1 parent 494c837 commit 183392b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/contextualizers/protocol/boombox/boombox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
});
Expand Down
52 changes: 35 additions & 17 deletions src/contextualizers/protocol/boombox/boombox.ts
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down Expand Up @@ -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: {
Expand Down
25 changes: 25 additions & 0 deletions src/contextualizers/protocol/boombox/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 183392b

Please sign in to comment.