From 32b408b3ebb948a85549edad5e799868989a117c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yago=20P=C3=A9rez=20V=C3=A1zquez?= Date: Fri, 8 Nov 2024 13:43:45 +0100 Subject: [PATCH] feat: Add deploymentType (#1032) --- .../src/contracts/safeDeploymentContracts.ts | 42 ++++++++++++------- .../src/managers/contractManager.ts | 6 ++- .../src/packs/safe-4337/Safe4337Pack.ts | 6 ++- .../relay-kit/src/packs/safe-4337/types.ts | 3 +- packages/sdk-starter-kit/src/constants.ts | 4 ++ packages/sdk-starter-kit/src/index.ts | 39 +++++++++++++---- packages/sdk-starter-kit/src/types.ts | 1 + 7 files changed, 75 insertions(+), 26 deletions(-) diff --git a/packages/protocol-kit/src/contracts/safeDeploymentContracts.ts b/packages/protocol-kit/src/contracts/safeDeploymentContracts.ts index 9e2685c42..405d2d595 100644 --- a/packages/protocol-kit/src/contracts/safeDeploymentContracts.ts +++ b/packages/protocol-kit/src/contracts/safeDeploymentContracts.ts @@ -112,13 +112,15 @@ export async function getCompatibilityFallbackHandlerContract({ export async function getMultiSendContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const multiSendContract = await getMultiSendContractInstance( safeVersion, safeProvider, customContracts?.multiSendAddress, - customContracts?.multiSendAbi + customContracts?.multiSendAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed(multiSendContract.getAddress()) @@ -131,13 +133,15 @@ export async function getMultiSendContract({ export async function getMultiSendCallOnlyContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const multiSendCallOnlyContract = await getMultiSendCallOnlyContractInstance( safeVersion, safeProvider, customContracts?.multiSendCallOnlyAddress, - customContracts?.multiSendCallOnlyAbi + customContracts?.multiSendCallOnlyAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed( @@ -152,13 +156,15 @@ export async function getMultiSendCallOnlyContract({ export async function getSignMessageLibContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const signMessageLibContract = await getSignMessageLibContractInstance( safeVersion, safeProvider, customContracts?.signMessageLibAddress, - customContracts?.signMessageLibAbi + customContracts?.signMessageLibAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed( @@ -173,13 +179,15 @@ export async function getSignMessageLibContract({ export async function getCreateCallContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const createCallContract = await getCreateCallContractInstance( safeVersion, safeProvider, customContracts?.createCallAddress, - customContracts?.createCallAbi + customContracts?.createCallAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed(createCallContract.getAddress()) @@ -192,13 +200,15 @@ export async function getCreateCallContract({ export async function getSimulateTxAccessorContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const simulateTxAccessorContract = await getSimulateTxAccessorContractInstance( safeVersion, safeProvider, customContracts?.simulateTxAccessorAddress, - customContracts?.simulateTxAccessorAbi + customContracts?.simulateTxAccessorAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed( @@ -213,13 +223,15 @@ export async function getSimulateTxAccessorContract({ export async function getSafeWebAuthnSignerFactoryContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const safeWebAuthnSignerFactoryContract = await getSafeWebAuthnSignerFactoryContractInstance( safeVersion, safeProvider, customContracts?.safeWebAuthnSignerFactoryAddress, - customContracts?.safeWebAuthnSignerFactoryAbi + customContracts?.safeWebAuthnSignerFactoryAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed( @@ -234,13 +246,15 @@ export async function getSafeWebAuthnSignerFactoryContract({ export async function getSafeWebAuthnSharedSignerContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType }: GetContractInstanceProps): Promise { const safeWebAuthnSharedSignerContract = await getSafeWebAuthnSharedSignerContractInstance( safeVersion, safeProvider, customContracts?.safeWebAuthnSharedSignerAddress, - customContracts?.safeWebAuthnSharedSignerAbi + customContracts?.safeWebAuthnSharedSignerAbi, + deploymentType ) const isContractDeployed = await safeProvider.isContractDeployed( diff --git a/packages/protocol-kit/src/managers/contractManager.ts b/packages/protocol-kit/src/managers/contractManager.ts index f71590c8e..651a66fa1 100644 --- a/packages/protocol-kit/src/managers/contractManager.ts +++ b/packages/protocol-kit/src/managers/contractManager.ts @@ -62,13 +62,15 @@ class ContractManager { this.#multiSendContract = await getMultiSendContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType: predictedSafe?.safeDeploymentConfig?.deploymentType }) this.#multiSendCallOnlyContract = await getMultiSendCallOnlyContract({ safeProvider, safeVersion, - customContracts + customContracts, + deploymentType: predictedSafe?.safeDeploymentConfig?.deploymentType }) } diff --git a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts index 41e56cfa0..aa045d232 100644 --- a/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts +++ b/packages/relay-kit/src/packs/safe-4337/Safe4337Pack.ts @@ -293,7 +293,8 @@ export class Safe4337Pack extends RelayKitBasePack<{ if (isBatch) { const multiSendContract = await getMultiSendContract({ safeProvider, - safeVersion + safeVersion, + deploymentType: options.deploymentType || undefined }) const batchData = encodeFunctionData({ @@ -315,7 +316,8 @@ export class Safe4337Pack extends RelayKitBasePack<{ predictedSafe: { safeDeploymentConfig: { safeVersion, - saltNonce: options.saltNonce || undefined + saltNonce: options.saltNonce || undefined, + deploymentType: options.deploymentType || undefined }, safeAccountConfig: { owners: options.owners, diff --git a/packages/relay-kit/src/packs/safe-4337/types.ts b/packages/relay-kit/src/packs/safe-4337/types.ts index 5ddafabcc..a64bda523 100644 --- a/packages/relay-kit/src/packs/safe-4337/types.ts +++ b/packages/relay-kit/src/packs/safe-4337/types.ts @@ -1,5 +1,5 @@ import { Account, Address, Chain, Hash, Hex, PublicClient, PublicRpcSchema, Transport } from 'viem' -import Safe, { SafeProviderConfig } from '@safe-global/protocol-kit' +import Safe, { DeploymentType, SafeProviderConfig } from '@safe-global/protocol-kit' import { EstimateGasData, MetaTransactionData, @@ -19,6 +19,7 @@ type PredictedSafeOptions = { threshold: number safeVersion?: SafeVersion saltNonce?: string + deploymentType?: DeploymentType } export type SponsoredPaymasterOption = { diff --git a/packages/sdk-starter-kit/src/constants.ts b/packages/sdk-starter-kit/src/constants.ts index 20da24056..9d0afda04 100644 --- a/packages/sdk-starter-kit/src/constants.ts +++ b/packages/sdk-starter-kit/src/constants.ts @@ -1,3 +1,7 @@ +import { DeploymentType } from '@safe-global/protocol-kit' + +export const DEFAULT_DEPLOYMENT_TYPE: DeploymentType = 'canonical' + export enum SafeClientTxStatus { DEPLOYED_AND_EXECUTED = 'DEPLOYED_AND_EXECUTED', DEPLOYED_AND_PENDING_SIGNATURES = 'DEPLOYED_AND_PENDING_SIGNATURES', diff --git a/packages/sdk-starter-kit/src/index.ts b/packages/sdk-starter-kit/src/index.ts index 259987af5..28f4cbd50 100644 --- a/packages/sdk-starter-kit/src/index.ts +++ b/packages/sdk-starter-kit/src/index.ts @@ -1,9 +1,10 @@ -import Safe from '@safe-global/protocol-kit' +import Safe, { SafeConfig } from '@safe-global/protocol-kit' import SafeApiKit from '@safe-global/api-kit' import { SafeClient } from '@safe-global/sdk-starter-kit/SafeClient' import { isValidAddress, isValidSafeConfig } from '@safe-global/sdk-starter-kit/utils' import { SdkStarterKitConfig } from '@safe-global/sdk-starter-kit/types' +import { DEFAULT_DEPLOYMENT_TYPE } from './constants' /** * Initializes a Safe client with the given configuration options. @@ -13,7 +14,7 @@ import { SdkStarterKitConfig } from '@safe-global/sdk-starter-kit/types' */ export async function createSafeClient(config: SdkStarterKitConfig): Promise { const protocolKit = await getProtocolKitInstance(config) - const apiKit = await getApiKitInstance(protocolKit) + const apiKit = await getApiKitInstance(protocolKit, config) if (!protocolKit || !apiKit) throw new Error('Failed to create a kit instances') @@ -36,7 +37,8 @@ async function getProtocolKitInstance(config: SdkStarterKitConfig): Promise { +async function getApiKitInstance( + protocolKit: Safe, + config: SdkStarterKitConfig +): Promise { const chainId = await protocolKit.getChainId() - return new SafeApiKit({ chainId }) + return new SafeApiKit({ chainId, txServiceUrl: config.txServiceUrl }) } export * from './types' diff --git a/packages/sdk-starter-kit/src/types.ts b/packages/sdk-starter-kit/src/types.ts index 2fc62862f..839a8ac55 100644 --- a/packages/sdk-starter-kit/src/types.ts +++ b/packages/sdk-starter-kit/src/types.ts @@ -59,6 +59,7 @@ export type PredictedSafeConfig = { export type SdkStarterKitRootConfig = { provider: SafeProvider['provider'] signer?: SafeProvider['signer'] + txServiceUrl?: string } export type SdkStarterKitConfig = SdkStarterKitRootConfig &