Skip to content

Commit

Permalink
parallel evm funnel: fix internal events not propagated and incorret …
Browse files Browse the repository at this point in the history
…network in cde_tracking (#314)

* don't schedule data during presync

* fix emulated funnel not propagating internal events

* move network from ChainData to each extension
  • Loading branch information
ecioppettini authored Mar 12, 2024
1 parent f828a6c commit 6a86fa7
Show file tree
Hide file tree
Showing 23 changed files with 221 additions and 123 deletions.
9 changes: 6 additions & 3 deletions packages/engine/paima-funnel/src/cde/cardanoPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default async function getCdeData(
fromAbsoluteSlot: number,
toAbsoluteSlot: number,
getBlockNumber: (slot: number) => number,
absoluteSlotToEpoch: (slot: number) => number
absoluteSlotToEpoch: (slot: number) => number,
network: string
): Promise<ChainDataExtensionDatum[]> {
const events = await timeout(
query(url, Routes.delegationForPool, {
Expand All @@ -24,15 +25,16 @@ export default async function getCdeData(
);

return events.map(e =>
eventToCdeDatum(e, extension, getBlockNumber(e.slot), absoluteSlotToEpoch(e.slot))
eventToCdeDatum(e, extension, getBlockNumber(e.slot), absoluteSlotToEpoch(e.slot), network)
);
}

function eventToCdeDatum(
event: DelegationForPoolResponse[0],
extension: ChainDataExtensionCardanoDelegation,
blockNumber: number,
epoch: number
epoch: number,
network: string
): CdeCardanoPoolDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -44,5 +46,6 @@ function eventToCdeDatum(
epoch,
},
scheduledPrefix: extension.scheduledPrefix,
network,
};
}
9 changes: 6 additions & 3 deletions packages/engine/paima-funnel/src/cde/cardanoProjectedNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default async function getCdeProjectedNFTData(
extension: ChainDataExtensionCardanoProjectedNFT,
fromAbsoluteSlot: number,
toAbsoluteSlot: number,
getBlockNumber: (slot: number) => number
getBlockNumber: (slot: number) => number,
network: string
): Promise<ChainDataExtensionDatum[]> {
const events = await timeout(
query(url, Routes.projectedNftEventsRange, {
Expand All @@ -24,15 +25,16 @@ export default async function getCdeProjectedNFTData(
);

return events
.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.actionSlot)))
.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.actionSlot), network))
.filter(e => e != null)
.map(e => e!);
}

function eventToCdeDatum(
event: ProjectedNftRangeResponse[0],
extension: ChainDataExtensionCardanoProjectedNFT,
blockNumber: number
blockNumber: number,
network: string
): CdeCardanoProjectedNFTDatum | null {
if (
event.actionTxId === null ||
Expand Down Expand Up @@ -65,5 +67,6 @@ function eventToCdeDatum(
forHowLong: event.forHowLong != null ? event.forHowLong : undefined,
},
scheduledPrefix: extension.scheduledPrefix,
network,
};
}
9 changes: 6 additions & 3 deletions packages/engine/paima-funnel/src/cde/delayedAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default async function getCdeData(
extension: ChainDataExtensionCardanoDelayedAsset,
fromAbsoluteSlot: number,
toAbsoluteSlot: number,
getBlockNumber: (slot: number) => number
getBlockNumber: (slot: number) => number,
network: string
): Promise<ChainDataExtensionDatum[]> {
const events = await timeout(
query(url, Routes.assetUtxos, {
Expand All @@ -23,13 +24,14 @@ export default async function getCdeData(
DEFAULT_FUNNEL_TIMEOUT
);

return events.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.slot)));
return events.map(e => eventToCdeDatum(e, extension, getBlockNumber(e.slot), network));
}

function eventToCdeDatum(
event: AssetUtxosResponse[0],
extension: ChainDataExtensionCardanoDelayedAsset,
blockNumber: number
blockNumber: number,
network: string
): CdeCardanoAssetUtxoDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -44,5 +46,6 @@ function eventToCdeDatum(
policyId: event.policyId,
assetName: event.assetName,
},
network,
};
}
12 changes: 9 additions & 3 deletions packages/engine/paima-funnel/src/cde/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { DEFAULT_FUNNEL_TIMEOUT } from '@paima/utils';
export default async function getCdeData(
extension: ChainDataExtensionErc20,
fromBlock: number,
toBlock: number
toBlock: number,
network: string
): Promise<ChainDataExtensionDatum[]> {
// TOOD: typechain is missing the proper type generation for getPastEvents
// https://github.com/dethcrypto/TypeChain/issues/767
Expand All @@ -21,10 +22,14 @@ export default async function getCdeData(
}),
DEFAULT_FUNNEL_TIMEOUT
)) as unknown as ERC20Transfer[];
return events.map((e: ERC20Transfer) => transferToCdeDatum(e, extension.cdeId));
return events.map((e: ERC20Transfer) => transferToCdeDatum(e, extension.cdeId, network));
}

