-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgroupcreator.html
212 lines (196 loc) · 7.38 KB
/
groupcreator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Gnosis Safe Group Creator</title>
<!-- Load ethers.js from a CDN -->
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 0;
background: #f7f7f7;
}
h1 {
color: #333;
text-align: center;
}
form {
background: #fff;
padding: 20px;
border-radius: 8px;
max-width: 500px;
margin: 20px auto;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
label {
display: block;
margin-top: 15px;
font-weight: bold;
}
input, textarea {
width: 100%;
padding: 8px;
margin-top: 5px;
box-sizing: border-box;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
button {
margin-top: 20px;
padding: 10px 20px;
font-size: 16px;
background: #5C49E4;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
display: block;
width: 100%;
}
button:hover {
background: #4A39CC;
}
#status {
margin-top: 20px;
font-size: 14px;
color: #333;
text-align: center;
white-space: pre-wrap;
}
</style>
</head>
<body>
<h1>Gnosis Safe Group Creator</h1>
<form id="createGroupForm">
<label for="service">Service Address:</label>
<!-- Will be prefilled with the connected address -->
<input type="text" id="service" value="" required />
<label for="conditions">Initial Conditions (comma separated):</label>
<!-- Leave empty for no initial conditions -->
<textarea id="conditions" rows="2" placeholder="Optional conditions (comma separated)"></textarea>
<label for="name">Group Name:</label>
<!-- Default group name -->
<input type="text" id="name" value="My Group Name" required />
<label for="symbol">Symbol:</label>
<!-- Default symbol -->
<input type="text" id="symbol" value="SYMBOL" required />
<label for="metadata">Metadata Digest (bytes32 hex):</label>
<!-- Prefilled with the 32-byte zero value -->
<input type="text" id="metadata" value="0x0000000000000000000000000000000000000000000000000000000000000000" required />
<button type="submit">Create Group</button>
</form>
<div id="status"></div>
<script>
window.addEventListener('load', async () => {
// Check for an Ethereum provider (e.g., injected by Gnosis Safe or MetaMask)
if (typeof window.ethereum === 'undefined') {
document.getElementById('status').innerText =
"No Ethereum provider detected. Please install MetaMask (or a compatible wallet).";
return;
}
// Create an ethers provider and signer from the injected provider
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send("eth_requestAccounts", []);
const signer = provider.getSigner();
// Set the service input to the connected (signer's) address
const connectedAddress = await signer.getAddress();
document.getElementById('service').value = connectedAddress;
// Contract details for the group creator
const contractAddress = "0x55785b41703728f1F1F05E77e22B13c3FCc9ce65";
const abi = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "proxy", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "mintHandler", "type": "address" },
{ "indexed": false, "internalType": "address", "name": "redemptionHandler", "type": "address" }
],
"name": "CMGroupCreated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "mastercopy", "type": "address" }
],
"name": "MasterCopyDeployed",
"type": "event"
},
{
"inputs": [
{ "internalType": "address", "name": "_service", "type": "address" },
{ "internalType": "address[]", "name": "_initialConditions", "type": "address[]" },
{ "internalType": "string", "name": "_name", "type": "string" },
{ "internalType": "string", "name": "_symbol", "type": "string" },
{ "internalType": "bytes32", "name": "_metadataDigest", "type": "bytes32" }
],
"name": "createCMGroup",
"outputs": [
{ "internalType": "address", "name": "", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "masterCopyCMGroup",
"outputs": [
{ "internalType": "contract CoreMembersGroup", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
}
];
// Create a contract instance with the signer
const contract = new ethers.Contract(contractAddress, abi, signer);
// Handle the group creation form submission
document.getElementById('createGroupForm').addEventListener('submit', async (event) => {
event.preventDefault();
document.getElementById('status').innerText = "Submitting transaction...";
// Retrieve values from the form fields
const service = document.getElementById('service').value.trim();
const conditionsInput = document.getElementById('conditions').value.trim();
const name = document.getElementById('name').value.trim();
const symbol = document.getElementById('symbol').value.trim();
const metadata = document.getElementById('metadata').value.trim();
// Process initial conditions as an array (if provided)
let initialConditions = [];
if (conditionsInput.length > 0) {
initialConditions = conditionsInput.split(',')
.map(addr => addr.trim())
.filter(addr => addr.length > 0);
}
// Validate metadata digest format (expecting "0x" followed by 64 hex characters)
if (!/^0x[0-9a-fA-F]{64}$/.test(metadata)) {
document.getElementById('status').innerText =
"Invalid metadata digest. It must be a 0x-prefixed 64-hex character string.";
return;
}
try {
// Call createCMGroup with the provided parameters
const tx = await contract.createCMGroup(service, initialConditions, name, symbol, metadata);
document.getElementById('status').innerText =
`Transaction submitted. Tx hash: ${tx.hash}\nWaiting for confirmation...`;
// Wait for the transaction to be mined
await tx.wait();
document.getElementById('status').innerText =
`Group created successfully! Tx hash: ${tx.hash}`;
} catch (error) {
console.error(error);
document.getElementById('status').innerText = `Error: ${error.message}`;
}
});
});
</script>
</body>
</html>