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

For catchall context if there is 1 erc20 and some eth #364

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
15 changes: 15 additions & 0 deletions src/contextualizers/catchall/catchall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import catchall0x6331ce46 from '../test/transactions/catchall-0x6331ce46.json';
import catchall0xdfdb78fd from '../test/transactions/catchall-0xdfdb78fd.json';
import catchall0x80c1b6eb from '../test/transactions/catchall-0x80c1b6eb.json';
import catchall0x26f6c382 from '../test/transactions/catchall-0x26f6c382.json';
import catchall0x27cdbe9f from '../test/transactions/catchall-0x27cdbe9f.json';

describe('catchall', () => {
it('Should detect catchall transaction', () => {
Expand Down Expand Up @@ -98,5 +99,19 @@ describe('catchall', () => {
expect(desc9).toBe(
'0x4337003fcd2f56de3977ccb806383e9161628d0e INTERACTED_WITH 0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789 and 171.202858968251372 ETH was transferred',
);
// 1 ERC20
const txResult10 = generate(catchall0x27cdbe9f as unknown as Transaction);
const variables10 = txResult10.context?.variables;
expect(variables10?.totalEth['type']).toBe('eth');
expect(variables10?.totalEth['value']).toBe('17230758755630');
expect(variables10?.totalERC20s['type']).toBe('erc20');
expect(variables10?.totalERC20s['token']).toBe(
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913',
);
expect(variables10?.totalERC20s['value']).toBe('10991363');
const desc10 = contextSummary(txResult10.context);
expect(desc10).toBe(
'0x433702256b464248dcbe403c1334757be4ed9f26 INTERACTED_WITH 0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789 and 10991363 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913 and 0.00001723075875563 ETH were transferred',
);
});
});
21 changes: 15 additions & 6 deletions src/contextualizers/catchall/catchall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export function generate(transaction: Transaction): Transaction {

const nftAssets = new Set();
const tokenAssets = new Set();
const tokenTransfers: ERC20Asset[] = [];
const ethTransfers: ETHAsset[] = [];
Object.keys(transaction.netAssetTransfers).forEach((address) => {
const sentAssets = transaction.netAssetTransfers
Expand All @@ -83,6 +84,7 @@ export function generate(transaction: Transaction): Transaction {
break;
case 'erc20':
tokenAssets.add(assetTransfer.contract);
tokenTransfers.push(assetTransfer);
break;
case 'eth':
ethTransfers.push(assetTransfer);
Expand Down Expand Up @@ -148,12 +150,19 @@ export function generate(transaction: Transaction): Transaction {
const unit = tokenAssets.size > 1 ? 'ERC20s' : 'ERC20';
assetAmount += tokenAssets.size;

variables['totalERC20s'] = {
type: 'number',
value: tokenAssets.size,
unit,
emphasis: true,
};
variables['totalERC20s'] =
tokenAssets.size > 1
? {
type: 'number',
value: tokenAssets.size,
unit,
emphasis: true,
}
: {
type: AssetType.ERC20,
token: tokenTransfers[0].contract,
value: tokenTransfers[0].value,
};
desc += 'and[[totalERC20s]]';
}
if (ethTransfers.length > 0) {
Expand Down
Loading
Loading