Skip to content

Commit

Permalink
Spread deploymentType
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Sep 25, 2024
1 parent 52b8e99 commit b943451
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 66 deletions.
7 changes: 6 additions & 1 deletion packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,12 @@ class Safe {
}

const safeVersion = this.getContractVersion()
this.#safeProvider = await SafeProvider.init(provider, signer, safeVersion, contractNetworks)
this.#safeProvider = await SafeProvider.init({
provider,
signer,
safeVersion,
contractNetworks
})

this.#ownerManager = new OwnerManager(this.#safeProvider, this.#contractManager.safeContract)
this.#moduleManager = new ModuleManager(this.#safeProvider, this.#contractManager.safeContract)
Expand Down
1 change: 0 additions & 1 deletion packages/protocol-kit/src/contracts/BaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class BaseContract<ContractAbiType extends Abi> {
Array.isArray(contractAddress) && contractAddress.length
? contractAddress.find((a) => a === customDeploymentTypeAddress) || contractAddress[0]
: contractAddress.toString()

this.contractAbi =
customContractAbi ||
(deployment?.abi as unknown as ContractAbiType) || // this cast is required because abi is set as any[] in safe-deployments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Abi } from 'abitype'

import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import BaseContract from '@safe-global/protocol-kit/contracts/BaseContract'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import { SafeVersion } from '@safe-global/types-kit'
import { contractName } from '@safe-global/protocol-kit/contracts/config'

Expand Down Expand Up @@ -40,7 +41,8 @@ abstract class CompatibilityFallbackHandlerBaseContract<
defaultAbi: CompatibilityFallbackHandlerContractAbiType,
safeVersion: SafeVersion,
customContractAddress?: string,
customContractAbi?: CompatibilityFallbackHandlerContractAbiType
customContractAbi?: CompatibilityFallbackHandlerContractAbiType,
deploymentType?: DeploymentType
) {
const contractName = 'compatibilityFallbackHandler'

Expand All @@ -51,7 +53,8 @@ abstract class CompatibilityFallbackHandlerBaseContract<
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)

this.contractName = contractName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CompatibilityFallbackHandlerBaseContract from '@safe-global/protocol-kit/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
CompatibilityFallbackHandlerContract_v1_3_0_Abi,
CompatibilityFallbackHandlerContract_v1_3_0_Contract,
Expand Down Expand Up @@ -30,12 +31,21 @@ class CompatibilityFallbackHandlerContract_v1_3_0
chainId: bigint,
safeProvider: SafeProvider,
customContractAddress?: string,
customContractAbi?: CompatibilityFallbackHandlerContract_v1_3_0_Abi
customContractAbi?: CompatibilityFallbackHandlerContract_v1_3_0_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.3.0'
const defaultAbi = compatibilityFallbackHandler_1_3_0_ContractArtifacts.abi

super(chainId, safeProvider, defaultAbi, safeVersion, customContractAddress, customContractAbi)
super(
chainId,
safeProvider,
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi,
deploymentType
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CompatibilityFallbackHandlerBaseContract from '@safe-global/protocol-kit/contracts/CompatibilityFallbackHandler/CompatibilityFallbackHandlerBaseContract'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
compatibilityFallbackHandler_1_4_1_ContractArtifacts,
CompatibilityFallbackHandlerContract_v1_4_1_Abi,
Expand Down Expand Up @@ -30,12 +31,21 @@ class CompatibilityFallbackHandlerContract_v1_4_1
chainId: bigint,
safeProvider: SafeProvider,
customContractAddress?: string,
customContractAbi?: CompatibilityFallbackHandlerContract_v1_4_1_Abi
customContractAbi?: CompatibilityFallbackHandlerContract_v1_4_1_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.4.1'
const defaultAbi = compatibilityFallbackHandler_1_4_1_ContractArtifacts.abi

super(chainId, safeProvider, defaultAbi, safeVersion, customContractAddress, customContractAbi)
super(
chainId,
safeProvider,
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi,
deploymentType
)
}
}

