Skip to content

Commit 1d2b254

Browse files
committed
✨ deploy solidity and stylus contracts
1 parent b81c7df commit 1d2b254

File tree

1 file changed

+72
-4
lines changed

1 file changed

+72
-4
lines changed

paradigmctf.py/ctf_launchers/utils.py

Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,64 @@ def deploy_cairo(
107107
return output[:65]
108108

109109

110+
def deploy_no_impersonate(
111+
web3: Web3,
112+
project_location: str,
113+
mnemonic: str,
114+
deploy_script: str = "script/Deploy.s.sol:Deploy",
115+
env: Dict = {},
116+
) -> str:
117+
rfd, wfd = os.pipe2(os.O_NONBLOCK)
118+
119+
proc = subprocess.Popen(
120+
args=[
121+
"/opt/foundry/bin/forge",
122+
"script",
123+
"--rpc-url",
124+
web3.provider.endpoint_uri,
125+
"--out",
126+
"/artifacts/out",
127+
"--cache-path",
128+
"/artifacts/cache",
129+
"--broadcast",
130+
"--unlocked",
131+
"--sender",
132+
"0x0000000000000000000000000000000000000000",
133+
deploy_script,
134+
],
135+
env={
136+
"PATH": "/opt/huff/bin:/opt/foundry/bin:/usr/bin:" + os.getenv("PATH", "/fake"),
137+
"MNEMONIC": mnemonic,
138+
"OUTPUT_FILE": f"/proc/self/fd/{wfd}",
139+
}
140+
| env,
141+
pass_fds=[wfd],
142+
cwd=project_location,
143+
text=True,
144+
encoding="utf8",
145+
stdin=subprocess.DEVNULL,
146+
stdout=subprocess.PIPE,
147+
stderr=subprocess.PIPE,
148+
)
149+
stdout, stderr = proc.communicate()
150+
151+
if proc.returncode != 0:
152+
print(stdout)
153+
print(stderr)
154+
raise Exception("forge failed to run")
155+
156+
result = os.read(rfd, 256).decode("utf8")
157+
158+
os.close(rfd)
159+
os.close(wfd)
160+
161+
return result
162+
163+
110164
def deploy_nitro(
111165
web3: Web3,
112166
project_location: str,
113-
credentials: list,
114-
deploy_script: str = "deploy.py",
167+
mnemonic: list,
115168
env: Dict = {},
116169
) -> str:
117170
rfd, wfd = os.pipe2(os.O_NONBLOCK)
@@ -141,11 +194,26 @@ def deploy_nitro(
141194
print(stderr)
142195
raise Exception("script failed to run")
143196

144-
address = stdout.split('Activating program at address ')[1].replace("\\n", "")
197+
address = stdout.split('Activating program at address ')[
198+
1].replace("\\n", "")
145199

146200
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
147201

148-
output = ansi_escape.sub('', address)[:42]
202+
token = ansi_escape.sub('', address)[:42]
203+
204+
env = {
205+
"PATH": "/opt/huff/bin:/opt/foundry/bin:/usr/bin:" + os.getenv("PATH", "/fake"),
206+
"MNEMONIC": mnemonic,
207+
"OUTPUT_FILE": f"/proc/self/fd/{wfd}",
208+
"TOKEN": token
209+
}
210+
211+
output = deploy_no_impersonate(
212+
web3,
213+
project_location,
214+
"",
215+
env=env,
216+
)
149217

150218
return output
151219

0 commit comments

Comments
 (0)