Skip to content

Commit

Permalink
Make 'erc-1155' scheduledPrefix optional, add optional burnScheduledP…
Browse files Browse the repository at this point in the history
…refix
  • Loading branch information
SpaceManiac committed Apr 17, 2024
1 parent c92b9ee commit f28e4d8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 2 additions & 0 deletions packages/engine/paima-funnel/src/cde/erc1155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function transferSingleToDatum(
},
contractAddress: extension.contractAddress,
scheduledPrefix: extension.scheduledPrefix,
burnScheduledPrefix: extension.burnScheduledPrefix,
network,
};
}
Expand All @@ -79,6 +80,7 @@ function transferBatchToDatum(
},
contractAddress: extension.contractAddress,
scheduledPrefix: extension.scheduledPrefix,
burnScheduledPrefix: extension.burnScheduledPrefix,
network,
};
}
37 changes: 24 additions & 13 deletions packages/engine/paima-sm/src/cde-erc1155-transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ export default async function processErc1155TransferDatum(
cdeDatum: CdeErc1155TransferDatum,
inPresync: boolean
): Promise<SQLUpdate[]> {
const { cdeId, scheduledPrefix, payload, blockNumber } = cdeDatum;
if (!scheduledPrefix) {
return [];
}
const { cdeId, scheduledPrefix, burnScheduledPrefix, payload, blockNumber } = cdeDatum;
const { operator, from, to, ids, values } = payload;
const isMint = from == '0x0000000000000000000000000000000000000000';
const isBurn = /^0x0+(dead)?$/i.test(to);
Expand All @@ -29,15 +26,29 @@ export default async function processErc1155TransferDatum(

// Always schedule the plain old transfer event.
const scheduledBlockHeight = inPresync ? ENV.SM_START_BLOCKHEIGHT + 1 : blockNumber;
const scheduledInputData = [
scheduledPrefix,
operator,
from.toLowerCase(),
to.toLowerCase(),
JSON.stringify(ids),
JSON.stringify(values),
].join('|');
updateList.push(createScheduledData(scheduledInputData, scheduledBlockHeight));
if (scheduledPrefix) {
const scheduledInputData = [
scheduledPrefix,
operator,
from.toLowerCase(),
to.toLowerCase(),
JSON.stringify(ids),
JSON.stringify(values),
].join('|');
updateList.push(createScheduledData(scheduledInputData, scheduledBlockHeight));
}

if (isBurn && burnScheduledPrefix) {
const burnData = [
burnScheduledPrefix,
operator,
from.toLowerCase(),
// to is excluded because it's presumed 0
JSON.stringify(ids),
JSON.stringify(values),
].join('|');
updateList.push(createScheduledData(burnData, scheduledBlockHeight));
}

// Update balance + burn tables.
for (let i = 0; i < ids.length; ++i) {
Expand Down
6 changes: 4 additions & 2 deletions packages/engine/paima-sm/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ export interface CdeErc1155TransferDatum extends CdeDatumBase {
cdeDatumType: ChainDataExtensionDatumType.Erc1155Transfer;
payload: CdeDatumErc1155TransferPayload;
contractAddress: string;
scheduledPrefix: string;
scheduledPrefix?: string | undefined;
burnScheduledPrefix?: string | undefined;
}

export interface CdeGenericDatum extends CdeDatumBase {
Expand Down Expand Up @@ -344,7 +345,8 @@ export const ChainDataExtensionErc1155Config = Type.Intersect([
Type.Object({
type: Type.Literal(CdeEntryTypeName.ERC1155),
contractAddress: EvmAddress,
scheduledPrefix: Type.String(),
scheduledPrefix: Type.Optional(Type.String()),
burnScheduledPrefix: Type.Optional(Type.String()),
}),
]);
export type ChainDataExtensionErc1155 = ChainDataExtensionBase &
Expand Down

0 comments on commit f28e4d8

Please sign in to comment.