diff --git a/packages/mask/src/extension/background-script/EthereumServices/interceptor.ts b/packages/mask/src/extension/background-script/EthereumServices/interceptor.ts new file mode 100644 index 000000000000..174f7849b87e --- /dev/null +++ b/packages/mask/src/extension/background-script/EthereumServices/interceptor.ts @@ -0,0 +1,38 @@ +import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' +import { ChainId, createLookupTableResolver } from '@masknet/web3-shared-evm' +import { BobaInterceptor } from './interceptors' +import type { Interceptor } from './types' + +const getInterceptor = createLookupTableResolver( + { + [ChainId.Mainnet]: null, + [ChainId.Ropsten]: null, + [ChainId.Kovan]: null, + [ChainId.Rinkeby]: null, + [ChainId.Gorli]: null, + [ChainId.BSC]: null, + [ChainId.BSCT]: null, + [ChainId.Matic]: null, + [ChainId.Mumbai]: null, + [ChainId.Arbitrum]: null, + [ChainId.Arbitrum_Rinkeby]: null, + [ChainId.xDai]: null, + [ChainId.Celo]: null, + [ChainId.Fantom]: null, + [ChainId.Aurora]: null, + [ChainId.Avalanche]: null, + [ChainId.Boba]: new BobaInterceptor(), + [ChainId.Optimistic]: null, + }, + null, +) + +export function encodePayload(chainId: ChainId, payload: JsonRpcPayload) { + const interceptor = getInterceptor(chainId) + return interceptor?.encode?.(payload) ?? payload +} + +export function decodeResponse(chainId: ChainId, error: Error | null, response?: JsonRpcResponse) { + const interceptor = getInterceptor(chainId) + return interceptor?.decode?.(error, response) ?? [error, response] +} diff --git a/packages/mask/src/extension/background-script/EthereumServices/interceptors/Boba.ts b/packages/mask/src/extension/background-script/EthereumServices/interceptors/Boba.ts new file mode 100644 index 000000000000..c6dfb82ceadc --- /dev/null +++ b/packages/mask/src/extension/background-script/EthereumServices/interceptors/Boba.ts @@ -0,0 +1,13 @@ +import type { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' +import type { Interceptor } from '../types' + +export class BobaInterceptor implements Interceptor { + encode(payload: JsonRpcPayload): JsonRpcPayload { + throw new Error('Method not implemented.') + } + decode(error: Error | null, response?: JsonRpcResponse): [Error | null, JsonRpcResponse] { + throw new Error('Method not implemented.') + } + getPayloadHash(payload: JsonRpcPayload) {} + getPayloadNonce(payload: JsonRpcPayload) {} +} diff --git a/packages/mask/src/extension/background-script/EthereumServices/interceptors/index.ts b/packages/mask/src/extension/background-script/EthereumServices/interceptors/index.ts new file mode 100644 index 000000000000..bc6be114f9b6 --- /dev/null +++ b/packages/mask/src/extension/background-script/EthereumServices/interceptors/index.ts @@ -0,0 +1 @@ +export * from './Boba' diff --git a/packages/web3-shared/evm/types/index.ts b/packages/web3-shared/evm/types/index.ts index 86d36bcc85f1..9a03e5dc13ed 100644 --- a/packages/web3-shared/evm/types/index.ts +++ b/packages/web3-shared/evm/types/index.ts @@ -366,6 +366,10 @@ export enum EthereumMethodType { MASK_REPLACE_TRANSACTION = 'mask_replaceTransaction', MASK_LOGIN_FORTMATIC = 'mask_loginFortmatic', MASK_LOGOUT_FORTMATIC = 'mask_logoutFortmatic', + + // optimistic, boba + ROLLUP_GET_INFO = 'rollup_getInfo', + ROLLUP_GAS_PRICES = 'rollup_gasPrices', } export enum EthereumErrorType {