Skip to content

Commit

Permalink
Merge ac4a098 into 3514f96
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Sep 12, 2023
2 parents 3514f96 + ac4a098 commit d2f54ae
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 65 deletions.
6 changes: 3 additions & 3 deletions guides/integrating-the-safe-core-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ const safeSdk = await Safe.create({ ethAdapter, safeAddress })

There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.

By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the property `isL1SafeMasterCopy` to force the use of the `Safe.sol` contract.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the property `isL1SafeSingleton` to force the use of the `Safe.sol` contract.

```js
const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeMasterCopy: true })
const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeSingleton: true })

const safeSdk = await Safe.create({ ethAdapter, safeAddress, isL1SafeMasterCopy: true })
const safeSdk = await Safe.create({ ethAdapter, safeAddress, isL1SafeSingleton: true })
```

If the Safe contracts are not deployed to your current network, the property `contractNetworks` will be required to point to the addresses of the Safe contracts previously deployed by you.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Monerium() {
const safeSdk = await Safe.create({
ethAdapter: ethAdapter,
safeAddress: selectedSafe,
isL1SafeMasterCopy: true
isL1SafeSingleton: true
})

const pack = new MoneriumPack({
Expand Down
18 changes: 9 additions & 9 deletions packages/protocol-kit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ import { SafeFactory } from '@safe-global/protocol-kit'
const safeFactory = await SafeFactory.create({ ethAdapter })
```
- The `isL1SafeMasterCopy` flag
- The `isL1SafeSingleton` flag
There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeMasterCopy` flag to force the use of the `Safe.sol` contract.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeSingleton` flag to force the use of the `Safe.sol` contract.
```js
const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeMasterCopy: true })
const safeFactory = await SafeFactory.create({ ethAdapter, isL1SafeSingleton: true })
```
- The `contractNetworks` property
Expand Down Expand Up @@ -317,14 +317,14 @@ const predictedSafe: PredictedSafeProps = {
const safeSdk = await Safe.create({ ethAdapter, predictedSafe })
```
- The `isL1SafeMasterCopy` flag
- The `isL1SafeSingleton` flag
There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeMasterCopy` flag to force the use of the `Safe.sol` contract.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeSingleton` flag to force the use of the `Safe.sol` contract.
```js
const safeSdk = await Safe.create({ ethAdapter, safeAddress, isL1SafeMasterCopy: true })
const safeSdk = await Safe.create({ ethAdapter, safeAddress, isL1SafeSingleton: true })
```
- The `contractNetworks` property
Expand Down Expand Up @@ -382,14 +382,14 @@ const predictedSafe: PredictedSafeProps = {
const safeSdk = await safeSdk.connect({ ethAdapter, predictedSafe })
```
- The `isL1SafeMasterCopy` flag
- The `isL1SafeSingleton` flag
There are two versions of the Safe contracts: [Safe.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/Safe.sol) that does not trigger events in order to save gas and [SafeL2.sol](https://github.com/safe-global/safe-contracts/blob/v1.4.1/contracts/SafeL2.sol) that does, which is more appropriate for L2 networks.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeMasterCopy` flag to force the use of the `Safe.sol` contract.
By default `Safe.sol` will be only used on Ethereum Mainnet. For the rest of the networks where the Safe contracts are already deployed, the `SafeL2.sol` contract will be used unless you add the `isL1SafeSingleton` flag to force the use of the `Safe.sol` contract.
```js
const safeSdk = await Safe.connect({ ethAdapter, safeAddress, isL1SafeMasterCopy: true })
const safeSdk = await Safe.connect({ ethAdapter, safeAddress, isL1SafeSingleton: true })
```
- The `contractNetworks` property
Expand Down
18 changes: 9 additions & 9 deletions packages/protocol-kit/src/Safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Safe {
* @throws "MultiSendCallOnly contract is not deployed on the current network"
*/
private async init(config: SafeConfig): Promise<void> {
const { ethAdapter, isL1SafeMasterCopy, contractNetworks } = config
const { ethAdapter, isL1SafeSingleton, contractNetworks } = config

this.#ethAdapter = ethAdapter

Expand All @@ -103,14 +103,14 @@ class Safe {
this.#contractManager = await ContractManager.create({
ethAdapter: this.#ethAdapter,
predictedSafe: this.#predictedSafe,
isL1SafeMasterCopy,
isL1SafeSingleton,
contractNetworks
})
} else {
this.#contractManager = await ContractManager.create({
ethAdapter: this.#ethAdapter,
safeAddress: config.safeAddress,
isL1SafeMasterCopy,
isL1SafeSingleton,
contractNetworks
})
}
Expand All @@ -133,10 +133,10 @@ class Safe {
* @throws "MultiSendCallOnly contract is not deployed on the current network"
*/
async connect(config: ConnectSafeConfig): Promise<Safe> {
const { ethAdapter, safeAddress, predictedSafe, isL1SafeMasterCopy, contractNetworks } = config
const { ethAdapter, safeAddress, predictedSafe, isL1SafeSingleton, contractNetworks } = config
const configProps: SafeConfigProps = {
ethAdapter: ethAdapter || this.#ethAdapter,
isL1SafeMasterCopy: isL1SafeMasterCopy || this.#contractManager.isL1SafeMasterCopy,
isL1SafeSingleton: isL1SafeSingleton || this.#contractManager.isL1SafeSingleton,
contractNetworks: contractNetworks || this.#contractManager.contractNetworks
}

Expand Down Expand Up @@ -1031,12 +1031,12 @@ class Safe {
const safeVersion = await this.getContractVersion()
const chainId = await this.getChainId()
const customContracts = this.#contractManager.contractNetworks?.[chainId]
const isL1SafeMasterCopy = this.#contractManager.isL1SafeMasterCopy
const isL1SafeSingleton = this.#contractManager.isL1SafeSingleton

const safeSingletonContract = await getSafeContract({
ethAdapter: this.#ethAdapter,
safeVersion: safeVersion,
isL1SafeMasterCopy,
isL1SafeSingleton,
customContracts
})

Expand Down Expand Up @@ -1136,13 +1136,13 @@ class Safe {
const safeVersion = await this.getContractVersion()
const ethAdapter = this.#ethAdapter
const chainId = await ethAdapter.getChainId()
const isL1SafeMasterCopy = this.#contractManager.isL1SafeMasterCopy
const isL1SafeSingleton = this.#contractManager.isL1SafeSingleton
const customContracts = this.#contractManager.contractNetworks?.[chainId]

const safeSingletonContract = await getSafeContract({
ethAdapter: this.#ethAdapter,
safeVersion,
isL1SafeMasterCopy,
isL1SafeSingleton,
customContracts
})

Expand Down
10 changes: 5 additions & 5 deletions packages/protocol-kit/src/contracts/safeDeploymentContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ interface GetContractInstanceProps {
}

interface GetSafeContractInstanceProps extends GetContractInstanceProps {
isL1SafeMasterCopy?: boolean
isL1SafeSingleton?: boolean
customSafeAddress?: string
}

export function getSafeContractDeployment(
safeVersion: SafeVersion,
chainId: number,
isL1SafeMasterCopy = false
isL1SafeSingleton = false
): SingletonDeployment | undefined {
const version = safeDeploymentsVersions[safeVersion].safeMasterCopyVersion
const filters: DeploymentFilter = { version, network: chainId.toString(), released: true }
if (safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeMasterCopy) {
if (safeDeploymentsL1ChainIds.includes(chainId) || isL1SafeSingleton) {
return getSafeSingletonDeployment(filters)
}
return getSafeL2SingletonDeployment(filters)
Expand Down Expand Up @@ -114,11 +114,11 @@ export async function getSafeContract({
ethAdapter,
safeVersion,
customSafeAddress,
isL1SafeMasterCopy,
isL1SafeSingleton,
customContracts
}: GetSafeContractInstanceProps): Promise<SafeContract> {
const chainId = await ethAdapter.getChainId()
const singletonDeployment = getSafeContractDeployment(safeVersion, chainId, isL1SafeMasterCopy)
const singletonDeployment = getSafeContractDeployment(safeVersion, chainId, isL1SafeSingleton)
const safeContract = await ethAdapter.getSafeContract({
safeVersion,
singletonDeployment,
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol-kit/src/contracts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface PredictSafeAddressProps {
ethAdapter: EthAdapter
safeAccountConfig: SafeAccountConfig
safeDeploymentConfig?: SafeDeploymentConfig
isL1SafeMasterCopy?: boolean
isL1SafeSingleton?: boolean
customContracts?: ContractNetworkConfig
}

Expand Down Expand Up @@ -156,7 +156,7 @@ export async function predictSafeAddress({
ethAdapter,
safeAccountConfig,
safeDeploymentConfig = {},
isL1SafeMasterCopy = false,
isL1SafeSingleton = false,
customContracts
}: PredictSafeAddressProps): Promise<string> {
validateSafeAccountConfig(safeAccountConfig)
Expand All @@ -180,7 +180,7 @@ export async function predictSafeAddress({
const safeContract = await memoizedGetSafeContract({
ethAdapter,
safeVersion,
isL1SafeMasterCopy,
isL1SafeSingleton,
customContracts
})

Expand Down
14 changes: 7 additions & 7 deletions packages/protocol-kit/src/managers/contractManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { isSafeConfigWithPredictedSafe } from '../utils/types'

class ContractManager {
#contractNetworks?: ContractNetworksConfig
#isL1SafeMasterCopy?: boolean
#isL1SafeSingleton?: boolean
#safeContract?: SafeContract
#multiSendContract!: MultiSendContract
#multiSendCallOnlyContract!: MultiSendCallOnlyContract
Expand All @@ -27,12 +27,12 @@ class ContractManager {
}

async init(config: SafeConfig): Promise<void> {
const { ethAdapter, isL1SafeMasterCopy, contractNetworks, predictedSafe, safeAddress } = config
const { ethAdapter, isL1SafeSingleton, contractNetworks, predictedSafe, safeAddress } = config

const chainId = await ethAdapter.getChainId()
const customContracts = contractNetworks?.[chainId]
this.#contractNetworks = contractNetworks
this.#isL1SafeMasterCopy = isL1SafeMasterCopy
this.#isL1SafeSingleton = isL1SafeSingleton

let safeVersion: SafeVersion

Expand All @@ -43,7 +43,7 @@ class ContractManager {
const defaultSafeContractInstance = await getSafeContract({
ethAdapter,
safeVersion: DEFAULT_SAFE_VERSION,
isL1SafeMasterCopy,
isL1SafeSingleton,
customSafeAddress: safeAddress,
customContracts
})
Expand All @@ -59,7 +59,7 @@ class ContractManager {
: await getSafeContract({
ethAdapter,
safeVersion,
isL1SafeMasterCopy,
isL1SafeSingleton,
customSafeAddress: safeAddress,
customContracts
})
Expand All @@ -82,8 +82,8 @@ class ContractManager {
return this.#contractNetworks
}

get isL1SafeMasterCopy(): boolean | undefined {
return this.#isL1SafeMasterCopy
get isL1SafeSingleton(): boolean | undefined {
return this.#isL1SafeSingleton
}

get safeContract(): SafeContract | undefined {
Expand Down
24 changes: 12 additions & 12 deletions packages/protocol-kit/src/safeFactory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export interface SafeFactoryConfig {
ethAdapter: EthAdapter
/** safeVersion - Versions of the Safe deployed by this Factory contract */
safeVersion?: SafeVersion
/** isL1SafeMasterCopy - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeMasterCopy?: boolean
/** isL1SafeSingleton - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeSingleton?: boolean
/** contractNetworks - Contract network configuration */
contractNetworks?: ContractNetworksConfig
}
Expand All @@ -47,15 +47,15 @@ interface SafeFactoryInitConfig {
ethAdapter: EthAdapter
/** safeVersion - Versions of the Safe deployed by this Factory contract */
safeVersion: SafeVersion
/** isL1SafeMasterCopy - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeMasterCopy?: boolean
/** isL1SafeSingleton - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeSingleton?: boolean
/** contractNetworks - Contract network configuration */
contractNetworks?: ContractNetworksConfig
}

class SafeFactory {
#contractNetworks?: ContractNetworksConfig
#isL1SafeMasterCopy?: boolean
#isL1SafeSingleton?: boolean
#safeVersion!: SafeVersion
#ethAdapter!: EthAdapter
#safeProxyFactoryContract!: SafeProxyFactoryContract
Expand All @@ -64,23 +64,23 @@ class SafeFactory {
static async create({
ethAdapter,
safeVersion = DEFAULT_SAFE_VERSION,
isL1SafeMasterCopy = false,
isL1SafeSingleton = false,
contractNetworks
}: SafeFactoryConfig): Promise<SafeFactory> {
const safeFactorySdk = new SafeFactory()
await safeFactorySdk.init({ ethAdapter, safeVersion, isL1SafeMasterCopy, contractNetworks })
await safeFactorySdk.init({ ethAdapter, safeVersion, isL1SafeSingleton, contractNetworks })
return safeFactorySdk
}

private async init({
ethAdapter,
safeVersion,
isL1SafeMasterCopy,
isL1SafeSingleton,
contractNetworks
}: SafeFactoryInitConfig): Promise<void> {
this.#ethAdapter = ethAdapter
this.#safeVersion = safeVersion
this.#isL1SafeMasterCopy = isL1SafeMasterCopy
this.#isL1SafeSingleton = isL1SafeSingleton
this.#contractNetworks = contractNetworks
const chainId = await this.#ethAdapter.getChainId()
const customContracts = contractNetworks?.[chainId]
Expand All @@ -92,7 +92,7 @@ class SafeFactory {
this.#safeContract = await getSafeContract({
ethAdapter,
safeVersion,
isL1SafeMasterCopy,
isL1SafeSingleton,
customContracts
})
}
Expand Down Expand Up @@ -126,7 +126,7 @@ class SafeFactory {
ethAdapter: this.#ethAdapter,
safeAccountConfig,
safeDeploymentConfig,
isL1SafeMasterCopy: this.#isL1SafeMasterCopy,
isL1SafeSingleton: this.#isL1SafeSingleton,
customContracts
})
}
Expand Down Expand Up @@ -174,7 +174,7 @@ class SafeFactory {
const safe = await Safe.create({
ethAdapter: this.#ethAdapter,
safeAddress,
isL1SafeMasterCopy: this.#isL1SafeMasterCopy,
isL1SafeSingleton: this.#isL1SafeSingleton,
contractNetworks: this.#contractNetworks
})
return safe
Expand Down
8 changes: 4 additions & 4 deletions packages/protocol-kit/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type SafeConfigWithPredictedSafeProps = {
export type SafeConfigProps = {
/** ethAdapter - Ethereum adapter */
ethAdapter: EthAdapter
/** isL1SafeMasterCopy - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeMasterCopy?: boolean
/** isL1SafeSingleton - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeSingleton?: boolean
/** contractNetworks - Contract network configuration */
contractNetworks?: ContractNetworksConfig
}
Expand All @@ -113,8 +113,8 @@ type ConnectSafeConfigWithPredictedSafeProps = {
type ConnectSafeConfigProps = {
/** ethAdapter - Ethereum adapter */
ethAdapter?: EthAdapter
/** isL1SafeMasterCopy - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeMasterCopy?: boolean
/** isL1SafeSingleton - Forces to use the Safe L1 version of the contract instead of the L2 version */
isL1SafeSingleton?: boolean
/** contractNetworks - Contract network configuration */
contractNetworks?: ContractNetworksConfig
}
Expand Down
Loading

0 comments on commit d2f54ae

Please sign in to comment.