From 392a7a7f416c9e56264c297641c27f6fd458c9af Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 11 Jun 2024 10:07:33 +0530 Subject: [PATCH 01/14] feat : plug specific confirmations --- scripts/rpcConfig/constants/finality.ts | 646 ++++++++++++++++++++++++ scripts/rpcConfig/constants/index.ts | 1 + scripts/rpcConfig/rpcConfig.ts | 2 + src/index.ts | 2 +- src/socket-types.ts | 31 ++ 5 files changed, 681 insertions(+), 1 deletion(-) create mode 100644 scripts/rpcConfig/constants/finality.ts diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts new file mode 100644 index 00000000..54f6dbd2 --- /dev/null +++ b/scripts/rpcConfig/constants/finality.ts @@ -0,0 +1,646 @@ +import { ChainFinalityInfo, ChainSlug, FinalityBucket, FinalityType } from "../../../src"; + +export const finality :{ + [chainSlug in ChainSlug]?: ChainFinalityInfo; +} = { + [ChainSlug.AEVO]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:2, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.ARBITRUM]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.LYRA]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:2, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.OPTIMISM]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:15, + time:0 + }, + [FinalityBucket.medium]:{ + block:30, + time:0 + }, + [FinalityBucket.slow]:{ + block:40, + time:0 + } + }, + [ChainSlug.BSC]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.POLYGON_MAINNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.slow, + [FinalityBucket.fast]:{ + block:50, + time:0 + }, + [FinalityBucket.medium]:{ + block:150, + time:0 + }, + [FinalityBucket.slow]:{ + block:256, + time:0 + } + }, + [ChainSlug.MAINNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.slow, + [FinalityBucket.fast]:{ + block:6, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:18, + time:0 + } + }, + [ChainSlug.BASE]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.MODE]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:2, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.ARBITRUM_GOERLI]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.AEVO_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.LYRA_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.OPTIMISM_GOERLI]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.GOERLI]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.XAI_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.SX_NETWORK_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.SX_NETWORK]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.MODE_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.VICTION_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.CDK_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.ARBITRUM_SEPOLIA]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.OPTIMISM_SEPOLIA]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.SEPOLIA]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.ANCIENT8_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.ANCIENT8_TESTNET2]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.HOOK_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.HOOK]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.PARALLEL]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.MANTLE]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.REYA_CRONOS]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.REYA]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.SYNDR_SEPOLIA_L3]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.POLYNOMIAL_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, + [ChainSlug.BOB]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.KINTO]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.KINTO_DEVNET]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.SIPHER_FUNKI_TESTNET]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.WINR]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.BLAST]: { + type:FinalityType.time, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:0, + time:30 + }, + [FinalityBucket.medium]:{ + time:60, + block:0, + }, + [FinalityBucket.slow]:{ + time:120, + block:0, + } + }, + [ChainSlug.BSC_TESTNET]: { + type:FinalityType.block, + defaultBucket:FinalityBucket.fast, + [FinalityBucket.fast]:{ + block:1, + time:0 + }, + [FinalityBucket.medium]:{ + block:10, + time:0 + }, + [FinalityBucket.slow]:{ + block:20, + time:0 + } + }, +}; diff --git a/scripts/rpcConfig/constants/index.ts b/scripts/rpcConfig/constants/index.ts index 21a613be..9213ce92 100644 --- a/scripts/rpcConfig/constants/index.ts +++ b/scripts/rpcConfig/constants/index.ts @@ -4,3 +4,4 @@ export * from "./explorers"; export * from "./icons"; export * from "./rpc"; export * from "./version"; +export * from "./finality"; diff --git a/scripts/rpcConfig/rpcConfig.ts b/scripts/rpcConfig/rpcConfig.ts index 85e3b4c8..5ad28d7d 100644 --- a/scripts/rpcConfig/rpcConfig.ts +++ b/scripts/rpcConfig/rpcConfig.ts @@ -27,6 +27,7 @@ import { rpcs, version, } from "./constants"; +import { finality } from "./constants/finality"; import { getChainTxData } from "./txdata-builder/generate-calldata"; import dotenv from "dotenv"; @@ -92,6 +93,7 @@ const getChainData = async ( nativeToken: getCurrency(chainSlug), chainType: getChainType(chainSlug), confirmations: confirmations[chainSlug], + finalityInfo: finality[chainSlug], icon: icons[chainSlug], }; }; diff --git a/src/index.ts b/src/index.ts index 3934760f..3649b6c2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { DeploymentMode } from "./socket-types"; - +export * from "../scripts/rpcConfig/constants"; export * from "./socket-types"; export * from "./enums"; export * from "./addresses"; diff --git a/src/socket-types.ts b/src/socket-types.ts index b8163433..cd08179c 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -206,6 +206,36 @@ export enum ChainType { default = "default", } +export enum FinalityBucket { + fast = "fast", + medium = "medium", + slow = "slow", +} + +export enum FinalityType { + block = "block", + time = "time" +} + +export type ChainFinalityInfo = { + type: FinalityType; + defaultBucket: FinalityBucket; + [FinalityBucket.fast]:{ + block: number; + time: number; + }; + [FinalityBucket.medium]:{ + block: number; + time: number; + }; + [FinalityBucket.slow]:{ + block: number; + time: number; + }; + } + + + export type TxData = { [chainSlug in ChainSlug]?: ChainTxData; }; @@ -229,6 +259,7 @@ export interface S3ChainConfig { chainTxData?: ChainTxData; explorer?: string; icon?: string; + finalityInfo?: ChainFinalityInfo; } export type S3Config = { From 2dbea7842b8522f5dae0dc460f6fd55feef63027 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 11 Jun 2024 10:07:47 +0530 Subject: [PATCH 02/14] chore : lint --- scripts/rpcConfig/constants/finality.ts | 975 ++++++++++++------------ src/socket-types.ts | 12 +- 2 files changed, 495 insertions(+), 492 deletions(-) diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index 54f6dbd2..e567f15b 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -1,646 +1,651 @@ -import { ChainFinalityInfo, ChainSlug, FinalityBucket, FinalityType } from "../../../src"; +import { + ChainFinalityInfo, + ChainSlug, + FinalityBucket, + FinalityType, +} from "../../../src"; -export const finality :{ - [chainSlug in ChainSlug]?: ChainFinalityInfo; +export const finality: { + [chainSlug in ChainSlug]?: ChainFinalityInfo; } = { [ChainSlug.AEVO]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:2, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 2, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.ARBITRUM]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.LYRA]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:2, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 2, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.OPTIMISM]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:15, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 15, + time: 0, }, - [FinalityBucket.medium]:{ - block:30, - time:0 + [FinalityBucket.medium]: { + block: 30, + time: 0, + }, + [FinalityBucket.slow]: { + block: 40, + time: 0, }, - [FinalityBucket.slow]:{ - block:40, - time:0 - } }, [ChainSlug.BSC]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.POLYGON_MAINNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.slow, - [FinalityBucket.fast]:{ - block:50, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.slow, + [FinalityBucket.fast]: { + block: 50, + time: 0, + }, + [FinalityBucket.medium]: { + block: 150, + time: 0, }, - [FinalityBucket.medium]:{ - block:150, - time:0 + [FinalityBucket.slow]: { + block: 256, + time: 0, }, - [FinalityBucket.slow]:{ - block:256, - time:0 - } }, [ChainSlug.MAINNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.slow, - [FinalityBucket.fast]:{ - block:6, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.slow, + [FinalityBucket.fast]: { + block: 6, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 18, + time: 0, }, - [FinalityBucket.slow]:{ - block:18, - time:0 - } }, [ChainSlug.BASE]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.MODE]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:2, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 2, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.ARBITRUM_GOERLI]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.AEVO_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.LYRA_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.OPTIMISM_GOERLI]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.GOERLI]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.XAI_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.SX_NETWORK_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.SX_NETWORK]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.MODE_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.VICTION_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.CDK_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.ARBITRUM_SEPOLIA]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.OPTIMISM_SEPOLIA]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.SEPOLIA]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.ANCIENT8_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.ANCIENT8_TESTNET2]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.HOOK_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.HOOK]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.PARALLEL]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.MANTLE]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.REYA_CRONOS]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.REYA]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.medium]: { + time: 60, + block: 0, + }, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.SYNDR_SEPOLIA_L3]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.POLYNOMIAL_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, }, - [FinalityBucket.medium]:{ - block:10, - time:0 + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } }, [ChainSlug.BOB]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, + }, + [FinalityBucket.medium]: { + time: 60, + block: 0, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.KINTO]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, + }, + [FinalityBucket.medium]: { + time: 60, + block: 0, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.KINTO_DEVNET]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.medium]: { + time: 60, + block: 0, + }, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.SIPHER_FUNKI_TESTNET]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, + }, + [FinalityBucket.medium]: { + time: 60, + block: 0, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.WINR]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.medium]: { + time: 60, + block: 0, + }, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.BLAST]: { - type:FinalityType.time, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:0, - time:30 + type: FinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, + }, + [FinalityBucket.medium]: { + time: 60, + block: 0, }, - [FinalityBucket.medium]:{ - time:60, - block:0, + [FinalityBucket.slow]: { + time: 120, + block: 0, }, - [FinalityBucket.slow]:{ - time:120, - block:0, - } }, [ChainSlug.BSC_TESTNET]: { - type:FinalityType.block, - defaultBucket:FinalityBucket.fast, - [FinalityBucket.fast]:{ - block:1, - time:0 - }, - [FinalityBucket.medium]:{ - block:10, - time:0 - }, - [FinalityBucket.slow]:{ - block:20, - time:0 - } + type: FinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, + }, }, }; diff --git a/src/socket-types.ts b/src/socket-types.ts index cd08179c..f4156b05 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -214,27 +214,25 @@ export enum FinalityBucket { export enum FinalityType { block = "block", - time = "time" + time = "time", } export type ChainFinalityInfo = { type: FinalityType; defaultBucket: FinalityBucket; - [FinalityBucket.fast]:{ + [FinalityBucket.fast]: { block: number; time: number; }; - [FinalityBucket.medium]:{ + [FinalityBucket.medium]: { block: number; time: number; }; - [FinalityBucket.slow]:{ + [FinalityBucket.slow]: { block: number; time: number; }; - } - - +}; export type TxData = { [chainSlug in ChainSlug]?: ChainTxData; From e4d860339f8ec15bf53c579a44a919b092c1cf19 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 11 Jun 2024 11:24:04 +0530 Subject: [PATCH 03/14] chore : build fix --- package.json | 1 + scripts/rpcConfig/constants/finality.ts | 7 ++++--- scripts/rpcConfig/rpcConfig.ts | 2 +- src/index.ts | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 78c18b14..dd0d65a4 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "scripts": { "lint": "prettier \"./**\" --write", "build": "hardhat export-abi && tsc --project lib.tsconfig.json", + "tsc": "tsc --project lib.tsconfig.json", "abi": "hardhat export-abi", "compile": "forge build", "test": "prettier --write $(git diff --name-only --diff-filter d | xargs) && forge test", diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index e567f15b..abc65f01 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -1,9 +1,10 @@ +import { ChainSlug } from "../../../src/enums/chainSlug"; + import { - ChainFinalityInfo, - ChainSlug, FinalityBucket, FinalityType, -} from "../../../src"; + ChainFinalityInfo, +} from "../../../src/socket-types"; export const finality: { [chainSlug in ChainSlug]?: ChainFinalityInfo; diff --git a/scripts/rpcConfig/rpcConfig.ts b/scripts/rpcConfig/rpcConfig.ts index 5ad28d7d..8fa7eb25 100644 --- a/scripts/rpcConfig/rpcConfig.ts +++ b/scripts/rpcConfig/rpcConfig.ts @@ -26,8 +26,8 @@ import { prodFeesUpdaterSupportedChainSlugs, rpcs, version, + finality, } from "./constants"; -import { finality } from "./constants/finality"; import { getChainTxData } from "./txdata-builder/generate-calldata"; import dotenv from "dotenv"; diff --git a/src/index.ts b/src/index.ts index 3649b6c2..1a92e8d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { DeploymentMode } from "./socket-types"; -export * from "../scripts/rpcConfig/constants"; +export { finality } from "../scripts/rpcConfig/constants/finality"; export * from "./socket-types"; export * from "./enums"; export * from "./addresses"; From 079cde7844b4d5ba5768de4999be8ecae6895005 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 11 Jun 2024 17:26:00 +0530 Subject: [PATCH 04/14] feat: added transmission utils --- src/index.ts | 1 + src/socket-types.ts | 11 ++++---- src/transmission-utils.ts | 54 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/transmission-utils.ts diff --git a/src/index.ts b/src/index.ts index 1a92e8d7..361111da 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ export * from "./socket-types"; export * from "./enums"; export * from "./addresses"; export * from "./currency-util"; +export * from "./transmission-utils"; export const version = { [DeploymentMode.DEV]: "IMLI", diff --git a/src/socket-types.ts b/src/socket-types.ts index f4156b05..66c5b77f 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -207,14 +207,15 @@ export enum ChainType { } export enum FinalityBucket { - fast = "fast", - medium = "medium", - slow = "slow", + fast = 1, + medium = 2, + slow = 3, } export enum FinalityType { - block = "block", - time = "time", + bucket = 1, + block = 2, + time = 3, } export type ChainFinalityInfo = { diff --git a/src/transmission-utils.ts b/src/transmission-utils.ts new file mode 100644 index 00000000..a754aba5 --- /dev/null +++ b/src/transmission-utils.ts @@ -0,0 +1,54 @@ +import { FinalityType } from "./socket-types"; + +export const decodeTransmissionParams = (transmissionParam: string) => { + if (transmissionParam.length !== 64 && transmissionParam.length !== 66) { + throw new Error("Invalid transmission param length"); + } + transmissionParam = transmissionParam.replace("0x", ""); + const version = parseInt("0x" + transmissionParam.slice(0, 2)); + const finalityType = parseInt("0x" + transmissionParam.slice(2, 4)); // bucket, block, time + const value = parseInt("0x" + transmissionParam.slice(4, 12)); + + return { version, finalityType, value }; +}; + +export const encodeTransmissionParams = ( + version: number, + finalityType: number, + value: number +) => { + let transmissionParam = "0x"; + transmissionParam += version.toString(16).padStart(2, "0"); + transmissionParam += finalityType.toString(16).padStart(2, "0"); + transmissionParam += value.toString(16).padStart(8, "0"); + transmissionParam = transmissionParam.padEnd(66, "0"); + return transmissionParam; +}; + +export const isTxFinalized = (data: { + type: FinalityType; + currentBlock: number; + eventBlock: number; + currentTime: number; + eventTime: number; + finalityBlockDiff: number; + finalityTimeDiff: number; +}) => { + if (data.type === FinalityType.block) { + const { currentBlock, eventBlock, finalityBlockDiff } = data; + if (!currentBlock || !eventBlock || !finalityBlockDiff) { + console.log("Invalid data for block finality check"); + return false; + } + return currentBlock - eventBlock >= finalityBlockDiff; + } else if (data.type === FinalityType.time) { + if (!data.currentTime || !data.eventTime || !data.finalityTimeDiff) { + console.log("Invalid data for time finality check"); + return false; + } + return data.currentTime - data.eventTime >= data.finalityTimeDiff; + } else { + console.log("Invalid finality type"); + return false; + } +}; From eedc45e86e3df43042369da83932b43a31bb9111 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 11 Jun 2024 17:37:26 +0530 Subject: [PATCH 05/14] chore : comments --- src/transmission-utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/transmission-utils.ts b/src/transmission-utils.ts index a754aba5..c5123866 100644 --- a/src/transmission-utils.ts +++ b/src/transmission-utils.ts @@ -5,9 +5,9 @@ export const decodeTransmissionParams = (transmissionParam: string) => { throw new Error("Invalid transmission param length"); } transmissionParam = transmissionParam.replace("0x", ""); - const version = parseInt("0x" + transmissionParam.slice(0, 2)); + const version = parseInt("0x" + transmissionParam.slice(0, 2)); // version 1 const finalityType = parseInt("0x" + transmissionParam.slice(2, 4)); // bucket, block, time - const value = parseInt("0x" + transmissionParam.slice(4, 12)); + const value = parseInt("0x" + transmissionParam.slice(4, 12)); // bucket (see FinalityBucket enum), block (block number), time value in seconds return { version, finalityType, value }; }; From 8881b41e2db10f5875dde58211337308012655b7 Mon Sep 17 00:00:00 2001 From: arthcp Date: Tue, 11 Jun 2024 19:11:29 +0530 Subject: [PATCH 06/14] chore: publish and upload --- package.json | 2 +- scripts/rpcConfig/constants/version.ts | 2 +- yarn.lock | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index dd0d65a4..6f29ba9b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@socket.tech/dl-core", "license": "UNLICENSED", - "version": "2.9.0", + "version": "2.10.0", "description": "Smart contracts for socket data layer.", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", diff --git a/scripts/rpcConfig/constants/version.ts b/scripts/rpcConfig/constants/version.ts index 2dbfaaa4..2a1b7b12 100644 --- a/scripts/rpcConfig/constants/version.ts +++ b/scripts/rpcConfig/constants/version.ts @@ -1,6 +1,6 @@ import { DeploymentMode } from "../../../src"; export const version = { - [DeploymentMode.DEV]: "1.0.1", + [DeploymentMode.DEV]: "1.0.2", [DeploymentMode.PROD]: "1.0.18", }; diff --git a/yarn.lock b/yarn.lock index e24b4dbd..c4e1fc17 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11343,6 +11343,11 @@ semver@^7.3.8: dependencies: lru-cache "^6.0.0" +semver@^7.5.4: + version "7.6.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13" + integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w== + semver@^7.6.0: version "7.6.0" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.0.tgz#1a46a4db4bffcccd97b743b5005c8325f23d4e2d" From e70341756c368dbf714f8c52da1840baf96c6cf4 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 11 Jun 2024 20:53:05 +0530 Subject: [PATCH 07/14] chore : refactor, cleanup, comments --- package.json | 2 +- scripts/rpcConfig/constants/finality.ts | 675 +++++------------------- scripts/rpcConfig/rpcConfig.ts | 4 +- src/socket-types.ts | 9 +- src/transmission-utils.ts | 50 +- 5 files changed, 166 insertions(+), 574 deletions(-) diff --git a/package.json b/package.json index 6f29ba9b..3bfdbbd1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@socket.tech/dl-core", "license": "UNLICENSED", - "version": "2.10.0", + "version": "2.10.0-test.1", "description": "Smart contracts for socket data layer.", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index abc65f01..759c9b9a 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -1,16 +1,112 @@ +import { arbL3Chains, opStackL2Chain, polygonCDKChains } from "../../../src"; import { ChainSlug } from "../../../src/enums/chainSlug"; import { FinalityBucket, - FinalityType, + BucketFinalityType, ChainFinalityInfo, } from "../../../src/socket-types"; +const chainsWithZeroBlockFinality = [ + ChainSlug.REYA, + ChainSlug.BOB, + ChainSlug.KINTO, + ChainSlug.KINTO_DEVNET, + ChainSlug.SIPHER_FUNKI_TESTNET, + ChainSlug.WINR, + ChainSlug.BLAST, +]; + +const zeroBlockFinalityDefault = { + type: BucketFinalityType.time, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 0, + time: 30, + }, + [FinalityBucket.medium]: { + time: 60, + block: 0, + }, + [FinalityBucket.slow]: { + time: 120, + block: 0, + }, +}; + +const polygonCDKChainsDefault = { + type: BucketFinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, + }, +}; + +const opStackL2ChainDefault = { + type: BucketFinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, + }, +}; + +const arbL3ChainsDefault = { + type: BucketFinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, + }, +}; + +const defaultFinality = { + type: BucketFinalityType.block, + defaultBucket: FinalityBucket.fast, + [FinalityBucket.fast]: { + block: 1, + time: 0, + }, + [FinalityBucket.medium]: { + block: 10, + time: 0, + }, + [FinalityBucket.slow]: { + block: 20, + time: 0, + }, +}; + export const finality: { [chainSlug in ChainSlug]?: ChainFinalityInfo; } = { [ChainSlug.AEVO]: { - type: FinalityType.block, + type: BucketFinalityType.block, defaultBucket: FinalityBucket.fast, [FinalityBucket.fast]: { block: 2, @@ -25,24 +121,9 @@ export const finality: { time: 0, }, }, - [ChainSlug.ARBITRUM]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, + [ChainSlug.LYRA]: { - type: FinalityType.block, + type: BucketFinalityType.block, defaultBucket: FinalityBucket.fast, [FinalityBucket.fast]: { block: 2, @@ -58,7 +139,7 @@ export const finality: { }, }, [ChainSlug.OPTIMISM]: { - type: FinalityType.block, + type: BucketFinalityType.block, defaultBucket: FinalityBucket.fast, [FinalityBucket.fast]: { block: 15, @@ -73,24 +154,8 @@ export const finality: { time: 0, }, }, - [ChainSlug.BSC]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, [ChainSlug.POLYGON_MAINNET]: { - type: FinalityType.block, + type: BucketFinalityType.block, defaultBucket: FinalityBucket.slow, [FinalityBucket.fast]: { block: 50, @@ -106,7 +171,7 @@ export const finality: { }, }, [ChainSlug.MAINNET]: { - type: FinalityType.block, + type: BucketFinalityType.block, defaultBucket: FinalityBucket.slow, [FinalityBucket.fast]: { block: 6, @@ -121,24 +186,8 @@ export const finality: { time: 0, }, }, - [ChainSlug.BASE]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, [ChainSlug.MODE]: { - type: FinalityType.block, + type: BucketFinalityType.block, defaultBucket: FinalityBucket.fast, [FinalityBucket.fast]: { block: 2, @@ -153,500 +202,24 @@ export const finality: { time: 0, }, }, - [ChainSlug.ARBITRUM_GOERLI]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.AEVO_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.LYRA_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.OPTIMISM_GOERLI]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.GOERLI]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.XAI_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.SX_NETWORK_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.SX_NETWORK]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.MODE_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.VICTION_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.CDK_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.ARBITRUM_SEPOLIA]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.OPTIMISM_SEPOLIA]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.SEPOLIA]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.ANCIENT8_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.ANCIENT8_TESTNET2]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.HOOK_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.HOOK]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.PARALLEL]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.MANTLE]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.REYA_CRONOS]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.REYA]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.SYNDR_SEPOLIA_L3]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.POLYNOMIAL_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, - [ChainSlug.BOB]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.KINTO]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.KINTO_DEVNET]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.SIPHER_FUNKI_TESTNET]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.WINR]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.BLAST]: { - type: FinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, - }, - [ChainSlug.BSC_TESTNET]: { - type: FinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, - }, +}; + +export const getFinality = (chainSlug: ChainSlug): ChainFinalityInfo => { + let finalityOverride = finality[chainSlug]; + // if override exists, return it + if (finalityOverride) return finalityOverride; + + if (chainsWithZeroBlockFinality.includes(chainSlug)) { + return zeroBlockFinalityDefault; + } + if (polygonCDKChains.includes(chainSlug)) { + return polygonCDKChainsDefault; + } + if (opStackL2Chain.includes(chainSlug)) { + return opStackL2ChainDefault; + } + if (arbL3Chains.includes(chainSlug)) { + return arbL3ChainsDefault; + } + return defaultFinality; }; diff --git a/scripts/rpcConfig/rpcConfig.ts b/scripts/rpcConfig/rpcConfig.ts index 8fa7eb25..189aacd2 100644 --- a/scripts/rpcConfig/rpcConfig.ts +++ b/scripts/rpcConfig/rpcConfig.ts @@ -26,7 +26,7 @@ import { prodFeesUpdaterSupportedChainSlugs, rpcs, version, - finality, + getFinality, } from "./constants"; import { getChainTxData } from "./txdata-builder/generate-calldata"; @@ -93,7 +93,7 @@ const getChainData = async ( nativeToken: getCurrency(chainSlug), chainType: getChainType(chainSlug), confirmations: confirmations[chainSlug], - finalityInfo: finality[chainSlug], + finalityInfo: getFinality(chainSlug), icon: icons[chainSlug], }; }; diff --git a/src/socket-types.ts b/src/socket-types.ts index 66c5b77f..54e8e47e 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -212,14 +212,19 @@ export enum FinalityBucket { slow = 3, } -export enum FinalityType { +export enum TransmissionParamFinalityType { bucket = 1, block = 2, time = 3, } +export enum BucketFinalityType { + block = 1, + time = 2, +} + export type ChainFinalityInfo = { - type: FinalityType; + type: BucketFinalityType; defaultBucket: FinalityBucket; [FinalityBucket.fast]: { block: number; diff --git a/src/transmission-utils.ts b/src/transmission-utils.ts index c5123866..59d790c7 100644 --- a/src/transmission-utils.ts +++ b/src/transmission-utils.ts @@ -1,13 +1,28 @@ -import { FinalityType } from "./socket-types"; +import { BucketFinalityType } from "./socket-types"; + +/* +Transmission param format: +- first byte - version - current version is 1 +- 2nd byte - finalityType - specify if using buckets, block, or time. (1: bucket, 2: block, 3: time) +- next 4 bytes - value - bucket (1:fast, 2:medium, 3:slow), block (min block confirmations) or time (min time elapsed) + +eg : want to transmit message with slow speed - +transmissionParam = 0x0101000000030000000000000000000000000000000000000000000000000000 + +eg : want to transmit message with fast speed - +transmissionParam = 0x0101000000010000000000000000000000000000000000000000000000000000 + +if version is 0, or invalid finality type, or invalid value is mentioned, it will use the default Bucket for that chain +*/ export const decodeTransmissionParams = (transmissionParam: string) => { if (transmissionParam.length !== 64 && transmissionParam.length !== 66) { throw new Error("Invalid transmission param length"); } transmissionParam = transmissionParam.replace("0x", ""); - const version = parseInt("0x" + transmissionParam.slice(0, 2)); // version 1 - const finalityType = parseInt("0x" + transmissionParam.slice(2, 4)); // bucket, block, time - const value = parseInt("0x" + transmissionParam.slice(4, 12)); // bucket (see FinalityBucket enum), block (block number), time value in seconds + const version = parseInt("0x" + transmissionParam.slice(0, 2)); + const finalityType = parseInt("0x" + transmissionParam.slice(2, 4)); + const value = parseInt("0x" + transmissionParam.slice(4, 12)); return { version, finalityType, value }; }; @@ -25,28 +40,27 @@ export const encodeTransmissionParams = ( return transmissionParam; }; -export const isTxFinalized = (data: { - type: FinalityType; - currentBlock: number; - eventBlock: number; - currentTime: number; - eventTime: number; - finalityBlockDiff: number; - finalityTimeDiff: number; -}) => { - if (data.type === FinalityType.block) { - const { currentBlock, eventBlock, finalityBlockDiff } = data; +export const isTxFinalized = ( + type: BucketFinalityType, + currentBlock: number, + eventBlock: number, + currentTime: number, + eventTime: number, + finalityBlockDiff: number, + finalityTimeDiff: number +) => { + if (type === BucketFinalityType.block) { if (!currentBlock || !eventBlock || !finalityBlockDiff) { console.log("Invalid data for block finality check"); return false; } return currentBlock - eventBlock >= finalityBlockDiff; - } else if (data.type === FinalityType.time) { - if (!data.currentTime || !data.eventTime || !data.finalityTimeDiff) { + } else if (type === BucketFinalityType.time) { + if (!currentTime || !eventTime || !finalityTimeDiff) { console.log("Invalid data for time finality check"); return false; } - return data.currentTime - data.eventTime >= data.finalityTimeDiff; + return currentTime - eventTime >= finalityTimeDiff; } else { console.log("Invalid finality type"); return false; From f9e5867b8f1e6d4a6f50308ab5463c130ba9b4a1 Mon Sep 17 00:00:00 2001 From: Akash Date: Wed, 12 Jun 2024 13:32:55 +0530 Subject: [PATCH 08/14] fix : comments, cleanup --- package.json | 2 +- scripts/rpcConfig/constants/finality.ts | 203 +++++------------- .../constants/zeroBlockFinalityChains.ts | 12 ++ src/index.ts | 2 +- src/socket-types.ts | 21 +- src/transmission-utils.ts | 39 ++-- 6 files changed, 92 insertions(+), 187 deletions(-) create mode 100644 scripts/rpcConfig/constants/zeroBlockFinalityChains.ts diff --git a/package.json b/package.json index 3bfdbbd1..c1030eea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@socket.tech/dl-core", "license": "UNLICENSED", - "version": "2.10.0-test.1", + "version": "2.10.0-test.2", "description": "Smart contracts for socket data layer.", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index 759c9b9a..a090d857 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -3,209 +3,102 @@ import { ChainSlug } from "../../../src/enums/chainSlug"; import { FinalityBucket, - BucketFinalityType, + ChainFinalityType, ChainFinalityInfo, } from "../../../src/socket-types"; +import { chainsWithZeroBlockFinality } from "./zeroBlockFinalityChains"; -const chainsWithZeroBlockFinality = [ - ChainSlug.REYA, - ChainSlug.BOB, - ChainSlug.KINTO, - ChainSlug.KINTO_DEVNET, - ChainSlug.SIPHER_FUNKI_TESTNET, - ChainSlug.WINR, - ChainSlug.BLAST, -]; const zeroBlockFinalityDefault = { - type: BucketFinalityType.time, + type: ChainFinalityType.time, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 0, - time: 30, - }, - [FinalityBucket.medium]: { - time: 60, - block: 0, - }, - [FinalityBucket.slow]: { - time: 120, - block: 0, - }, + [FinalityBucket.fast]:30, + [FinalityBucket.medium]:60, + [FinalityBucket.slow]:120 }; const polygonCDKChainsDefault = { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]: 1, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]:20, }; const opStackL2ChainDefault = { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]:1, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]:20, }; const arbL3ChainsDefault = { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]:1, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]: 20, }; const defaultFinality = { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 1, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]:1, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]:20, }; -export const finality: { +export const finalityOverrides: { [chainSlug in ChainSlug]?: ChainFinalityInfo; } = { [ChainSlug.AEVO]: { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 2, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]:2, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]:20, }, [ChainSlug.LYRA]: { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 2, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]:2, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]:20, }, [ChainSlug.OPTIMISM]: { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 15, - time: 0, - }, - [FinalityBucket.medium]: { - block: 30, - time: 0, - }, - [FinalityBucket.slow]: { - block: 40, - time: 0, - }, + [FinalityBucket.fast]:15, + [FinalityBucket.medium]:30, + [FinalityBucket.slow]:40, }, [ChainSlug.POLYGON_MAINNET]: { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.slow, - [FinalityBucket.fast]: { - block: 50, - time: 0, - }, - [FinalityBucket.medium]: { - block: 150, - time: 0, - }, - [FinalityBucket.slow]: { - block: 256, - time: 0, - }, + [FinalityBucket.fast]:50, + [FinalityBucket.medium]:150, + [FinalityBucket.slow]:256, }, [ChainSlug.MAINNET]: { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.slow, - [FinalityBucket.fast]: { - block: 6, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 18, - time: 0, - }, + [FinalityBucket.fast]:6, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]:18, }, [ChainSlug.MODE]: { - type: BucketFinalityType.block, + type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: { - block: 2, - time: 0, - }, - [FinalityBucket.medium]: { - block: 10, - time: 0, - }, - [FinalityBucket.slow]: { - block: 20, - time: 0, - }, + [FinalityBucket.fast]:2, + [FinalityBucket.medium]:10, + [FinalityBucket.slow]:20, }, }; export const getFinality = (chainSlug: ChainSlug): ChainFinalityInfo => { - let finalityOverride = finality[chainSlug]; + let finalityOverride = finalityOverrides[chainSlug]; // if override exists, return it if (finalityOverride) return finalityOverride; diff --git a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts new file mode 100644 index 00000000..4cd74372 --- /dev/null +++ b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts @@ -0,0 +1,12 @@ +import { ChainSlug } from "../../../src"; + + +export const chainsWithZeroBlockFinality = [ + ChainSlug.REYA, + ChainSlug.BOB, + ChainSlug.KINTO, + ChainSlug.KINTO_DEVNET, + ChainSlug.SIPHER_FUNKI_TESTNET, + ChainSlug.WINR, + ChainSlug.BLAST, + ]; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 361111da..aa1241ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { DeploymentMode } from "./socket-types"; -export { finality } from "../scripts/rpcConfig/constants/finality"; +export { getFinality } from "../scripts/rpcConfig/constants/finality"; export * from "./socket-types"; export * from "./enums"; export * from "./addresses"; diff --git a/src/socket-types.ts b/src/socket-types.ts index 54e8e47e..b9cdd99c 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -214,30 +214,19 @@ export enum FinalityBucket { export enum TransmissionParamFinalityType { bucket = 1, - block = 2, - time = 3, } -export enum BucketFinalityType { +export enum ChainFinalityType { block = 1, time = 2, } export type ChainFinalityInfo = { - type: BucketFinalityType; + type: ChainFinalityType; defaultBucket: FinalityBucket; - [FinalityBucket.fast]: { - block: number; - time: number; - }; - [FinalityBucket.medium]: { - block: number; - time: number; - }; - [FinalityBucket.slow]: { - block: number; - time: number; - }; + [FinalityBucket.fast]:number; + [FinalityBucket.medium]:number; + [FinalityBucket.slow]:number; }; export type TxData = { diff --git a/src/transmission-utils.ts b/src/transmission-utils.ts index 59d790c7..95860717 100644 --- a/src/transmission-utils.ts +++ b/src/transmission-utils.ts @@ -1,10 +1,10 @@ -import { BucketFinalityType } from "./socket-types"; +import { ChainFinalityType } from "./socket-types"; /* Transmission param format: - first byte - version - current version is 1 -- 2nd byte - finalityType - specify if using buckets, block, or time. (1: bucket, 2: block, 3: time) -- next 4 bytes - value - bucket (1:fast, 2:medium, 3:slow), block (min block confirmations) or time (min time elapsed) +- 2nd byte - finalityType (1: bucket) +- next 4 bytes - value - bucket (1:fast, 2:medium, 3:slow) eg : want to transmit message with slow speed - transmissionParam = 0x0101000000030000000000000000000000000000000000000000000000000000 @@ -41,7 +41,7 @@ export const encodeTransmissionParams = ( }; export const isTxFinalized = ( - type: BucketFinalityType, + type: ChainFinalityType, currentBlock: number, eventBlock: number, currentTime: number, @@ -49,20 +49,31 @@ export const isTxFinalized = ( finalityBlockDiff: number, finalityTimeDiff: number ) => { - if (type === BucketFinalityType.block) { - if (!currentBlock || !eventBlock || !finalityBlockDiff) { - console.log("Invalid data for block finality check"); - return false; + if (type === ChainFinalityType.block) { + if ( + currentBlock == null || + currentBlock == undefined || + eventBlock == null || + eventBlock == undefined || + finalityBlockDiff == null || + finalityBlockDiff == undefined + ) { + throw new Error("Invalid data for block finality check"); } return currentBlock - eventBlock >= finalityBlockDiff; - } else if (type === BucketFinalityType.time) { - if (!currentTime || !eventTime || !finalityTimeDiff) { - console.log("Invalid data for time finality check"); - return false; + } else if (type === ChainFinalityType.time) { + if ( + currentTime == null || + currentTime == undefined || + eventTime == null || + eventTime == undefined || + finalityTimeDiff == null || + finalityTimeDiff == undefined + ) { + throw new Error("Invalid data for time finality check"); } return currentTime - eventTime >= finalityTimeDiff; } else { - console.log("Invalid finality type"); - return false; + throw new Error("Invalid finality type"); } }; From 306343347effd07b3953eb5812d76d831084b86c Mon Sep 17 00:00:00 2001 From: Akash Date: Wed, 12 Jun 2024 13:33:23 +0530 Subject: [PATCH 09/14] chore: lint --- scripts/rpcConfig/constants/finality.ts | 61 +++++++++---------- .../constants/zeroBlockFinalityChains.ts | 17 +++--- src/socket-types.ts | 6 +- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index a090d857..0f649b57 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -8,13 +8,12 @@ import { } from "../../../src/socket-types"; import { chainsWithZeroBlockFinality } from "./zeroBlockFinalityChains"; - const zeroBlockFinalityDefault = { type: ChainFinalityType.time, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:30, - [FinalityBucket.medium]:60, - [FinalityBucket.slow]:120 + [FinalityBucket.fast]: 30, + [FinalityBucket.medium]: 60, + [FinalityBucket.slow]: 120, }; const polygonCDKChainsDefault = { @@ -22,31 +21,31 @@ const polygonCDKChainsDefault = { defaultBucket: FinalityBucket.fast, [FinalityBucket.fast]: 1, [FinalityBucket.medium]: 10, - [FinalityBucket.slow]:20, + [FinalityBucket.slow]: 20, }; const opStackL2ChainDefault = { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:1, - [FinalityBucket.medium]:10, - [FinalityBucket.slow]:20, + [FinalityBucket.fast]: 1, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]: 20, }; const arbL3ChainsDefault = { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:1, - [FinalityBucket.medium]:10, + [FinalityBucket.fast]: 1, + [FinalityBucket.medium]: 10, [FinalityBucket.slow]: 20, }; const defaultFinality = { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:1, - [FinalityBucket.medium]:10, - [FinalityBucket.slow]:20, + [FinalityBucket.fast]: 1, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]: 20, }; export const finalityOverrides: { @@ -55,45 +54,45 @@ export const finalityOverrides: { [ChainSlug.AEVO]: { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:2, - [FinalityBucket.medium]:10, - [FinalityBucket.slow]:20, + [FinalityBucket.fast]: 2, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]: 20, }, [ChainSlug.LYRA]: { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:2, - [FinalityBucket.medium]:10, - [FinalityBucket.slow]:20, + [FinalityBucket.fast]: 2, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]: 20, }, [ChainSlug.OPTIMISM]: { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:15, - [FinalityBucket.medium]:30, - [FinalityBucket.slow]:40, + [FinalityBucket.fast]: 15, + [FinalityBucket.medium]: 30, + [FinalityBucket.slow]: 40, }, [ChainSlug.POLYGON_MAINNET]: { type: ChainFinalityType.block, defaultBucket: FinalityBucket.slow, - [FinalityBucket.fast]:50, - [FinalityBucket.medium]:150, - [FinalityBucket.slow]:256, + [FinalityBucket.fast]: 50, + [FinalityBucket.medium]: 150, + [FinalityBucket.slow]: 256, }, [ChainSlug.MAINNET]: { type: ChainFinalityType.block, defaultBucket: FinalityBucket.slow, - [FinalityBucket.fast]:6, - [FinalityBucket.medium]:10, - [FinalityBucket.slow]:18, + [FinalityBucket.fast]: 6, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]: 18, }, [ChainSlug.MODE]: { type: ChainFinalityType.block, defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]:2, - [FinalityBucket.medium]:10, - [FinalityBucket.slow]:20, + [FinalityBucket.fast]: 2, + [FinalityBucket.medium]: 10, + [FinalityBucket.slow]: 20, }, }; diff --git a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts index 4cd74372..2e98005c 100644 --- a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts +++ b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts @@ -1,12 +1,11 @@ import { ChainSlug } from "../../../src"; - export const chainsWithZeroBlockFinality = [ - ChainSlug.REYA, - ChainSlug.BOB, - ChainSlug.KINTO, - ChainSlug.KINTO_DEVNET, - ChainSlug.SIPHER_FUNKI_TESTNET, - ChainSlug.WINR, - ChainSlug.BLAST, - ]; \ No newline at end of file + ChainSlug.REYA, + ChainSlug.BOB, + ChainSlug.KINTO, + ChainSlug.KINTO_DEVNET, + ChainSlug.SIPHER_FUNKI_TESTNET, + ChainSlug.WINR, + ChainSlug.BLAST, +]; diff --git a/src/socket-types.ts b/src/socket-types.ts index b9cdd99c..00bba999 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -224,9 +224,9 @@ export enum ChainFinalityType { export type ChainFinalityInfo = { type: ChainFinalityType; defaultBucket: FinalityBucket; - [FinalityBucket.fast]:number; - [FinalityBucket.medium]:number; - [FinalityBucket.slow]:number; + [FinalityBucket.fast]: number; + [FinalityBucket.medium]: number; + [FinalityBucket.slow]: number; }; export type TxData = { From c29e5af25c52f847b2f94f80183ec8a989dffbaf Mon Sep 17 00:00:00 2001 From: Akash Date: Wed, 12 Jun 2024 13:34:01 +0530 Subject: [PATCH 10/14] fix : dl api base url --- scripts/deploy/helpers/send-msg/allPathTest.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/deploy/helpers/send-msg/allPathTest.ts b/scripts/deploy/helpers/send-msg/allPathTest.ts index bd16f732..e5b4e4db 100644 --- a/scripts/deploy/helpers/send-msg/allPathTest.ts +++ b/scripts/deploy/helpers/send-msg/allPathTest.ts @@ -9,15 +9,16 @@ import { isTestnet, isMainnet, CORE_CONTRACTS, + DeploymentMode, } from "../../../../src"; import { getAddresses, getRelayUrl, getRelayAPIKEY } from "../../utils"; import { BigNumber, Contract, ethers } from "ethers"; import Counter from "../../../../out/Counter.sol/Counter.json"; import Socket from "../../../../out/Socket.sol/Socket.json"; -import { chains, mode, overrides } from "../../config"; import { getProviderFromChainSlug } from "../../../constants/networks"; import { formatEther } from "ethers/lib/utils"; +import { chains, mode, overrides } from "../../config/config"; interface RequestObj { to: string; @@ -28,6 +29,10 @@ interface RequestObj { gasLimit: string | number | undefined; } +const API_BASE_URL = + mode == DeploymentMode.DEV + ? "https://raf5spoep4.execute-api.us-east-1.amazonaws.com/dev/v1" + : "https://prod.dlapi.socket.tech"; const getSiblingSlugs = (chainSlug: ChainSlug): ChainSlug[] => { console.log(chainSlug, isMainnet(chainSlug)); if (isTestnet(chainSlug)) @@ -208,7 +213,7 @@ export const sendMessagesToAllPaths = async (params: { provider ); console.log( - `Track message here: https://prod.dlapi.socket.tech/messages-from-tx?srcChainSlug=${chainSlug}&srcTxHash=${response?.hash}` + `Track message here: ${API_BASE_URL}/messages-from-tx?srcChainSlug=${chainSlug}&srcTxHash=${response?.hash}` ); }) ); From 7269de53185c44011e1480c3814499ab2fc0e31b Mon Sep 17 00:00:00 2001 From: Akash Date: Wed, 12 Jun 2024 13:43:41 +0530 Subject: [PATCH 11/14] fix : build --- scripts/rpcConfig/constants/zeroBlockFinalityChains.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts index 2e98005c..1ed0cd85 100644 --- a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts +++ b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts @@ -1,4 +1,4 @@ -import { ChainSlug } from "../../../src"; +import { ChainSlug } from "../../../src/enums/chainSlug"; export const chainsWithZeroBlockFinality = [ ChainSlug.REYA, From 40ce36242c4286af62a7ac33b7b3bf93162f1152 Mon Sep 17 00:00:00 2001 From: Akash Date: Sat, 15 Jun 2024 19:50:29 +0530 Subject: [PATCH 12/14] fix : update for safe and finalized --- scripts/rpcConfig/constants/confirmations.ts | 40 +------ .../constants/defaultFinalityBucket.ts | 8 ++ scripts/rpcConfig/constants/finality.ts | 108 +----------------- .../constants/zeroBlockFinalityChains.ts | 11 -- scripts/rpcConfig/rpcConfig.ts | 22 +++- src/socket-types.ts | 14 +-- src/transmission-utils.ts | 44 ++----- 7 files changed, 46 insertions(+), 201 deletions(-) create mode 100644 scripts/rpcConfig/constants/defaultFinalityBucket.ts delete mode 100644 scripts/rpcConfig/constants/zeroBlockFinalityChains.ts diff --git a/scripts/rpcConfig/constants/confirmations.ts b/scripts/rpcConfig/constants/confirmations.ts index 2122152d..72099c9b 100644 --- a/scripts/rpcConfig/constants/confirmations.ts +++ b/scripts/rpcConfig/constants/confirmations.ts @@ -1,44 +1,6 @@ import { ChainSlug } from "../../../src"; export const confirmations = { - [ChainSlug.AEVO]: 2, - [ChainSlug.ARBITRUM]: 1, - [ChainSlug.LYRA]: 2, - [ChainSlug.OPTIMISM]: 15, - [ChainSlug.BSC]: 1, [ChainSlug.POLYGON_MAINNET]: 256, - [ChainSlug.MAINNET]: 18, - [ChainSlug.BASE]: 1, - [ChainSlug.MODE]: 2, - [ChainSlug.ARBITRUM_GOERLI]: 1, - [ChainSlug.AEVO_TESTNET]: 1, - [ChainSlug.LYRA_TESTNET]: 1, - [ChainSlug.OPTIMISM_GOERLI]: 1, - [ChainSlug.GOERLI]: 1, - [ChainSlug.XAI_TESTNET]: 1, - [ChainSlug.SX_NETWORK_TESTNET]: 1, - [ChainSlug.SX_NETWORK]: 1, - [ChainSlug.MODE_TESTNET]: 1, - [ChainSlug.VICTION_TESTNET]: 1, - [ChainSlug.CDK_TESTNET]: 1, - [ChainSlug.ARBITRUM_SEPOLIA]: 1, - [ChainSlug.OPTIMISM_SEPOLIA]: 1, - [ChainSlug.SEPOLIA]: 1, - [ChainSlug.ANCIENT8_TESTNET]: 1, - [ChainSlug.ANCIENT8_TESTNET2]: 1, - [ChainSlug.HOOK_TESTNET]: 1, - [ChainSlug.HOOK]: 1, - [ChainSlug.PARALLEL]: 1, - [ChainSlug.MANTLE]: 1, - [ChainSlug.REYA_CRONOS]: 1, - [ChainSlug.REYA]: 0, - [ChainSlug.SYNDR_SEPOLIA_L3]: 1, - [ChainSlug.POLYNOMIAL_TESTNET]: 1, - [ChainSlug.BOB]: 0, - [ChainSlug.KINTO]: 0, - [ChainSlug.KINTO_DEVNET]: 0, - [ChainSlug.SIPHER_FUNKI_TESTNET]: 0, - [ChainSlug.WINR]: 0, - [ChainSlug.BLAST]: 0, - [ChainSlug.BSC_TESTNET]: 1, + [ChainSlug.MAINNET]: 6, }; diff --git a/scripts/rpcConfig/constants/defaultFinalityBucket.ts b/scripts/rpcConfig/constants/defaultFinalityBucket.ts new file mode 100644 index 00000000..2ef68df1 --- /dev/null +++ b/scripts/rpcConfig/constants/defaultFinalityBucket.ts @@ -0,0 +1,8 @@ +import { ChainSlug } from "../../../src/enums/chainSlug"; + +import { FinalityBucket } from "../../../src/socket-types"; + +export const defaultFinalityBucket = { + [ChainSlug.POLYGON_MAINNET]: FinalityBucket.slow, + [ChainSlug.MAINNET]: FinalityBucket.medium, +}; diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index 0f649b57..b37c5de2 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -1,117 +1,13 @@ -import { arbL3Chains, opStackL2Chain, polygonCDKChains } from "../../../src"; import { ChainSlug } from "../../../src/enums/chainSlug"; -import { - FinalityBucket, - ChainFinalityType, - ChainFinalityInfo, -} from "../../../src/socket-types"; -import { chainsWithZeroBlockFinality } from "./zeroBlockFinalityChains"; - -const zeroBlockFinalityDefault = { - type: ChainFinalityType.time, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 30, - [FinalityBucket.medium]: 60, - [FinalityBucket.slow]: 120, -}; - -const polygonCDKChainsDefault = { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 1, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, -}; - -const opStackL2ChainDefault = { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 1, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, -}; - -const arbL3ChainsDefault = { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 1, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, -}; - -const defaultFinality = { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 1, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, -}; +import { ChainFinalityInfo, FinalityBucket } from "../../../src/socket-types"; export const finalityOverrides: { [chainSlug in ChainSlug]?: ChainFinalityInfo; } = { - [ChainSlug.AEVO]: { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 2, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, - }, - - [ChainSlug.LYRA]: { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 2, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, - }, - [ChainSlug.OPTIMISM]: { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 15, - [FinalityBucket.medium]: 30, - [FinalityBucket.slow]: 40, - }, [ChainSlug.POLYGON_MAINNET]: { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.slow, - [FinalityBucket.fast]: 50, + [FinalityBucket.fast]: 64, [FinalityBucket.medium]: 150, [FinalityBucket.slow]: 256, }, - [ChainSlug.MAINNET]: { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.slow, - [FinalityBucket.fast]: 6, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 18, - }, - [ChainSlug.MODE]: { - type: ChainFinalityType.block, - defaultBucket: FinalityBucket.fast, - [FinalityBucket.fast]: 2, - [FinalityBucket.medium]: 10, - [FinalityBucket.slow]: 20, - }, -}; - -export const getFinality = (chainSlug: ChainSlug): ChainFinalityInfo => { - let finalityOverride = finalityOverrides[chainSlug]; - // if override exists, return it - if (finalityOverride) return finalityOverride; - - if (chainsWithZeroBlockFinality.includes(chainSlug)) { - return zeroBlockFinalityDefault; - } - if (polygonCDKChains.includes(chainSlug)) { - return polygonCDKChainsDefault; - } - if (opStackL2Chain.includes(chainSlug)) { - return opStackL2ChainDefault; - } - if (arbL3Chains.includes(chainSlug)) { - return arbL3ChainsDefault; - } - return defaultFinality; }; diff --git a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts b/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts deleted file mode 100644 index 1ed0cd85..00000000 --- a/scripts/rpcConfig/constants/zeroBlockFinalityChains.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { ChainSlug } from "../../../src/enums/chainSlug"; - -export const chainsWithZeroBlockFinality = [ - ChainSlug.REYA, - ChainSlug.BOB, - ChainSlug.KINTO, - ChainSlug.KINTO_DEVNET, - ChainSlug.SIPHER_FUNKI_TESTNET, - ChainSlug.WINR, - ChainSlug.BLAST, -]; diff --git a/scripts/rpcConfig/rpcConfig.ts b/scripts/rpcConfig/rpcConfig.ts index 189aacd2..1b0a0147 100644 --- a/scripts/rpcConfig/rpcConfig.ts +++ b/scripts/rpcConfig/rpcConfig.ts @@ -17,6 +17,8 @@ import { arbL3Chains, polygonCDKChains, S3ChainConfig, + ChainFinalityInfo, + FinalityBucket, } from "../../src"; import { confirmations, @@ -26,8 +28,9 @@ import { prodFeesUpdaterSupportedChainSlugs, rpcs, version, - getFinality, + finalityOverrides, } from "./constants"; +import { defaultFinalityBucket } from "./constants/defaultFinalityBucket"; import { getChainTxData } from "./txdata-builder/generate-calldata"; import dotenv from "dotenv"; @@ -92,8 +95,9 @@ const getChainData = async ( chainTxData: await getChainTxData(chainSlug, txData), nativeToken: getCurrency(chainSlug), chainType: getChainType(chainSlug), - confirmations: confirmations[chainSlug], + confirmations: getConfirmations(chainSlug), finalityInfo: getFinality(chainSlug), + defaultFinalityBucket: getDefaultFinalityBucket(chainSlug), icon: icons[chainSlug], }; }; @@ -160,3 +164,17 @@ export const generateProdConfig = async (txData: TxData): Promise => { chainSlugToId: ChainSlugToId, }; }; + +export const getFinality = (chainSlug: ChainSlug): ChainFinalityInfo => { + return finalityOverrides[chainSlug]; +}; + +export const getDefaultFinalityBucket = ( + chainSlug: ChainSlug +): FinalityBucket => { + return defaultFinalityBucket[chainSlug] ?? FinalityBucket.fast; +}; + +export const getConfirmations = (chainSlug: ChainSlug) => { + return confirmations[chainSlug] ?? 0; +}; diff --git a/src/socket-types.ts b/src/socket-types.ts index 00bba999..584313cf 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -207,23 +207,16 @@ export enum ChainType { } export enum FinalityBucket { - fast = 1, - medium = 2, - slow = 3, + fast = 1, // latest + medium = 2, // safe + slow = 3, // finalized } export enum TransmissionParamFinalityType { bucket = 1, } -export enum ChainFinalityType { - block = 1, - time = 2, -} - export type ChainFinalityInfo = { - type: ChainFinalityType; - defaultBucket: FinalityBucket; [FinalityBucket.fast]: number; [FinalityBucket.medium]: number; [FinalityBucket.slow]: number; @@ -253,6 +246,7 @@ export interface S3ChainConfig { explorer?: string; icon?: string; finalityInfo?: ChainFinalityInfo; + defaultFinalityBucket?: FinalityBucket; } export type S3Config = { diff --git a/src/transmission-utils.ts b/src/transmission-utils.ts index 95860717..7467d96d 100644 --- a/src/transmission-utils.ts +++ b/src/transmission-utils.ts @@ -1,5 +1,3 @@ -import { ChainFinalityType } from "./socket-types"; - /* Transmission param format: - first byte - version - current version is 1 @@ -41,39 +39,19 @@ export const encodeTransmissionParams = ( }; export const isTxFinalized = ( - type: ChainFinalityType, currentBlock: number, eventBlock: number, - currentTime: number, - eventTime: number, - finalityBlockDiff: number, - finalityTimeDiff: number + finalityBlockDiff: number ) => { - if (type === ChainFinalityType.block) { - if ( - currentBlock == null || - currentBlock == undefined || - eventBlock == null || - eventBlock == undefined || - finalityBlockDiff == null || - finalityBlockDiff == undefined - ) { - throw new Error("Invalid data for block finality check"); - } - return currentBlock - eventBlock >= finalityBlockDiff; - } else if (type === ChainFinalityType.time) { - if ( - currentTime == null || - currentTime == undefined || - eventTime == null || - eventTime == undefined || - finalityTimeDiff == null || - finalityTimeDiff == undefined - ) { - throw new Error("Invalid data for time finality check"); - } - return currentTime - eventTime >= finalityTimeDiff; - } else { - throw new Error("Invalid finality type"); + if ( + currentBlock == null || + currentBlock == undefined || + eventBlock == null || + eventBlock == undefined || + finalityBlockDiff == null || + finalityBlockDiff == undefined + ) { + throw new Error("Invalid data for block finality check"); } + return currentBlock - eventBlock >= finalityBlockDiff; }; From ad0276b6b59f0d9bea31bd981cc066400293c038 Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 18 Jun 2024 16:31:25 +0530 Subject: [PATCH 13/14] chore : cleanup --- package.json | 2 +- scripts/rpcConfig/constants/finality.ts | 6 ++++++ scripts/rpcConfig/rpcConfig.ts | 7 +------ 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index c1030eea..fbc8a879 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@socket.tech/dl-core", "license": "UNLICENSED", - "version": "2.10.0-test.2", + "version": "2.10.0-test.5", "description": "Smart contracts for socket data layer.", "main": "./dist/src/index.js", "types": "./dist/src/index.d.ts", diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index b37c5de2..d82a83aa 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -2,6 +2,12 @@ import { ChainSlug } from "../../../src/enums/chainSlug"; import { ChainFinalityInfo, FinalityBucket } from "../../../src/socket-types"; +export const getFinality = ( + chainSlug: ChainSlug +): ChainFinalityInfo | undefined => { + return finalityOverrides[chainSlug]; +}; + export const finalityOverrides: { [chainSlug in ChainSlug]?: ChainFinalityInfo; } = { diff --git a/scripts/rpcConfig/rpcConfig.ts b/scripts/rpcConfig/rpcConfig.ts index 1b0a0147..801b8646 100644 --- a/scripts/rpcConfig/rpcConfig.ts +++ b/scripts/rpcConfig/rpcConfig.ts @@ -17,7 +17,6 @@ import { arbL3Chains, polygonCDKChains, S3ChainConfig, - ChainFinalityInfo, FinalityBucket, } from "../../src"; import { @@ -28,7 +27,7 @@ import { prodFeesUpdaterSupportedChainSlugs, rpcs, version, - finalityOverrides, + getFinality, } from "./constants"; import { defaultFinalityBucket } from "./constants/defaultFinalityBucket"; import { getChainTxData } from "./txdata-builder/generate-calldata"; @@ -165,10 +164,6 @@ export const generateProdConfig = async (txData: TxData): Promise => { }; }; -export const getFinality = (chainSlug: ChainSlug): ChainFinalityInfo => { - return finalityOverrides[chainSlug]; -}; - export const getDefaultFinalityBucket = ( chainSlug: ChainSlug ): FinalityBucket => { From 8eb8710c8b02abd24ef36ea5c950506db6b27e6b Mon Sep 17 00:00:00 2001 From: Akash Date: Tue, 18 Jun 2024 18:49:35 +0530 Subject: [PATCH 14/14] fix : rename confirmations,polygon finality update --- scripts/rpcConfig/constants/defaultFinalityBucket.ts | 2 +- scripts/rpcConfig/constants/finality.ts | 4 ++-- scripts/rpcConfig/constants/index.ts | 2 +- .../constants/{confirmations.ts => reSyncInterval.ts} | 2 +- scripts/rpcConfig/rpcConfig.ts | 8 ++++---- src/socket-types.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) rename scripts/rpcConfig/constants/{confirmations.ts => reSyncInterval.ts} (77%) diff --git a/scripts/rpcConfig/constants/defaultFinalityBucket.ts b/scripts/rpcConfig/constants/defaultFinalityBucket.ts index 2ef68df1..0e07a4e0 100644 --- a/scripts/rpcConfig/constants/defaultFinalityBucket.ts +++ b/scripts/rpcConfig/constants/defaultFinalityBucket.ts @@ -3,6 +3,6 @@ import { ChainSlug } from "../../../src/enums/chainSlug"; import { FinalityBucket } from "../../../src/socket-types"; export const defaultFinalityBucket = { - [ChainSlug.POLYGON_MAINNET]: FinalityBucket.slow, + [ChainSlug.POLYGON_MAINNET]: FinalityBucket.medium, [ChainSlug.MAINNET]: FinalityBucket.medium, }; diff --git a/scripts/rpcConfig/constants/finality.ts b/scripts/rpcConfig/constants/finality.ts index d82a83aa..75a1a162 100644 --- a/scripts/rpcConfig/constants/finality.ts +++ b/scripts/rpcConfig/constants/finality.ts @@ -13,7 +13,7 @@ export const finalityOverrides: { } = { [ChainSlug.POLYGON_MAINNET]: { [FinalityBucket.fast]: 64, - [FinalityBucket.medium]: 150, - [FinalityBucket.slow]: 256, + [FinalityBucket.medium]: 256, + [FinalityBucket.slow]: 1000, }, }; diff --git a/scripts/rpcConfig/constants/index.ts b/scripts/rpcConfig/constants/index.ts index 9213ce92..701451b6 100644 --- a/scripts/rpcConfig/constants/index.ts +++ b/scripts/rpcConfig/constants/index.ts @@ -1,5 +1,5 @@ export * from "./batcherSupportedChainSlug"; -export * from "./confirmations"; +export * from "./reSyncInterval"; export * from "./explorers"; export * from "./icons"; export * from "./rpc"; diff --git a/scripts/rpcConfig/constants/confirmations.ts b/scripts/rpcConfig/constants/reSyncInterval.ts similarity index 77% rename from scripts/rpcConfig/constants/confirmations.ts rename to scripts/rpcConfig/constants/reSyncInterval.ts index 72099c9b..91ecbcd9 100644 --- a/scripts/rpcConfig/constants/confirmations.ts +++ b/scripts/rpcConfig/constants/reSyncInterval.ts @@ -1,6 +1,6 @@ import { ChainSlug } from "../../../src"; -export const confirmations = { +export const reSyncInterval = { [ChainSlug.POLYGON_MAINNET]: 256, [ChainSlug.MAINNET]: 6, }; diff --git a/scripts/rpcConfig/rpcConfig.ts b/scripts/rpcConfig/rpcConfig.ts index 801b8646..cdc8d210 100644 --- a/scripts/rpcConfig/rpcConfig.ts +++ b/scripts/rpcConfig/rpcConfig.ts @@ -20,7 +20,7 @@ import { FinalityBucket, } from "../../src"; import { - confirmations, + reSyncInterval, explorers, icons, batcherSupportedChainSlugs, @@ -94,7 +94,7 @@ const getChainData = async ( chainTxData: await getChainTxData(chainSlug, txData), nativeToken: getCurrency(chainSlug), chainType: getChainType(chainSlug), - confirmations: getConfirmations(chainSlug), + reSyncInterval: getReSyncInterval(chainSlug), finalityInfo: getFinality(chainSlug), defaultFinalityBucket: getDefaultFinalityBucket(chainSlug), icon: icons[chainSlug], @@ -170,6 +170,6 @@ export const getDefaultFinalityBucket = ( return defaultFinalityBucket[chainSlug] ?? FinalityBucket.fast; }; -export const getConfirmations = (chainSlug: ChainSlug) => { - return confirmations[chainSlug] ?? 0; +export const getReSyncInterval = (chainSlug: ChainSlug) => { + return reSyncInterval[chainSlug] ?? 0; }; diff --git a/src/socket-types.ts b/src/socket-types.ts index 584313cf..afb2b056 100644 --- a/src/socket-types.ts +++ b/src/socket-types.ts @@ -236,7 +236,7 @@ export interface ChainTxData { export interface S3ChainConfig { rpc: string; blockNumber: number; - confirmations: number; + reSyncInterval: number; siblings: ChainSlug[]; chainName: string; eventBlockRange?: number;