Expand Down
7 changes: 5 additions & 2 deletions packages/protocol-kit/src/contracts/Safe/SafeBaseContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { SafeVersion } from '@safe-global/types-kit'
import BaseContract from '@safe-global/protocol-kit/contracts/BaseContract'
import { contractName, safeDeploymentsL1ChainIds } from '@safe-global/protocol-kit/contracts/config'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import { SAFE_FEATURES, hasSafeFeature } from '@safe-global/protocol-kit/utils'

/**
Expand Down Expand Up @@ -46,7 +47,8 @@ abstract class SafeBaseContract<
safeVersion: SafeVersion,
isL1SafeSingleton = false,
customContractAddress?: string,
customContractAbi?: SafeContractAbiType
customContractAbi?: SafeContractAbiType,
deploymentType?: DeploymentType
) {
const isL1Contract =
safeDeploymentsL1ChainIds.includes(chainId) ||
Expand All @@ -62,7 +64,8 @@ abstract class SafeBaseContract<
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)

this.contractName = contractName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SafeBaseContract from '@safe-global/protocol-kit/contracts/Safe/SafeBaseC
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'
import { sameString, isSentinelAddress } from '@safe-global/protocol-kit/utils'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeContract_v1_0_0_Abi,
SafeContract_v1_0_0_Function,
Expand Down Expand Up @@ -42,7 +43,8 @@ class SafeContract_v1_0_0
safeProvider: SafeProvider,
isL1SafeSingleton = false,
customContractAddress?: string,
customContractAbi?: SafeContract_v1_0_0_Abi
customContractAbi?: SafeContract_v1_0_0_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.0.0'
const defaultAbi = safe_1_0_0_ContractArtifacts.abi
Expand All @@ -54,7 +56,8 @@ class SafeContract_v1_0_0
safeVersion,
isL1SafeSingleton,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SafeBaseContract from '@safe-global/protocol-kit/contracts/Safe/SafeBaseC
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'
import { sameString } from '@safe-global/protocol-kit/utils'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeContract_v1_1_1_Abi,
SafeContract_v1_1_1_Contract,
Expand Down Expand Up @@ -41,7 +42,8 @@ class SafeContract_v1_1_1
safeProvider: SafeProvider,
isL1SafeSingleton = false,
customContractAddress?: string,
customContractAbi?: SafeContract_v1_1_1_Abi
customContractAbi?: SafeContract_v1_1_1_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.1.1'
const defaultAbi = safe_1_1_1_ContractArtifacts.abi
Expand All @@ -53,7 +55,8 @@ class SafeContract_v1_1_1
safeVersion,
isL1SafeSingleton,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { simulateContract } from 'viem/actions'
import SafeBaseContract from '@safe-global/protocol-kit/contracts/Safe/SafeBaseContract'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeContract_v1_2_0_Abi,
SafeContract_v1_2_0_Contract,
Expand Down Expand Up @@ -40,7 +41,8 @@ class SafeContract_v1_2_0
safeProvider: SafeProvider,
isL1SafeSingleton = false,
customContractAddress?: string,
customContractAbi?: SafeContract_v1_2_0_Abi
customContractAbi?: SafeContract_v1_2_0_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.2.0'
const defaultAbi = safe_1_2_0_ContractArtifacts.abi
Expand All @@ -52,7 +54,8 @@ class SafeContract_v1_2_0
safeVersion,
isL1SafeSingleton,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SafeBaseContract from '@safe-global/protocol-kit/contracts/Safe/SafeBaseC
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'
import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/utils/constants'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeContract_v1_3_0_Abi,
SafeContract_v1_3_0_Contract,
Expand Down Expand Up @@ -41,7 +42,8 @@ class SafeContract_v1_3_0
safeProvider: SafeProvider,
isL1SafeSingleton = false,
customContractAddress?: string,
customContractAbi?: SafeContract_v1_3_0_Abi
customContractAbi?: SafeContract_v1_3_0_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.3.0'
const defaultAbi = safe_1_3_0_ContractArtifacts.abi
Expand All @@ -53,7 +55,8 @@ class SafeContract_v1_3_0
safeVersion,
isL1SafeSingleton,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SafeBaseContract from '@safe-global/protocol-kit/contracts/Safe/SafeBaseC
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { toTxResult } from '@safe-global/protocol-kit/contracts/utils'
import { SENTINEL_ADDRESS } from '@safe-global/protocol-kit/utils/constants'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeContract_v1_4_1_Abi,
SafeContract_v1_4_1_Contract,
Expand Down Expand Up @@ -41,7 +42,8 @@ class SafeContract_v1_4_1
safeProvider: SafeProvider,
isL1SafeSingleton = false,
customContractAddress?: string,
customContractAbi?: SafeContract_v1_4_1_Abi
customContractAbi?: SafeContract_v1_4_1_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.4.1'
const defaultAbi = safe_1_4_1_ContractArtifacts.abi
Expand All @@ -53,7 +55,8 @@ class SafeContract_v1_4_1
safeVersion,
isL1SafeSingleton,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Abi } from 'abitype'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import BaseContract from '@safe-global/protocol-kit/contracts/BaseContract'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeVersion,
TransactionOptions,
Expand Down Expand Up @@ -50,7 +51,8 @@ abstract class SafeProxyFactoryBaseContract<
defaultAbi: SafeProxyFactoryContractAbiType,
safeVersion: SafeVersion,
customContractAddress?: string,
customContractAbi?: SafeProxyFactoryContractAbiType
customContractAbi?: SafeProxyFactoryContractAbiType,
deploymentType?: DeploymentType
) {
const contractName = 'safeProxyFactoryVersion'

Expand All @@ -61,7 +63,8 @@ abstract class SafeProxyFactoryBaseContract<
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi
customContractAbi,
deploymentType
)

this.contractName = contractName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SafeProxyFactoryBaseContract, {
CreateProxyProps
} from '@safe-global/protocol-kit/contracts/SafeProxyFactory/SafeProxyFactoryBaseContract'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeProxyFactoryContract_v1_0_0_Abi,
SafeProxyFactoryContract_v1_0_0_Contract,
Expand Down Expand Up @@ -36,12 +37,21 @@ class SafeProxyFactoryContract_v1_0_0
chainId: bigint,
safeProvider: SafeProvider,
customContractAddress?: string,
customContractAbi?: SafeProxyFactoryContract_v1_0_0_Abi
customContractAbi?: SafeProxyFactoryContract_v1_0_0_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.0.0'
const defaultAbi = safeProxyFactory_1_0_0_ContractArtifacts.abi

super(chainId, safeProvider, defaultAbi, safeVersion, customContractAddress, customContractAbi)
super(
chainId,
safeProvider,
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi,
deploymentType
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SafeProxyFactoryBaseContract, {
CreateProxyProps
} from '@safe-global/protocol-kit/contracts/SafeProxyFactory/SafeProxyFactoryBaseContract'
import SafeProvider from '@safe-global/protocol-kit/SafeProvider'
import { DeploymentType } from '@safe-global/protocol-kit/types'
import {
SafeProxyFactoryContract_v1_1_1_Abi,
SafeProxyFactoryContract_v1_1_1_Contract,
Expand Down Expand Up @@ -36,12 +37,21 @@ class SafeProxyFactoryContract_v1_1_1
chainId: bigint,
safeProvider: SafeProvider,
customContractAddress?: string,
customContractAbi?: SafeProxyFactoryContract_v1_1_1_Abi
customContractAbi?: SafeProxyFactoryContract_v1_1_1_Abi,
deploymentType?: DeploymentType
) {
const safeVersion = '1.1.1'
const defaultAbi = safeProxyFactory_1_1_1_ContractArtifacts.abi

super(chainId, safeProvider, defaultAbi, safeVersion, customContractAddress, customContractAbi)
super(
chainId,
safeProvider,
defaultAbi,
safeVersion,
customContractAddress,
customContractAbi,
deploymentType
)
}

/**
Expand Down
Loading

0 comments on commit b943451

Please sign in to comment.