-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.edn
119 lines (106 loc) · 4.26 KB
/
deploy.edn
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
; SPDX-License-Identifier: BUSL-1.1
; Copyright © 2021 Fragcolor Pte. Ltd.
(def salt-string "Hasten Smart Contracts v1, property of Fragcolor Pte. Ltd. and minted on the 19th day of September 2021")
(def create-abi "[{
\"constant\": false,
\"inputs\": [
{
\"internalType\": \"bytes\",
\"name\": \"_initCode\",
\"type\": \"bytes\"
},
{
\"internalType\": \"bytes32\",
\"name\": \"_salt\",
\"type\": \"bytes32\"
}
],
\"name\": \"deploy\",
\"outputs\": [
{
\"internalType\": \"address payable\",
\"name\": \"createdContract\",
\"type\": \"address\"
}
],
\"payable\": false,
\"stateMutability\": \"nonpayable\",
\"type\": \"function\"
}]")
(def fragment-abi "[{
\"inputs\": [],
\"name\": \"bootstrap\",
\"outputs\": [],
\"stateMutability\": \"payable\",
\"type\": \"function\",
\"payable\": true
}]")
(def utility-bytecode (slurp "deployer-utils/utility-bytecode.txt"))
(def entity-bytecode (slurp "deployer-utils/entity-bytecode.txt"))
(def vault-bytecode (slurp "deployer-utils/vault-bytecode.txt"))
(def admin-bytecode (slurp "deployer-utils/admin-bytecode.txt"))
(def fragment-bytecode (slurp "deployer-utils/nft-bytecode.txt"))
(def fragment-proxy-bytecode (slurp "deployer-utils/nftProxy-bytecode.txt"))
(defn metamask-call [dest call]
(->
(str "await ethereum.request({method: 'eth_sendTransaction', params: [{from: ethereum.selectedAddress, to: \"" dest "\", data: \"") (PrependTo call)
"\"}]})" (AppendTo call) call))
(defchain find-address
"0xFF" (HexToBytes) >= .bytes
(Input) (Take 0) (AppendTo .bytes) ; address
(Input) (Take 1) (AppendTo .bytes) ; salt
(Input) (Take 2) (Hash.Keccak-256) (AppendTo .bytes) ; bytecode
.bytes (Hash.Keccak-256) (ToHex) (Slice :From 26) >= .res
"0x" (PrependTo .res) .res)
(defchain checksum
(Slice :From 2) = .low-addr
(Hash.Keccak-256) (ToHex) (Slice :From 2) = .str-hash
0 >= .idx
"0x" >= .res
(Repeat
(->
.idx (Math.Add 1) = .idx+1
.low-addr (Slice :From .idx :To .idx+1) = .a
.str-hash (Slice :From .idx :To .idx+1) = .b
.b (ParseInt :Base 16)
(If (IsMoreEqual 8)
(-> .a (String.ToUpper) (AppendTo .res))
(-> .a (AppendTo .res)))
(Math.Inc .idx))
:Forever true
:Until (-> .idx (Is 40)))
.res)
(defn deploy [bytecode name salt]
(Chain "deploy"
bytecode (HexToBytes) = .bytecode
salt = .salt
[.bytecode .salt]
(Eth.EncodeCall create-abi "deploy")
(ToHex) >= .call
(metamask-call "0xe14B5aE0D1E8A4e9039D40e5BF203fD21E2f6241" .call)
(Log name)
"0xe14B5aE0D1E8A4e9039D40e5BF203fD21E2f6241" (HexToBytes) >> .args
.salt >> .args
.bytecode >> .args
.args (Do find-address) (Do checksum) (Log "Address")))
(defnode main)
(schedule main (deploy utility-bytecode "utility" (-> salt-string (Hash.Keccak-256))))
(schedule main (deploy entity-bytecode "entity" (-> salt-string (Hash.Keccak-256))))
(schedule main (deploy vault-bytecode "vault" (-> salt-string (Hash.Keccak-256))))
; fragment will need editing to set correct above final deploy addresses!
(schedule main (deploy fragment-bytecode "fragment" (-> salt-string (Hash.Keccak-256))))
(schedule main (deploy admin-bytecode "admin" (-> salt-string (Hash.Keccak-256))))
; this will need further editing with fragment logic and admin address!
(schedule main (deploy fragment-proxy-bytecode "fragment-proxy" (-> salt-string (Hash.Keccak-256))))
(schedule main (Chain "bootstrap"
[] (Eth.EncodeCall fragment-abi "bootstrap")
(ToHex) >= .call
(metamask-call "0x878576534EA9C7ec24FcBf512C6f56d4ED1B9a56" .call)
(Log "bootstrap")))
(defchain slots
"fragcolor.fragment.utilityLibrary" (Hash.Keccak-256) (ToHex) (Log "utilityLibrary")
"fragcolor.fragment.entityLogic" (Hash.Keccak-256) (ToHex) (Log "entityLogic")
"fragcolor.fragment.vaultLogic" (Hash.Keccak-256) (ToHex) (Log "vaultLogic")
"fragcolor.fragment.controller" (Hash.Keccak-256) (ToHex) (Log "controller"))
(schedule main slots)
(run main)