Skip to content

Commit

Permalink
Merge pull request #407 from Once-Upon/feature/ou-2726-update-make-tr…
Browse files Browse the repository at this point in the history
…ansformations-logs-and-contextualizations

Update make transformations logs and contextualizations
  • Loading branch information
pcowgill committed Jul 31, 2024
2 parents d82f721 + 43b975b commit 66b0d3f
Show file tree
Hide file tree
Showing 38 changed files with 4,668 additions and 112 deletions.
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/acrossProtocol/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ACROSS_PROTOCOL_RELAYER_ABI,
ACROSS_PROTOCOL_RELAYERS,
} from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isAcrossProtocol = detect(transaction);
Expand All @@ -28,7 +28,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const filledRelayLog = logs.find((log: Log) => {
if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false;

Expand All @@ -50,7 +50,7 @@ export function detect(transaction: Transaction): boolean {

export function generate(transaction: Transaction): Transaction {
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let filledRelayEvent;
const filledRelayLog = logs.find((log: Log) => {
if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false;
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/acrossProtocol/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ACROSS_PROTOCOL_RELAYER_ABI,
ACROSS_PROTOCOL_RELAYERS,
} from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isAcrossProtocol = detect(transaction);
Expand All @@ -28,7 +28,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const fundsDepositedLog = logs.find((log: Log) => {
if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false;

Expand All @@ -51,7 +51,7 @@ export function detect(transaction: Transaction): boolean {

export function generate(transaction: Transaction): Transaction {
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let fundsDepositedEvent;
const fundsDepositedLog = logs.find((log: Log) => {
if (log.address !== ACROSS_PROTOCOL_RELAYERS[originChainId]) return false;
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/hopTransferToL1/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Transaction,
} from '../../../types';
import { HOP_WITHDRAWAL_BONDED_EVENT_ABI, HOP_RELAYERS } from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isHopTransferToL1 = detect(transaction);
Expand All @@ -24,7 +24,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const withdrawalBondedLog = logs.find((log: any) => {
if (log.address !== HOP_RELAYERS[originChainId]) return false;

Expand All @@ -49,7 +49,7 @@ export function generate(transaction: Transaction): Transaction {
const chainId = transaction.chainId;
if (!chainId) return transaction;

const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let decodedWithdrawalBondedLog;
for (const log of logs) {
if (log.address !== HOP_RELAYERS[originChainId]) continue;
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/hopTransferToL1/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Transaction,
} from '../../../types';
import { HOP_TRANSFER_SENT_EVENT_ABI, HOP_RELAYERS } from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isHopTransferToL1 = detect(transaction);
Expand All @@ -24,7 +24,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const transferSentLog = logs.find((log: any) => {
if (log.address !== HOP_RELAYERS[originChainId]) return false;

Expand All @@ -46,7 +46,7 @@ export function detect(transaction: Transaction): boolean {

export function generate(transaction: Transaction): Transaction {
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let decodedTransferSentLog;
for (const log of logs) {
if (log.address !== HOP_RELAYERS[originChainId]) continue;
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/hopTransferToL2/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
HOP_TRANSFER_FROM_L1_COMPLETED_EVENT_ABI,
HOP_RELAYERS,
} from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isHopTransferToL1 = detect(transaction);
Expand All @@ -27,7 +27,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const transferFromL1CompletedLog = logs.find((log: any) => {
if (log.address !== HOP_RELAYERS[originChainId]) return false;

Expand All @@ -51,7 +51,7 @@ export function generate(transaction: Transaction): Transaction {
const chainId = transaction.chainId;
if (!chainId) return transaction;

const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let decodedTransferFromL1CompletedLog;
for (const log of logs) {
if (log.address !== HOP_RELAYERS[chainId]) continue;
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/hopTransferToL2/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Transaction,
} from '../../../types';
import { HOP_TRANSFER_SENT_TO_L2_EVENT_ABI, HOP_RELAYERS } from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isHopTransferToL1 = detect(transaction);
Expand All @@ -24,7 +24,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const transferSentToL2Log = logs.find((log: any) => {
if (log.address !== HOP_RELAYERS[originChainId]) return false;

Expand All @@ -46,7 +46,7 @@ export function detect(transaction: Transaction): boolean {

export function generate(transaction: Transaction): Transaction {
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let decodedTransferSentToL2Log;
for (const log of logs) {
if (log.address !== HOP_RELAYERS[originChainId]) continue;
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/opStack/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TRANSACTION_DEPOSITED_EVENT_ABI,
TRANSACTION_DEPOSITED_EVENT_HASH,
} from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isOpStack = detect(transaction);
Expand All @@ -36,7 +36,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
if (transaction.chainId === 1) {
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const transactionDepositedLog = logs.find((log: any) => {
return log.topic0 === TRANSACTION_DEPOSITED_EVENT_HASH;
});
Expand All @@ -58,7 +58,7 @@ export function generate(transaction: Transaction): Transaction {
}
const assetTransfer: Asset = assetSent[0];

const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const transactionDepositedLog = logs.find((log: any) => {
return log.topic0 === TRANSACTION_DEPOSITED_EVENT_HASH;
});
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/starGate/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
STAR_GATE_PACKET_RECEIVED_EVENT_ABI,
STAR_GATE_CHAIN_IDS,
} from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isStarGate = detect(transaction);
Expand All @@ -34,7 +34,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);

const packetReceivedLog = logs.find((log: Log) => {
if (log.address !== STAR_GATE_RELAYERS[originChainId]) return false;
Expand All @@ -58,7 +58,7 @@ export function detect(transaction: Transaction): boolean {

export function generate(transaction: Transaction): Transaction {
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let decodedPacketReceivedLog;

for (const log of logs) {
Expand Down
6 changes: 3 additions & 3 deletions src/contextualizers/bridges/starGate/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
STAR_GATE_PACKET_EVENT_ABI,
STAR_GATE_CHAIN_IDS,
} from './constants';
import { decodeLog } from '../../../helpers/utils';
import { decodeLog, grabLogsFromTransaction } from '../../../helpers/utils';

export function contextualize(transaction: Transaction): Transaction {
const isStarGate = detect(transaction);
Expand All @@ -33,7 +33,7 @@ export function detect(transaction: Transaction): boolean {
* and it also serves to decouple the logic, thereby simplifying the testing process
*/
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
const sendMsgLog = logs.find((log: Log) => {
if (log.address !== STAR_GATE_BRIDGES[originChainId]) return false;
const decoded = decodeLog(
Expand Down Expand Up @@ -79,7 +79,7 @@ export function detect(transaction: Transaction): boolean {

export function generate(transaction: Transaction): Transaction {
const originChainId = transaction.chainId ?? 1;
const logs = transaction.logs ?? [];
const logs = grabLogsFromTransaction(transaction);
let decodedSwapLog;

for (const log of logs) {
Expand Down
21 changes: 21 additions & 0 deletions src/contextualizers/contextualizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ import ensBulkRenew0x25add712 from './test/transactions/ensBulkRenew-0x25add712.
import skyoneerPlotAction0x9436b659 from './test/transactions/skyoneerPlotAction-0x9436b659.json';
import skyoneerPlotAction0x9bb5a737 from './test/transactions/skyoneerPlotAction-0x9bb5a737.json';
import skyoneerPlotAction0x496c6309 from './test/transactions/skyoneerPlotAction-0x496c6309.json';
// untransformed transactions
import registrarWithConfigRaw0x5d31a49e from './test/transactions/registrarWithConfig-raw-0x5d31a49e.json';
import ensRegistrarRaw0xb14b4771 from './test/transactions/ensRegistrar-raw-0xb14b4771.json';
import nftMintRaw0xf264bbc2685 from './test/transactions/nft-mint-raw-0xf264bbc2685.json';

describe('ContextualizerService', () => {
describe('Detect transactions correctly', () => {
Expand Down Expand Up @@ -255,5 +259,22 @@ describe('ContextualizerService', () => {
);
expect(plotAction3.context?.summaries?.en.title).toBe('Skyoneer');
});

it('Should detect raw transactions', () => {
const ens1 = contextualizer.contextualize(
ensRegistrarRaw0xb14b4771 as unknown as Transaction,
);
expect(ens1.context?.summaries?.en.title).toBe('ENS');

const ens2 = contextualizer.contextualize(
registrarWithConfigRaw0x5d31a49e as unknown as Transaction,
);
expect(ens2.context?.summaries?.en.title).toBe('ENS');

const nftMint1 = contextualizer.contextualize(
nftMintRaw0xf264bbc2685 as unknown as Transaction,
);
expect(nftMint1.context?.summaries?.en.title).toBe('NFT Mint');
});
});
});
4 changes: 3 additions & 1 deletion src/contextualizers/heuristics/ethTransfer/ethTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { grabLogsFromTransaction } from '../../../helpers/utils';
import {
AssetType,
HeuristicContextActionEnum,
Expand All @@ -12,12 +13,13 @@ export function contextualize(transaction: Transaction): Transaction {
}

export function detect(transaction: Transaction): boolean {
const logs = grabLogsFromTransaction(transaction);
// TODO; check logs from transaction
if (
transaction.to &&
transaction.input === '0x' &&
transaction.value !== BigInt(0) &&
transaction.logs?.length === 0
logs.length === 0
) {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/contextualizers/protocol/boombox/boombox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import {
decodeEVMAddress,
decodeTransactionInput,
grabLogsFromTransaction,
} from '../../../helpers/utils';
import { CHAIN_IDS } from '../../../helpers/constants';

Expand Down Expand Up @@ -123,12 +124,11 @@ export const generate = (transaction: Transaction): Transaction => {
case 'distribute':
const distributeArtistId =
decoded.args && decoded.args.length > 0 ? decoded.args[0] : '';
const logs = grabLogsFromTransaction(transaction);
// decode logs
const distributeLogs = transaction.logs
? transaction.logs.filter(
(log) => log.topic0 === EVENT_DISTRIBUTE_TOPIC,
)
: [];
const distributeLogs = logs.filter(
(log) => log.topic0 === EVENT_DISTRIBUTE_TOPIC,
);
const recipients = distributeLogs.map((log) =>
decodeEVMAddress(log.topic2),
);
Expand Down
8 changes: 6 additions & 2 deletions src/contextualizers/protocol/cryptopunks/cryptopunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
Transaction,
} from '../../../types';
import { CryptopunksContracts, CRYPTOPUNK_ABIS } from './constants';
import { decodeTransactionInput } from '../../../helpers/utils';
import {
decodeTransactionInput,
grabLogsFromTransaction,
} from '../../../helpers/utils';

export const contextualize = (transaction: Transaction): Transaction => {
const isENS = detect(transaction);
Expand Down Expand Up @@ -357,7 +360,8 @@ export const generate = (transaction: Transaction): Transaction => {
unit: 'wei',
};
if (transaction.receipt?.status) {
const transferTopic = transaction.logs?.filter(
const logs = grabLogsFromTransaction(transaction);
const transferTopic = logs.filter(
(log) =>
log.topic0 ===
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
Expand Down
9 changes: 7 additions & 2 deletions src/contextualizers/protocol/eas/eas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
EventLogTopics,
EASContextActionEnum,
} from '../../../types';
import { decodeTransactionInput, decodeLog } from '../../../helpers/utils';
import {
decodeTransactionInput,
decodeLog,
grabLogsFromTransaction,
} from '../../../helpers/utils';
import { ABIs, EAS_LINKS } from './constants';

export const contextualize = (transaction: Transaction): Transaction => {
Expand Down Expand Up @@ -70,7 +74,8 @@ const getAttestationID = (transaction: Transaction): string | null => {
return null;
}
// TODO: Confirm that the event matches the expected name
const transactionLog = transaction?.logs?.[0];
const logs = grabLogsFromTransaction(transaction);
const transactionLog = logs?.[0];
const decoded = decodeLog(
ABIs.EAS,
transactionLog?.data as Hex,
Expand Down
10 changes: 8 additions & 2 deletions src/contextualizers/protocol/eas/schemaRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
EventLogTopics,
Transaction,
} from '../../../types';
import { decodeTransactionInput, decodeLog } from '../../../helpers/utils';
import {
decodeTransactionInput,
decodeLog,
grabLogsFromTransaction,
} from '../../../helpers/utils';
import { ABIs, EAS_LINKS } from './constants';

export const contextualize = (transaction: Transaction): Transaction => {
Expand Down Expand Up @@ -54,11 +58,13 @@ export const generate = (transaction: Transaction): Transaction => {
}
if (!transaction.chainId) return transaction;

const logs = grabLogsFromTransaction(transaction);

switch (decoded.functionName) {
case 'register': {
let id = '';
if (transaction.receipt?.status) {
const registerLog = transaction.logs?.find((log) => {
const registerLog = logs.find((log) => {
const decoded = decodeLog(
ABIs.SchemaRegistry,
log.data as Hex,
Expand Down
Loading

0 comments on commit 66b0d3f

Please sign in to comment.