-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesign2
181 lines (138 loc) · 5.08 KB
/
design2
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
here's the flow:
contract ->
targets ->
proxy, implementation
all contracts deployed using create2
version string identifies contract
address = create2_predict(deployer_account, proxy_bytecode, concat(target_name, target_version))
requireAndGetAddress("TakeMarket") -> create2_predict(this.deployer, this.proxy_bytecode_hash, concat(targetName, ))
nah simpler
deploy implementation
deploy proxy
import addresses into AddressResolver
rebuild caches for every contract
now initialize contracts
for each contract:
end state:
each target:
proxy
implementation
proxy.implementation = implementation
wired up:
addressresolver.cache = {
...targets.map(target => {
return { [target.name]: [proxy.address] }
})
}
each target:
target.cacheFresh = true
target.rebuildCache()
initialize:
this could be:
- calling initialize() which is once-only per implementation
- calling a variety of functions - ie. setParam(var), calculateDebtCache()
- calling a function that is only callable by the owner
potentially could cut this up as:
.allerrc.js
{
state: {
'SystemSettings': {
issuanceRatio: '0.1'
}
}
}
{
state: {
'SystemSettings': {
initialize: {
args: []
}
}
}
}
Script.s.sol:
function run() {
TakeMarketToken.initialize(rewardsDistributor)
SystemSettings.setIssuanceRatio(0.1)
FarmingThing.importAccounts(accounts)
}
script.js:
function run(sys) {
// TakeMarketToken.initialize(rewardsDistributor)
await sys.initialize({
contract: "TakeMarketToken",
args: [rewardsDistributor]
})
// SystemSettings.setIssuanceRatio(0.1)
await sys.setProperty({
contract: 'SystemSettings',
name: 'issuanceRatio',
value: '0.1',
action: 'setIssuanceRatio'
})
// FarmingThing.importAccounts()
await sys.setValue({
contract: 'FarmingThing',
name: 'importAccounts',
action: 'importAccounts',
value: [...accounts],
})
}
script2.js:
function run(sys) {
const {
TakeMarketToken,
SystemSettings,
FarmingThing,
} = sys.contracts
await TakeMarketToken.initialize(rewardsDistributor)
await SystemSettings.setIssuanceRatio(0.1)
await FarmingThing.importAccounts()
}
script2-with-smart-changes.js:
function run(sys) {
const {
TakeMarketToken,
SystemSettings,
FarmingThing,
} = sys.contracts
if(!(await TakeMarketShares.initialized())) {
await TakeMarketToken.initialize(rewardsDistributor)
}
// ...
// Alternatively:
await initialize({
contract: TakeMarketToken,
args: [rewardsDistributor],
})
await runStep({
contract: SystemSettings,
read: 'totalSupply',
expected: input => input === '0',
write: 'setTotalSupply',
writeArg: '0',
});
await TakeMarketToken.initialize(rewardsDistributor)
await SystemSettings.setIssuanceRatio(0.1)
await FarmingThing.importAccounts()
}
For each of these runStep calls:
- read the contract's state
- compare it to the expected value
- if it's different, run the write function
- if it's the same, skip it
We could also write an entire solidity block for this.
But this would require a smart wallet / AA - ie. to pass the owner checks.
await sys.script(async () => {
await runStep({
contract: SystemSettings,
read: 'totalSupply',
expected: input => input === '0',
write: 'setTotalSupply',
writeArg: '0',
});
})
All of these could be run locally to detect changes in state.
could use eth-verifiable-rpc for ethereum
This would be harder in the StarkNet example, because there's no library for this rn.
ideally an entire deployment would be atomic.