Skip to content

Commit c8acfca

Browse files
author
Pax G
committed
moved magic values to constans
1 parent 3555282 commit c8acfca

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

src/chain/mod.rs

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,29 @@ const DOT_OS_TBA: &str = "0x9b3853358ede717fc7D4806cF75d7A4d4517A9C9";
2626
//.os Token ID
2727
const DOT_OS_TOKEN_ID: &str = "0xdeeac81ae11b64e7cab86d089c306e5d223552a630f02633ce170d2786ff1bbd";
2828

29+
const DOT_OS_LABAL_HEX: &str = "0x6f73"; // "os" label (2 bytes)
30+
31+
const TBA_OF_SELECTOR: &str = "0x27244d1e";
32+
2933
const DEFAULT_MAX_ATTEMPTS: u16 = 16;
34+
3035
const DEFAULT_CONFIG: &str = include_str!("./Contracts.toml");
3136

37+
// Verify Hypermap proxy - symbol()
38+
const SYMBOL_CALLDATA: &str = "0x95d89b41";
39+
40+
// Verify ERC6551 Registry - account(address,uint256,address,uint256,uint256)
41+
// Using fake data: implementation=0x0, chainId=1, tokenContract=0x0, tokenId=1, salt=0
42+
const VERIFY_REGISTRY_CALLDATA: &str = "0x8a54c52f\
43+
0000000000000000000000000000000000000000000000000000000000000000\
44+
0000000000000000000000000000000000000000000000000000000000000001\
45+
0000000000000000000000000000000000000000000000000000000000000000\
46+
0000000000000000000000000000000000000000000000000000000000000001\
47+
0000000000000000000000000000000000000000000000000000000000000000";
48+
49+
// Verify Multicall3 - getBasefee()
50+
const VERIFY_MULTICALL_CALLDATA: &str = "0x3e64a696";
51+
3252
#[derive(Debug, Clone)]
3353
pub struct ContractAddresses {
3454
hypermap_proxy: String,
@@ -751,11 +771,12 @@ async fn mint_test_tbas(port: u16, addresses: &mut ContractAddresses) -> Result<
751771
return Ok(());
752772
};
753773

754-
// Call tbaOf(0) to get zeroth_tba address
755-
let tba_of_zero_calldata =
756-
"0x27244d1e0000000000000000000000000000000000000000000000000000000000000000";
774+
let tba_of_calldata = format!(
775+
"{}{}",
776+
TBA_OF_SELECTOR, "0000000000000000000000000000000000000000000000000000000000000000"
777+
);
757778
let zeroth_tba_result =
758-
call_contract(port, &addresses.hypermap_proxy, tba_of_zero_calldata).await?;
779+
call_contract(port, &addresses.hypermap_proxy, &tba_of_calldata).await?;
759780
info!("zeroth_tba_result: {}", zeroth_tba_result);
760781

761782
// Extract address from result (last 20 bytes / 40 hex chars)
@@ -773,16 +794,14 @@ async fn mint_test_tbas(port: u16, addresses: &mut ContractAddresses) -> Result<
773794
let nonce = get_nonce(port, &client, OWNER_ADDRESS).await?;
774795

775796
// Build mint calldata: mint(address to, bytes label, bytes initialization, address implementation)
776-
let label_hex = "0x6f73"; // "os" label (2 bytes)
777-
778797
let mint_args = vec![
779798
ConstructorArg {
780799
arg_type: "address".to_string(),
781800
value: OWNER_ADDRESS.to_string(),
782801
},
783802
ConstructorArg {
784803
arg_type: "bytes".to_string(),
785-
value: label_hex.to_string(),
804+
value: DOT_OS_LABAL_HEX.to_string(),
786805
},
787806
ConstructorArg {
788807
arg_type: "bytes".to_string(),
@@ -847,7 +866,7 @@ async fn mint_test_tbas(port: u16, addresses: &mut ContractAddresses) -> Result<
847866

848867
sleep(Duration::from_millis(200)).await;
849868

850-
let tba_of_calldata = format!("0x27244d1e{}", &DOT_OS_TOKEN_ID[2..]);
869+
let tba_of_calldata = format!("{}{}", TBA_OF_SELECTOR, &DOT_OS_TOKEN_ID[2..]);
851870

852871
if let Ok(dot_os_tba_result) =
853872
call_contract(port, &addresses.hypermap_proxy, &tba_of_calldata).await
@@ -1166,9 +1185,7 @@ pub async fn call_contract(port: u16, target: &str, data: &str) -> Result<String
11661185
pub async fn verify_contracts(port: u16, addresses: &ContractAddresses) -> Result<()> {
11671186
info!("Verifying deployed contracts...");
11681187

1169-
// Verify Hypermap proxy - symbol()
1170-
let symbol_calldata = "0x95d89b41";
1171-
match call_contract(port, &addresses.hypermap_proxy, symbol_calldata).await {
1188+
match call_contract(port, &addresses.hypermap_proxy, SYMBOL_CALLDATA).await {
11721189
Ok(result) => {
11731190
if result == "0x" || result.is_empty() {
11741191
return Err(eyre!("Hypermap symbol() returned empty result"));
@@ -1199,15 +1216,7 @@ pub async fn verify_contracts(port: u16, addresses: &ContractAddresses) -> Resul
11991216
}
12001217
}
12011218

1202-
// Verify ERC6551 Registry - account(address,uint256,address,uint256,uint256)
1203-
// Using fake data: implementation=0x0, chainId=1, tokenContract=0x0, tokenId=1, salt=0
1204-
let account_calldata = "0x8a54c52f\
1205-
0000000000000000000000000000000000000000000000000000000000000000\
1206-
0000000000000000000000000000000000000000000000000000000000000001\
1207-
0000000000000000000000000000000000000000000000000000000000000000\
1208-
0000000000000000000000000000000000000000000000000000000000000001\
1209-
0000000000000000000000000000000000000000000000000000000000000000";
1210-
match call_contract(port, &addresses.erc6551registry, account_calldata).await {
1219+
match call_contract(port, &addresses.erc6551registry, VERIFY_REGISTRY_CALLDATA).await {
12111220
Ok(result) => {
12121221
if result == "0x" || result.is_empty() {
12131222
return Err(eyre!("ERC6551Registry account() returned empty result"));
@@ -1219,9 +1228,7 @@ pub async fn verify_contracts(port: u16, addresses: &ContractAddresses) -> Resul
12191228
}
12201229
}
12211230

1222-
// Verify Multicall3 - getBasefee()
1223-
let basefee_calldata = "0x3e64a696";
1224-
match call_contract(port, &addresses.multicall, basefee_calldata).await {
1231+
match call_contract(port, &addresses.multicall, VERIFY_MULTICALL_CALLDATA).await {
12251232
Ok(result) => {
12261233
if result == "0x" || result.is_empty() {
12271234
return Err(eyre!("Multicall3 getBasefee() returned empty result"));

0 commit comments

Comments
 (0)