Skip to content

Commit 0b133d4

Browse files
authored
feat: deployed contract to Celo Alfajores testnet (#3)
* updated * updated
1 parent 796bfda commit 0b133d4

File tree

16 files changed

+292
-99
lines changed

16 files changed

+292
-99
lines changed

.env.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
DEPLOYER_SK=
12
ID_HUB_ADDR=
23
SELF_SCOPE=
34
SELF_CONFIG_ID=
45

56
NEXT_PUBLIC_SELF_APP_NAME=
6-
NEXT_PUBLIC_SELF_SCOPE=
7-
NEXT_PUBLIC_SELF_ENDPOINT=
7+
NEXT_PUBLIC_VERIFICATION_DEPLOYED_ADDR=
8+
NEXT_PUBLIC_SELF_SCOPE_SEED=

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ DHK dao snapshot-self plugin prototype
88

99
- Snapshot: https://docs.snapshot.box/developer-guides/validation-strategy
1010
- [DHK dao snapshot page](https://snapshot.box/#/s:dhkdao.eth)
11+
12+
- Get Celo Alfajores Testnet token at: [learnweb3](https://learnweb3.io/)
13+
- Get LINK testnet token: https://faucets.chain.link/celo-alfajores-testnet
14+
- Swap for Celo native tokens: https://app.mento.org/
15+
16+
## Deployment
17+
18+
- SelfVerification:
19+
20+
Celo Alfajores Testnet: [`0xED3C8a827cE54C4D74A6476d93A9352D91d4e88E`](https://celo-alfajores.blockscout.com/address/0xED3C8a827cE54C4D74A6476d93A9352D91d4e88E)

packages/contracts/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ out/
55
# Ignores development broadcast logs
66
!/broadcast
77
/broadcast/*/31337/
8+
9+
# Celo Alfajores Testnet
10+
/broadcast/*/44787/
811
/broadcast/**/dry-run/
912

1013
# Docs
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as fs from 'fs';
2+
import * as path from 'path';
3+
import "dotenv/config";
4+
5+
import { createPublicClient, webSocket, parseAbi } from 'viem';
6+
7+
const RPC_URL = "http://localhost:8545";
8+
const contractAddress = process.env.NEXT_PUBLIC_VERIFICATION_DEPLOYED_ADDR || '';
9+
10+
const publicClient = createPublicClient({
11+
transport: webSocket(RPC_URL),
12+
});
13+
14+
console.log(`Listening to on-chain events\nrpc-url: ${RPC_URL}, address: ${contractAddress}`);
15+
16+
// Event types listen to
17+
const unwatch = publicClient.watchEvent({
18+
address: contractAddress,
19+
events: parseAbi([
20+
'event VerificationCompleted(address indexed sender, string indexed nationality, bytes userData)'
21+
]),
22+
onLogs: (logs) => console.log(logs)
23+
});

packages/contracts/package.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,25 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"test": "forge test"
7+
"build": "forge build",
8+
"dev": "pnpm build && conc -n 'node,deploy' -c auto 'pnpm node' 'pnpm deploy:dev'",
9+
"node": "anvil -f https://alfajores-forno.celo-testnet.org/",
10+
"test": "forge test",
11+
"deploy:dev": "wait-on -t 10s tcp:localhost:8545 && forge script script/DeploySelfVerification.s.sol --rpc-url http://localhost:8545 --broadcast",
12+
"listenEvents": "tsx lib/listenEvents.ts"
813
},
914
"keywords": [],
1015
"author": "",
1116
"license": "ISC",
1217
"packageManager": "pnpm@10.14.0",
13-
"dependencies": {
18+
"devDependencies": {
1419
"@selfxyz/contracts": "^1.2.0",
20+
"concurrently": "catalog:",
21+
"dotenv": "catalog:",
22+
"viem": "catalog:",
1523
"forge-std": "github:foundry-rs/forge-std#v1.10.0",
16-
"solady": "^0.1.24"
24+
"solady": "^0.1.24",
25+
"tsx": "catalog:",
26+
"wait-on": "catalog:"
1727
}
1828
}

packages/contracts/script/Counter.s.sol

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import {Script, console} from "forge-std/Script.sol";
5+
import {SelfVerification} from "../src/SelfVerification.sol";
6+
7+
contract SelfVerificationScript is Script {
8+
SelfVerification public sv;
9+
10+
function setUp() public {}
11+
12+
function run() public {
13+
uint256 deployerPrivateKey = vm.envUint("DEPLOYER_SK");
14+
15+
// what's needed to deploy SelfVerification
16+
address idHubAddr = vm.envAddress("ID_HUB_ADDR");
17+
uint256 scope = vm.envUint("SELF_SCOPE");
18+
bytes32 configId = vm.envBytes32("SELF_CONFIG_ID");
19+
20+
21+
vm.startBroadcast(deployerPrivateKey);
22+
23+
sv = new SelfVerification(idHubAddr, scope, configId);
24+
25+
console.log("YourContract deployed at:", address(sv));
26+
27+
vm.stopBroadcast();
28+
}
29+
}

packages/contracts/src/Counter.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/contracts/src/SelfVerification.sol

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import {ISelfVerificationRoot} from "@selfxyz/contracts/contracts/interfaces/ISe
66
import {Ownable} from "solady/auth/Ownable.sol";
77

88
contract SelfVerification is SelfVerificationRoot, Ownable {
9-
// Store verification status for each user
10-
mapping(address => bool) public verifiedHumans;
9+
// Store no, of times a wallet owner has been verified with a valid ID
10+
mapping(address => uint32) public verifiedHumans;
1111
bytes32 public verificationConfigId;
1212
address public lastUserAddress;
1313

1414
// Event to track successful verifications
15-
event VerificationCompleted(
16-
ISelfVerificationRoot.GenericDiscloseOutputV2 output,
17-
bytes userData
18-
);
15+
event VerificationCompleted(address indexed sender, string indexed nationality, bytes userData);
1916

2017
/**
2118
* @notice Constructor for the contract
@@ -42,10 +39,11 @@ contract SelfVerification is SelfVerificationRoot, Ownable {
4239
ISelfVerificationRoot.GenericDiscloseOutputV2 memory output,
4340
bytes memory userData
4441
) internal override {
45-
lastUserAddress = address(uint160(output.userIdentifier));
46-
verifiedHumans[lastUserAddress] = true;
42+
address userId = address(uint160(output.userIdentifier));
43+
string memory nationality = output.nationality;
44+
verifiedHumans[userId] += 1;
4745

48-
emit VerificationCompleted(output, userData);
46+
emit VerificationCompleted(userId, nationality, userData);
4947

5048
// Add your custom logic here:
5149
// - Mint NFT to verified user
@@ -55,21 +53,29 @@ contract SelfVerification is SelfVerificationRoot, Ownable {
5553
}
5654

5755
function getConfigId(
58-
bytes32 _destinationChainId,
59-
bytes32 _userIdentifier,
60-
bytes memory _userDefinedData
56+
bytes32 /* _destinationChainId */,
57+
bytes32 /* _userIdentifier */,
58+
bytes memory /* _userDefinedData */
6159
) public view override returns (bytes32) {
6260
return verificationConfigId;
6361
}
6462

6563
/**
6664
* @notice Check if an address is a verified human
6765
*/
68-
function isVerifiedHuman(address _user) external view returns (bool) {
69-
return verifiedHumans[_user];
66+
function isVerifiedHuman(address user) external view returns (bool) {
67+
return verifiedHumans[user] > 0;
7068
}
7169

72-
function setConfigId(bytes32 _configId) external onlyOwner {
73-
verificationConfigId = _configId;
70+
function setConfigId(bytes32 configId) external onlyOwner {
71+
verificationConfigId = configId;
72+
}
73+
74+
/**
75+
* @notice Expose the internal _setScope function for testing
76+
* @param newScope The new scope value to set
77+
*/
78+
function setScope(uint256 newScope) external onlyOwner {
79+
_setScope(newScope);
7480
}
7581
}

0 commit comments

Comments
 (0)