From 691c36faf7a96c598731f3deca99261acab5ed6e Mon Sep 17 00:00:00 2001 From: Enzo Cioppettini <48031343+ecioppettini@users.noreply.github.com> Date: Fri, 3 May 2024 18:41:16 -0300 Subject: [PATCH] add confirmationDepth setting too --- .../engine/paima-funnel/src/funnels/parallelEvm/funnel.ts | 8 +++++--- packages/paima-sdk/paima-utils/src/config/loading.ts | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/engine/paima-funnel/src/funnels/parallelEvm/funnel.ts b/packages/engine/paima-funnel/src/funnels/parallelEvm/funnel.ts index cba325be..6d8d56f4 100644 --- a/packages/engine/paima-funnel/src/funnels/parallelEvm/funnel.ts +++ b/packages/engine/paima-funnel/src/funnels/parallelEvm/funnel.ts @@ -469,7 +469,7 @@ export class ParallelEvmFunnel extends BaseFunnel implements ChainFunnel { return newEntry; })(); - cacheEntry.updateState(config.chainId, latestBlock); + cacheEntry.updateState(config.chainId, latestBlock - (config.confirmationDepth ?? 0)); const evmCacheEntry = ((): EvmFunnelCacheEntry => { const entry = sharedData.cacheManager.cacheEntries[EvmFunnelCacheEntry.SYMBOL]; @@ -513,12 +513,14 @@ export class ParallelEvmFunnel extends BaseFunnel implements ChainFunnel { GET_BLOCK_NUMBER_TIMEOUT ); + const delayedBlock = newLatestBlock - Math.max(this.config.confirmationDepth ?? 0, 0); + this.sharedData.cacheManager.cacheEntries[RpcCacheEntry.SYMBOL]?.updateState( this.config.chainId, - newLatestBlock + delayedBlock ); - return newLatestBlock; + return delayedBlock; } private getState(): EvmFunnelCacheEntryState { diff --git a/packages/paima-sdk/paima-utils/src/config/loading.ts b/packages/paima-sdk/paima-utils/src/config/loading.ts index de9db6b1..46f63fdf 100644 --- a/packages/paima-sdk/paima-utils/src/config/loading.ts +++ b/packages/paima-sdk/paima-utils/src/config/loading.ts @@ -40,6 +40,7 @@ const MainNetworkDiscrimination = Type.Union([ }), Type.Object({ delay: Type.Optional(Type.Number()), + confirmationDepth: Type.Optional(Type.Number()), type: Type.Literal(ConfigNetworkType.EVM_OTHER), }), ]);