Skip to content

Commit

Permalink
feat: adding delegation wall contract
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosgj94 committed Nov 9, 2024
1 parent 23618a3 commit ed637a6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 68 deletions.
8 changes: 4 additions & 4 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import { Foo } from "../src/Foo.sol";
import { DelegationWall } from "../src/DelegationWall.sol";

import { BaseScript } from "./Base.s.sol";

/// @dev See the Solidity Scripting tutorial: https://book.getfoundry.sh/tutorials/solidity-scripting
contract Deploy is BaseScript {
function run() public broadcast returns (Foo foo) {
foo = new Foo();
}
function run() public broadcast returns (DelegationWall delegationWall) {
delegationWall = new DelegationWall();
}
}
47 changes: 47 additions & 0 deletions src/DelegationWall.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
pragma solidity ^0.8.25;

/// @title DelegationWall - Release 1, Build 1
/// @author Aragon Association - 2024
/// @notice A smart contract where any wallet can announce itself as a delegate by providing an IPFS Id
contract DelegationWall {
struct Candidate {
bytes contentUrl;
}

/// @dev Stores the data registered by the delegate candidates
mapping(address => Candidate) public candidates;

/// @dev Keeps track of the addresses that have been already registered, used to enumerate.
address[] public candidateAddresses;

/// @notice Emitted when a wallet registers as a candidate
event CandidateRegistered(address indexed candidate, bytes contentUrl);

/// @notice Raised when a delegate registers with an empty contentUrl
error EmptyContent();

/// @notice Registers the given data as a new delegation candidate
function register(bytes memory _contentUrl) public {
if (_contentUrl.length == 0) revert EmptyContent();

if (candidates[msg.sender].contentUrl.length == 0) {
candidateAddresses.push(msg.sender);
}

candidates[msg.sender].contentUrl = _contentUrl;

emit CandidateRegistered(msg.sender, _contentUrl);
}

/// @notice Returns the list of candidate addresses registered
/// @dev Use this function to get all addresses in a single call. You can still call candidateAddresses[idx] to resolve them one by one.
function getCandidateAddresses() public view returns (address[] memory) {
return candidateAddresses;
}

/// @notice Returns the number of candidate entries available
function candidateCount() public view returns (uint256) {
return candidateAddresses.length;
}
}
8 changes: 0 additions & 8 deletions src/Foo.sol

This file was deleted.

23 changes: 23 additions & 0 deletions test/DelegationWall.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.25 <0.9.0;

import { Test } from "forge-std/src/Test.sol";
import { console2 } from "forge-std/src/console2.sol";

import { DelegationWall } from "../src/DelegationWall.sol";

interface IERC20 {
function balanceOf(address account) external view returns (uint256);
}

/// @dev If this is your first time with Forge, read this tutorial in the Foundry Book:
/// https://book.getfoundry.sh/forge/writing-tests
contract DelegationWallTest is Test {
DelegationWall internal delegationWall;

/// @dev A function invoked before each test case is run.
function setUp() public virtual {
// Instantiate the contract-under-test.
delegationWall = new DelegationWall();
}
}
56 changes: 0 additions & 56 deletions test/Foo.t.sol

This file was deleted.

0 comments on commit ed637a6

Please sign in to comment.