function transferToCdeDatum(event: ERC20Transfer, cdeId: number): CdeErc20TransferDatum {
function transferToCdeDatum(
event: ERC20Transfer,
cdeId: number,
network: string
): CdeErc20TransferDatum {
return {
cdeId: cdeId,
cdeDatumType: ChainDataExtensionDatumType.ERC20Transfer,
Expand All @@ -34,5 +39,6 @@ function transferToCdeDatum(event: ERC20Transfer, cdeId: number): CdeErc20Transf
to: event.returnValues.to.toLowerCase(),
value: event.returnValues.value,
},
network,
};
}
9 changes: 6 additions & 3 deletions packages/engine/paima-funnel/src/cde/erc20Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { DEFAULT_FUNNEL_TIMEOUT } from '@paima/utils';
export default async function getCdeData(
extension: ChainDataExtensionErc20Deposit,
fromBlock: number,
toBlock: number
toBlock: number,
network: string
): Promise<ChainDataExtensionDatum[]> {
// TOOD: typechain is missing the proper type generation for getPastEvents
// https://github.com/dethcrypto/TypeChain/issues/767
Expand All @@ -18,12 +19,13 @@ export default async function getCdeData(
}),
DEFAULT_FUNNEL_TIMEOUT
)) as unknown as Transfer[];
return events.map((e: Transfer) => transferToCdeDatum(e, extension)).flat();
return events.map((e: Transfer) => transferToCdeDatum(e, extension, network)).flat();
}

function transferToCdeDatum(
event: Transfer,
extension: ChainDataExtensionErc20Deposit
extension: ChainDataExtensionErc20Deposit,
network: string
): ChainDataExtensionDatum[] {
if (event.returnValues.to.toLowerCase() !== extension.depositAddress) {
return [];
Expand All @@ -38,6 +40,7 @@ function transferToCdeDatum(
value: event.returnValues.value,
},
scheduledPrefix: extension.scheduledPrefix,
network,
},
];
}
9 changes: 6 additions & 3 deletions packages/engine/paima-funnel/src/cde/erc6551Registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import type { AccountCreated } from '@paima/utils';
export default async function getCdeData(
extension: ChainDataExtensionErc6551Registry,
fromBlock: number,
toBlock: number
toBlock: number,
network: string
): Promise<ChainDataExtensionDatum[]> {
const { implementation, tokenContract, tokenId } = extension;

Expand Down Expand Up @@ -61,13 +62,14 @@ export default async function getCdeData(
: withFilter.filter(e => e.returnValues.tokenId === extension.tokenId);
return withFilter;
})();
const result = filteredEvents.map((e: AccountCreated) => toDatum(e, extension)).flat();
const result = filteredEvents.map((e: AccountCreated) => toDatum(e, extension, network)).flat();
return result;
}

function toDatum(
event: AccountCreated,
extension: ChainDataExtensionErc6551Registry
extension: ChainDataExtensionErc6551Registry,
network: string
): CdeErc6551RegistryDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -81,5 +83,6 @@ function toDatum(
tokenId: event.returnValues.tokenId,
salt: event.returnValues.salt,
},
network,
};
}
20 changes: 13 additions & 7 deletions packages/engine/paima-funnel/src/cde/erc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import type { ERC721Transfer as Transfer } from '@paima/utils';
export default async function getCdeData(
extension: ChainDataExtensionErc721,
fromBlock: number,
toBlock: number
toBlock: number,
network: string
): Promise<ChainDataExtensionDatum[]> {
// TOOD: typechain is missing the proper type generation for getPastEvents
// https://github.com/dethcrypto/TypeChain/issues/767
Expand All @@ -21,12 +22,13 @@ export default async function getCdeData(
}),
DEFAULT_FUNNEL_TIMEOUT
)) as unknown as Transfer[];
return events.map((e: Transfer) => transferToCdeData(e, extension)).flat();
return events.map((e: Transfer) => transferToCdeData(e, extension, network)).flat();
}

