This repository has been archived by the owner on Mar 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
pygen.py
executable file
·112 lines (88 loc) · 2.5 KB
/
pygen.py
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
#! /usr/bin/python3
import binascii
class Cdef(object):
def __init__(self, name, saltString):
self.name = name
self.saltString = saltString
def make(dat):
out = []
for d in dat:
out.append(Cdef(d[0],d[1]))
return out
def build(cdefs):
ocurl = "{"
ccurl = "}"
outf = f"""
// SPDX-License-Identifier: MIT-open-group
pragma solidity 0.8.11;
import "./DeterministicAddress.sol";
abstract contract ImmutableFactory is DeterministicAddress {ocurl}
address private immutable _factory;
constructor(address factory_) {ocurl}
_factory = factory_;
{ccurl}
modifier onlyFactory() {ocurl}
require(msg.sender == _factory, "onlyFactory");
_;
{ccurl}
function _factoryAddress() internal view returns(address) {ocurl}
return _factory;
{ccurl}
{ccurl}
"""
tmpl = (
lambda name, salt: f"""
abstract contract immutable{name} is ImmutableFactory {ocurl}
address private immutable _{name};
constructor() {ocurl}
_{name} = getMetamorphicContractAddress(0x{salt}, _factoryAddress());
{ccurl}
modifier only{name}() {ocurl}
require(msg.sender == _{name}, "only{name}");
_;
{ccurl}
function _{name}Address() internal view returns(address) {ocurl}
return _{name};
{ccurl}
function _saltFor{name}() internal pure returns(bytes32) {ocurl}
return 0x{salt};
{ccurl}
{ccurl}
"""
)
for c in cdefs:
name = c.name
salt = c.saltString.encode().ljust(32, binascii.unhexlify(b"00"))
salt = binascii.hexlify(salt).decode("utf-8")
render = tmpl(name, salt)
outf = "".join([outf, render])
return outf
def run():
clst = [
("ValidatorNFT", "ValidatorNFT"),
("MadToken", "MadToken"),
("StakeNFT", "StakeNFT"),
("MadByte", "MadByte"),
("Governance", "Governance"),
("ValidatorPool", "ValidatorPool"),
("ETHDKG", "ETHDKG"),
("ETHDKGAccusations", "ETHDKGAccusations"),
("Snapshots", "Snapshots"),
("ETHDKGPhases", "ETHDKGPhases"),
("StakeNFTLP", "StakeNFTLP"),
("Foundation", "Foundation")
]
c=make(clst)
raw = build(c)
print(raw)
run()
"""
replace last line in gomod
use dummy mad token to mint stake nft positions
EX: tests/tokens/periphery/validatorPool/business-logic.ts
register validators line 88 of above
finally validatorPool.initializeEthDKG
run golang
bridge: new-shapshot-contract
madnet: changes
"""