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

feat: update highlight #299

Merged
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
2 changes: 1 addition & 1 deletion src/commands/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const grabTx = async (txHash: string, prefix: string) => {
const defaultApiUrl = 'https://api.onceupon.gg';
const API_URL = process.env.API_URL || defaultApiUrl;
const transaction = await fetch(
`${API_URL}/v1/transactions/${txHash}?withContext=false`,
`${API_URL}/v2/transactions/${txHash}?withContext=false`,
).then((res) => res.json());

// write to file
Expand Down
28 changes: 27 additions & 1 deletion src/contextualizers/protocol/highlight/highlight.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
import { Transaction } from '../../../types';
import { detect } from './highlight';
import { detect, generate } from './highlight';
import catchall0xc35c01ac from '../../test/transactions/catchall-0xc35c01ac.json';
import highlight0x61e3c3cb from '../../test/transactions/highlight-0x61e3c3cb.json';
import { containsBigInt, contextSummary } from '../../../helpers/utils';

describe('Highlight', () => {
it('Should detect as highlight', () => {
const highlightMintWithRewards1 = detect(
highlight0x61e3c3cb as unknown as Transaction,
);
expect(highlightMintWithRewards1).toBe(true);
});

it('Should generate context for mintWithRewards transaction', () => {
const highlightMintWithRewards1 = generate(
highlight0x61e3c3cb as unknown as Transaction,
);
expect(highlightMintWithRewards1.context?.summaries?.category).toBe(
'PROTOCOL_1',
);
expect(highlightMintWithRewards1.context?.summaries?.en.title).toBe(
'Highlight',
);
const desc1 = contextSummary(highlightMintWithRewards1.context);
expect(desc1).toBe(
'0x0989cd2871b36d638140354731301a32d2409c3a MINTED 0x31c5c70330c9a1d3099d8f77381e82a218d5c71a #2 for 0.0008 ETH with 0.0004 ETH for 0x0989cd2871b36d638140354731301a32d2409c3a',
);
expect(containsBigInt(highlightMintWithRewards1.context)).toBe(false);
});

it('Should not detect as highlight', () => {
const highlightMintWithRewards1 = detect(
catchall0xc35c01ac as unknown as Transaction,
Expand Down
29 changes: 14 additions & 15 deletions src/contextualizers/protocol/highlight/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
AssetType,
ERC1155AssetTransfer,
ERC721AssetTransfer,
ETHAsset,
EventLogTopics,
Transaction,
HeuristicContextActionEnum,
Expand Down Expand Up @@ -69,13 +68,8 @@ export const generate = (transaction: Transaction): Transaction => {
const recipient = assetTransfer.to;
const amount = mints.filter((ele) => ele.type === assetTransfer.type).length;

const assetSent = transaction.netAssetTransfers[transaction.from]
?.sent as ETHAsset[];
const price =
assetSent && assetSent.length > 0 && assetSent[0]?.value
? assetSent[0].value
: '0';

const mintPrice = transaction.value ? transaction.value.toString() : '0';
const mintReferralAmount = decodedLog.args['amount'].toString();
const sender = transaction.from;

transaction.context = {
Expand All @@ -88,9 +82,14 @@ export const generate = (transaction: Transaction): Transaction => {
type: 'address',
value: sender,
},
price: {
mintReferralAmount: {
type: AssetType.ETH,
value: mintReferralAmount,
unit: 'wei',
},
mintPrice: {
type: AssetType.ETH,
value: price,
value: mintPrice,
unit: 'wei',
},
minted: {
Expand Down Expand Up @@ -159,8 +158,8 @@ export const generate = (transaction: Transaction): Transaction => {
: '[[sender]][[minted]][[amount]][[token]]to[[recipient]]',
},
};
if (BigInt(price) > BigInt(0)) {
transaction.context.summaries['en'].default += 'for[[price]]';
if (BigInt(mintPrice) > BigInt(0)) {
transaction.context.summaries['en'].default += 'for[[mintPrice]]';
}
} else {
transaction.context.summaries = {
Expand All @@ -173,13 +172,13 @@ export const generate = (transaction: Transaction): Transaction => {
: '[[sender]][[minted]][[token]]to[[recipient]]',
},
};
if (BigInt(price) > BigInt(0)) {
transaction.context.summaries['en'].default += 'for[[price]]';
if (BigInt(mintPrice) > BigInt(0)) {
transaction.context.summaries['en'].default += 'for[[mintPrice]]';
}
}

transaction.context.summaries['en'].default +=
'with[[vectorId]]for[[mintReferral]]';
'with[[mintReferralAmount]]for[[mintReferral]]';

return transaction;
};
Loading
Loading