forked from gmh5225/aptos-aave-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
executable file
·2501 lines (2227 loc) · 76.4 KB
/
deploy.py
File metadata and controls
executable file
·2501 lines (2227 loc) · 76.4 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import argparse
import json
import logging
import os
import pathlib
import subprocess
import tempfile
from datetime import datetime, UTC
from threading import Thread, Lock
from typing import Optional, List, Dict, Tuple, IO, AnyStr
APTOS_BIN = "aptos"
PROJECT_DIR = pathlib.Path(__file__).parent.resolve()
#
# Utilities to execute a command and also log its output
#
class AtomicBool:
"""
A minimal atomic boolean implementation
"""
def __init__(self) -> None:
self.flag = False
self.lock = Lock()
def set(self) -> None:
with self.lock:
self.flag = True
def get(self) -> bool:
with self.lock:
return self.flag
def _poll_stream(tag: str, stream: IO[AnyStr], completed: AtomicBool) -> List[str]:
output = []
while not completed.get():
for line in stream:
line = line.rstrip()
logging.debug(f"[{tag}] {line}")
output.append(line)
return output
class StreamPollingThread(Thread):
"""
A thread that automatically polls an IO stream and also accumulates the text
"""
def __init__(self, tag: str, stream: IO[AnyStr], completed: AtomicBool):
Thread.__init__(self, target=_poll_stream, args=(tag, stream, completed))
self._return = None
def run(self):
if self._target is not None:
self._return = self._target(*self._args, **self._kwargs)
def join(self, *args) -> List[str]:
Thread.join(self, *args)
return self._return
def _checked_execute(
command: List[str],
cwd: Optional[str | pathlib.Path] = None,
) -> Tuple[List[str], List[str]]:
# log the command
logging.debug(f"Executing command: {command}")
# start the process
kwargs = {}
if cwd is not None:
kwargs["cwd"] = cwd
proc = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
**kwargs,
)
flag = AtomicBool()
# spawn threads to read the streams
thread_stdout = StreamPollingThread("stdout", proc.stdout, flag)
thread_stdout.start()
thread_stderr = StreamPollingThread("stderr", proc.stderr, flag)
thread_stderr.start()
# wait for the completion of the process
proc.wait()
# inform the threads to stop
flag.set()
captured_stdout = thread_stdout.join()
captured_stderr = thread_stderr.join()
# raise an exception if the command fails
if proc.returncode != 0:
raise subprocess.CalledProcessError(
returncode=proc.returncode,
cmd=command,
output="\n".join(captured_stdout),
stderr="\n".join(captured_stderr),
)
# return the outputs
return captured_stdout, captured_stderr
#
# Generic publication logic
#
def clear_staging_area(
deployer: str,
fullnode: str,
multisig_address: Optional[str] = None,
large_packages_module_address: Optional[str] = None,
) -> None:
"""
Clear the staging area for chunked publication
:param deployer: profile name of the account who initializes the deployment
:param fullnode: fullnode URL of the chain
:param multisig_address: multisig address of the account (if needed)
:param large_packages_module_address: large packages module address
"""
if multisig_address is None:
commands = [
APTOS_BIN,
"move",
"clear-staging-area",
"--profile",
deployer,
"--url",
fullnode,
]
else:
commands = [
APTOS_BIN,
"multisig",
"create-transaction",
"--multisig-address",
multisig_address,
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{large_packages_module_address}::large_packages::cleanup_staging_area",
]
_checked_execute(commands, cwd=PROJECT_DIR)
def _get_deployed_address(package_name: str) -> str:
"""
Retrieve the deployed (object) address of a package
:param package_name: name of the package
:return: address of the deployed package
"""
with open(PROJECT_DIR / f"deploy-{package_name}-object.txt", "r") as f:
return f.read().strip()
def _set_deployed_address(package_name: str, deployed_address: str) -> None:
"""
Store the deployed (object) address of a package in a file
:param package_name: name of the package
:param deployed_address: address of the deployed package
"""
with open(PROJECT_DIR / f"deploy-{package_name}-object.txt", "w") as f:
f.write(deployed_address)
def _publish(
deployer: str,
fullnode: str,
upgrade: bool,
package_path: str | pathlib.Path,
address_name: str,
object_named_addresses: List[str],
preset_named_addresses: Optional[Dict[str, str]] = None,
chunked_publish: bool = False,
max_gas: Optional[int] = 100_0000,
fetch_latest_git_deps: bool = False,
) -> None:
"""
Publish a Move package on-chain via the deploy-object model
:param deployer: profile name of the account who initializes the deployment
:param fullnode: fullnode URL of the chain
:param upgrade: whether this is to publish a new package or upgrade an existing one
:param package_path: local filesystem path of the package to be published
:param address_name: the main named address of the package
:param object_named_addresses: dependencies that are previously deployed as objects
:param preset_named_addresses: other named addresses needed to build the package
:param chunked_publish: whether to publish in chunks or in one transaction
:param max_gas: if set, limit gas consumption but also skip local simulation
"""
# log the action
logging.info(
f"Starting to %s package %s",
"upgrade" if upgrade else "publish",
address_name,
)
# build the command
named_address_list = [
"{}={}".format(i, _get_deployed_address(i)) for i in object_named_addresses
]
if preset_named_addresses is not None:
named_address_list.extend(
[f"{k}={v}" for k, v in preset_named_addresses.items()]
)
commands = [
APTOS_BIN,
"move",
"upgrade-object" if upgrade else "deploy-object",
"--profile",
deployer,
"--url",
fullnode,
"--included-artifacts",
"sparse",
"--address-name",
address_name,
]
if upgrade:
commands.extend(["--object-address", _get_deployed_address(address_name)])
if len(named_address_list) != 0:
commands.extend(["--named-addresses", ",".join(named_address_list)])
if chunked_publish:
commands.append("--chunked-publish")
if max_gas is not None:
commands.extend(["--max-gas", str(max_gas)])
if not fetch_latest_git_deps:
commands.append("--skip-fetch-latest-git-deps")
# execute the deployment
output, _ = _checked_execute(commands, cwd=package_path)
# parse the output only on publishing
if upgrade:
needle = "Code was successfully upgraded at object address "
else:
needle = "Code was successfully deployed to object address "
deployed_address = None
for line in output:
line = line.lstrip()
if line.startswith(needle):
# rare case, just to be caution
if deployed_address is not None:
raise RuntimeError(
f"Package {address_name} is deployed "
f"but we find more than one deployment addresses in the output"
)
deployed_address = line.removeprefix(needle)
if deployed_address is None:
raise RuntimeError(
f"Package {address_name} is deployed "
f"but we are unable to find deployment address in the output"
)
# set the deployment address
if upgrade:
assert deployed_address == _get_deployed_address(address_name)
logging.info("Package '%s' upgraded at %s", address_name, deployed_address)
else:
_set_deployed_address(address_name, deployed_address)
logging.info("Package '%s' deployed at %s", address_name, deployed_address)
def _create_chunks(data: bytes, chunk_size: int) -> List[bytes]:
"""
Split bytes (byte array) into chunks of requested sizes
:param data: bytes or bytes array
:param chunk_size: desired chunk size
:return: a list of chunks (in bytes)
"""
total_size = len(data)
accumulated = 0
result = []
while accumulated < total_size:
chunk = data[accumulated : accumulated + chunk_size]
result.append(chunk)
accumulated += chunk_size
return result
def _large_packages_stage_code_chunk_via_multisig(
deployer: str,
fullnode: str,
multisig_address: str,
metadata_chunk: bytes,
code_indices: List[int],
code_chunks: List[bytes],
large_packages_module_address: str,
) -> None:
"""
Stage metadata and/or code chunks via multisig
:param deployer: profile name of the deployer
:param fullnode: fullnode URL of the chain
:param multisig_address: address of the multisig account
:param metadata_chunk: metadata chunk bytes to be staged, if any
:param code_indices: code indices to be staged, if any
:param code_chunks: code chunks to be staged, if any
:param large_packages_module_address: address of the large packages module
"""
commands = [
APTOS_BIN,
"multisig",
"create-transaction",
"--multisig-address",
multisig_address,
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{large_packages_module_address}::large_packages::stage_code_chunk",
"--args",
"u8:[]" if len(metadata_chunk) == 0 else "hex:0x" + metadata_chunk.hex(),
"u16:[{}]".format(",".join([str(i) for i in code_indices])),
"hex:[{}]".format(
",".join(['"0x' + code_chunk.hex() + '"' for code_chunk in code_chunks])
),
]
_checked_execute(commands, cwd=PROJECT_DIR)
def _execute_multisig_chunked_upgrade_workflow(
deployer: str,
fullnode: str,
owner_multisig: str,
object_address: str,
tx_json: str | pathlib.Path,
chunk_size: int,
large_packages_module_address: str,
) -> int:
"""
Upgrade a package (deployer at an object address that is owned by a multisig account)
via chynked publishing
:param deployer: profile name of the deployer
:param fullnode: fullnode URL of the chain
:param owner_multisig: address of the multisig account that owns the package
:param object_address: address of the object address that hosts the package
:param tx_json: path to the transaction json file that holds the transaction
:param chunk_size: desired chunk size
:param large_packages_module_address: address of the large packages module
:return: number of multisig transactions sequenced
"""
with open(tx_json, "r") as f:
tx_details = json.load(f)
# sanity checks
assert tx_details["function_id"] == "0x1::code::publish_package_txn"
assert len(tx_details["args"]) == 2
# chunks the metadata
arg0 = tx_details["args"][0]
assert arg0["type"] == "hex"
assert arg0["value"].startswith("0x")
metadata = bytes.fromhex(arg0["value"].removeprefix("0x"))
metadata_chunks = _create_chunks(metadata, chunk_size)
# special handling for last metadata chunk
last_metadata_chunk = metadata_chunks.pop()
# stage metadata chunks first
counter = 0
for chunk in metadata_chunks:
logging.debug("staging chunk %d", counter)
_large_packages_stage_code_chunk_via_multisig(
deployer,
fullnode,
owner_multisig,
chunk,
[],
[],
large_packages_module_address,
)
counter += 1
# stage code chunks now
taken_size = len(last_metadata_chunk)
code_indices = []
code_chunks = []
arg1 = tx_details["args"][1]
assert arg1["type"] == "hex"
code_vec = arg1["value"]
for idx, hex_repr in enumerate(code_vec):
assert hex_repr.startswith("0x")
module_code = bytes.fromhex(hex_repr.removeprefix("0x"))
for chunk in _create_chunks(module_code, chunk_size):
if taken_size + len(chunk) > chunk_size:
logging.debug("staging chunk %d", counter)
_large_packages_stage_code_chunk_via_multisig(
deployer,
fullnode,
owner_multisig,
last_metadata_chunk,
code_indices,
code_chunks,
large_packages_module_address,
)
counter += 1
# clear the accumulation
last_metadata_chunk = bytes()
taken_size = 0
code_indices.clear()
code_chunks.clear()
# accumulate
code_indices.append(idx)
code_chunks.append(chunk)
taken_size += len(chunk)
# send the final transaction
commands = [
APTOS_BIN,
"multisig",
"create-transaction",
"--multisig-address",
owner_multisig,
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{large_packages_module_address}::large_packages::stage_code_chunk_and_upgrade_object_code",
"--args",
(
"u8:[]"
if len(last_metadata_chunk) == 0
else "hex:0x" + last_metadata_chunk.hex()
),
"u16:[{}]".format(",".join([str(i) for i in code_indices])),
"hex:[{}]".format(
",".join(['"0x' + code_chunk.hex() + '"' for code_chunk in code_chunks])
),
f"address:{object_address}",
]
_checked_execute(commands, cwd=PROJECT_DIR)
return counter + 1
def _upgrade_via_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
package_path: str | pathlib.Path,
address_name: str,
object_named_addresses: List[str],
preset_named_addresses: Optional[Dict[str, str]] = None,
chunked_publish: Optional[Tuple[int, str]] = None,
max_gas: Optional[int] = 100_0000,
fetch_latest_git_deps: bool = False,
) -> int:
# log the action
logging.info(f"Starting to upgrade package %s via multisig", address_name)
# everything occurs inside a temp dir
with tempfile.TemporaryDirectory() as tmpdir:
tx_json = os.path.join(tmpdir, "tx.json")
# create the transaction
object_address = _get_deployed_address(address_name)
named_address_list = [f"{address_name}={object_address}"]
named_address_list.extend(
[
"{}={}".format(i, _get_deployed_address(i))
for i in object_named_addresses
]
)
if preset_named_addresses is not None:
named_address_list.extend(
[f"{k}={v}" for k, v in preset_named_addresses.items()]
)
commands = [
APTOS_BIN,
"move",
"build-publish-payload",
"--profile",
deployer,
"--url",
fullnode,
"--included-artifacts",
"sparse",
"--json-output-file",
tx_json,
"--named-addresses",
",".join(named_address_list),
]
if chunked_publish is not None:
# NOTE: until Aptos CLI has support for chunked publication for multisig, we
# need to implement this ourselves, hence not using `--chunked-publish`
commands.append("--override-size-check")
if max_gas is not None:
commands.extend(["--max-gas", str(max_gas)])
if not fetch_latest_git_deps:
commands.append("--skip-fetch-latest-git-deps")
_checked_execute(commands, cwd=package_path)
# special flow for chunked publication
if chunked_publish is not None:
chunk_size, large_packages_module_address = chunked_publish
number_of_transactions = _execute_multisig_chunked_upgrade_workflow(
deployer,
fullnode,
owner_multisig,
object_address,
tx_json,
chunk_size,
large_packages_module_address,
)
# short-circuit, as the rest is normal upgrading flow
return number_of_transactions
# modify the transaction json file
with open(tx_json, "r") as f1:
tx_details = json.load(f1)
assert tx_details["function_id"] == "0x1::code::publish_package_txn"
tx_details["function_id"] = "0x1::object_code_deployment::upgrade"
assert len(tx_details["args"]) == 2
tx_details["args"].append(
{
"type": "address",
"value": object_address,
}
)
with open(tx_json, "w") as f2:
json.dump(tx_details, f2)
# send the transaction to the multisig account
_create_multisig_transaction_with_json_payload(
deployer, fullnode, owner_multisig, tx_json
)
return 1
#
# Logics per each package
#
def publish_aave_config(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "aave-config",
"aave_config",
[],
)
def upgrade_aave_config_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core" / "aave-config",
"aave_config",
[],
)
def publish_aave_acl(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "aave-acl",
"aave_acl",
["aave_config"],
)
def upgrade_aave_acl_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core" / "aave-acl",
"aave_acl",
["aave_config"],
)
def publish_aave_math(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "aave-math",
"aave_math",
["aave_config"],
)
def upgrade_aave_math_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core" / "aave-math",
"aave_math",
["aave_config"],
)
def publish_mock_underlyings(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "aave-mock-underlyings",
"aave_mock_underlyings",
["aave_config"],
)
def upgrade_mock_underlyings_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core" / "aave-mock-underlyings",
"aave_mock_underlyings",
["aave_config"],
)
def publish_chainlink_platform(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "chainlink-platform",
"platform",
[],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
)
def publish_chainlink_data_feeds(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "chainlink-data-feeds",
"data_feeds",
["platform"],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
)
def publish_aave_oracle(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "aave-oracle",
"aave_oracle",
[
"aave_config",
"aave_acl",
"aave_math",
"platform",
"data_feeds",
],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
)
def upgrade_aave_oracle_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core" / "aave-oracle",
"aave_oracle",
[
"aave_config",
"aave_acl",
"aave_math",
"platform",
"data_feeds",
],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
)
def publish_aave_core(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core",
"aave_pool",
[
"aave_config",
"aave_acl",
"aave_math",
"aave_oracle",
"platform",
"data_feeds",
],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
chunked_publish=True,
)
def upgrade_aave_core_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
chunk_size: int,
large_packages_module_address: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core",
"aave_pool",
[
"aave_config",
"aave_acl",
"aave_math",
"aave_oracle",
"platform",
"data_feeds",
],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
chunked_publish=(chunk_size, large_packages_module_address),
)
def publish_aave_data(deployer: str, fullnode: str, upgrade: bool) -> None:
_publish(
deployer,
fullnode,
upgrade,
PROJECT_DIR / "aave-core" / "aave-data",
"aave_data",
[
"aave_config",
"aave_acl",
"aave_math",
"aave_mock_underlyings",
"aave_oracle",
"aave_pool",
"platform",
"data_feeds",
],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
chunked_publish=True,
)
def upgrade_aave_data_multisig(
deployer: str,
fullnode: str,
owner_multisig: str,
chunk_size: int,
large_packages_module_address: str,
) -> int:
return _upgrade_via_multisig(
deployer,
fullnode,
owner_multisig,
PROJECT_DIR / "aave-core" / "aave-data",
"aave_data",
[
"aave_config",
"aave_acl",
"aave_math",
"aave_mock_underlyings",
"aave_oracle",
"aave_pool",
"platform",
"data_feeds",
],
preset_named_addresses={"aave_oracle_racc_address": "0x0"},
chunked_publish=(chunk_size, large_packages_module_address),
)
def deploy_all_localnet(
deployer: str,
fullnode: str,
upgrade: bool,
) -> None:
"""
Deploy all packages on-chain
:param deployer: profile name of the account who initializes the deployment
:param fullnode: fullnode URL of the chain
:param upgrade: if True, upgrade packages instead of initially publishign them
"""
publish_aave_config(deployer, fullnode, upgrade)
publish_aave_acl(deployer, fullnode, upgrade)
publish_aave_math(deployer, fullnode, upgrade)
publish_mock_underlyings(deployer, fullnode, upgrade)
publish_chainlink_platform(deployer, fullnode, upgrade)
publish_chainlink_data_feeds(deployer, fullnode, upgrade)
publish_aave_oracle(deployer, fullnode, upgrade)
publish_aave_core(deployer, fullnode, upgrade)
publish_aave_data(deployer, fullnode, upgrade)
#
# Initialize scripts
#
def change_ownership(
deployer: str,
fullnode: str,
package_name: str,
new_owner_address: str,
) -> None:
"""
Change ownership of the object where the package is deployed at
:param deployer: profile name of the previous owner of the object
:param fullnode: fullnode URL of the chain
:param package_name: name of the package
:param new_owner_address: address of the new owner
"""
logging.info(
"Changing ownership for package '%s' from deployer '%s' to address %s",
package_name,
deployer,
new_owner_address,
)
deployed_address = _get_deployed_address(package_name)
commands = [
APTOS_BIN,
"move",
"run",
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
"0x1::object::transfer",
"--type-args",
"0x1::object::ObjectCore",
"--args",
f"address:{deployed_address}",
f"address:{new_owner_address}",
]
_checked_execute(commands, cwd=PROJECT_DIR)
def configure_acl(
deployer: str, fullnode: str, multisig_aave_acl: str, network: str
) -> None:
# log the action
logging.info("Setup: ACL")
# run the configuration as super admin
aave_data_address = _get_deployed_address("aave_data")
commands = [
APTOS_BIN,
"move",
"run",
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{aave_data_address}::v1_deployment::configure_acl",
"--args",
f"string:{network}",
]
_checked_execute(commands, cwd=PROJECT_DIR)
# renounce and transfer the super admin role to the AaveACL multisig
aave_acl_address = _get_deployed_address("aave_acl")
commands = [
APTOS_BIN,
"move",
"run",
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{aave_acl_address}::acl_manage::add_default_admin",
"--args",
f"address:{multisig_aave_acl}",
]
_checked_execute(commands, cwd=PROJECT_DIR)
commands = [
APTOS_BIN,
"move",
"run",
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{aave_acl_address}::acl_manage::renounce_default_admin",
]
_checked_execute(commands, cwd=PROJECT_DIR)
def configure_acl_localnet(
deployer: str, fullnode: str, multisig_pool_admin: str
) -> None:
# log the action
logging.info("Setup: ACL")
# use a simplified ACL configuration process
aave_acl_address = _get_deployed_address("aave_acl")
commands = [
APTOS_BIN,
"move",
"run",
"--profile",
deployer,
"--url",
fullnode,
"--sender-account",
deployer,
"--function-id",
f"{aave_acl_address}::acl_manage::add_pool_admin",
"--args",
f"address:{multisig_pool_admin}",
]
_checked_execute(commands, cwd=PROJECT_DIR)