Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and tests for assigning protocol-specific context mint actions #394

Open
wants to merge 6 commits into
base: 1.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/contextualizers/protocol/highlight/highlight.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ describe('Highlight', () => {
expect(containsBigInt(highlightMultipleMint1.context)).toBe(false);
});

it('Should have protocol-specific context action', () => {
const highlight1 = detect(
highlightErc20_0x1f0c411b as unknown as Transaction,
);
expect(highlight1).toBe(true);

const contextualized = generate(
highlightErc20_0x1f0c411b as unknown as Transaction,
);
if (!contextualized.context) {
throw new Error('Context is undefined');
}
expect(contextualized['context']['actions']).toContain('HIGHLIGHT.MINTED');
});

it('Should not detect as highlight', () => {
const highlightMintWithRewards1 = detect(
catchall0xc35c01ac as unknown as Transaction,
Expand Down
11 changes: 6 additions & 5 deletions src/contextualizers/protocol/highlight/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const generate = (transaction: Transaction): Transaction => {
transaction.context.summaries.category = 'PROTOCOL_1';
transaction.context.summaries.en.title = 'Highlight';

// update context action list
transaction.context.actions = [
`${Protocols.HIGHLIGHT}.${HighlightContextActionEnum.MINTED}`,
...(transaction.context.actions || []),
];

// check if mint with rewards
const logs = transaction.logs ?? [];
let decodedLog;
Expand All @@ -62,11 +68,6 @@ export const generate = (transaction: Transaction): Transaction => {
const mintReferralAmount = decodedLog.args['amount'].toString();
const mintReferralCurrency = decodedLog.args['currency'].toLowerCase();

transaction.context.actions = [
`${Protocols.HIGHLIGHT}.${HighlightContextActionEnum.MINTED}`,
...(transaction.context.actions || []),
];

transaction.context.variables = {
...transaction.context.variables,
vectorId: {
Expand Down
11 changes: 11 additions & 0 deletions src/contextualizers/protocol/rodeo/rodeo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ describe('Rodeo Mint', () => {
);
expect(zoraMintWithRewards1).toBe(false);
});

it('Should have protocol-specific context action', () => {
const rodeo1 = detect(rodeo0x3c346a6d as unknown as Transaction);
expect(rodeo1).toBe(true);

const contextualized = generate(rodeo0x3c346a6d as unknown as Transaction);
if (!contextualized.context) {
throw new Error('Context is undefined');
}
expect(contextualized['context']['actions']).toContain('RODEO.MINTED');
});
});
10 changes: 6 additions & 4 deletions src/contextualizers/protocol/rodeo/rodeo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const generate = (transaction: Transaction): Transaction => {
transaction.context.summaries.category = 'PROTOCOL_1';
transaction.context.summaries.en.title = 'Rodeo';

// update context action list
transaction.context.actions = [
`${Protocols.RODEO}.${RodeoContextActionEnum.MINTED}`,
...(transaction.context.actions || []),
];

const logs =
transaction.logs && transaction.logs.length > 0 ? transaction.logs : [];
const mintFromFixedPriceSaleLog = findMintFromFixedPriceSaleLog(logs);
Expand All @@ -68,10 +74,6 @@ export const generate = (transaction: Transaction): Transaction => {
)
return transaction;

transaction.context.actions = [
`${Protocols.RODEO}.${RodeoContextActionEnum.MINTED}`,
...(transaction.context.actions || []),
];
transaction.context.variables = {
...transaction.context.variables,
numOfEth: {
Expand Down
16 changes: 16 additions & 0 deletions src/contextualizers/protocol/zoraCreator/zoraCreator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { detect, generate } from './zoraCreator';
import { containsBigInt, contextSummary } from '../../../helpers/utils';
import mintWithRewards0x6ccb3140 from '../../test/transactions/mintWithRewards-0x6ccb3140.json';
import zoraMintWithRewards0x837a9a69 from '../../test/transactions/zoraMintWithRewards-0x837a9a69.json';
import zoraProtocolSpecific0xf811acb9 from '../../test/transactions/zoraProtocolSpecific-0xf811acb9.json';
import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json';

describe('Zora Mint', () => {
Expand Down Expand Up @@ -52,4 +53,19 @@ describe('Zora Mint', () => {
);
expect(zoraMintWithRewards1).toBe(false);
});

it('Should have protocol-specific context action even with early return', () => {
const zoraProtocolSpecific1 = detect(
zoraProtocolSpecific0xf811acb9 as unknown as Transaction,
);
expect(zoraProtocolSpecific1).toBe(true);

const contextualized = generate(
zoraProtocolSpecific0xf811acb9 as unknown as Transaction,
);
if (!contextualized.context) {
throw new Error('Context is undefined');
}
expect(contextualized['context']['actions']).toContain('ZORA.MINTED');
});
});
10 changes: 6 additions & 4 deletions src/contextualizers/protocol/zoraCreator/zoraCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export const generate = (transaction: Transaction): Transaction => {
transaction.context.summaries.category = 'PROTOCOL_1';
transaction.context.summaries.en.title = 'Zora';

// update context action list
transaction.context.actions = [
`${Protocols.ZORA}.${ZoraContextActionEnum.MINTED}`,
...(transaction.context.actions || []),
];

const logs =
transaction.logs && transaction.logs.length > 0 ? transaction.logs : [];
const rewardsDepositLog = logs.find(
Expand All @@ -73,10 +79,6 @@ export const generate = (transaction: Transaction): Transaction => {
)
return transaction;

transaction.context.actions = [
`${Protocols.ZORA}.${ZoraContextActionEnum.MINTED}`,
...(transaction.context.actions || []),
];
transaction.context.variables = {
...transaction.context.variables,
numOfEth: {
Expand Down
Loading