function transferToTransferDatum(
event: Transfer,
extension: ChainDataExtensionErc721
extension: ChainDataExtensionErc721,
network: string
): CdeErc721TransferDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -37,12 +39,14 @@ function transferToTransferDatum(
to: event.returnValues.to.toLowerCase(),
tokenId: event.returnValues.tokenId,
},
network,
};
}

function transferToMintDatum(
event: Transfer,
extension: ChainDataExtensionErc721
extension: ChainDataExtensionErc721,
network: string
): CdeErc721MintDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -54,17 +58,19 @@ function transferToMintDatum(
},
contractAddress: extension.contractAddress,
scheduledPrefix: extension.scheduledPrefix,
network,
};
}

function transferToCdeData(
event: Transfer,
extension: ChainDataExtensionErc721
extension: ChainDataExtensionErc721,
network: string
): ChainDataExtensionDatum[] {
const transferDatum = transferToTransferDatum(event, extension);
const transferDatum = transferToTransferDatum(event, extension, network);
const fromAddr = event.returnValues.from;
if (fromAddr.match(/^0x0+$/g)) {
const mintDatum = transferToMintDatum(event, extension);
const mintDatum = transferToMintDatum(event, extension, network);
return [mintDatum, transferDatum];
} else {
return [transferDatum];
Expand Down
12 changes: 9 additions & 3 deletions packages/engine/paima-funnel/src/cde/generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import type {
export default async function getCdeData(
extension: ChainDataExtensionGeneric,
fromBlock: number,
toBlock: number
toBlock: number,
network: string
): Promise<ChainDataExtensionDatum[]> {
// TOOD: typechain is missing the proper type generation for getPastEvents
// https://github.com/dethcrypto/TypeChain/issues/767
Expand All @@ -23,15 +24,20 @@ export default async function getCdeData(
}),
DEFAULT_FUNNEL_TIMEOUT
);
return events.map(e => eventToCdeDatum(e, extension));
return events.map(e => eventToCdeDatum(e, extension, network));
}

function eventToCdeDatum(event: EventData, extension: ChainDataExtensionGeneric): CdeGenericDatum {
function eventToCdeDatum(
event: EventData,
extension: ChainDataExtensionGeneric,
network: string
): CdeGenericDatum {
return {
cdeId: extension.cdeId,
cdeDatumType: ChainDataExtensionDatumType.Generic,
blockNumber: event.blockNumber,
scheduledPrefix: extension.scheduledPrefix,
payload: event.returnValues,
network,
};
}
17 changes: 12 additions & 5 deletions packages/engine/paima-funnel/src/cde/paimaErc721.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ import type { PaimaMinted as Minted, PaimaERC721Transfer as Transfer } from '@pa
export default async function getCdeData(
extension: ChainDataExtensionPaimaErc721,
fromBlock: number,
toBlock: number
toBlock: number,
network: string
): Promise<ChainDataExtensionDatum[]> {
// TOOD: typechain is missing the proper type generation for getPastEvents
// https://github.com/dethcrypto/TypeChain/issues/767
const [transferEvents, mintedEvents] = await Promise.all([
fetchTransferEvents(extension, fromBlock, toBlock),
fetchMintedEvents(extension, fromBlock, toBlock),
]);
const transferData = transferEvents.map((e: Transfer) => transferToTransferDatum(e, extension));
const mintData = mintedEvents.map((e: Minted) => mintedToMintDatum(e, extension));
const transferData = transferEvents.map((e: Transfer) =>
transferToTransferDatum(e, extension, network)
);
const mintData = mintedEvents.map((e: Minted) => mintedToMintDatum(e, extension, network));
return mergeSortedArrays<ChainDataExtensionDatum>(
mintData,
transferData,
Expand Down Expand Up @@ -62,7 +65,8 @@ async function fetchMintedEvents(

function transferToTransferDatum(
event: Transfer,
extension: ChainDataExtensionPaimaErc721
extension: ChainDataExtensionPaimaErc721,
network: string
): CdeErc721TransferDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -73,12 +77,14 @@ function transferToTransferDatum(
to: event.returnValues.to.toLowerCase(),
tokenId: event.returnValues.tokenId,
},
network,
};
}

function mintedToMintDatum(
event: Minted,
extension: ChainDataExtensionPaimaErc721
extension: ChainDataExtensionPaimaErc721,
network: string
): CdeErc721MintDatum {
return {
cdeId: extension.cdeId,
Expand All @@ -90,5 +96,6 @@ function mintedToMintDatum(
},
contractAddress: extension.contractAddress,
scheduledPrefix: extension.scheduledPrefix,
network,
};
}
Loading

0 comments on commit 6a86fa7

Please sign in to comment.