Skip to content
This repository has been archived by the owner on Oct 27, 2023. It is now read-only.

Commit

Permalink
Use safe-core-protocol package (5afe#12)
Browse files Browse the repository at this point in the history
* Use safe-core-protocol package

* Update protocol dependency

* Update Sample Plugin
  • Loading branch information
rmeissner authored Jul 13, 2023
1 parent 6135abf commit 4e29e09
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 221 deletions.
1 change: 1 addition & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
build
.env
coverage
coverage.json
Expand Down
20 changes: 0 additions & 20 deletions contracts/contracts/DataTypes.sol

This file was deleted.

24 changes: 12 additions & 12 deletions contracts/contracts/Plugins.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.18;

import {ISafe} from "./interfaces/Accounts.sol";
import {ISafeProtocolPlugin} from "./interfaces/Integrations.sol";
import {ISafeProtocolManager} from "./interfaces/Manager.sol";
import {SafeTransaction, SafeRootAccess} from "./DataTypes.sol";
import {ISafe} from "@safe-global/safe-core-protocol/contracts/interfaces/Accounts.sol";
import {ISafeProtocolPlugin} from "@safe-global/safe-core-protocol/contracts/interfaces/Integrations.sol";
import {ISafeProtocolManager} from "@safe-global/safe-core-protocol/contracts/interfaces/Manager.sol";
import {SafeTransaction, SafeRootAccess} from "@safe-global/safe-core-protocol/contracts/DataTypes.sol";

enum MetaDataProviderType {
IPFS,
Expand Down Expand Up @@ -75,15 +75,15 @@ abstract contract BasePlugin is ISafeProtocolPlugin, MetaDataProvider {
}

contract SamplePlugin is BasePlugin {
constructor()
BasePlugin(PluginMetaData({name: "Sample Plugin", version: "1.0.0", requiresRootAccess: false, iconUrl: "", appUrl: ""}))
{}
ISafeProtocolManager public immutable manager;

function executeFromPlugin(
ISafeProtocolManager manager,
ISafe safe,
SafeTransaction calldata safetx
) external returns (bytes[] memory data) {
constructor(
ISafeProtocolManager _manager
) BasePlugin(PluginMetaData({name: "Sample Plugin", version: "1.0.0", requiresRootAccess: false, iconUrl: "", appUrl: ""})) {
manager = _manager;
}

function executeFromPlugin(ISafe safe, SafeTransaction calldata safetx) external returns (bytes[] memory data) {
(data) = manager.executeTransaction(safe, safetx);
}
}
21 changes: 0 additions & 21 deletions contracts/contracts/interfaces/Accounts.sol

This file was deleted.

118 changes: 0 additions & 118 deletions contracts/contracts/interfaces/Integrations.sol

This file was deleted.

32 changes: 0 additions & 32 deletions contracts/contracts/interfaces/Manager.sol

This file was deleted.

10 changes: 0 additions & 10 deletions contracts/contracts/interfaces/Registry.sol

This file was deleted.

8 changes: 7 additions & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import yargs from "yargs";
import { HttpNetworkUserConfig } from "hardhat/types";
import "hardhat-deploy";
import { DeterministicDeploymentInfo } from "hardhat-deploy/dist/types";
import { getSingletonFactoryInfo } from "@gnosis.pm/safe-singleton-factory";
import { getSingletonFactoryInfo } from "@safe-global/safe-singleton-factory";
import { ethers } from "ethers";

// Load environment variables.
Expand Down Expand Up @@ -54,6 +54,12 @@ const config: HardhatUserConfig = {
gasReporter: {
enabled: (process.env.REPORT_GAS) ? true : false
},
paths: {
artifacts: "build/artifacts",
cache: "build/cache",
deploy: "src/deploy",
sources: "contracts",
},
networks: {
hardhat: {
allowUnlimitedContractSize: true,
Expand Down
3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"@nomicfoundation/hardhat-verify": "^1.0.0",
"@openzeppelin/contracts": "^4.9.1",
"@safe-global/mock-contract": "^4.0.0",
"@gnosis.pm/safe-singleton-factory": "^1.0.14",
"@safe-global/safe-singleton-factory": "^1.0.14",
"@safe-global/safe-core-protocol": "^0.1.0-alpha.3",
"@typechain/ethers-v6": "^0.4.0",
"@typechain/hardhat": "^8.0.0",
"@types/chai": "^4.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getProtocolManagerAddress } from "../utils/protocol";

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;

const manager = await getProtocolManagerAddress(hre)
console.log({manager})

await deploy("SamplePlugin", {
from: deployer,
args: [],
args: [manager],
log: true,
deterministicDeployment: true,
});
Expand Down
41 changes: 41 additions & 0 deletions contracts/src/utils/protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import protocolDeployments from "@safe-global/safe-core-protocol"
import { id } from "ethers";

const deployMock = async(hre: HardhatRuntimeEnvironment, name: string): Promise<string> => {
const { deployments, getNamedAccounts } = hre;
const { deployer } = await getNamedAccounts();
const { deploy } = deployments;

const result = await deploy("MockContract", {
from: deployer,
args: [],
log: true,
deterministicDeployment: id(name),
});
return result.address
}

export const getProtocolManagerAddress = async(hre: HardhatRuntimeEnvironment): Promise<string> => {
const chainId = await hre.getChainId()

// For the tests we deploy a mock for the manager
if (chainId === "31337") return deployMock(hre, "ManagerMock")

if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain")
const manager = (protocolDeployments as any)[chainId][0].contracts.SafeProtocolManager.address
if (typeof manager !== "string") throw Error("Unexpected Manager")
return manager
}

export const getProtocolRegistryAddress = async(hre: HardhatRuntimeEnvironment): Promise<string> => {
const chainId = await hre.getChainId()

// For the tests we deploy a mock for the registry
if (chainId === "31337") return deployMock(hre, "RegistryMock")

if (!(chainId in protocolDeployments)) throw Error("Unsupported Chain")
const registry = (protocolDeployments as any)[chainId][0].contracts.SafeProtocolRegistry.address
if (typeof registry !== "string") throw Error("Unexpected Registry")
return registry
}
15 changes: 10 additions & 5 deletions contracts/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,6 @@
"@ethersproject/properties" "^5.7.0"
"@ethersproject/strings" "^5.7.0"

"@gnosis.pm/safe-singleton-factory@^1.0.14":
version "1.0.14"
resolved "https://registry.yarnpkg.com/@gnosis.pm/safe-singleton-factory/-/safe-singleton-factory-1.0.14.tgz#42dae9a91fda21b605f94bfe310a7fccc6a4d738"
integrity sha512-xZ26c9uKzpd5Sm8ux0sZHt5QC8n+Q2z1/X5xjPnd8aT5EcKH5t1GgLbAqjrMFmXVIOkiWSc7wi2Bj4XfgtiyaQ==

"@humanwhocodes/config-array@^0.11.10":
version "0.11.10"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.10.tgz#5a3ffe32cc9306365fb3fd572596cd602d5e12d2"
Expand Down Expand Up @@ -793,6 +788,16 @@
resolved "https://registry.yarnpkg.com/@safe-global/mock-contract/-/mock-contract-4.0.0.tgz#8e1e17e93af5d4b343a6bb6cef8c1f513cb7a92e"
integrity sha512-6ijStTgQI6JzYe8Nsc4j1VW4XQ89qCl7ZkRGxwwlxnaOMDYzVekwPACbg2kDDzhtJ4p8vSvE6ZroxSkvP7610A==

"@safe-global/safe-core-protocol@^0.1.0-alpha.3":
version "0.1.0-alpha.3"
resolved "https://registry.yarnpkg.com/@safe-global/safe-core-protocol/-/safe-core-protocol-0.1.0-alpha.3.tgz#355b81283b4ce611aa651af76186b1cd91ea0f45"
integrity sha512-iXIaqOrPuJVkTyLHlnzxa5+/oicK43snL6iH/m1f7nFqySvUlXcV29MeS9b3S5a6k8r3cMX9IlmK6GpWk0tx4w==

"@safe-global/safe-singleton-factory@^1.0.14":
version "1.0.14"
resolved "https://registry.yarnpkg.com/@safe-global/safe-singleton-factory/-/safe-singleton-factory-1.0.14.tgz#a4c3937670946d21428b45f09c779d672cc716de"
integrity sha512-5dyEfPU8oVY/2whxcc14eqWS2WJ8V1j1h3XiretSi9bb09IA+/FTlpooArtOiNs14v6KsMMRnwsHhpDQuZV6Sw==

"@scure/base@~1.1.0":
version "1.1.1"
resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.1.tgz#ebb651ee52ff84f420097055f4bf46cfba403938"
Expand Down

0 comments on commit 4e29e09

Please sign in to comment.