Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : plug specific security #378

Merged
merged 17 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@socket.tech/dl-core",
"license": "UNLICENSED",
"version": "2.9.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",
Expand Down Expand Up @@ -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",
Expand Down
225 changes: 225 additions & 0 deletions scripts/rpcConfig/constants/finality.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
import { arbL3Chains, opStackL2Chain, polygonCDKChains } from "../../../src";
import { ChainSlug } from "../../../src/enums/chainSlug";

import {
FinalityBucket,
BucketFinalityType,
ChainFinalityInfo,
} from "../../../src/socket-types";

const chainsWithZeroBlockFinality = [
ChainSlug.REYA,
ChainSlug.BOB,
arthcp marked this conversation as resolved.
Show resolved Hide resolved
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,
},
};
arthcp marked this conversation as resolved.
Show resolved Hide resolved

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]: {
arthcp marked this conversation as resolved.
Show resolved Hide resolved
type: BucketFinalityType.block,
defaultBucket: FinalityBucket.fast,
[FinalityBucket.fast]: {
block: 2,
time: 0,
},
[FinalityBucket.medium]: {
block: 10,
time: 0,
},
[FinalityBucket.slow]: {
block: 20,
time: 0,
},
},

[ChainSlug.LYRA]: {
type: BucketFinalityType.block,
arthcp marked this conversation as resolved.
Show resolved Hide resolved
defaultBucket: FinalityBucket.fast,
[FinalityBucket.fast]: {
block: 2,
time: 0,
},
[FinalityBucket.medium]: {
block: 10,
time: 0,
},
[FinalityBucket.slow]: {
block: 20,
time: 0,
},
},
[ChainSlug.OPTIMISM]: {
type: BucketFinalityType.block,
defaultBucket: FinalityBucket.fast,
[FinalityBucket.fast]: {
block: 15,
time: 0,
},
[FinalityBucket.medium]: {
block: 30,
time: 0,
},
[FinalityBucket.slow]: {
block: 40,
time: 0,
},
},
[ChainSlug.POLYGON_MAINNET]: {
type: BucketFinalityType.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: BucketFinalityType.block,
defaultBucket: FinalityBucket.slow,
[FinalityBucket.fast]: {
block: 6,
time: 0,
},
[FinalityBucket.medium]: {
block: 10,
time: 0,
},
[FinalityBucket.slow]: {
block: 18,
time: 0,
},
},
[ChainSlug.MODE]: {
type: BucketFinalityType.block,
defaultBucket: FinalityBucket.fast,
[FinalityBucket.fast]: {
block: 2,
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;
};
1 change: 1 addition & 0 deletions scripts/rpcConfig/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./explorers";
export * from "./icons";
export * from "./rpc";
export * from "./version";
export * from "./finality";
2 changes: 1 addition & 1 deletion scripts/rpcConfig/constants/version.ts
Original file line number Diff line number Diff line change
@@ -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",
};
2 changes: 2 additions & 0 deletions scripts/rpcConfig/rpcConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
prodFeesUpdaterSupportedChainSlugs,
rpcs,
version,
getFinality,
} from "./constants";
import { getChainTxData } from "./txdata-builder/generate-calldata";

Expand Down Expand Up @@ -92,6 +93,7 @@ const getChainData = async (
nativeToken: getCurrency(chainSlug),
chainType: getChainType(chainSlug),
confirmations: confirmations[chainSlug],
finalityInfo: getFinality(chainSlug),
icon: icons[chainSlug],
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { DeploymentMode } from "./socket-types";

export { finality } from "../scripts/rpcConfig/constants/finality";
export * from "./socket-types";
export * from "./enums";
export * from "./addresses";
export * from "./currency-util";
export * from "./transmission-utils";

export const version = {
[DeploymentMode.DEV]: "IMLI",
Expand Down
35 changes: 35 additions & 0 deletions src/socket-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,40 @@ export enum ChainType {
default = "default",
}

export enum FinalityBucket {
fast = 1,
medium = 2,
slow = 3,
}

export enum TransmissionParamFinalityType {
bucket = 1,
block = 2,
time = 3,
arthcp marked this conversation as resolved.
Show resolved Hide resolved
}

export enum BucketFinalityType {
block = 1,
time = 2,
}
arthcp marked this conversation as resolved.
Show resolved Hide resolved

export type ChainFinalityInfo = {
type: BucketFinalityType;
defaultBucket: FinalityBucket;
arthcp marked this conversation as resolved.
Show resolved Hide resolved
[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;
};
Expand All @@ -229,6 +263,7 @@ export interface S3ChainConfig {
chainTxData?: ChainTxData;
explorer?: string;
icon?: string;
finalityInfo?: ChainFinalityInfo;
}

export type S3Config = {
Expand Down
Loading
Loading