https://github.com/5afe/safe-core-protocol
This project is an implementation of Safe{Core} Protocol specification
https://github.com/5afe/safe-core-protocol
Last synced: 10 months ago
JSON representation
This project is an implementation of Safe{Core} Protocol specification
- Host: GitHub
- URL: https://github.com/5afe/safe-core-protocol
- Owner: 5afe
- License: lgpl-3.0
- Created: 2023-06-16T07:54:14.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-24T01:08:23.000Z (almost 2 years ago)
- Last Synced: 2024-12-10T20:51:45.921Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 442 KB
- Stars: 39
- Watchers: 11
- Forks: 17
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
**:warning: This repository is not actively developed at the moment. :warning:**
[](https://coveralls.io/github/safe-global/safe-core-protocol)
# Safe{Core} Protocol
This project is an implementation of [Safe{Core} Protocol specification](https://github.com/safe-global/safe-core-protocol-specs)
## Architecture
Safe{Core} Protocol implementation consists of following main components:
- [SafeProtocolManager](./contracts/SafeProtocolManager.sol)
- [SafeProtocolRegistry](./contracts/SafeProtocolRegistry.sol)
- [Interfaces for Modules](./contracts/interfaces/Modules.sol)
A high level overview of the architecture is as follows:
```mermaid
graph TD
Account -->|Execute transaction| Monitor
Account -->|Manage Modules| Store
Account -->|SafeProtocolManager handling fallback functionality| FunctionHandlerSupport
PluginInstance(Plugin Instance) -->|Execute transaction from Plugin| Monitor
RegistryOwner("Registry Owner") --> Maintain
RegistryOwner("Registry Owner") --> Flag
subgraph SafeProtocolManager
Store(Maintain Enabled Modules per Safe)
Monitor(Mediate Account transaction execution)
FunctionHandlerSupport("Provide additional functionality using Function Handler(s)")
HooksSupport("Hooks for validating transaction execution")
Monitor -.- HooksSupport
end
subgraph SafeProtocolRegistry
AllowQuery(Provide information about Modules)
Maintain("Maintain list of permitted Modules")
Flag("Mark Module as Malicious")
Monitor -...- AllowQuery
Store -...- AllowQuery
end
```
### Modules
```mermaid
graph TD
style Modules font-size:20px;
subgraph Modules
Plugin(Plugin)
Hooks(Hooks)
FunctionHandler(Function Handler)
SignatureValidator(Signature validator)
end
```
Currently implemented components of the Safe{Core} Protocol are:
- **SafeProtocolManager**
- **SafeProtocolRegistry**
- **Plugins**
- **Hooks**
- **Function Handler**
- Additionally a test version of registry **TestSafeProtocolRegistryUnrestricted** is also available.
[Execution flows](./docs/execution_flows.md) give a high-level overview of the different flows for the Safe{Core} Protocol.
## Deployments
All the deployed addresses of contracts are available in [deployments.ts](./deployments.ts) for each network along with contract abis. Alternatively, all the addresses are also available in a [markdown file](./docs/deployments.md)
## Using solidity interfaces
The solidity interfaces for the Safe{Core} Protocol contracts are available in [interfaces](./contracts/interfaces) directory. These interfaces are available for import into solidity smart contracts via the npm artifact.
To install the npm package, run the following command:
```bash
npm i @safe-global/safe-core-protocol
```
E.g. Create a plugin
```solidity
import {ISafeProtocolPlugin} from "@safe-global/safe-core-protocol/contracts/interfaces/Modules.sol";
contract SamplePlugin is ISafeProtocolPlugin {
function name() external view returns (string memory name) {
...
}
function version() external view returns (string memory version){
...
}
function metadataProvider() external view returns (uint256 providerType, bytes memory location){
...
}
function requiresPermissions() external view returns (uint8 permissions){
...
}
}
```
For more examples and information on adding Module(s) to the Registry, refer to [Safe{Core} Protocol demo](https://github.com/safe-global/safe-core-protocol-demo/tree/main/contracts)
## Useful commands
### Install
```bash
yarn
```
### Compile
```bash
npx hardhat compile
```
### Test
```bash
npx hardhat test
```
### Deploy
- Deploy test contracts network to goerli.
- [test registry](./contracts/test/TestSafeProtocolRegistryUnrestricted.sol)
- [test manager](./contracts/test/TestSafeProtocolManager.sol)
```bash
yarn hardhat deploy --network goerli --tags test-protocol --export-all deployments.ts
```
- Deploy contracts with [SafeProtocolRegistry](./contracts/test/TestSafeProtocolRegistryUnrestricted.sol) registry network to goerli.
```bash
yarn hardhat deploy --network goerli --tags protocol --export-all deployments.ts
```
### Other commands
| Command | Description |
| -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| `yarn hardhat generate:deployments` | Generate deployments markdown in [./docs/deployments.md](./docs/deployments.md) from [./deployments.ts](./deployments.ts) |
| `yarn hardhat verify --network goerli ` | Verify Registry contract(s)
Applicable for
- SafeProtocolRegistry.sol
- TestSafeProtocolRegistryUnrestricted.sol
|
| `yarn hardhat verify --network goerli ` | Verify SafeProtocolManager.sol |