├── .gitignore
├── docs
├── .gitignore
├── book.css
├── src
│ ├── src
│ │ ├── README.md
│ │ ├── Dagon.sol
│ │ │ ├── interface.IOwnable.md
│ │ │ ├── interface.IAuth.md
│ │ │ └── contract.Dagon.md
│ │ └── Summoner.sol
│ │ │ ├── interface.IAccounts.md
│ │ │ └── contract.Summoner.md
│ ├── SUMMARY.md
│ └── README.md
├── book.toml
└── solidity.min.js
├── .env.example
├── Dagon.pdf
├── .gitmodules
├── scripts
└── initCodeHash.sh
├── foundry.toml
├── .github
└── workflows
│ └── ci.yml
├── abi
├── Summoner.json
└── Dagon.json
├── src
├── Summoner.sol
└── Dagon.sol
├── .gas-snapshot
├── README.md
├── LICENSE
└── test
└── Dagon.t.sol
/.gitignore:
--------------------------------------------------------------------------------
1 | out
2 | cache
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | book/
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | ETHERSCAN_API_KEY=
2 | ARBISCAN_API_KEY=
3 | OPTIMISM_API_KEY=
--------------------------------------------------------------------------------
/Dagon.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Moloch-Mystics/dagon/HEAD/Dagon.pdf
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "lib/forge-std"]
2 | path = lib/forge-std
3 | url = https://github.com/foundry-rs/forge-std
4 | [submodule "lib/solady"]
5 | path = lib/solady
6 | url = https://github.com/vectorized/solady
7 |
--------------------------------------------------------------------------------
/docs/book.css:
--------------------------------------------------------------------------------
1 | table {
2 | margin: 0 auto;
3 | border-collapse: collapse;
4 | width: 100%;
5 | }
6 |
7 | table td:first-child {
8 | width: 15%;
9 | }
10 |
11 | table td:nth-child(2) {
12 | width: 25%;
13 | }
--------------------------------------------------------------------------------
/scripts/initCodeHash.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo $(cast keccak $(cast concat-hex "$(forge inspect $1 bytecode)" "$(cast abi-encode "constructor($(forge inspect $1 abi \
3 | | jq -r '.[] | select(.type == "constructor") | .inputs | map(.type) | join(",")'))" ${@:2})"))
--------------------------------------------------------------------------------
/docs/src/src/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # Contents
4 | - [Dagon](Dagon.sol/contract.Dagon.md)
5 | - [IAuth](Dagon.sol/interface.IAuth.md)
6 | - [IOwnable](Dagon.sol/interface.IOwnable.md)
7 | - [Summoner](Summoner.sol/contract.Summoner.md)
8 | - [IAccounts](Summoner.sol/interface.IAccounts.md)
9 |
--------------------------------------------------------------------------------
/docs/book.toml:
--------------------------------------------------------------------------------
1 | [book]
2 | src = "src"
3 | title = ""
4 |
5 | [output.html]
6 | no-section-label = true
7 | additional-js = ["solidity.min.js"]
8 | additional-css = ["book.css"]
9 | git-repository-url = "https://github.com/Moloch-Mystics/dagon"
10 |
11 | [output.html.fold]
12 | enable = true
13 |
--------------------------------------------------------------------------------
/docs/src/SUMMARY.md:
--------------------------------------------------------------------------------
1 | # Summary
2 | - [Home](README.md)
3 | # src
4 | - [Dagon](src/Dagon.sol/contract.Dagon.md)
5 | - [IAuth](src/Dagon.sol/interface.IAuth.md)
6 | - [IOwnable](src/Dagon.sol/interface.IOwnable.md)
7 | - [Summoner](src/Summoner.sol/contract.Summoner.md)
8 | - [IAccounts](src/Summoner.sol/interface.IAccounts.md)
9 |
--------------------------------------------------------------------------------
/docs/src/src/Dagon.sol/interface.IOwnable.md:
--------------------------------------------------------------------------------
1 | # IOwnable
2 | [Git Source](https://github.com/Moloch-Mystics/dagon/blob/d39dde7073476515dbf75345b60f2ea3d623186a/src/Dagon.sol)
3 |
4 | Simple ownership interface for handover requests.
5 |
6 |
7 | ## Functions
8 | ### requestOwnershipHandover
9 |
10 |
11 | ```solidity
12 | function requestOwnershipHandover() external payable;
13 | ```
14 |
15 |
--------------------------------------------------------------------------------
/foundry.toml:
--------------------------------------------------------------------------------
1 | [profile.default]
2 | solc_version = "0.8.26"
3 | evm_version = "cancun"
4 |
5 | optimizer = true
6 | optimizer_runs = 9_999_999
7 |
8 | remappings = [
9 | "@solady=lib/solady/",
10 | "@forge=lib/forge-std/src/"
11 | ]
12 |
13 | [fmt]
14 | line_length = 100
15 |
16 | [rpc_endpoints]
17 | main = "https://rpc.ankr.com/eth"
18 | opti = "https://rpc.ankr.com/optimism"
19 | arbi = "https://rpc.ankr.com/arbitrum"
--------------------------------------------------------------------------------
/docs/src/src/Summoner.sol/interface.IAccounts.md:
--------------------------------------------------------------------------------
1 | # IAccounts
2 | [Git Source](https://github.com/Moloch-Mystics/dagon/blob/d39dde7073476515dbf75345b60f2ea3d623186a/src/Summoner.sol)
3 |
4 | *Simple interface for Nani (𒀭) user account creation and setup.*
5 |
6 |
7 | ## Functions
8 | ### createAccount
9 |
10 |
11 | ```solidity
12 | function createAccount(address, bytes32) external payable returns (address);
13 | ```
14 |
15 | ### execute
16 |
17 |
18 | ```solidity
19 | function execute(address, uint256, bytes calldata) external payable returns (bytes memory);
20 | ```
21 |
22 |
--------------------------------------------------------------------------------
/docs/src/src/Dagon.sol/interface.IAuth.md:
--------------------------------------------------------------------------------
1 | # IAuth
2 | [Git Source](https://github.com/Moloch-Mystics/dagon/blob/d39dde7073476515dbf75345b60f2ea3d623186a/src/Dagon.sol)
3 |
4 | Simple authority interface for contracts.
5 |
6 |
7 | ## Functions
8 | ### validateTransfer
9 |
10 |
11 | ```solidity
12 | function validateTransfer(address, address, uint256, uint256) external payable returns (uint256);
13 | ```
14 |
15 | ### validateCall
16 |
17 |
18 | ```solidity
19 | function validateCall(address, address, uint256, bytes calldata)
20 | external
21 | payable
22 | returns (uint256);
23 | ```
24 |
25 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: ci
2 |
3 | on: [push]
4 |
5 | jobs:
6 | tests:
7 | name: Forge Testing
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v3
11 | with:
12 | submodules: recursive
13 | - uses: foundry-rs/foundry-toolchain@v1
14 | with:
15 | version: nightly
16 | - name: dependencies
17 | run: forge install
18 | - name: tests
19 | run: forge test
20 |
21 | snapshot:
22 | name: Forge Snapshot
23 | runs-on: ubuntu-latest
24 | steps:
25 | - uses: actions/checkout@v3
26 | with:
27 | submodules: recursive
28 | - uses: foundry-rs/foundry-toolchain@v1
29 | with:
30 | version: nightly
31 | - name: dependencies
32 | run: forge install
33 | - name: check contract sizes
34 | run: forge build --sizes
35 | - name: check gas snapshots
36 | run: forge snapshot --check
--------------------------------------------------------------------------------
/docs/src/src/Summoner.sol/contract.Summoner.md:
--------------------------------------------------------------------------------
1 | # Summoner
2 | [Git Source](https://github.com/Moloch-Mystics/dagon/blob/d39dde7073476515dbf75345b60f2ea3d623186a/src/Summoner.sol)
3 |
4 | Simple summoner for Dagon (𒀭) group accounts.
5 |
6 |
7 | ## State Variables
8 | ### DAGON
9 |
10 | ```solidity
11 | address internal constant DAGON = 0x000000000000FEb893BB5D63bA33323EdCC237cE;
12 | ```
13 |
14 |
15 | ### FACTORY
16 |
17 | ```solidity
18 | IAccounts internal constant FACTORY = IAccounts(0x0000000000009f1E546FC4A8F68eB98031846cb8);
19 | ```
20 |
21 |
22 | ## Functions
23 | ### summon
24 |
25 |
26 | ```solidity
27 | function summon(Ownership[] calldata summoners, uint88 threshold, bool locked, bytes12 salt)
28 | public
29 | payable
30 | returns (IAccounts account);
31 | ```
32 |
33 | ### summonForToken
34 |
35 |
36 | ```solidity
37 | function summonForToken(address token, Standard standard, uint88 threshold, bytes12 salt)
38 | public
39 | payable
40 | returns (IAccounts account);
41 | ```
42 |
43 | ## Structs
44 | ### Ownership
45 |
46 | ```solidity
47 | struct Ownership {
48 | address owner;
49 | uint96 shares;
50 | }
51 | ```
52 |
53 | ## Enums
54 | ### Standard
55 |
56 | ```solidity
57 | enum Standard {
58 | DAGON,
59 | ERC20,
60 | ERC721,
61 | ERC1155,
62 | ERC6909
63 | }
64 | ```
65 |
66 |
--------------------------------------------------------------------------------
/abi/Summoner.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "type": "function",
4 | "name": "summon",
5 | "inputs": [
6 | {
7 | "name": "summoners",
8 | "type": "tuple[]",
9 | "internalType": "struct Summoner.Ownership[]",
10 | "components": [
11 | {
12 | "name": "owner",
13 | "type": "address",
14 | "internalType": "address"
15 | },
16 | {
17 | "name": "shares",
18 | "type": "uint96",
19 | "internalType": "uint96"
20 | }
21 | ]
22 | },
23 | {
24 | "name": "threshold",
25 | "type": "uint88",
26 | "internalType": "uint88"
27 | },
28 | {
29 | "name": "locked",
30 | "type": "bool",
31 | "internalType": "bool"
32 | },
33 | {
34 | "name": "salt",
35 | "type": "bytes12",
36 | "internalType": "bytes12"
37 | }
38 | ],
39 | "outputs": [
40 | {
41 | "name": "account",
42 | "type": "address",
43 | "internalType": "contract IAccounts"
44 | }
45 | ],
46 | "stateMutability": "payable"
47 | },
48 | {
49 | "type": "function",
50 | "name": "summonForToken",
51 | "inputs": [
52 | {
53 | "name": "token",
54 | "type": "address",
55 | "internalType": "address"
56 | },
57 | {
58 | "name": "standard",
59 | "type": "uint8",
60 | "internalType": "enum Summoner.Standard"
61 | },
62 | {
63 | "name": "threshold",
64 | "type": "uint88",
65 | "internalType": "uint88"
66 | },
67 | {
68 | "name": "salt",
69 | "type": "bytes12",
70 | "internalType": "bytes12"
71 | }
72 | ],
73 | "outputs": [
74 | {
75 | "name": "account",
76 | "type": "address",
77 | "internalType": "contract IAccounts"
78 | }
79 | ],
80 | "stateMutability": "payable"
81 | }
82 | ]
--------------------------------------------------------------------------------
/src/Summoner.sol:
--------------------------------------------------------------------------------
1 | // ᗪᗩGOᑎ 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭
2 | // SPDX-License-Identifier: AGPL-3.0-only
3 | pragma solidity 0.8.26;
4 |
5 | /// @notice Simple summoner for Dagon (𒀭) group accounts.
6 | /// @custom:version 1.1.1
7 | contract Summoner {
8 | address internal constant DAGON = 0x000000000000FEb893BB5D63bA33323EdCC237cE;
9 | IAccounts internal constant FACTORY = IAccounts(0x0000000000009f1E546FC4A8F68eB98031846cb8);
10 |
11 | struct Ownership {
12 | address owner;
13 | uint96 shares;
14 | }
15 |
16 | enum Standard {
17 | DAGON,
18 | ERC20,
19 | ERC721,
20 | ERC1155,
21 | ERC6909
22 | }
23 |
24 | function summon(Ownership[] calldata summoners, uint88 threshold, bool locked, bytes12 salt) public payable returns (IAccounts account) {
25 | account = IAccounts(FACTORY.createAccount{value: msg.value}(address(this), bytes32(abi.encodePacked(this, salt))));
26 | for (uint256 i; i != summoners.length; ++i)
27 | account.execute(DAGON, 0, abi.encodeWithSignature("mint(address,uint96)", summoners[i].owner, summoners[i].shares));
28 | if (locked) account.execute(DAGON, 0, abi.encodeWithSignature("setAuth(address)", address(0xdead)));
29 | account.execute(DAGON, 0, abi.encodeWithSignature("setThreshold(uint88)", threshold));
30 | account.execute(address(account), 0, abi.encodeWithSignature("transferOwnership(address)", DAGON));
31 | }
32 |
33 | function summonForToken(address token, Standard standard, uint88 threshold, bytes12 salt) public payable returns (IAccounts account) {
34 | account = IAccounts(FACTORY.createAccount{value: msg.value}(address(this), bytes32(abi.encodePacked(this, salt))));
35 | account.execute(DAGON, 0, abi.encodeWithSignature("setToken(address,uint8)", token, standard));
36 | account.execute(DAGON, 0, abi.encodeWithSignature("setThreshold(uint88)", threshold));
37 | account.execute(address(account), 0, abi.encodeWithSignature("transferOwnership(address)", DAGON));
38 | }
39 | }
40 |
41 | /// @dev Simple interface for Nani (𒀭) user account creation and setup.
42 | interface IAccounts {
43 | function createAccount(address, bytes32) external payable returns (address);
44 | function execute(address, uint256, bytes calldata) external payable returns (bytes memory);
45 | }
--------------------------------------------------------------------------------
/.gas-snapshot:
--------------------------------------------------------------------------------
1 | DagonTest:testBurn(address,uint96) (runs: 260, μ: 138940, ~: 138940)
2 | DagonTest:testDeploy() (gas: 2367822)
3 | DagonTest:testFailBurnOverBalance(address,uint96) (runs: 260, μ: 153811, ~: 154347)
4 | DagonTest:testFailBurnOverThreshold(address,uint96) (runs: 260, μ: 185086, ~: 185622)
5 | DagonTest:testFailInvalidThresholdExceedsSupply() (gas: 124461)
6 | DagonTest:testFailInvalidThresholdExceedsSupply2() (gas: 129541)
7 | DagonTest:testFailInvalidThresholdNull() (gas: 124442)
8 | DagonTest:testFailIsValidSignature2of3ForInsufficientSignatures() (gas: 174649)
9 | DagonTest:testFailIsValidSignatureOutOfOrder() (gas: 214164)
10 | DagonTest:testFailIsValidSignatureSpoofed() (gas: 136100)
11 | DagonTest:testFailIsValidSignatureWeighted() (gas: 203856)
12 | DagonTest:testFailIsValidSignatureWeightedERC1155() (gas: 28447)
13 | DagonTest:testFailIsValidSignatureWeightedERC20() (gas: 213804)
14 | DagonTest:testFailIsValidSignatureWeightedERC6909() (gas: 214171)
15 | DagonTest:testFailIsValidSignatureWeightedERC721() (gas: 184747)
16 | DagonTest:testFailSetTokenInvalidStd(address) (runs: 260, μ: 123417, ~: 123417)
17 | DagonTest:testFailTransferFromInactiveAuth(address,address,uint96) (runs: 260, μ: 157582, ~: 158195)
18 | DagonTest:testFailTransferOverBalance(address,address,uint96) (runs: 260, μ: 152047, ~: 152660)
19 | DagonTest:testInstall() (gas: 122700)
20 | DagonTest:testIsValidSignature() (gas: 136470)
21 | DagonTest:testIsValidSignature2of3() (gas: 182924)
22 | DagonTest:testIsValidSignature3of3() (gas: 191246)
23 | DagonTest:testIsValidSignatureMany() (gas: 398475)
24 | DagonTest:testIsValidSignatureOnchain() (gas: 183289)
25 | DagonTest:testIsValidSignatureOnchainRaw() (gas: 174353)
26 | DagonTest:testIsValidSignatureWeighted() (gas: 220501)
27 | DagonTest:testIsValidSignatureWeightedERC1155() (gas: 236247)
28 | DagonTest:testIsValidSignatureWeightedERC20() (gas: 235763)
29 | DagonTest:testIsValidSignatureWeightedERC6909() (gas: 236233)
30 | DagonTest:testIsValidSignatureWeightedERC721() (gas: 195773)
31 | DagonTest:testNameAndSymbolAndDecimals(uint256) (runs: 260, μ: 18063, ~: 18063)
32 | DagonTest:testSetAuth(address) (runs: 260, μ: 131040, ~: 131040)
33 | DagonTest:testSetThreshold() (gas: 133204)
34 | DagonTest:testSetToken(address) (runs: 260, μ: 134663, ~: 134663)
35 | DagonTest:testSetURI() (gas: 150131)
36 | DagonTest:testSpoofSignatures(bytes) (runs: 260, μ: 14131, ~: 14090)
37 | DagonTest:testTransfer(address,address,uint88) (runs: 260, μ: 161001, ~: 161614)
38 | DagonTest:testTransferWithAuth(address,address,uint96) (runs: 260, μ: 165518, ~: 166131)
39 | DagonTest:testUserVoted() (gas: 184022)
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Dagon (𒀭)
2 | > minimalist and modular governance abstraction for accounts today through singletons
3 |
4 | 
5 |
6 | Built with *[Foundry](https://github.com/foundry-rs/forge-std)* and *[Solady](https://github.com/vectorized/solady)*.
7 |
8 | ## [Beta Deployment](https://contractscan.xyz/contract/0x000000000000FEb893BB5D63bA33323EdCC237cE)
9 |
10 | Chains | Address |
11 | ----------------|-----------------------------------------|
12 | Ethereum, Arbitrum, Optimism, Base, Blast, Zora, Gnosis, Polygon, Avalanche and BNB (& testnets) | [0x000000000000FEb893BB5D63bA33323EdCC237cE](https://etherscan.io/address/0x000000000000FEb893BB5D63bA33323EdCC237cE#code) |
13 |
14 | > Summoner: [0x000000004356af01f3b800d93b0066e4b71e3609](https://etherscan.io/address/0x000000004356af01f3b800d93b0066e4b71e3609#code)
15 |
16 | Dagon deployments are generated as [efficient create2 addresses](https://medium.com/coinmonks/on-efficient-ethereum-addresses-3fef0596e263) through the [canonical create2 factory](https://etherscan.io/address/0x0000000000ffe8b47b3e2130213b802212439497#code). As such they share the same exact address and code on every blockchain.
17 |
18 | ## Premise
19 |
20 | Dagon is a contract singleton system that allows any smart contract account to give any token a threshold right to sign for it. This means you can add "more owners" to your smart account. It also means you can give these different owners different "weights" to simulate a DAO voting engine or company captable. Equal weights are equivalent to a multi-sig or coop. These weights can be associated with existing tokens or created within Dagon itself. The sky is the limit as long as [`ERC-173`](https://eips.ethereum.org/EIPS/eip-173) and [`ERC-1271`](https://eips.ethereum.org/EIPS/eip-1271) are followed.
21 |
22 | Dagon thus supports existing token communities and DAO deployments out-of-the-gate. This voting format is optimized especially for most off-chain voting methods, like snapshot proposals, as well, initially offers a platform-agnostic upgrade path into smart account-based governance abstraction following, *e.g.*, [`ERC-4337`](https://eips.ethereum.org/EIPS/eip-4337).
23 |
24 | ## More specifically
25 |
26 | By just validating contract signatures remotely for accounts following `ERC-1271`, and not dealing with execution or more opinionated proposal logic, Dagon can complement more organizations today, as well as serve as a source of record for the greater DAO ecosystem, which are all free to implement their own custom hooks and checks to Dagon validation. In `V1`, which is focused as a voting engine, the Dagon pattern can be used for offchain polling for any token, including `ERC-20`, `ERC-721`, `ERC-1155`, `ERC-6909`, and includes a native token mint and burn function to allow tokens to upgrade (or new tokens to be issued) under `DAGON` (itself [`ERC-6909`](https://eips.ethereum.org/EIPS/eip-6909)), but can also validate onchain user operations (`userOp`s) that submit ownership to Dagon validation using the `ERC-173` `transferOwnership` flow.
27 |
28 | For example, DAOs might use Dagon singletons in small ways to start as an extension to their ordinary operating system and governor contracts, such as to prove the results of group polls and for simple dapp display purposes, but if Dagon is also registered as the owner of a group smart account (which could be earmarked or the full treasury), Dagon can then work as the DAO's proposal engine, validating userOps and letting them be posted onchain. In this mode, Dagon supports both token-weighted and m/n signature schemes. Collection of Dagon signatures is gasless, and can be posted in a single transaction through the Dagon `isValidSignature` function in response to a typical `ERC-4337` userOp flow.
29 |
30 | Overall, Dagon is designed with `ERC-4337`-enabled contracts and account abstraction in mind, but works well enough for accounts that at least support both the `ERC-1271` (Contract Signatures) and `ERC-173` (Ownership) standard interfaces. There is likely much to explore.
31 |
32 | ## Getting Started
33 |
34 | Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup`
35 |
36 | Build the foundry project with `forge build`. Run contract tests with `forge test`. Measure gas fees with `forge snapshot`. Format code with `forge fmt`.
37 |
38 | ## Disclaimer
39 |
40 | *These smart contracts and testing suite are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of anything provided herein or through related user interfaces. This repository and related code have not been audited and as such there can be no assurance anything will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk.*
41 |
42 | ## License
43 |
44 | See [LICENSE](./LICENSE) for more details.
45 |
--------------------------------------------------------------------------------
/docs/src/README.md:
--------------------------------------------------------------------------------
1 | # Dagon (𒀭)
2 | > minimalist and modular governance abstraction for accounts today through singletons
3 |
4 | 
5 |
6 | Built with *[Foundry](https://github.com/foundry-rs/forge-std)* and *[Solady](https://github.com/vectorized/solady)*.
7 |
8 | ## [Beta Deployment](https://contractscan.xyz/contract/0x000000000000FEb893BB5D63bA33323EdCC237cE)
9 |
10 | Chains | Address |
11 | ----------------|-----------------------------------------|
12 | Ethereum, Arbitrum, Optimism, Base, Blast, Zora, Gnosis, Polygon, Avalanche and BNB (& testnets) | [0x000000000000FEb893BB5D63bA33323EdCC237cE](https://etherscan.io/address/0x000000000000FEb893BB5D63bA33323EdCC237cE#code) |
13 |
14 | > Summoner: [0x000000004356af01f3b800d93b0066e4b71e3609](https://etherscan.io/address/0x000000004356af01f3b800d93b0066e4b71e3609#code)
15 |
16 | Dagon deployments are generated as [efficient create2 addresses](https://medium.com/coinmonks/on-efficient-ethereum-addresses-3fef0596e263) through the [canonical create2 factory](https://etherscan.io/address/0x0000000000ffe8b47b3e2130213b802212439497#code). As such they share the same exact address and code on every blockchain.
17 |
18 | ## Premise
19 |
20 | Dagon is a contract singleton system that allows any smart contract account to give any token a threshold right to sign for it. This means you can add "more owners" to your smart account. It also means you can give these different owners different "weights" to simulate a DAO voting engine or company captable. Equal weights are equivalent to a multi-sig or coop. These weights can be associated with existing tokens or created within Dagon itself. The sky is the limit as long as [`ERC-173`](https://eips.ethereum.org/EIPS/eip-173) and [`ERC-1271`](https://eips.ethereum.org/EIPS/eip-1271) are followed.
21 |
22 | Dagon thus supports existing token communities and DAO deployments out-of-the-gate. This voting format is optimized especially for most off-chain voting methods, like snapshot proposals, as well, initially offers a platform-agnostic upgrade path into smart account-based governance abstraction following, *e.g.*, [`ERC-4337`](https://eips.ethereum.org/EIPS/eip-4337).
23 |
24 | ## More specifically
25 |
26 | By just validating contract signatures remotely for accounts following `ERC-1271`, and not dealing with execution or more opinionated proposal logic, Dagon can complement more organizations today, as well as serve as a source of record for the greater DAO ecosystem, which are all free to implement their own custom hooks and checks to Dagon validation. In `V1`, which is focused as a voting engine, the Dagon pattern can be used for offchain polling for any token, including `ERC-20`, `ERC-721`, `ERC-1155`, `ERC-6909`, and includes a native token mint and burn function to allow tokens to upgrade (or new tokens to be issued) under `DAGON` (itself [`ERC-6909`](https://eips.ethereum.org/EIPS/eip-6909)), but can also validate onchain user operations (`userOp`s) that submit ownership to Dagon validation using the `ERC-173` `transferOwnership` flow.
27 |
28 | For example, DAOs might use Dagon singletons in small ways to start as an extension to their ordinary operating system and governor contracts, such as to prove the results of group polls and for simple dapp display purposes, but if Dagon is also registered as the owner of a group smart account (which could be earmarked or the full treasury), Dagon can then work as the DAO's proposal engine, validating userOps and letting them be posted onchain. In this mode, Dagon supports both token-weighted and m/n signature schemes. Collection of Dagon signatures is gasless, and can be posted in a single transaction through the Dagon `isValidSignature` function in response to a typical `ERC-4337` userOp flow.
29 |
30 | Overall, Dagon is designed with `ERC-4337`-enabled contracts and account abstraction in mind, but works well enough for accounts that at least support both the `ERC-1271` (Contract Signatures) and `ERC-173` (Ownership) standard interfaces. There is likely much to explore.
31 |
32 | ## Getting Started
33 |
34 | Run: `curl -L https://foundry.paradigm.xyz | bash && source ~/.bashrc && foundryup`
35 |
36 | Build the foundry project with `forge build`. Run contract tests with `forge test`. Measure gas fees with `forge snapshot`. Format code with `forge fmt`.
37 |
38 | ## Disclaimer
39 |
40 | *These smart contracts and testing suite are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of anything provided herein or through related user interfaces. This repository and related code have not been audited and as such there can be no assurance anything will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk.*
41 |
42 | ## License
43 |
44 | See [LICENSE](./LICENSE) for more details.
45 |
--------------------------------------------------------------------------------
/docs/solidity.min.js:
--------------------------------------------------------------------------------
1 | hljs.registerLanguage("solidity",(()=>{"use strict";function e(){try{return!0
2 | }catch(e){return!1}}
3 | var a=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/
4 | ;e()&&(a=a.source.replace(/\\b/g,"(?{
14 | var a=r(e),o=l(e),c=/[A-Za-z_$][A-Za-z_$0-9.]*/,d=e.inherit(e.TITLE_MODE,{
15 | begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:c,keywords:n}),u={className:"params",
16 | begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:c,keywords:n,
17 | contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,o,s]},_={
18 | className:"operator",begin:/:=|->/};return{keywords:n,lexemes:c,
19 | contains:[a,o,i,t,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,s,_,{
20 | className:"function",lexemes:c,beginKeywords:"function",end:"{",excludeEnd:!0,
21 | contains:[d,u,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,_]}]}},
22 | solAposStringMode:r,solQuoteStringMode:l,HEX_APOS_STRING_MODE:i,
23 | HEX_QUOTE_STRING_MODE:t,SOL_NUMBER:s,isNegativeLookbehindAvailable:e}
24 | ;const{baseAssembly:c,solAposStringMode:d,solQuoteStringMode:u,HEX_APOS_STRING_MODE:_,HEX_QUOTE_STRING_MODE:m,SOL_NUMBER:b,isNegativeLookbehindAvailable:E}=o
25 | ;return e=>{for(var a=d(e),s=u(e),n=[],i=0;i<32;i++)n[i]=i+1
26 | ;var t=n.map((e=>8*e)),r=[];for(i=0;i<=80;i++)r[i]=i
27 | ;var l=n.map((e=>"bytes"+e)).join(" ")+" ",o=t.map((e=>"uint"+e)).join(" ")+" ",g=t.map((e=>"int"+e)).join(" ")+" ",M=[].concat.apply([],t.map((e=>r.map((a=>e+"x"+a))))),p={
28 | keyword:"var bool string int uint "+g+o+"byte bytes "+l+"fixed ufixed "+M.map((e=>"fixed"+e)).join(" ")+" "+M.map((e=>"ufixed"+e)).join(" ")+" enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using pragma contract interface library is abstract type assembly",
29 | literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years",
30 | built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4"
31 | },O={className:"operator",begin:/[+\-!~*\/%<>&^|=]/
32 | },C=/[A-Za-z_$][A-Za-z_$0-9]*/,N={className:"params",begin:/\(/,end:/\)/,
33 | excludeBegin:!0,excludeEnd:!0,lexemes:C,keywords:p,
34 | contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,a,s,b,"self"]},f={
35 | begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{
36 | built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max"
37 | },relevance:2},y=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,
38 | lexemes:C,keywords:p}),w={className:"built_in",
39 | begin:(E()?"(? Metadata) internal _metadata;
20 | ```
21 |
22 |
23 | ### _settings
24 | *Stores mapping of ownership settings to accounts.*
25 |
26 |
27 | ```solidity
28 | mapping(address account => Settings) internal _settings;
29 | ```
30 |
31 |
32 | ### votingTally
33 | *Stores mapping of voting tallies to account operation hashes.*
34 |
35 |
36 | ```solidity
37 | mapping(address account => mapping(bytes32 hash => uint256)) public votingTally;
38 | ```
39 |
40 |
41 | ### voted
42 | *Stores mapping of account owner shares cast on account operation hashes.*
43 |
44 |
45 | ```solidity
46 | mapping(address account => mapping(address owner => mapping(bytes32 hash => uint256 shares))) public
47 | voted;
48 | ```
49 |
50 |
51 | ## Functions
52 | ### name
53 |
54 | ================= ERC6909 METADATA & SUPPLY ================= ///
55 |
56 | *Returns the name for token `id` using this contract.*
57 |
58 |
59 | ```solidity
60 | function name(uint256 id) public view virtual override(ERC6909) returns (string memory);
61 | ```
62 |
63 | ### symbol
64 |
65 | *Returns the symbol for token `id` using this contract.*
66 |
67 |
68 | ```solidity
69 | function symbol(uint256 id) public view virtual override(ERC6909) returns (string memory);
70 | ```
71 |
72 | ### tokenURI
73 |
74 | *Returns the URI for token `id` using this contract.*
75 |
76 |
77 | ```solidity
78 | function tokenURI(uint256 id) public view virtual override(ERC6909) returns (string memory);
79 | ```
80 |
81 | ### totalSupply
82 |
83 | *Returns the total supply for token `id` using this contract.*
84 |
85 |
86 | ```solidity
87 | function totalSupply(uint256 id) public view virtual returns (uint256);
88 | ```
89 |
90 | ### constructor
91 |
92 | ======================== CONSTRUCTOR ======================== ///
93 |
94 | *Constructs
95 | this implementation.*
96 |
97 |
98 | ```solidity
99 | constructor() payable;
100 | ```
101 |
102 | ### isValidSignature
103 |
104 | =================== VALIDATION OPERATIONS =================== ///
105 |
106 | *Validates ERC1271 signature with additional auth logic flow among owners.
107 | note: This implementation is designed to be the ERC-173-owner-of-4337-accounts.*
108 |
109 |
110 | ```solidity
111 | function isValidSignature(bytes32 hash, bytes calldata signature)
112 | public
113 | view
114 | virtual
115 | returns (bytes4);
116 | ```
117 |
118 | ### validateUserOp
119 |
120 | *Validates packed userOp with additional auth logic flow among owners.
121 | note: This is expected to be called in a validator plugin-like userOp flow.*
122 |
123 |
124 | ```solidity
125 | function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash, uint256)
126 | public
127 | virtual
128 | returns (uint256 validationData);
129 | ```
130 |
131 | ### _validateReturn
132 |
133 | *Returns validated signature result within the conventional ERC1271 syntax.*
134 |
135 |
136 | ```solidity
137 | function _validateReturn(bool success) internal pure virtual returns (bytes4 result);
138 | ```
139 |
140 | ### vote
141 |
142 | ===================== VOTING OPERATIONS ===================== ///
143 |
144 | *Casts account owners' voting shares on a given operation hash.*
145 |
146 |
147 | ```solidity
148 | function vote(address account, bytes32 hash, bytes calldata signature)
149 | public
150 | virtual
151 | returns (uint256);
152 | ```
153 |
154 | ### vote
155 |
156 | *Casts caller voting shares on a given operation hash and returns tally.*
157 |
158 |
159 | ```solidity
160 | function vote(address account, bytes32 hash) public virtual returns (uint256);
161 | ```
162 |
163 | ### install
164 |
165 | ======================== INSTALLATION ======================== ///
166 |
167 | *Initializes ownership settings for the caller account.
168 | note: Finalizes with transfer request in two-step pattern.
169 | See, e.g., Ownable.sol:
170 | https://github.com/Vectorized/solady/blob/main/src/auth/Ownable.sol*
171 |
172 |
173 | ```solidity
174 | function install(Ownership[] calldata owners, Settings calldata setting, Metadata calldata meta)
175 | public
176 | virtual;
177 | ```
178 |
179 | ### getSettings
180 |
181 | ===================== OWNERSHIP SETTINGS ===================== ///
182 |
183 | *Returns the account settings.*
184 |
185 |
186 | ```solidity
187 | function getSettings(address account) public view virtual returns (address, uint88, Standard);
188 | ```
189 |
190 | ### setAuth
191 |
192 | *Sets new authority contract for the caller account.*
193 |
194 |
195 | ```solidity
196 | function setAuth(IAuth auth) public virtual;
197 | ```
198 |
199 | ### setToken
200 |
201 | *Sets new token ownership interface standard for the caller account.*
202 |
203 |
204 | ```solidity
205 | function setToken(address token, Standard standard) public virtual;
206 | ```
207 |
208 | ### setThreshold
209 |
210 | *Sets new ownership threshold for the caller account.*
211 |
212 |
213 | ```solidity
214 | function setThreshold(uint88 threshold) public virtual;
215 | ```
216 |
217 | ### getMetadata
218 |
219 | ====================== TOKEN OPERATIONS ====================== ///
220 |
221 | *Returns the account metadata.*
222 |
223 |
224 | ```solidity
225 | function getMetadata(address account)
226 | public
227 | view
228 | virtual
229 | returns (string memory, string memory, string memory, IAuth);
230 | ```
231 |
232 | ### mint
233 |
234 | *Mints shares for an owner of the caller account.*
235 |
236 |
237 | ```solidity
238 | function mint(address owner, uint96 shares) public virtual;
239 | ```
240 |
241 | ### burn
242 |
243 | *Burns shares from an owner of the caller account.*
244 |
245 |
246 | ```solidity
247 | function burn(address owner, uint96 shares) public virtual;
248 | ```
249 |
250 | ### setURI
251 |
252 | *Sets new token URI metadata for the caller account.*
253 |
254 |
255 | ```solidity
256 | function setURI(string calldata uri) public virtual;
257 | ```
258 |
259 | ### _balanceOf
260 |
261 | =================== EXTERNAL TOKEN HELPERS =================== ///
262 |
263 | *Returns the amount of ERC20/721 `token` owned by `account`.*
264 |
265 |
266 | ```solidity
267 | function _balanceOf(address token, address account)
268 | internal
269 | view
270 | virtual
271 | returns (uint256 amount);
272 | ```
273 |
274 | ### _balanceOf
275 |
276 | *Returns the amount of ERC1155/6909 `token` `id` owned by `account`.*
277 |
278 |
279 | ```solidity
280 | function _balanceOf(address token, address account, uint256 id)
281 | internal
282 | view
283 | virtual
284 | returns (uint256 amount);
285 | ```
286 |
287 | ### _totalSupply
288 |
289 | *Returns the total supply of ERC20/721 `token`.*
290 |
291 |
292 | ```solidity
293 | function _totalSupply(address token) internal view virtual returns (uint256 supply);
294 | ```
295 |
296 | ### _totalSupply
297 |
298 | *Returns the total supply of ERC1155/6909 `token` `id`.*
299 |
300 |
301 | ```solidity
302 | function _totalSupply(address token, uint256 id) internal view virtual returns (uint256 supply);
303 | ```
304 |
305 | ### _beforeTokenTransfer
306 |
307 | ========================= OVERRIDES ========================= ///
308 |
309 | *Hook that is called before any transfer of tokens.
310 | This includes minting and burning. Also requests authority for token transfers.*
311 |
312 |
313 | ```solidity
314 | function _beforeTokenTransfer(address from, address to, uint256 id, uint256 amount)
315 | internal
316 | virtual
317 | override(ERC6909);
318 | ```
319 |
320 | ## Events
321 | ### URI
322 | =========================== EVENTS =========================== ///
323 |
324 | *Logs new metadata for an account ID.*
325 |
326 |
327 | ```solidity
328 | event URI(string uri, uint256 indexed id);
329 | ```
330 |
331 | ### AuthSet
332 | *Logs new authority contract for an account.*
333 |
334 |
335 | ```solidity
336 | event AuthSet(address indexed account, IAuth auth);
337 | ```
338 |
339 | ### ThresholdSet
340 | *Logs new ownership threshold for an account.*
341 |
342 |
343 | ```solidity
344 | event ThresholdSet(address indexed account, uint88 threshold);
345 | ```
346 |
347 | ### TokenSet
348 | *Logs new token ownership standard for an account.*
349 |
350 |
351 | ```solidity
352 | event TokenSet(address indexed account, address token, Standard standard);
353 | ```
354 |
355 | ## Errors
356 | ### InvalidSetting
357 | ======================= CUSTOM ERRORS ======================= ///
358 |
359 | *Inputs are invalid for an ownership setting.*
360 |
361 |
362 | ```solidity
363 | error InvalidSetting();
364 | ```
365 |
366 | ## Structs
367 | ### Metadata
368 | ========================== STRUCTS ========================== ///
369 |
370 | *The account token metadata struct.*
371 |
372 |
373 | ```solidity
374 | struct Metadata {
375 | string name;
376 | string symbol;
377 | string tokenURI;
378 | IAuth authority;
379 | uint96 totalSupply;
380 | }
381 | ```
382 |
383 | ### Ownership
384 | *The account ownership shares struct.*
385 |
386 |
387 | ```solidity
388 | struct Ownership {
389 | address owner;
390 | uint96 shares;
391 | }
392 | ```
393 |
394 | ### Signature
395 | *The signature struct.*
396 |
397 |
398 | ```solidity
399 | struct Signature {
400 | address owner;
401 | bytes sigData;
402 | }
403 | ```
404 |
405 | ### Settings
406 | *The account ownership settings struct.*
407 |
408 |
409 | ```solidity
410 | struct Settings {
411 | address token;
412 | uint88 threshold;
413 | Standard standard;
414 | }
415 | ```
416 |
417 | ### PackedUserOperation
418 | *The packed ERC4337 user operation (userOp) struct.*
419 |
420 |
421 | ```solidity
422 | struct PackedUserOperation {
423 | address sender;
424 | uint256 nonce;
425 | bytes initCode;
426 | bytes callData;
427 | bytes32 accountGasLimits;
428 | uint256 preVerificationGas;
429 | bytes32 gasFees;
430 | bytes paymasterAndData;
431 | bytes signature;
432 | }
433 | ```
434 |
435 | ## Enums
436 | ### Standard
437 | =========================== ENUMS =========================== ///
438 |
439 | *The token standard interface enum.*
440 |
441 |
442 | ```solidity
443 | enum Standard {
444 | DAGON,
445 | ERC20,
446 | ERC721,
447 | ERC1155,
448 | ERC6909
449 | }
450 | ```
451 |
452 |
--------------------------------------------------------------------------------
/src/Dagon.sol:
--------------------------------------------------------------------------------
1 | // ᗪᗩGOᑎ 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭 𒀭
2 | // SPDX-License-Identifier: AGPL-3.0-only
3 | pragma solidity 0.8.26;
4 |
5 | import {ERC6909} from "@solady/src/tokens/ERC6909.sol";
6 | import {SignatureCheckerLib} from "@solady/src/utils/SignatureCheckerLib.sol";
7 |
8 | /// @notice Simple ownership singleton for smart accounts. Version 1x.
9 | contract Dagon is ERC6909 {
10 | /// ======================= CUSTOM ERRORS ======================= ///
11 |
12 | /// @dev Inputs are invalid for an ownership setting.
13 | error InvalidSetting();
14 |
15 | /// =========================== EVENTS =========================== ///
16 |
17 | /// @dev Logs new metadata for an account ID.
18 | event URI(string uri, uint256 indexed id);
19 |
20 | /// @dev Logs new authority contract for an account.
21 | event AuthSet(address indexed account, IAuth auth);
22 |
23 | /// @dev Logs new ownership threshold for an account.
24 | event ThresholdSet(address indexed account, uint88 threshold);
25 |
26 | /// @dev Logs new token ownership standard for an account.
27 | event TokenSet(address indexed account, address token, Standard standard);
28 |
29 | /// ========================== STRUCTS ========================== ///
30 |
31 | /// @dev The account token metadata struct.
32 | struct Metadata {
33 | string name;
34 | string symbol;
35 | string tokenURI;
36 | IAuth authority;
37 | uint96 totalSupply;
38 | }
39 |
40 | /// @dev The account ownership shares struct.
41 | struct Ownership {
42 | address owner;
43 | uint96 shares;
44 | }
45 |
46 | /// @dev The signature struct.
47 | struct Signature {
48 | address owner;
49 | bytes sigData;
50 | }
51 |
52 | /// @dev The account ownership settings struct.
53 | struct Settings {
54 | address token;
55 | uint88 threshold;
56 | Standard standard;
57 | }
58 |
59 | /// @dev The packed ERC4337 user operation (userOp) struct.
60 | struct PackedUserOperation {
61 | address sender;
62 | uint256 nonce;
63 | bytes initCode;
64 | bytes callData;
65 | bytes32 accountGasLimits;
66 | uint256 preVerificationGas;
67 | bytes32 gasFees;
68 | bytes paymasterAndData;
69 | bytes signature;
70 | }
71 |
72 | /// =========================== ENUMS =========================== ///
73 |
74 | /// @dev The token standard interface enum.
75 | enum Standard {
76 | DAGON,
77 | ERC20,
78 | ERC721,
79 | ERC1155,
80 | ERC6909
81 | }
82 |
83 | /// ========================== STORAGE ========================== ///
84 |
85 | /// @dev Stores mapping of metadata settings to account token IDs.
86 | /// note: IDs are unique to addresses (`uint256(uint160(account))`).
87 | mapping(uint256 id => Metadata) internal _metadata;
88 |
89 | /// @dev Stores mapping of ownership settings to accounts.
90 | mapping(address account => Settings) internal _settings;
91 |
92 | /// @dev Stores mapping of voting tallies to account operation hashes.
93 | mapping(address account => mapping(bytes32 hash => uint256)) public votingTally;
94 |
95 | /// @dev Stores mapping of account owner shares cast on account operation hashes.
96 | mapping(address account => mapping(address owner => mapping(bytes32 hash => uint256 shares)))
97 | public voted;
98 |
99 | /// ================= ERC6909 METADATA & SUPPLY ================= ///
100 |
101 | /// @dev Returns the name for token `id` using this contract.
102 | function name(uint256 id) public view virtual override(ERC6909) returns (string memory) {
103 | return _metadata[id].name;
104 | }
105 |
106 | /// @dev Returns the symbol for token `id` using this contract.
107 | function symbol(uint256 id) public view virtual override(ERC6909) returns (string memory) {
108 | return _metadata[id].symbol;
109 | }
110 |
111 | /// @dev Returns the URI for token `id` using this contract.
112 | function tokenURI(uint256 id) public view virtual override(ERC6909) returns (string memory) {
113 | return _metadata[id].tokenURI;
114 | }
115 |
116 | /// @dev Returns the total supply for token `id` using this contract.
117 | function totalSupply(uint256 id) public view virtual returns (uint256) {
118 | return _metadata[id].totalSupply;
119 | }
120 |
121 | /// ======================== CONSTRUCTOR ======================== ///
122 |
123 | /// @dev Constructs
124 | /// this implementation.
125 | constructor() payable {}
126 |
127 | /// =================== VALIDATION OPERATIONS =================== ///
128 |
129 | /// @dev Validates ERC1271 signature with additional auth logic flow among owners.
130 | /// note: This implementation is designed to be the ERC-173-owner-of-4337-accounts.
131 | function isValidSignature(bytes32 hash, bytes calldata signature)
132 | public
133 | view
134 | virtual
135 | returns (bytes4)
136 | {
137 | Settings memory setting = _settings[msg.sender];
138 | if (signature.length != 0) {
139 | unchecked {
140 | Signature[] memory signatures = abi.decode(signature, (Signature[]));
141 | address prev;
142 | address owner;
143 | uint256 tally;
144 | for (uint256 i; i != signatures.length; ++i) {
145 | if (
146 | SignatureCheckerLib.isValidSignatureNow(
147 | owner = signatures[i].owner, hash, signatures[i].sigData
148 | ) && prev < owner // Check double voting.
149 | ) {
150 | prev = owner;
151 | tally += setting.standard == Standard.DAGON
152 | ? balanceOf(owner, uint256(uint160(msg.sender)))
153 | : setting.standard == Standard.ERC20 || setting.standard == Standard.ERC721
154 | ? _balanceOf(setting.token, owner)
155 | : _balanceOf(setting.token, owner, uint256(uint160(msg.sender)));
156 | } else {
157 | return 0xffffffff; // Failure code.
158 | }
159 | }
160 | return _validateReturn(tally >= setting.threshold);
161 | }
162 | }
163 | return _validateReturn(votingTally[msg.sender][hash] >= setting.threshold);
164 | }
165 |
166 | /// @dev Validates packed userOp with additional auth logic flow among owners.
167 | /// note: This is expected to be called in a validator plugin-like userOp flow.
168 | function validateUserOp(
169 | PackedUserOperation calldata userOp,
170 | bytes32 userOpHash,
171 | uint256 /*missingAccountFunds*/
172 | ) public virtual returns (uint256 validationData) {
173 | IAuth auth = _metadata[uint256(uint160(msg.sender))].authority;
174 | if (auth != IAuth(address(0))) {
175 | (address target, uint256 value, bytes memory data) =
176 | abi.decode(userOp.callData[4:], (address, uint256, bytes));
177 | auth.validateCall(msg.sender, target, value, data);
178 | }
179 | if (isValidSignature(userOpHash, userOp.signature) != this.isValidSignature.selector) {
180 | validationData = 0x01; // Failure code.
181 | }
182 | }
183 |
184 | /// @dev Returns validated signature result within the conventional ERC1271 syntax.
185 | function _validateReturn(bool success) internal pure virtual returns (bytes4 result) {
186 | assembly ("memory-safe") {
187 | // `success ? bytes4(keccak256("isValidSignature(bytes32,bytes)")) : 0xffffffff`.
188 | result := shl(224, or(0x1626ba7e, sub(0, iszero(success))))
189 | }
190 | }
191 |
192 | /// ===================== VOTING OPERATIONS ===================== ///
193 |
194 | /// @dev Casts account owners' voting shares on a given operation hash.
195 | function vote(address account, bytes32 hash, bytes calldata signature)
196 | public
197 | virtual
198 | returns (uint256)
199 | {
200 | Signature[] memory signatures = abi.decode(signature, (Signature[]));
201 | Settings memory setting = _settings[account];
202 | unchecked {
203 | address owner;
204 | uint256 tally;
205 | for (uint256 i; i != signatures.length; ++i) {
206 | if (
207 | SignatureCheckerLib.isValidSignatureNow(
208 | owner = signatures[i].owner, hash, signatures[i].sigData
209 | ) && voted[account][owner][hash] == 0 // Check double voting.
210 | ) {
211 | tally += voted[account][owner][hash] = setting.standard == Standard.DAGON
212 | ? balanceOf(owner, uint256(uint160(account)))
213 | : setting.standard == Standard.ERC20 || setting.standard == Standard.ERC721
214 | ? _balanceOf(setting.token, owner)
215 | : _balanceOf(setting.token, owner, uint256(uint160(account)));
216 | }
217 | }
218 | return votingTally[account][hash] += tally; // Return latest total tally.
219 | }
220 | }
221 |
222 | /// @dev Casts caller voting shares on a given operation hash and returns tally.
223 | function vote(address account, bytes32 hash) public virtual returns (uint256) {
224 | if (voted[account][msg.sender][hash] != 0) revert InsufficientPermission();
225 | Settings storage setting = _settings[account];
226 | unchecked {
227 | return votingTally[account][hash] += voted[account][msg.sender][hash] = setting.standard
228 | == Standard.DAGON
229 | ? balanceOf(msg.sender, uint256(uint160(account)))
230 | : setting.standard == Standard.ERC20 || setting.standard == Standard.ERC721
231 | ? _balanceOf(setting.token, msg.sender)
232 | : _balanceOf(setting.token, msg.sender, uint256(uint160(account)));
233 | }
234 | }
235 |
236 | /// ======================== INSTALLATION ======================== ///
237 |
238 | /// @dev Initializes ownership settings for the caller account.
239 | /// note: Finalizes with transfer request in two-step pattern.
240 | /// See, e.g., Ownable.sol:
241 | /// https://github.com/Vectorized/solady/blob/main/src/auth/Ownable.sol
242 | function install(Ownership[] calldata owners, Settings calldata setting, Metadata calldata meta)
243 | public
244 | virtual
245 | {
246 | uint256 id = uint256(uint160(msg.sender));
247 | if (owners.length != 0) {
248 | uint96 supply;
249 | for (uint256 i; i != owners.length; ++i) {
250 | supply += owners[i].shares;
251 | _mint(owners[i].owner, id, owners[i].shares);
252 | }
253 | _metadata[id].totalSupply += supply;
254 | }
255 | setToken(setting.token, setting.standard);
256 | setThreshold(setting.threshold);
257 | if (bytes(meta.name).length != 0) {
258 | _metadata[id].name = meta.name;
259 | _metadata[id].symbol = meta.symbol;
260 | }
261 | if (bytes(meta.tokenURI).length != 0) setURI(meta.tokenURI);
262 | if (meta.authority != IAuth(address(0))) setAuth(meta.authority);
263 | try IOwnable(msg.sender).requestOwnershipHandover() {} catch {} // Avoid revert.
264 | }
265 |
266 | /// ===================== OWNERSHIP SETTINGS ===================== ///
267 |
268 | /// @dev Returns the account settings.
269 | function getSettings(address account) public view virtual returns (address, uint88, Standard) {
270 | Settings storage set = _settings[account];
271 | return (set.token, set.threshold, set.standard);
272 | }
273 |
274 | /// @dev Sets new authority contract for the caller account.
275 | function setAuth(IAuth auth) public virtual {
276 | emit AuthSet(msg.sender, (_metadata[uint256(uint160(msg.sender))].authority = auth));
277 | }
278 |
279 | /// @dev Sets new token ownership interface standard for the caller account.
280 | function setToken(address token, Standard standard) public virtual {
281 | emit TokenSet(
282 | msg.sender,
283 | _settings[msg.sender].token = token,
284 | _settings[msg.sender].standard = standard
285 | );
286 | }
287 |
288 | /// @dev Sets new ownership threshold for the caller account.
289 | function setThreshold(uint88 threshold) public virtual {
290 | Settings storage set = _settings[msg.sender];
291 | if (
292 | threshold
293 | > (
294 | set.standard == Standard.DAGON
295 | ? totalSupply(uint256(uint160(msg.sender)))
296 | : set.standard == Standard.ERC20 || set.standard == Standard.ERC721
297 | ? _totalSupply(set.token)
298 | : _totalSupply(set.token, uint256(uint160(msg.sender)))
299 | ) || threshold == 0
300 | ) revert InvalidSetting();
301 | emit ThresholdSet(msg.sender, (set.threshold = threshold));
302 | }
303 |
304 | /// ====================== TOKEN OPERATIONS ====================== ///
305 |
306 | /// @dev Returns the account metadata.
307 | function getMetadata(address account)
308 | public
309 | view
310 | virtual
311 | returns (string memory, string memory, string memory, IAuth)
312 | {
313 | Metadata storage meta = _metadata[uint256(uint160(account))];
314 | return (meta.name, meta.symbol, meta.tokenURI, meta.authority);
315 | }
316 |
317 | /// @dev Mints shares for an owner of the caller account.
318 | function mint(address owner, uint96 shares) public virtual {
319 | uint256 id = uint256(uint160(msg.sender));
320 | _metadata[id].totalSupply += shares;
321 | _mint(owner, id, shares);
322 | }
323 |
324 | /// @dev Burns shares from an owner of the caller account.
325 | function burn(address owner, uint96 shares) public virtual {
326 | uint256 id = uint256(uint160(msg.sender));
327 | unchecked {
328 | if (_settings[msg.sender].threshold > (_metadata[id].totalSupply -= shares)) {
329 | revert InvalidSetting();
330 | }
331 | }
332 | _burn(owner, id, shares);
333 | }
334 |
335 | /// @dev Sets new token URI metadata for the caller account.
336 | function setURI(string calldata uri) public virtual {
337 | uint256 id = uint256(uint160(msg.sender));
338 | emit URI((_metadata[id].tokenURI = uri), id);
339 | }
340 |
341 | /// =================== EXTERNAL TOKEN HELPERS =================== ///
342 |
343 | /// @dev Returns the amount of ERC20/721 `token` owned by `account`.
344 | function _balanceOf(address token, address account)
345 | internal
346 | view
347 | virtual
348 | returns (uint256 amount)
349 | {
350 | assembly ("memory-safe") {
351 | mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
352 | mstore(0x14, account) // Store the `account` argument.
353 | pop(staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20))
354 | amount := mload(0x20)
355 | }
356 | }
357 |
358 | /// @dev Returns the amount of ERC1155/6909 `token` `id` owned by `account`.
359 | function _balanceOf(address token, address account, uint256 id)
360 | internal
361 | view
362 | virtual
363 | returns (uint256 amount)
364 | {
365 | assembly ("memory-safe") {
366 | mstore(0x00, 0x00fdd58e000000000000000000000000) // `balanceOf(address,uint256)`.
367 | mstore(0x14, account) // Store the `account` argument.
368 | mstore(0x34, id) // Store the `id` argument.
369 | pop(staticcall(gas(), token, 0x10, 0x44, 0x20, 0x20))
370 | amount := mload(0x20)
371 | mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
372 | }
373 | }
374 |
375 | /// @dev Returns the total supply of ERC20/721 `token`.
376 | function _totalSupply(address token) internal view virtual returns (uint256 supply) {
377 | assembly ("memory-safe") {
378 | mstore(0x00, 0x18160ddd) // `totalSupply()`.
379 | pop(staticcall(gas(), token, 0x1c, 0x04, 0x20, 0x20))
380 | supply := mload(0x20)
381 | }
382 | }
383 |
384 | /// @dev Returns the total supply of ERC1155/6909 `token` `id`.
385 | function _totalSupply(address token, uint256 id)
386 | internal
387 | view
388 | virtual
389 | returns (uint256 supply)
390 | {
391 | assembly ("memory-safe") {
392 | mstore(0x00, 0xbd85b039) // `totalSupply(uint256)`.
393 | mstore(0x20, id) // Store the `id` argument.
394 | pop(staticcall(gas(), token, 0x1c, 0x24, 0x20, 0x20))
395 | supply := mload(0x20)
396 | }
397 | }
398 |
399 | /// ========================= OVERRIDES ========================= ///
400 |
401 | /// @dev Hook that is called before any transfer of tokens.
402 | /// This includes minting and burning. Also requests authority for token transfers.
403 | function _beforeTokenTransfer(address from, address to, uint256 id, uint256 amount)
404 | internal
405 | virtual
406 | override(ERC6909)
407 | {
408 | IAuth auth = _metadata[id].authority;
409 | if (auth != IAuth(address(0))) auth.validateTransfer(from, to, id, amount);
410 | }
411 | }
412 |
413 | /// @notice Simple authority interface for contracts.
414 | interface IAuth {
415 | function validateTransfer(address, address, uint256, uint256)
416 | external
417 | payable
418 | returns (uint256);
419 | function validateCall(address, address, uint256, bytes calldata)
420 | external
421 | payable
422 | returns (uint256);
423 | }
424 |
425 | /// @notice Simple ownership interface for handover requests.
426 | interface IOwnable {
427 | function requestOwnershipHandover() external payable;
428 | }
429 |
--------------------------------------------------------------------------------
/abi/Dagon.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "type": "constructor",
4 | "inputs": [],
5 | "stateMutability": "payable"
6 | },
7 | {
8 | "type": "function",
9 | "name": "allowance",
10 | "inputs": [
11 | {
12 | "name": "owner",
13 | "type": "address",
14 | "internalType": "address"
15 | },
16 | {
17 | "name": "spender",
18 | "type": "address",
19 | "internalType": "address"
20 | },
21 | {
22 | "name": "id",
23 | "type": "uint256",
24 | "internalType": "uint256"
25 | }
26 | ],
27 | "outputs": [
28 | {
29 | "name": "amount",
30 | "type": "uint256",
31 | "internalType": "uint256"
32 | }
33 | ],
34 | "stateMutability": "view"
35 | },
36 | {
37 | "type": "function",
38 | "name": "approve",
39 | "inputs": [
40 | {
41 | "name": "spender",
42 | "type": "address",
43 | "internalType": "address"
44 | },
45 | {
46 | "name": "id",
47 | "type": "uint256",
48 | "internalType": "uint256"
49 | },
50 | {
51 | "name": "amount",
52 | "type": "uint256",
53 | "internalType": "uint256"
54 | }
55 | ],
56 | "outputs": [
57 | {
58 | "name": "",
59 | "type": "bool",
60 | "internalType": "bool"
61 | }
62 | ],
63 | "stateMutability": "payable"
64 | },
65 | {
66 | "type": "function",
67 | "name": "balanceOf",
68 | "inputs": [
69 | {
70 | "name": "owner",
71 | "type": "address",
72 | "internalType": "address"
73 | },
74 | {
75 | "name": "id",
76 | "type": "uint256",
77 | "internalType": "uint256"
78 | }
79 | ],
80 | "outputs": [
81 | {
82 | "name": "amount",
83 | "type": "uint256",
84 | "internalType": "uint256"
85 | }
86 | ],
87 | "stateMutability": "view"
88 | },
89 | {
90 | "type": "function",
91 | "name": "burn",
92 | "inputs": [
93 | {
94 | "name": "owner",
95 | "type": "address",
96 | "internalType": "address"
97 | },
98 | {
99 | "name": "shares",
100 | "type": "uint96",
101 | "internalType": "uint96"
102 | }
103 | ],
104 | "outputs": [],
105 | "stateMutability": "nonpayable"
106 | },
107 | {
108 | "type": "function",
109 | "name": "decimals",
110 | "inputs": [
111 | {
112 | "name": "id",
113 | "type": "uint256",
114 | "internalType": "uint256"
115 | }
116 | ],
117 | "outputs": [
118 | {
119 | "name": "",
120 | "type": "uint8",
121 | "internalType": "uint8"
122 | }
123 | ],
124 | "stateMutability": "view"
125 | },
126 | {
127 | "type": "function",
128 | "name": "getMetadata",
129 | "inputs": [
130 | {
131 | "name": "account",
132 | "type": "address",
133 | "internalType": "address"
134 | }
135 | ],
136 | "outputs": [
137 | {
138 | "name": "",
139 | "type": "string",
140 | "internalType": "string"
141 | },
142 | {
143 | "name": "",
144 | "type": "string",
145 | "internalType": "string"
146 | },
147 | {
148 | "name": "",
149 | "type": "string",
150 | "internalType": "string"
151 | },
152 | {
153 | "name": "",
154 | "type": "address",
155 | "internalType": "contract IAuth"
156 | }
157 | ],
158 | "stateMutability": "view"
159 | },
160 | {
161 | "type": "function",
162 | "name": "getSettings",
163 | "inputs": [
164 | {
165 | "name": "account",
166 | "type": "address",
167 | "internalType": "address"
168 | }
169 | ],
170 | "outputs": [
171 | {
172 | "name": "",
173 | "type": "address",
174 | "internalType": "address"
175 | },
176 | {
177 | "name": "",
178 | "type": "uint88",
179 | "internalType": "uint88"
180 | },
181 | {
182 | "name": "",
183 | "type": "uint8",
184 | "internalType": "enum Dagon.Standard"
185 | }
186 | ],
187 | "stateMutability": "view"
188 | },
189 | {
190 | "type": "function",
191 | "name": "install",
192 | "inputs": [
193 | {
194 | "name": "owners",
195 | "type": "tuple[]",
196 | "internalType": "struct Dagon.Ownership[]",
197 | "components": [
198 | {
199 | "name": "owner",
200 | "type": "address",
201 | "internalType": "address"
202 | },
203 | {
204 | "name": "shares",
205 | "type": "uint96",
206 | "internalType": "uint96"
207 | }
208 | ]
209 | },
210 | {
211 | "name": "setting",
212 | "type": "tuple",
213 | "internalType": "struct Dagon.Settings",
214 | "components": [
215 | {
216 | "name": "token",
217 | "type": "address",
218 | "internalType": "address"
219 | },
220 | {
221 | "name": "threshold",
222 | "type": "uint88",
223 | "internalType": "uint88"
224 | },
225 | {
226 | "name": "standard",
227 | "type": "uint8",
228 | "internalType": "enum Dagon.Standard"
229 | }
230 | ]
231 | },
232 | {
233 | "name": "meta",
234 | "type": "tuple",
235 | "internalType": "struct Dagon.Metadata",
236 | "components": [
237 | {
238 | "name": "name",
239 | "type": "string",
240 | "internalType": "string"
241 | },
242 | {
243 | "name": "symbol",
244 | "type": "string",
245 | "internalType": "string"
246 | },
247 | {
248 | "name": "tokenURI",
249 | "type": "string",
250 | "internalType": "string"
251 | },
252 | {
253 | "name": "authority",
254 | "type": "address",
255 | "internalType": "contract IAuth"
256 | },
257 | {
258 | "name": "totalSupply",
259 | "type": "uint96",
260 | "internalType": "uint96"
261 | }
262 | ]
263 | }
264 | ],
265 | "outputs": [],
266 | "stateMutability": "nonpayable"
267 | },
268 | {
269 | "type": "function",
270 | "name": "isOperator",
271 | "inputs": [
272 | {
273 | "name": "owner",
274 | "type": "address",
275 | "internalType": "address"
276 | },
277 | {
278 | "name": "spender",
279 | "type": "address",
280 | "internalType": "address"
281 | }
282 | ],
283 | "outputs": [
284 | {
285 | "name": "status",
286 | "type": "bool",
287 | "internalType": "bool"
288 | }
289 | ],
290 | "stateMutability": "view"
291 | },
292 | {
293 | "type": "function",
294 | "name": "isValidSignature",
295 | "inputs": [
296 | {
297 | "name": "hash",
298 | "type": "bytes32",
299 | "internalType": "bytes32"
300 | },
301 | {
302 | "name": "signature",
303 | "type": "bytes",
304 | "internalType": "bytes"
305 | }
306 | ],
307 | "outputs": [
308 | {
309 | "name": "",
310 | "type": "bytes4",
311 | "internalType": "bytes4"
312 | }
313 | ],
314 | "stateMutability": "view"
315 | },
316 | {
317 | "type": "function",
318 | "name": "mint",
319 | "inputs": [
320 | {
321 | "name": "owner",
322 | "type": "address",
323 | "internalType": "address"
324 | },
325 | {
326 | "name": "shares",
327 | "type": "uint96",
328 | "internalType": "uint96"
329 | }
330 | ],
331 | "outputs": [],
332 | "stateMutability": "nonpayable"
333 | },
334 | {
335 | "type": "function",
336 | "name": "name",
337 | "inputs": [
338 | {
339 | "name": "id",
340 | "type": "uint256",
341 | "internalType": "uint256"
342 | }
343 | ],
344 | "outputs": [
345 | {
346 | "name": "",
347 | "type": "string",
348 | "internalType": "string"
349 | }
350 | ],
351 | "stateMutability": "view"
352 | },
353 | {
354 | "type": "function",
355 | "name": "setAuth",
356 | "inputs": [
357 | {
358 | "name": "auth",
359 | "type": "address",
360 | "internalType": "contract IAuth"
361 | }
362 | ],
363 | "outputs": [],
364 | "stateMutability": "nonpayable"
365 | },
366 | {
367 | "type": "function",
368 | "name": "setOperator",
369 | "inputs": [
370 | {
371 | "name": "operator",
372 | "type": "address",
373 | "internalType": "address"
374 | },
375 | {
376 | "name": "approved",
377 | "type": "bool",
378 | "internalType": "bool"
379 | }
380 | ],
381 | "outputs": [
382 | {
383 | "name": "",
384 | "type": "bool",
385 | "internalType": "bool"
386 | }
387 | ],
388 | "stateMutability": "payable"
389 | },
390 | {
391 | "type": "function",
392 | "name": "setThreshold",
393 | "inputs": [
394 | {
395 | "name": "threshold",
396 | "type": "uint88",
397 | "internalType": "uint88"
398 | }
399 | ],
400 | "outputs": [],
401 | "stateMutability": "nonpayable"
402 | },
403 | {
404 | "type": "function",
405 | "name": "setToken",
406 | "inputs": [
407 | {
408 | "name": "token",
409 | "type": "address",
410 | "internalType": "address"
411 | },
412 | {
413 | "name": "standard",
414 | "type": "uint8",
415 | "internalType": "enum Dagon.Standard"
416 | }
417 | ],
418 | "outputs": [],
419 | "stateMutability": "nonpayable"
420 | },
421 | {
422 | "type": "function",
423 | "name": "setURI",
424 | "inputs": [
425 | {
426 | "name": "uri",
427 | "type": "string",
428 | "internalType": "string"
429 | }
430 | ],
431 | "outputs": [],
432 | "stateMutability": "nonpayable"
433 | },
434 | {
435 | "type": "function",
436 | "name": "supportsInterface",
437 | "inputs": [
438 | {
439 | "name": "interfaceId",
440 | "type": "bytes4",
441 | "internalType": "bytes4"
442 | }
443 | ],
444 | "outputs": [
445 | {
446 | "name": "result",
447 | "type": "bool",
448 | "internalType": "bool"
449 | }
450 | ],
451 | "stateMutability": "view"
452 | },
453 | {
454 | "type": "function",
455 | "name": "symbol",
456 | "inputs": [
457 | {
458 | "name": "id",
459 | "type": "uint256",
460 | "internalType": "uint256"
461 | }
462 | ],
463 | "outputs": [
464 | {
465 | "name": "",
466 | "type": "string",
467 | "internalType": "string"
468 | }
469 | ],
470 | "stateMutability": "view"
471 | },
472 | {
473 | "type": "function",
474 | "name": "tokenURI",
475 | "inputs": [
476 | {
477 | "name": "id",
478 | "type": "uint256",
479 | "internalType": "uint256"
480 | }
481 | ],
482 | "outputs": [
483 | {
484 | "name": "",
485 | "type": "string",
486 | "internalType": "string"
487 | }
488 | ],
489 | "stateMutability": "view"
490 | },
491 | {
492 | "type": "function",
493 | "name": "totalSupply",
494 | "inputs": [
495 | {
496 | "name": "id",
497 | "type": "uint256",
498 | "internalType": "uint256"
499 | }
500 | ],
501 | "outputs": [
502 | {
503 | "name": "",
504 | "type": "uint256",
505 | "internalType": "uint256"
506 | }
507 | ],
508 | "stateMutability": "view"
509 | },
510 | {
511 | "type": "function",
512 | "name": "transfer",
513 | "inputs": [
514 | {
515 | "name": "to",
516 | "type": "address",
517 | "internalType": "address"
518 | },
519 | {
520 | "name": "id",
521 | "type": "uint256",
522 | "internalType": "uint256"
523 | },
524 | {
525 | "name": "amount",
526 | "type": "uint256",
527 | "internalType": "uint256"
528 | }
529 | ],
530 | "outputs": [
531 | {
532 | "name": "",
533 | "type": "bool",
534 | "internalType": "bool"
535 | }
536 | ],
537 | "stateMutability": "payable"
538 | },
539 | {
540 | "type": "function",
541 | "name": "transferFrom",
542 | "inputs": [
543 | {
544 | "name": "from",
545 | "type": "address",
546 | "internalType": "address"
547 | },
548 | {
549 | "name": "to",
550 | "type": "address",
551 | "internalType": "address"
552 | },
553 | {
554 | "name": "id",
555 | "type": "uint256",
556 | "internalType": "uint256"
557 | },
558 | {
559 | "name": "amount",
560 | "type": "uint256",
561 | "internalType": "uint256"
562 | }
563 | ],
564 | "outputs": [
565 | {
566 | "name": "",
567 | "type": "bool",
568 | "internalType": "bool"
569 | }
570 | ],
571 | "stateMutability": "payable"
572 | },
573 | {
574 | "type": "function",
575 | "name": "validateUserOp",
576 | "inputs": [
577 | {
578 | "name": "userOp",
579 | "type": "tuple",
580 | "internalType": "struct Dagon.PackedUserOperation",
581 | "components": [
582 | {
583 | "name": "sender",
584 | "type": "address",
585 | "internalType": "address"
586 | },
587 | {
588 | "name": "nonce",
589 | "type": "uint256",
590 | "internalType": "uint256"
591 | },
592 | {
593 | "name": "initCode",
594 | "type": "bytes",
595 | "internalType": "bytes"
596 | },
597 | {
598 | "name": "callData",
599 | "type": "bytes",
600 | "internalType": "bytes"
601 | },
602 | {
603 | "name": "accountGasLimits",
604 | "type": "bytes32",
605 | "internalType": "bytes32"
606 | },
607 | {
608 | "name": "preVerificationGas",
609 | "type": "uint256",
610 | "internalType": "uint256"
611 | },
612 | {
613 | "name": "gasFees",
614 | "type": "bytes32",
615 | "internalType": "bytes32"
616 | },
617 | {
618 | "name": "paymasterAndData",
619 | "type": "bytes",
620 | "internalType": "bytes"
621 | },
622 | {
623 | "name": "signature",
624 | "type": "bytes",
625 | "internalType": "bytes"
626 | }
627 | ]
628 | },
629 | {
630 | "name": "userOpHash",
631 | "type": "bytes32",
632 | "internalType": "bytes32"
633 | },
634 | {
635 | "name": "",
636 | "type": "uint256",
637 | "internalType": "uint256"
638 | }
639 | ],
640 | "outputs": [
641 | {
642 | "name": "validationData",
643 | "type": "uint256",
644 | "internalType": "uint256"
645 | }
646 | ],
647 | "stateMutability": "nonpayable"
648 | },
649 | {
650 | "type": "function",
651 | "name": "vote",
652 | "inputs": [
653 | {
654 | "name": "account",
655 | "type": "address",
656 | "internalType": "address"
657 | },
658 | {
659 | "name": "hash",
660 | "type": "bytes32",
661 | "internalType": "bytes32"
662 | }
663 | ],
664 | "outputs": [
665 | {
666 | "name": "",
667 | "type": "uint256",
668 | "internalType": "uint256"
669 | }
670 | ],
671 | "stateMutability": "nonpayable"
672 | },
673 | {
674 | "type": "function",
675 | "name": "vote",
676 | "inputs": [
677 | {
678 | "name": "account",
679 | "type": "address",
680 | "internalType": "address"
681 | },
682 | {
683 | "name": "hash",
684 | "type": "bytes32",
685 | "internalType": "bytes32"
686 | },
687 | {
688 | "name": "signature",
689 | "type": "bytes",
690 | "internalType": "bytes"
691 | }
692 | ],
693 | "outputs": [
694 | {
695 | "name": "",
696 | "type": "uint256",
697 | "internalType": "uint256"
698 | }
699 | ],
700 | "stateMutability": "nonpayable"
701 | },
702 | {
703 | "type": "function",
704 | "name": "voted",
705 | "inputs": [
706 | {
707 | "name": "account",
708 | "type": "address",
709 | "internalType": "address"
710 | },
711 | {
712 | "name": "owner",
713 | "type": "address",
714 | "internalType": "address"
715 | },
716 | {
717 | "name": "hash",
718 | "type": "bytes32",
719 | "internalType": "bytes32"
720 | }
721 | ],
722 | "outputs": [
723 | {
724 | "name": "shares",
725 | "type": "uint256",
726 | "internalType": "uint256"
727 | }
728 | ],
729 | "stateMutability": "view"
730 | },
731 | {
732 | "type": "function",
733 | "name": "votingTally",
734 | "inputs": [
735 | {
736 | "name": "account",
737 | "type": "address",
738 | "internalType": "address"
739 | },
740 | {
741 | "name": "hash",
742 | "type": "bytes32",
743 | "internalType": "bytes32"
744 | }
745 | ],
746 | "outputs": [
747 | {
748 | "name": "",
749 | "type": "uint256",
750 | "internalType": "uint256"
751 | }
752 | ],
753 | "stateMutability": "view"
754 | },
755 | {
756 | "type": "event",
757 | "name": "Approval",
758 | "inputs": [
759 | {
760 | "name": "owner",
761 | "type": "address",
762 | "indexed": true,
763 | "internalType": "address"
764 | },
765 | {
766 | "name": "spender",
767 | "type": "address",
768 | "indexed": true,
769 | "internalType": "address"
770 | },
771 | {
772 | "name": "id",
773 | "type": "uint256",
774 | "indexed": true,
775 | "internalType": "uint256"
776 | },
777 | {
778 | "name": "amount",
779 | "type": "uint256",
780 | "indexed": false,
781 | "internalType": "uint256"
782 | }
783 | ],
784 | "anonymous": false
785 | },
786 | {
787 | "type": "event",
788 | "name": "AuthSet",
789 | "inputs": [
790 | {
791 | "name": "account",
792 | "type": "address",
793 | "indexed": true,
794 | "internalType": "address"
795 | },
796 | {
797 | "name": "auth",
798 | "type": "address",
799 | "indexed": false,
800 | "internalType": "contract IAuth"
801 | }
802 | ],
803 | "anonymous": false
804 | },
805 | {
806 | "type": "event",
807 | "name": "OperatorSet",
808 | "inputs": [
809 | {
810 | "name": "owner",
811 | "type": "address",
812 | "indexed": true,
813 | "internalType": "address"
814 | },
815 | {
816 | "name": "operator",
817 | "type": "address",
818 | "indexed": true,
819 | "internalType": "address"
820 | },
821 | {
822 | "name": "approved",
823 | "type": "bool",
824 | "indexed": false,
825 | "internalType": "bool"
826 | }
827 | ],
828 | "anonymous": false
829 | },
830 | {
831 | "type": "event",
832 | "name": "ThresholdSet",
833 | "inputs": [
834 | {
835 | "name": "account",
836 | "type": "address",
837 | "indexed": true,
838 | "internalType": "address"
839 | },
840 | {
841 | "name": "threshold",
842 | "type": "uint88",
843 | "indexed": false,
844 | "internalType": "uint88"
845 | }
846 | ],
847 | "anonymous": false
848 | },
849 | {
850 | "type": "event",
851 | "name": "TokenSet",
852 | "inputs": [
853 | {
854 | "name": "account",
855 | "type": "address",
856 | "indexed": true,
857 | "internalType": "address"
858 | },
859 | {
860 | "name": "token",
861 | "type": "address",
862 | "indexed": false,
863 | "internalType": "address"
864 | },
865 | {
866 | "name": "standard",
867 | "type": "uint8",
868 | "indexed": false,
869 | "internalType": "enum Dagon.Standard"
870 | }
871 | ],
872 | "anonymous": false
873 | },
874 | {
875 | "type": "event",
876 | "name": "Transfer",
877 | "inputs": [
878 | {
879 | "name": "by",
880 | "type": "address",
881 | "indexed": false,
882 | "internalType": "address"
883 | },
884 | {
885 | "name": "from",
886 | "type": "address",
887 | "indexed": true,
888 | "internalType": "address"
889 | },
890 | {
891 | "name": "to",
892 | "type": "address",
893 | "indexed": true,
894 | "internalType": "address"
895 | },
896 | {
897 | "name": "id",
898 | "type": "uint256",
899 | "indexed": true,
900 | "internalType": "uint256"
901 | },
902 | {
903 | "name": "amount",
904 | "type": "uint256",
905 | "indexed": false,
906 | "internalType": "uint256"
907 | }
908 | ],
909 | "anonymous": false
910 | },
911 | {
912 | "type": "event",
913 | "name": "URI",
914 | "inputs": [
915 | {
916 | "name": "uri",
917 | "type": "string",
918 | "indexed": false,
919 | "internalType": "string"
920 | },
921 | {
922 | "name": "id",
923 | "type": "uint256",
924 | "indexed": true,
925 | "internalType": "uint256"
926 | }
927 | ],
928 | "anonymous": false
929 | },
930 | {
931 | "type": "error",
932 | "name": "BalanceOverflow",
933 | "inputs": []
934 | },
935 | {
936 | "type": "error",
937 | "name": "InsufficientBalance",
938 | "inputs": []
939 | },
940 | {
941 | "type": "error",
942 | "name": "InsufficientPermission",
943 | "inputs": []
944 | },
945 | {
946 | "type": "error",
947 | "name": "InvalidSetting",
948 | "inputs": []
949 | }
950 | ]
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/test/Dagon.t.sol:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: AGPL-3.0-only
2 | pragma solidity 0.8.26;
3 |
4 | import "@forge/Test.sol";
5 |
6 | import "@solady/test/utils/mocks/MockERC20.sol";
7 | import "@solady/test/utils/mocks/MockERC721.sol";
8 | import "@solady/test/utils/mocks/MockERC1155.sol";
9 | import "@solady/test/utils/mocks/MockERC6909.sol";
10 |
11 | import {SignatureCheckerLib} from "@solady/src/utils/SignatureCheckerLib.sol";
12 |
13 | import {IAuth, Dagon} from "../src/Dagon.sol";
14 |
15 | /// @dev The ERC4337 userOp struct.
16 | struct PackedUserOperation {
17 | address sender;
18 | uint256 nonce;
19 | bytes initCode;
20 | bytes callData;
21 | bytes32 accountGasLimits;
22 | uint256 preVerificationGas;
23 | bytes32 gasFees;
24 | bytes paymasterAndData;
25 | bytes signature;
26 | }
27 |
28 | /// @dev Simple smart account with ERC4337 functions.
29 | contract SimpleAccount {
30 | address public owner;
31 |
32 | constructor(address _owner) payable {
33 | owner = _owner;
34 | }
35 |
36 | function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash, uint256)
37 | external
38 | payable
39 | returns (uint256 validationData)
40 | {
41 | if (SignatureCheckerLib.isValidSignatureNowCalldata(owner, userOpHash, userOp.signature)) {
42 | return 0x00;
43 | } else {
44 | return 0x01;
45 | }
46 | }
47 |
48 | function execute(address to, uint256 value, bytes calldata data)
49 | public
50 | payable
51 | returns (bytes memory retData)
52 | {
53 | (bool ok, bytes memory ret) = to.call{value: value}(data);
54 | retData = ret;
55 | assert(ok);
56 | }
57 |
58 | function transferOwnership(address to) public {
59 | owner = to;
60 | }
61 |
62 | function isValidSignature(bytes32 hash, bytes calldata signature)
63 | public
64 | view
65 | returns (bytes4)
66 | {
67 | if (SignatureCheckerLib.isValidSignatureNowCalldata(owner, hash, signature)) {
68 | return this.isValidSignature.selector;
69 | } else {
70 | return 0xffffffff;
71 | }
72 | }
73 | }
74 |
75 | /// @dev Dagon singleton test coverage.
76 | contract DagonTest is Test {
77 | address internal alice;
78 | uint256 internal alicePk;
79 | address internal bob;
80 | uint256 internal bobPk;
81 | address internal chuck;
82 | uint256 internal chuckPk;
83 | address internal dave;
84 | uint256 internal davePk;
85 | address internal ed;
86 | uint256 internal edPk;
87 | address internal fargo;
88 | uint256 internal fargoPk;
89 | address internal gravy;
90 | uint256 internal gravyPk;
91 | address internal holly;
92 | uint256 internal hollyPk;
93 | address internal ignis;
94 | uint256 internal ignisPk;
95 | address internal jake;
96 | uint256 internal jakePk;
97 | address internal kate;
98 | uint256 internal katePk;
99 | address internal leo;
100 | uint256 internal leoPk;
101 | address internal mia;
102 | uint256 internal miaPk;
103 | address internal nora;
104 | uint256 internal noraPk;
105 | address internal oscar;
106 | uint256 internal oscarPk;
107 | address internal piper;
108 | uint256 internal piperPk;
109 | address internal quinn;
110 | uint256 internal quinnPk;
111 | address internal rick;
112 | uint256 internal rickPk;
113 | address internal sara;
114 | uint256 internal saraPk;
115 | address internal tina;
116 | uint256 internal tinaPk;
117 | address internal uma;
118 | uint256 internal umaPk;
119 | address internal vince;
120 | uint256 internal vincePk;
121 | address internal wendy;
122 | uint256 internal wendyPk;
123 | address internal xander;
124 | uint256 internal xanderPk;
125 | address internal yasmine;
126 | uint256 internal yasminePk;
127 | address internal zane;
128 | uint256 internal zanePk;
129 |
130 | mapping(address => uint256) internal keys;
131 |
132 | address internal erc20;
133 | address internal erc721;
134 | address internal erc1155;
135 | address internal erc6909;
136 |
137 | address internal mockAuth;
138 |
139 | SimpleAccount internal account;
140 | uint256 internal accountId;
141 | Dagon internal dagon;
142 |
143 | address internal constant _ENTRY_POINT = 0x0000000071727De22E5E9d8BAf0edAc6f37da032;
144 |
145 | error InsufficientPermission();
146 |
147 | struct Signature {
148 | address owner;
149 | bytes sigData;
150 | }
151 |
152 | function setUp() public payable {
153 | (alice, alicePk) = makeAddrAndKey("alice");
154 | keys[alice] = alicePk;
155 | (bob, bobPk) = makeAddrAndKey("bob");
156 | keys[bob] = bobPk;
157 | (chuck, chuckPk) = makeAddrAndKey("chuck");
158 | keys[chuck] = chuckPk;
159 | (dave, davePk) = makeAddrAndKey("dave");
160 | keys[dave] = davePk;
161 | (ed, edPk) = makeAddrAndKey("ed");
162 | keys[ed] = edPk;
163 | (fargo, fargoPk) = makeAddrAndKey("fargo");
164 | keys[fargo] = fargoPk;
165 | (gravy, gravyPk) = makeAddrAndKey("gravy");
166 | keys[gravy] = gravyPk;
167 | (holly, hollyPk) = makeAddrAndKey("holly");
168 | keys[holly] = hollyPk;
169 | (ignis, ignisPk) = makeAddrAndKey("ignis");
170 | keys[ignis] = ignisPk;
171 | (jake, jakePk) = makeAddrAndKey("jake");
172 | keys[jake] = jakePk;
173 | (kate, katePk) = makeAddrAndKey("kate");
174 | keys[kate] = katePk;
175 | (leo, leoPk) = makeAddrAndKey("leo");
176 | keys[leo] = leoPk;
177 | (mia, miaPk) = makeAddrAndKey("mia");
178 | keys[mia] = miaPk;
179 | (nora, noraPk) = makeAddrAndKey("nora");
180 | keys[nora] = noraPk;
181 | (oscar, oscarPk) = makeAddrAndKey("oscar");
182 | keys[oscar] = oscarPk;
183 | (piper, piperPk) = makeAddrAndKey("piper");
184 | keys[piper] = piperPk;
185 | (quinn, quinnPk) = makeAddrAndKey("quinn");
186 | keys[quinn] = quinnPk;
187 | (rick, rickPk) = makeAddrAndKey("rick");
188 | keys[rick] = rickPk;
189 | (sara, saraPk) = makeAddrAndKey("sara");
190 | keys[sara] = saraPk;
191 | (tina, tinaPk) = makeAddrAndKey("tina");
192 | keys[tina] = tinaPk;
193 | (uma, umaPk) = makeAddrAndKey("uma");
194 | keys[uma] = umaPk;
195 | (vince, vincePk) = makeAddrAndKey("vince");
196 | keys[vince] = vincePk;
197 | (wendy, wendyPk) = makeAddrAndKey("wendy");
198 | keys[wendy] = wendyPk;
199 | (xander, xanderPk) = makeAddrAndKey("xander");
200 | keys[xander] = xanderPk;
201 | (yasmine, yasminePk) = makeAddrAndKey("yasmine");
202 | keys[yasmine] = yasminePk;
203 | (zane, zanePk) = makeAddrAndKey("zane");
204 | keys[zane] = zanePk;
205 |
206 | // Etch something onto `_ENTRY_POINT` such that we can deploy the account implementation.
207 | vm.etch(_ENTRY_POINT, hex"00");
208 |
209 | account = new SimpleAccount(alice);
210 | accountId = uint256(uint160(address(account)));
211 |
212 | dagon = new Dagon();
213 |
214 | erc20 = address(new MockERC20("TEST", "TEST", 18));
215 | MockERC20(erc20).mint(alice, 40 ether);
216 | MockERC20(erc20).mint(bob, 20 ether);
217 | MockERC20(erc20).mint(chuck, 20 ether);
218 | MockERC20(erc20).mint(dave, 20 ether);
219 |
220 | erc721 = address(new MockERC721TotalSupply());
221 | MockERC721TotalSupply(erc721).mint(alice, 0);
222 | MockERC721TotalSupply(erc721).mint(bob, 1);
223 | MockERC721TotalSupply(erc721).mint(chuck, 2);
224 | MockERC721TotalSupply(erc721).mint(dave, 3);
225 |
226 | erc1155 = address(new MockERC1155TotalSupply());
227 | MockERC1155TotalSupply(erc1155).mint(alice, accountId, 40 ether, "");
228 | MockERC1155TotalSupply(erc1155).mint(bob, accountId, 20 ether, "");
229 | MockERC1155TotalSupply(erc1155).mint(chuck, accountId, 20 ether, "");
230 | MockERC1155TotalSupply(erc1155).mint(dave, accountId, 20 ether, "");
231 |
232 | erc6909 = address(new MockERC6909TotalSupply());
233 | MockERC6909TotalSupply(erc6909).mint(alice, accountId, 40 ether);
234 | MockERC6909TotalSupply(erc6909).mint(bob, accountId, 20 ether);
235 | MockERC6909TotalSupply(erc6909).mint(chuck, accountId, 20 ether);
236 | MockERC6909TotalSupply(erc6909).mint(dave, accountId, 20 ether);
237 |
238 | mockAuth = address(new MockAuth());
239 | }
240 |
241 | function testDeploy() public {
242 | new Dagon();
243 | }
244 |
245 | function testNameAndSymbolAndDecimals(uint256 id) public view {
246 | assertEq(dagon.name(id), "");
247 | assertEq(dagon.symbol(id), "");
248 | assertEq(dagon.decimals(id), 18);
249 | }
250 |
251 | function testInstall() public {
252 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](1);
253 | _owners[0].owner = alice;
254 | _owners[0].shares = 1;
255 |
256 | Dagon.Settings memory setting;
257 | setting.token = address(0);
258 | setting.standard = Dagon.Standard.DAGON;
259 | setting.threshold = 1;
260 |
261 | Dagon.Metadata memory meta;
262 | meta.name = "";
263 | meta.symbol = "";
264 | meta.tokenURI = "";
265 | meta.authority = IAuth(address(0));
266 |
267 | vm.prank(alice);
268 | account.execute(
269 | address(dagon),
270 | 0,
271 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
272 | );
273 |
274 | assertEq(dagon.balanceOf(alice, accountId), 1);
275 |
276 | vm.prank(alice);
277 | account.transferOwnership(address(dagon));
278 |
279 | (address setTkn, uint88 setThreshold, Dagon.Standard setStd) =
280 | dagon.getSettings(address(account));
281 |
282 | assertEq(address(setTkn), address(setting.token));
283 | assertEq(uint256(setThreshold), uint256(setting.threshold));
284 | assertEq(uint8(setStd), uint8(setting.standard));
285 |
286 | assertEq(dagon.tokenURI(accountId), "");
287 | (,,, IAuth authority) = dagon.getMetadata(address(account));
288 | assertEq(address(authority), address(0));
289 | }
290 |
291 | function testSetThreshold() public {
292 | testInstall();
293 | vm.prank(address(account));
294 | dagon.mint(alice, 1);
295 | vm.prank(address(account));
296 | dagon.setThreshold(2);
297 | (, uint88 setThreshold,) = dagon.getSettings(address(account));
298 | assertEq(setThreshold, 2);
299 | }
300 |
301 | function testSpoofSignatures(bytes calldata spoof) public payable {
302 | bytes32 hash; // Empty hash.
303 | assertEq(bytes4(0xffffffff), account.isValidSignature(hash, spoof));
304 | }
305 |
306 | function testFailInvalidThresholdNull() public {
307 | testInstall();
308 | vm.prank(address(account));
309 | dagon.setThreshold(0);
310 | }
311 |
312 | function testFailInvalidThresholdExceedsSupply() public {
313 | testInstall();
314 | vm.prank(address(account));
315 | dagon.setThreshold(2);
316 | }
317 |
318 | function testFailInvalidThresholdExceedsSupply2() public {
319 | testInstall();
320 | vm.prank(address(account));
321 | dagon.mint(alice, 1);
322 | vm.prank(address(account));
323 | dagon.setThreshold(3);
324 | (, uint88 setThreshold,) = dagon.getSettings(address(account));
325 | assertEq(setThreshold, 3);
326 | }
327 |
328 | function testSetURI() public {
329 | testInstall();
330 | vm.prank(address(account));
331 | dagon.setURI("TEST");
332 | assertEq(dagon.tokenURI(accountId), "TEST");
333 | }
334 |
335 | function testSetToken(address tkn) public {
336 | Dagon.Standard std = Dagon.Standard.DAGON;
337 | testInstall();
338 | vm.prank(address(account));
339 | dagon.setToken(tkn, std);
340 | (address setTkn,, Dagon.Standard setStd) = dagon.getSettings(address(account));
341 | assertEq(address(tkn), address(setTkn));
342 | assertEq(uint8(std), uint8(setStd));
343 | std = Dagon.Standard.ERC20;
344 | vm.prank(address(account));
345 | dagon.setToken(tkn, std);
346 | (setTkn,, setStd) = dagon.getSettings(address(account));
347 | assertEq(address(tkn), address(setTkn));
348 | }
349 |
350 | function testFailSetTokenInvalidStd(address tkn) public {
351 | testInstall();
352 | vm.prank(address(account));
353 | dagon.setToken(tkn, Dagon.Standard(uint8(5)));
354 | }
355 |
356 | function testSetAuth(IAuth auth) public {
357 | testInstall();
358 | vm.prank(address(account));
359 | dagon.setAuth(auth);
360 | (,,, IAuth authority) = dagon.getMetadata(address(account));
361 | assertEq(address(auth), address(authority));
362 | }
363 |
364 | function testTransfer(address from, address to, uint88 amount) public {
365 | vm.assume(from != alice && to != alice);
366 | vm.assume(from != address(0) && to != address(0));
367 | vm.assume(to != 0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF);
368 | vm.assume(amount < type(uint88).max);
369 | testInstall();
370 | vm.prank(address(account));
371 | dagon.mint(from, amount);
372 | assertEq(dagon.balanceOf(from, accountId), amount);
373 | vm.prank(from);
374 | dagon.transfer(to, accountId, amount);
375 | assertEq(dagon.balanceOf(to, accountId), amount);
376 | }
377 |
378 | function testFailTransferOverBalance(address from, address to, uint96 amount) public {
379 | vm.assume(from != alice && to != alice);
380 | vm.assume(amount < type(uint96).max);
381 | testInstall();
382 | vm.prank(address(account));
383 | dagon.mint(from, amount);
384 | vm.prank(from);
385 | dagon.transfer(to, accountId, amount + 1);
386 | }
387 |
388 | function testTransferWithAuth(address from, address to, uint96 amount) public {
389 | vm.assume(from != alice && to != alice);
390 | vm.assume(amount < type(uint96).max);
391 | testInstall();
392 | vm.prank(address(account));
393 | dagon.mint(from, amount);
394 | vm.prank(address(account));
395 | dagon.setAuth(IAuth(mockAuth));
396 | vm.prank(from);
397 | dagon.transfer(to, accountId, amount);
398 | }
399 |
400 | function testFailTransferFromInactiveAuth(address from, address to, uint96 amount) public {
401 | vm.assume(from != alice && to != alice);
402 | vm.assume(amount < type(uint96).max);
403 | testInstall();
404 | vm.prank(address(account));
405 | dagon.mint(from, amount);
406 | vm.prank(address(account));
407 | dagon.setAuth(IAuth(address(4269)));
408 | vm.prank(from);
409 | dagon.transfer(to, accountId, amount);
410 | }
411 |
412 | function testBurn(address from, uint96 amount) public {
413 | vm.assume(from != alice);
414 | vm.assume(amount < type(uint96).max);
415 | testInstall();
416 | vm.prank(address(account));
417 | dagon.mint(from, amount);
418 | assertEq(dagon.balanceOf(from, accountId), amount);
419 | vm.prank(address(account));
420 | dagon.burn(from, amount);
421 | assertEq(dagon.balanceOf(from, accountId), 0);
422 | }
423 |
424 | function testFailBurnOverBalance(address from, uint96 amount) public {
425 | vm.assume(from != alice);
426 | vm.assume(amount < type(uint96).max);
427 | testInstall();
428 | vm.prank(address(account));
429 | dagon.mint(from, amount);
430 | assertEq(dagon.balanceOf(from, accountId), amount);
431 | vm.prank(address(account));
432 | dagon.burn(from, amount + 1);
433 | }
434 |
435 | function testFailBurnOverThreshold(address from, uint96 amount) public {
436 | vm.assume(from != alice);
437 | vm.assume(amount < type(uint96).max);
438 | testInstall();
439 | vm.prank(address(account));
440 | dagon.mint(from, amount);
441 | assertEq(dagon.balanceOf(from, accountId), amount);
442 | vm.prank(address(account));
443 | dagon.burn(from, amount);
444 | vm.expectRevert(Dagon.InvalidSetting.selector);
445 | dagon.burn(alice, 1);
446 | }
447 |
448 | function testIsValidSignature() public {
449 | testInstall();
450 | bytes32 userOpHash = keccak256("OWN");
451 | PackedUserOperation memory userOp;
452 |
453 | Signature[] memory signature = new Signature[](1);
454 | signature[0].owner = alice;
455 | signature[0].sigData = _sign(alicePk, userOpHash);
456 |
457 | userOp.signature = abi.encode(signature);
458 | userOp.sender = address(account);
459 |
460 | vm.prank(_ENTRY_POINT);
461 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
462 | assertEq(validationData, 0x00);
463 | }
464 |
465 | function testIsValidSignatureOnchain() public {
466 | testInstall();
467 | bytes32 userOpHash = keccak256("OWN");
468 | PackedUserOperation memory userOp;
469 | userOp.sender = address(account);
470 | require(userOp.signature.length == 0, "INVALID_LEN");
471 |
472 | Signature[] memory signature = new Signature[](1);
473 | signature[0].owner = alice;
474 | signature[0].sigData = _sign(alicePk, userOpHash);
475 |
476 | bytes memory sig = abi.encode(signature);
477 |
478 | dagon.vote(address(account), userOpHash, sig);
479 |
480 | vm.prank(_ENTRY_POINT);
481 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
482 | assertEq(validationData, 0x00);
483 | }
484 |
485 | function testIsValidSignatureOnchainRaw() public {
486 | testInstall();
487 | bytes32 userOpHash = keccak256("OWN");
488 | PackedUserOperation memory userOp;
489 | userOp.sender = address(account);
490 | require(userOp.signature.length == 0, "INVALID_LEN");
491 |
492 | vm.prank(alice);
493 | dagon.vote(address(account), userOpHash);
494 |
495 | vm.prank(_ENTRY_POINT);
496 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
497 | assertEq(validationData, 0x00);
498 | }
499 |
500 | function testFailIsValidSignatureSpoofed() public {
501 | testInstall();
502 | bytes32 userOpHash = keccak256("OWN");
503 | PackedUserOperation memory userOp;
504 | userOp.sender = address(account);
505 | require(userOp.signature.length == 0, "INVALID_LEN");
506 |
507 | dagon.vote(address(account), userOpHash);
508 |
509 | vm.prank(_ENTRY_POINT);
510 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
511 | assertEq(validationData, 0x00);
512 | }
513 |
514 | function testUserVoted() public {
515 | testInstall();
516 | bytes32 userOpHash = keccak256("OWN");
517 | PackedUserOperation memory userOp;
518 | userOp.sender = address(account);
519 | require(userOp.signature.length == 0, "INVALID_LEN");
520 |
521 | Signature[] memory signature = new Signature[](1);
522 | signature[0].owner = alice;
523 | signature[0].sigData = _sign(alicePk, userOpHash);
524 |
525 | bytes memory sig = abi.encode(signature);
526 |
527 | dagon.vote(address(account), userOpHash, sig);
528 | assertEq(
529 | dagon.voted(address(account), alice, userOpHash),
530 | dagon.balanceOf(alice, uint256(uint160(address(account))))
531 | );
532 | // Flag and revert on double vote.
533 | vm.prank(alice);
534 | vm.expectRevert(InsufficientPermission.selector);
535 | dagon.vote(address(account), userOpHash);
536 | }
537 |
538 | // In 2-of-3, 3 signed.
539 | function testIsValidSignature3of3() public payable {
540 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](3);
541 | _owners[0].owner = alice;
542 | _owners[0].shares = 1;
543 | _owners[1].owner = bob;
544 | _owners[1].shares = 1;
545 | _owners[2].owner = chuck;
546 | _owners[2].shares = 1;
547 |
548 | address[] memory addrs = new address[](3);
549 | addrs[0] = alice;
550 | addrs[1] = bob;
551 | addrs[2] = chuck;
552 |
553 | Dagon.Settings memory setting;
554 | setting.token = address(0);
555 | setting.standard = Dagon.Standard.DAGON;
556 | setting.threshold = 2;
557 |
558 | Dagon.Metadata memory meta;
559 | meta.name = "";
560 | meta.symbol = "";
561 | meta.tokenURI = "";
562 | meta.authority = IAuth(address(0));
563 |
564 | vm.prank(alice);
565 | account.execute(
566 | address(dagon),
567 | 0,
568 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
569 | );
570 |
571 | vm.prank(alice);
572 | account.transferOwnership(address(dagon));
573 |
574 | PackedUserOperation memory userOp;
575 | bytes32 userOpHash = keccak256("OWN");
576 |
577 | addrs = _sortAddresses(addrs);
578 |
579 | Signature[] memory signature = new Signature[](3);
580 | signature[0].owner = addrs[0];
581 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
582 | signature[1].owner = addrs[1];
583 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
584 | signature[2].owner = addrs[2];
585 | signature[2].sigData = _sign(_getPkByAddr(addrs[2]), userOpHash);
586 |
587 | userOp.signature = abi.encode(signature);
588 | userOp.sender = address(account);
589 |
590 | vm.prank(_ENTRY_POINT);
591 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
592 | assertEq(validationData, 0x00);
593 | }
594 |
595 | // In 2-of-3, 2 signed.
596 | function testIsValidSignature2of3() public payable {
597 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](3);
598 | _owners[0].owner = alice;
599 | _owners[0].shares = 1;
600 | _owners[1].owner = bob;
601 | _owners[1].shares = 1;
602 | _owners[2].owner = chuck;
603 | _owners[2].shares = 1;
604 |
605 | address[] memory addrs = new address[](3);
606 | addrs[0] = alice;
607 | addrs[1] = bob;
608 | addrs[2] = chuck;
609 |
610 | Dagon.Settings memory setting;
611 | setting.token = address(0);
612 | setting.standard = Dagon.Standard.DAGON;
613 | setting.threshold = 2;
614 |
615 | Dagon.Metadata memory meta;
616 | meta.name = "";
617 | meta.symbol = "";
618 | meta.tokenURI = "";
619 | meta.authority = IAuth(address(0));
620 |
621 | vm.prank(alice);
622 | account.execute(
623 | address(dagon),
624 | 0,
625 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
626 | );
627 |
628 | vm.prank(alice);
629 | account.transferOwnership(address(dagon));
630 |
631 | PackedUserOperation memory userOp;
632 | bytes32 userOpHash = keccak256("OWN");
633 |
634 | addrs = _sortAddresses(addrs);
635 |
636 | Signature[] memory signature = new Signature[](2);
637 | signature[0].owner = addrs[0];
638 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
639 | signature[1].owner = addrs[1];
640 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
641 |
642 | userOp.signature = abi.encode(signature);
643 | userOp.sender = address(account);
644 |
645 | vm.prank(_ENTRY_POINT);
646 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
647 | assertEq(validationData, 0x00);
648 | }
649 |
650 | // In 6-of-9, 6 signed.
651 | function testIsValidSignatureMany() public payable {
652 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](9);
653 | _owners[0].owner = alice;
654 | _owners[0].shares = 1;
655 | _owners[1].owner = bob;
656 | _owners[1].shares = 1;
657 | _owners[2].owner = chuck;
658 | _owners[2].shares = 1;
659 | _owners[3].owner = dave;
660 | _owners[3].shares = 1;
661 | _owners[4].owner = ed;
662 | _owners[4].shares = 1;
663 | _owners[5].owner = fargo;
664 | _owners[5].shares = 1;
665 | _owners[6].owner = gravy;
666 | _owners[6].shares = 1;
667 | _owners[7].owner = holly;
668 | _owners[7].shares = 1;
669 | _owners[8].owner = ignis;
670 | _owners[8].shares = 1;
671 |
672 | address[] memory addrs = new address[](9);
673 | addrs[0] = alice;
674 | addrs[1] = bob;
675 | addrs[2] = chuck;
676 | addrs[3] = dave;
677 | addrs[4] = ed;
678 | addrs[5] = fargo;
679 | addrs[6] = gravy;
680 | addrs[7] = holly;
681 | addrs[8] = ignis;
682 |
683 | Dagon.Settings memory setting;
684 | setting.token = address(0);
685 | setting.standard = Dagon.Standard.DAGON;
686 | setting.threshold = 6;
687 |
688 | Dagon.Metadata memory meta;
689 | meta.name = "";
690 | meta.symbol = "";
691 | meta.tokenURI = "";
692 | meta.authority = IAuth(address(0));
693 |
694 | vm.prank(alice);
695 | account.execute(
696 | address(dagon),
697 | 0,
698 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
699 | );
700 |
701 | vm.prank(alice);
702 | account.transferOwnership(address(dagon));
703 |
704 | PackedUserOperation memory userOp;
705 | bytes32 userOpHash = keccak256("OWN");
706 |
707 | addrs = _sortAddresses(addrs);
708 |
709 | Signature[] memory signature = new Signature[](6);
710 | signature[0].owner = addrs[0];
711 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
712 | signature[1].owner = addrs[1];
713 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
714 | signature[2].owner = addrs[2];
715 | signature[2].sigData = _sign(_getPkByAddr(addrs[2]), userOpHash);
716 | signature[3].owner = addrs[3];
717 | signature[3].sigData = _sign(_getPkByAddr(addrs[3]), userOpHash);
718 | signature[4].owner = addrs[4];
719 | signature[4].sigData = _sign(_getPkByAddr(addrs[4]), userOpHash);
720 | signature[5].owner = addrs[5];
721 | signature[5].sigData = _sign(_getPkByAddr(addrs[5]), userOpHash);
722 |
723 | userOp.signature = abi.encode(signature);
724 | userOp.sender = address(account);
725 |
726 | vm.prank(_ENTRY_POINT);
727 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
728 | assertEq(validationData, 0x00);
729 | }
730 |
731 | // In 2-of-3, 1 signed. So fail.
732 | function testFailIsValidSignature2of3ForInsufficientSignatures() public payable {
733 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](3);
734 | _owners[0].owner = alice;
735 | _owners[0].shares = 1;
736 | _owners[1].owner = bob;
737 | _owners[1].shares = 1;
738 | _owners[2].owner = chuck;
739 | _owners[2].shares = 1;
740 |
741 | address[] memory addrs = new address[](3);
742 | addrs[0] = alice;
743 | addrs[1] = bob;
744 | addrs[2] = chuck;
745 |
746 | Dagon.Settings memory setting;
747 | setting.token = address(0);
748 | setting.standard = Dagon.Standard.DAGON;
749 | setting.threshold = 2;
750 |
751 | Dagon.Metadata memory meta;
752 | meta.name = "";
753 | meta.symbol = "";
754 | meta.tokenURI = "";
755 | meta.authority = IAuth(address(0));
756 |
757 | vm.prank(alice);
758 | account.execute(
759 | address(dagon),
760 | 0,
761 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
762 | );
763 |
764 | vm.prank(alice);
765 | account.transferOwnership(address(dagon));
766 |
767 | PackedUserOperation memory userOp;
768 | bytes32 userOpHash = keccak256("OWN");
769 |
770 | addrs = _sortAddresses(addrs);
771 |
772 | Signature[] memory signature = new Signature[](1);
773 | signature[0].owner = addrs[0];
774 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
775 |
776 | userOp.signature = abi.encode(signature);
777 | userOp.sender = address(account);
778 |
779 | vm.prank(_ENTRY_POINT);
780 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
781 | assertEq(validationData, 0x00);
782 | }
783 |
784 | // In 40-of-100, at least 40 units signed.
785 | function testIsValidSignatureWeighted() public payable {
786 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
787 | _owners[0].owner = alice;
788 | _owners[0].shares = 40;
789 | _owners[1].owner = bob;
790 | _owners[1].shares = 20;
791 | _owners[2].owner = chuck;
792 | _owners[2].shares = 20;
793 | _owners[3].owner = dave;
794 | _owners[3].shares = 20;
795 |
796 | address[] memory addrs = new address[](4);
797 | addrs[0] = alice;
798 | addrs[1] = bob;
799 | addrs[2] = chuck;
800 | addrs[3] = dave;
801 |
802 | Dagon.Settings memory setting;
803 | setting.token = address(0);
804 | setting.standard = Dagon.Standard.DAGON;
805 | setting.threshold = 40;
806 |
807 | Dagon.Metadata memory meta;
808 | meta.name = "";
809 | meta.symbol = "";
810 | meta.tokenURI = "";
811 | meta.authority = IAuth(address(0));
812 |
813 | vm.prank(alice);
814 | account.execute(
815 | address(dagon),
816 | 0,
817 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
818 | );
819 |
820 | vm.prank(alice);
821 | account.transferOwnership(address(dagon));
822 |
823 | PackedUserOperation memory userOp;
824 | bytes32 userOpHash = keccak256("OWN");
825 |
826 | addrs = _sortAddresses(addrs);
827 |
828 | Signature[] memory signature = new Signature[](3);
829 | signature[0].owner = addrs[0];
830 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
831 | signature[1].owner = addrs[1];
832 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
833 | signature[2].owner = addrs[2];
834 | signature[2].sigData = _sign(_getPkByAddr(addrs[2]), userOpHash);
835 |
836 | userOp.signature = abi.encode(signature);
837 | userOp.sender = address(account);
838 |
839 | vm.prank(_ENTRY_POINT);
840 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
841 | assertEq(validationData, 0x00);
842 | }
843 |
844 | // In 40-of-100, 20 units signed. So fail.
845 | function testFailIsValidSignatureWeighted() public payable {
846 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
847 | _owners[0].owner = alice;
848 | _owners[0].shares = 40;
849 | _owners[1].owner = bob;
850 | _owners[1].shares = 20;
851 | _owners[2].owner = chuck;
852 | _owners[2].shares = 20;
853 | _owners[3].owner = dave;
854 | _owners[3].shares = 20;
855 |
856 | address[] memory addrs = new address[](4);
857 | addrs[0] = alice;
858 | addrs[1] = bob;
859 | addrs[2] = chuck;
860 | addrs[3] = dave;
861 |
862 | Dagon.Settings memory setting;
863 | setting.token = address(0);
864 | setting.standard = Dagon.Standard.DAGON;
865 | setting.threshold = 40;
866 |
867 | Dagon.Metadata memory meta;
868 | meta.name = "";
869 | meta.symbol = "";
870 | meta.tokenURI = "";
871 | meta.authority = IAuth(address(0));
872 |
873 | vm.prank(alice);
874 | account.execute(
875 | address(dagon),
876 | 0,
877 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
878 | );
879 |
880 | vm.prank(alice);
881 | account.transferOwnership(address(dagon));
882 |
883 | PackedUserOperation memory userOp;
884 | bytes32 userOpHash = keccak256("OWN");
885 |
886 | addrs = _sortAddresses(addrs);
887 |
888 | Signature[] memory signature = new Signature[](1);
889 | signature[0].owner = addrs[0];
890 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
891 |
892 | userOp.signature = abi.encode(signature);
893 | userOp.sender = address(account);
894 |
895 | vm.prank(_ENTRY_POINT);
896 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
897 | assertEq(validationData, 0x00);
898 | }
899 |
900 | // In 40-of-100, at least 40 ERC20 units signed.
901 | function testIsValidSignatureWeightedERC20() public payable {
902 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
903 | _owners[0].owner = alice;
904 | _owners[0].shares = 40;
905 | _owners[1].owner = bob;
906 | _owners[1].shares = 20;
907 | _owners[2].owner = chuck;
908 | _owners[2].shares = 20;
909 | _owners[3].owner = dave;
910 | _owners[3].shares = 20;
911 |
912 | address[] memory addrs = new address[](4);
913 | addrs[0] = alice;
914 | addrs[1] = bob;
915 | addrs[2] = chuck;
916 | addrs[3] = dave;
917 |
918 | Dagon.Settings memory setting;
919 | setting.token = erc20;
920 | setting.standard = Dagon.Standard.ERC20;
921 | setting.threshold = 40 ether;
922 |
923 | Dagon.Metadata memory meta;
924 | meta.name = "";
925 | meta.symbol = "";
926 | meta.tokenURI = "";
927 | meta.authority = IAuth(address(0));
928 |
929 | vm.prank(alice);
930 | account.execute(
931 | address(dagon),
932 | 0,
933 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
934 | );
935 |
936 | vm.prank(alice);
937 | account.transferOwnership(address(dagon));
938 |
939 | PackedUserOperation memory userOp;
940 | bytes32 userOpHash = keccak256("OWN");
941 |
942 | addrs = _sortAddresses(addrs);
943 |
944 | Signature[] memory signature = new Signature[](3);
945 | signature[0].owner = addrs[0];
946 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
947 | signature[1].owner = addrs[1];
948 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
949 | signature[2].owner = addrs[2];
950 | signature[2].sigData = _sign(_getPkByAddr(addrs[2]), userOpHash);
951 |
952 | userOp.signature = abi.encode(signature);
953 | userOp.sender = address(account);
954 |
955 | vm.prank(_ENTRY_POINT);
956 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
957 | assertEq(validationData, 0x00);
958 | }
959 |
960 | // In 40-of-100, 20 ERC20 units signed. So fail.
961 | function testFailIsValidSignatureWeightedERC20() public payable {
962 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
963 | _owners[0].owner = alice;
964 | _owners[0].shares = 40;
965 | _owners[1].owner = bob;
966 | _owners[1].shares = 20;
967 | _owners[2].owner = chuck;
968 | _owners[2].shares = 20;
969 | _owners[3].owner = dave;
970 | _owners[3].shares = 20;
971 |
972 | address[] memory addrs = new address[](4);
973 | addrs[0] = alice;
974 | addrs[1] = bob;
975 | addrs[2] = chuck;
976 | addrs[3] = dave;
977 |
978 | Dagon.Settings memory setting;
979 | setting.token = erc20;
980 | setting.standard = Dagon.Standard.ERC20;
981 | setting.threshold = 40 ether;
982 |
983 | Dagon.Metadata memory meta;
984 | meta.name = "";
985 | meta.symbol = "";
986 | meta.tokenURI = "";
987 | meta.authority = IAuth(address(0));
988 |
989 | vm.prank(alice);
990 | account.execute(
991 | address(dagon),
992 | 0,
993 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
994 | );
995 |
996 | vm.prank(alice);
997 | account.transferOwnership(address(dagon));
998 |
999 | PackedUserOperation memory userOp;
1000 | bytes32 userOpHash = keccak256("OWN");
1001 |
1002 | addrs = _sortAddresses(addrs);
1003 |
1004 | Signature[] memory signature = new Signature[](1);
1005 | signature[0].owner = addrs[0];
1006 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1007 |
1008 | userOp.signature = abi.encode(signature);
1009 | userOp.sender = address(account);
1010 |
1011 | vm.prank(_ENTRY_POINT);
1012 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1013 | assertEq(validationData, 0x00);
1014 | }
1015 |
1016 | // In 2-of-3, at least 2 ERC721 units signed.
1017 | function testIsValidSignatureWeightedERC721() public payable {
1018 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](3);
1019 | _owners[0].owner = alice;
1020 | _owners[0].shares = 1;
1021 | _owners[1].owner = bob;
1022 | _owners[1].shares = 1;
1023 | _owners[2].owner = chuck;
1024 | _owners[2].shares = 1;
1025 |
1026 | address[] memory addrs = new address[](3);
1027 | addrs[0] = alice;
1028 | addrs[1] = bob;
1029 | addrs[2] = chuck;
1030 |
1031 | Dagon.Settings memory setting;
1032 | setting.token = erc721;
1033 | setting.standard = Dagon.Standard.ERC721;
1034 | setting.threshold = 2;
1035 |
1036 | Dagon.Metadata memory meta;
1037 | meta.name = "";
1038 | meta.symbol = "";
1039 | meta.tokenURI = "";
1040 | meta.authority = IAuth(address(0));
1041 |
1042 | vm.prank(alice);
1043 | account.execute(
1044 | address(dagon),
1045 | 0,
1046 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
1047 | );
1048 |
1049 | vm.prank(alice);
1050 | account.transferOwnership(address(dagon));
1051 |
1052 | PackedUserOperation memory userOp;
1053 | bytes32 userOpHash = keccak256("OWN");
1054 |
1055 | addrs = _sortAddresses(addrs);
1056 |
1057 | Signature[] memory signature = new Signature[](2);
1058 | signature[0].owner = addrs[0];
1059 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1060 | signature[1].owner = addrs[1];
1061 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
1062 |
1063 | userOp.signature = abi.encode(signature);
1064 | userOp.sender = address(account);
1065 |
1066 | vm.prank(_ENTRY_POINT);
1067 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1068 | assertEq(validationData, 0x00);
1069 | }
1070 |
1071 | // In 2-of-3, only 1 ERC721 units signed. So fail.
1072 | function testFailIsValidSignatureWeightedERC721() public payable {
1073 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](3);
1074 | _owners[0].owner = alice;
1075 | _owners[0].shares = 1;
1076 | _owners[1].owner = bob;
1077 | _owners[1].shares = 1;
1078 | _owners[2].owner = chuck;
1079 | _owners[2].shares = 1;
1080 |
1081 | address[] memory addrs = new address[](3);
1082 | addrs[0] = alice;
1083 | addrs[1] = bob;
1084 | addrs[2] = chuck;
1085 |
1086 | Dagon.Settings memory setting;
1087 | setting.token = erc721;
1088 | setting.standard = Dagon.Standard.ERC721;
1089 | setting.threshold = 2;
1090 |
1091 | Dagon.Metadata memory meta;
1092 | meta.name = "";
1093 | meta.symbol = "";
1094 | meta.tokenURI = "";
1095 | meta.authority = IAuth(address(0));
1096 |
1097 | vm.prank(alice);
1098 | account.execute(
1099 | address(dagon),
1100 | 0,
1101 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
1102 | );
1103 |
1104 | vm.prank(alice);
1105 | account.transferOwnership(address(dagon));
1106 |
1107 | PackedUserOperation memory userOp;
1108 | bytes32 userOpHash = keccak256("OWN");
1109 |
1110 | addrs = _sortAddresses(addrs);
1111 |
1112 | Signature[] memory signature = new Signature[](1);
1113 | signature[0].owner = addrs[0];
1114 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1115 |
1116 | userOp.signature = abi.encode(signature);
1117 | userOp.sender = address(account);
1118 |
1119 | vm.prank(_ENTRY_POINT);
1120 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1121 | assertEq(validationData, 0x00);
1122 | }
1123 |
1124 | // In 40-of-100, at least 40 ERC1155 units signed.
1125 | function testIsValidSignatureWeightedERC1155() public payable {
1126 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
1127 | _owners[0].owner = alice;
1128 | _owners[0].shares = 40;
1129 | _owners[1].owner = bob;
1130 | _owners[1].shares = 20;
1131 | _owners[2].owner = chuck;
1132 | _owners[2].shares = 20;
1133 | _owners[3].owner = dave;
1134 | _owners[3].shares = 20;
1135 |
1136 | address[] memory addrs = new address[](4);
1137 | addrs[0] = alice;
1138 | addrs[1] = bob;
1139 | addrs[2] = chuck;
1140 | addrs[3] = dave;
1141 |
1142 | Dagon.Settings memory setting;
1143 | setting.token = erc1155;
1144 | setting.standard = Dagon.Standard.ERC1155;
1145 | setting.threshold = 40 ether;
1146 |
1147 | Dagon.Metadata memory meta;
1148 | meta.name = "";
1149 | meta.symbol = "";
1150 | meta.tokenURI = "";
1151 | meta.authority = IAuth(address(0));
1152 |
1153 | vm.prank(alice);
1154 | account.execute(
1155 | address(dagon),
1156 | 0,
1157 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
1158 | );
1159 |
1160 | vm.prank(alice);
1161 | account.transferOwnership(address(dagon));
1162 |
1163 | PackedUserOperation memory userOp;
1164 | bytes32 userOpHash = keccak256("OWN");
1165 |
1166 | addrs = _sortAddresses(addrs);
1167 |
1168 | Signature[] memory signature = new Signature[](3);
1169 | signature[0].owner = addrs[0];
1170 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1171 | signature[1].owner = addrs[1];
1172 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
1173 | signature[2].owner = addrs[2];
1174 | signature[2].sigData = _sign(_getPkByAddr(addrs[2]), userOpHash);
1175 |
1176 | userOp.signature = abi.encode(signature);
1177 | userOp.sender = address(account);
1178 |
1179 | vm.prank(_ENTRY_POINT);
1180 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1181 | assertEq(validationData, 0x00);
1182 | }
1183 |
1184 | // In 40-of-100, 20 ERC1155 units signed. So fail.
1185 | function testFailIsValidSignatureWeightedERC1155() public payable {
1186 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
1187 | _owners[0].owner = alice;
1188 | _owners[0].shares = 40;
1189 | _owners[1].owner = bob;
1190 | _owners[1].shares = 20;
1191 | _owners[2].owner = chuck;
1192 | _owners[2].shares = 20;
1193 | _owners[3].owner = dave;
1194 | _owners[3].shares = 20;
1195 |
1196 | address[] memory addrs = new address[](4);
1197 | addrs[0] = alice;
1198 | addrs[1] = bob;
1199 | addrs[2] = chuck;
1200 | addrs[3] = dave;
1201 |
1202 | Dagon.Settings memory setting;
1203 | setting.token = erc1155;
1204 | setting.standard = Dagon.Standard.ERC1155;
1205 | setting.threshold = 40 ether;
1206 |
1207 | Dagon.Metadata memory meta;
1208 | meta.name = "";
1209 | meta.symbol = "";
1210 | meta.tokenURI = "";
1211 | meta.authority = IAuth(address(0));
1212 |
1213 | vm.prank(alice);
1214 | account.execute(
1215 | address(dagon), 0, abi.encodeWithSelector(Dagon.install.selector, setting, meta)
1216 | );
1217 |
1218 | vm.prank(alice);
1219 | account.transferOwnership(address(dagon));
1220 |
1221 | PackedUserOperation memory userOp;
1222 | bytes32 userOpHash = keccak256("OWN");
1223 |
1224 | addrs = _sortAddresses(addrs);
1225 |
1226 | Signature[] memory signature = new Signature[](1);
1227 | signature[0].owner = addrs[0];
1228 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1229 |
1230 | userOp.signature = abi.encode(signature);
1231 | userOp.sender = address(account);
1232 |
1233 | vm.prank(_ENTRY_POINT);
1234 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1235 | assertEq(validationData, 0x00);
1236 | }
1237 |
1238 | // In 40-of-100, at least 40 ERC6909 units signed.
1239 | function testIsValidSignatureWeightedERC6909() public payable {
1240 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
1241 | _owners[0].owner = alice;
1242 | _owners[0].shares = 40;
1243 | _owners[1].owner = bob;
1244 | _owners[1].shares = 20;
1245 | _owners[2].owner = chuck;
1246 | _owners[2].shares = 20;
1247 | _owners[3].owner = dave;
1248 | _owners[3].shares = 20;
1249 |
1250 | address[] memory addrs = new address[](4);
1251 | addrs[0] = alice;
1252 | addrs[1] = bob;
1253 | addrs[2] = chuck;
1254 | addrs[3] = dave;
1255 |
1256 | Dagon.Settings memory setting;
1257 | setting.token = erc6909;
1258 | setting.standard = Dagon.Standard.ERC6909;
1259 | setting.threshold = 40 ether;
1260 |
1261 | Dagon.Metadata memory meta;
1262 | meta.name = "";
1263 | meta.symbol = "";
1264 | meta.tokenURI = "";
1265 | meta.authority = IAuth(address(0));
1266 |
1267 | vm.prank(alice);
1268 | account.execute(
1269 | address(dagon),
1270 | 0,
1271 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
1272 | );
1273 |
1274 | vm.prank(alice);
1275 | account.transferOwnership(address(dagon));
1276 |
1277 | PackedUserOperation memory userOp;
1278 | bytes32 userOpHash = keccak256("OWN");
1279 |
1280 | addrs = _sortAddresses(addrs);
1281 |
1282 | Signature[] memory signature = new Signature[](3);
1283 | signature[0].owner = addrs[0];
1284 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1285 | signature[1].owner = addrs[1];
1286 | signature[1].sigData = _sign(_getPkByAddr(addrs[1]), userOpHash);
1287 | signature[2].owner = addrs[2];
1288 | signature[2].sigData = _sign(_getPkByAddr(addrs[2]), userOpHash);
1289 |
1290 | userOp.signature = abi.encode(signature);
1291 | userOp.sender = address(account);
1292 |
1293 | vm.prank(_ENTRY_POINT);
1294 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1295 | assertEq(validationData, 0x00);
1296 | }
1297 |
1298 | // In 40-of-100, 20 ERC6909 units signed. So fail.
1299 | function testFailIsValidSignatureWeightedERC6909() public payable {
1300 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
1301 | _owners[0].owner = alice;
1302 | _owners[0].shares = 40;
1303 | _owners[1].owner = bob;
1304 | _owners[1].shares = 20;
1305 | _owners[2].owner = chuck;
1306 | _owners[2].shares = 20;
1307 | _owners[3].owner = dave;
1308 | _owners[3].shares = 20;
1309 |
1310 | address[] memory addrs = new address[](4);
1311 | addrs[0] = alice;
1312 | addrs[1] = bob;
1313 | addrs[2] = chuck;
1314 | addrs[3] = dave;
1315 |
1316 | Dagon.Settings memory setting;
1317 | setting.token = erc6909;
1318 | setting.standard = Dagon.Standard.ERC6909;
1319 | setting.threshold = 40 ether;
1320 |
1321 | Dagon.Metadata memory meta;
1322 | meta.name = "";
1323 | meta.symbol = "";
1324 | meta.tokenURI = "";
1325 | meta.authority = IAuth(address(0));
1326 |
1327 | vm.prank(alice);
1328 | account.execute(
1329 | address(dagon),
1330 | 0,
1331 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
1332 | );
1333 |
1334 | vm.prank(alice);
1335 | account.transferOwnership(address(dagon));
1336 |
1337 | PackedUserOperation memory userOp;
1338 | bytes32 userOpHash = keccak256("OWN");
1339 |
1340 | addrs = _sortAddresses(addrs);
1341 |
1342 | Signature[] memory signature = new Signature[](1);
1343 | signature[0].owner = addrs[0];
1344 | signature[0].sigData = _sign(_getPkByAddr(addrs[0]), userOpHash);
1345 |
1346 | userOp.signature = abi.encode(signature);
1347 | userOp.sender = address(account);
1348 |
1349 | vm.prank(_ENTRY_POINT);
1350 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1351 | assertEq(validationData, 0x00);
1352 | }
1353 |
1354 | function testFailIsValidSignatureOutOfOrder() public payable {
1355 | Dagon.Ownership[] memory _owners = new Dagon.Ownership[](4);
1356 | _owners[0].owner = alice;
1357 | _owners[0].shares = 40;
1358 | _owners[1].owner = bob;
1359 | _owners[1].shares = 20;
1360 | _owners[2].owner = chuck;
1361 | _owners[2].shares = 20;
1362 | _owners[3].owner = dave;
1363 | _owners[3].shares = 20;
1364 |
1365 | address[] memory addrs = new address[](4);
1366 | addrs[0] = alice;
1367 | addrs[1] = bob;
1368 | addrs[2] = chuck;
1369 | addrs[3] = dave;
1370 |
1371 | Dagon.Settings memory setting;
1372 | setting.token = address(0);
1373 | setting.standard = Dagon.Standard.DAGON;
1374 | setting.threshold = 40;
1375 |
1376 | Dagon.Metadata memory meta;
1377 | meta.name = "";
1378 | meta.symbol = "";
1379 | meta.tokenURI = "";
1380 | meta.authority = IAuth(address(0));
1381 |
1382 | vm.prank(alice);
1383 | account.execute(
1384 | address(dagon),
1385 | 0,
1386 | abi.encodeWithSelector(Dagon.install.selector, _owners, setting, meta)
1387 | );
1388 |
1389 | vm.prank(alice);
1390 | account.transferOwnership(address(dagon));
1391 |
1392 | PackedUserOperation memory userOp;
1393 | bytes32 userOpHash = keccak256("OWN");
1394 |
1395 | Signature[] memory signature = new Signature[](3);
1396 | signature[0].owner = _owners[0].owner;
1397 | signature[0].sigData = _sign(_getPkByAddr(_owners[0].owner), userOpHash);
1398 | signature[1].owner = _owners[1].owner;
1399 | signature[1].sigData = _sign(_getPkByAddr(_owners[1].owner), userOpHash);
1400 | signature[2].owner = _owners[2].owner;
1401 | signature[2].sigData = _sign(_getPkByAddr(_owners[2].owner), userOpHash);
1402 |
1403 | userOp.signature = abi.encode(signature);
1404 | userOp.sender = address(account);
1405 |
1406 | vm.prank(_ENTRY_POINT);
1407 | uint256 validationData = account.validateUserOp(userOp, userOpHash, 0);
1408 | assertEq(validationData, 0x00);
1409 | }
1410 |
1411 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////
1412 |
1413 | function _getPkByAddr(address user) internal view returns (uint256) {
1414 | return keys[user];
1415 | }
1416 |
1417 | function _sign(uint256 pK, bytes32 hash) internal pure returns (bytes memory) {
1418 | (uint8 v, bytes32 r, bytes32 s) = vm.sign(pK, hash);
1419 | return abi.encodePacked(r, s, v);
1420 | }
1421 |
1422 | function _sortAddresses(address[] memory addresses) internal pure returns (address[] memory) {
1423 | for (uint256 i = 0; i < addresses.length; i++) {
1424 | for (uint256 j = i + 1; j < addresses.length; j++) {
1425 | if (uint160(addresses[i]) > uint160(addresses[j])) {
1426 | address temp = addresses[i];
1427 | addresses[i] = addresses[j];
1428 | addresses[j] = temp;
1429 | }
1430 | }
1431 | }
1432 | return addresses;
1433 | }
1434 | }
1435 |
1436 | contract MockERC721TotalSupply is MockERC721 {
1437 | uint256 public totalSupply;
1438 |
1439 | constructor() payable {}
1440 |
1441 | function mint(address to, uint256 id) public virtual override(MockERC721) {
1442 | _mint(to, id);
1443 |
1444 | unchecked {
1445 | ++totalSupply;
1446 | }
1447 | }
1448 | }
1449 |
1450 | contract MockERC1155TotalSupply is MockERC1155 {
1451 | mapping(uint256 => uint256) public totalSupply;
1452 |
1453 | constructor() payable {}
1454 |
1455 | function mint(address to, uint256 id, uint256 amount, bytes memory)
1456 | public
1457 | virtual
1458 | override(MockERC1155)
1459 | {
1460 | _mint(to, id, amount, "");
1461 |
1462 | totalSupply[id] += amount;
1463 | }
1464 | }
1465 |
1466 | contract MockERC6909TotalSupply is MockERC6909 {
1467 | mapping(uint256 => uint256) public totalSupply;
1468 |
1469 | constructor() payable {}
1470 |
1471 | function mint(address to, uint256 id, uint256 amount)
1472 | public
1473 | payable
1474 | virtual
1475 | override(MockERC6909)
1476 | {
1477 | _mint(to, id, amount);
1478 |
1479 | totalSupply[id] += amount;
1480 | }
1481 | }
1482 |
1483 | /// @dev Simple authority contract mock.
1484 | contract MockAuth {
1485 | function validateTransfer(address, address, uint256, uint256)
1486 | public
1487 | payable
1488 | returns (uint256)
1489 | {
1490 | return 0;
1491 | }
1492 |
1493 | function validateCall(address, address, uint256, bytes calldata)
1494 | public
1495 | payable
1496 | returns (uint256)
1497 | {
1498 | return 0;
1499 | }
1500 | }
1501 |
--------------------------------------------------------------------------------