Skip to content

Commit

Permalink
Merge pull request #357 from Once-Upon/feature/ou-2324-update-the-dis…
Browse files Browse the repository at this point in the history
…tribute-boombox-contextualization-to-pull-the

Update the distribute boombox contextualization to pull the
  • Loading branch information
pcowgill authored Apr 30, 2024
2 parents 8b242cf + c9e91c9 commit 494c837
Show file tree
Hide file tree
Showing 4 changed files with 30,423 additions and 6 deletions.
18 changes: 17 additions & 1 deletion src/contextualizers/protocol/boombox/boombox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { contextSummary, containsBigInt } from '../../../helpers/utils';
import boombox0x460925a4 from '../../test/transactions/boombox-0x460925a4.json';
import boombox0xde83b70f from '../../test/transactions/boombox-0xde83b70f.json';
import boombox0xe25e9ec5 from '../../test/transactions/boombox-0xe25e9ec5.json';
import boombox0xd996e83d from '../../test/transactions/boombox-0xd996e83d.json';
import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json';

describe('Boombox', () => {
Expand All @@ -16,6 +17,9 @@ describe('Boombox', () => {

const isBoombox3 = detect(boombox0xe25e9ec5 as unknown as Transaction);
expect(isBoombox3).toBe(true);

const isBoombox4 = detect(boombox0xd996e83d as unknown as Transaction);
expect(isBoombox4).toBe(true);
});

it('Should generate context', () => {
Expand Down Expand Up @@ -46,10 +50,22 @@ describe('Boombox', () => {
expect(boombox3.context?.variables?.artist['link']).toBe(
'https://open.spotify.com/artist/06HL4z0CvFAxyc27GXpf02',
);
expect(boombox3.context?.variables?.recipients['value'].length).toBe(798);
expect(contextSummary(boombox3.context)).toBe(
'0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED for 06HL4z0CvFAxyc27GXpf02',
'0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED 1050 for 06HL4z0CvFAxyc27GXpf02',
);
expect(containsBigInt(boombox3.context)).toBe(false);

const boombox4 = generate(boombox0xd996e83d as unknown as Transaction);
expect(boombox4.context?.summaries?.en.title).toBe('Boombox');
expect(boombox4.context?.variables?.artist['link']).toBe(
'https://open.spotify.com/artist/06HL4z0CvFAxyc27GXpf02',
);
expect(boombox4.context?.variables?.recipients['value'].length).toBe(817);
expect(contextSummary(boombox4.context)).toBe(
'0xab18fdc21c33c3c60bbca753997a657f00d43f9e DISTRIBUTED 1050 for 06HL4z0CvFAxyc27GXpf02',
);
expect(containsBigInt(boombox4.context)).toBe(false);
});

it('Should not detect transaction', () => {
Expand Down
37 changes: 32 additions & 5 deletions src/contextualizers/protocol/boombox/boombox.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { Abi, Hex } from 'viem';
import { Abi, Hex, hexToBigInt } from 'viem';
import { BoomboxContextActionEnum, Transaction } from '../../../types';
import { BOOMBOX_ABI, BOOMBOX_ARTIST_SPOTIFY_LINK } from './constants';
import { decodeTransactionInput } from '../../../helpers/utils';
import {
BOOMBOX_ABI,
BOOMBOX_ARTIST_SPOTIFY_LINK,
EVENT_DISTRIBUTE_TOPIC,
} from './constants';
import {
decodeEVMAddress,
decodeTransactionInput,
} from '../../../helpers/utils';
import { CHAIN_IDS } from '../../../helpers/constants';

export const contextualize = (transaction: Transaction): Transaction => {
Expand Down Expand Up @@ -116,7 +123,19 @@ export const generate = (transaction: Transaction): Transaction => {
case 'distribute':
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 recipients = distributeLogs.map((log) =>
decodeEVMAddress(log.topic2),
);
const amount =
distributeLogs.length > 0
? hexToBigInt(distributeLogs[0].topic1 as Hex).toString()
: '';
transaction.context = {
variables: {
sender: {
Expand All @@ -129,6 +148,14 @@ export const generate = (transaction: Transaction): Transaction => {
truncate: true,
link: `${BOOMBOX_ARTIST_SPOTIFY_LINK}/${distributeArtistId}`,
},
recipients: {
type: 'array',
value: recipients,
},
amount: {
type: 'string',
value: amount,
},
contextAction: {
type: 'contextAction',
value: BoomboxContextActionEnum.DISTRIBUTED,
Expand All @@ -138,7 +165,7 @@ export const generate = (transaction: Transaction): Transaction => {
category: 'PROTOCOL_1',
en: {
title: 'Boombox',
default: '[[sender]][[contextAction]]for[[artist]]',
default: '[[sender]][[contextAction]][[amount]]for[[artist]]',
},
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/contextualizers/protocol/boombox/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import boomBoxAbi from './abis/Boombox';

export const EVENT_DISTRIBUTE_TOPIC =
'0xa2283f96c6cf6736105c157e7e65bcdcb93a7d00384d129da2c964566b17c9a0';
export const BOOMBOX_ARTIST_SPOTIFY_LINK = 'https://open.spotify.com/artist';
export const BOOMBOX_ABI = boomBoxAbi;
Loading

0 comments on commit 494c837

Please sign in to comment.