Skip to content

Commit

Permalink
feat: add wip, try to move configurable to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
DefiCake committed Apr 12, 2024
1 parent e45c6f5 commit dddecf4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ configurable {
BRIDGED_TOKEN_GATEWAY: b256 = 0x00000000000000000000000096c53cd98B7297564716a8f2E1de2C83928Af2fe,
}

#[namespace(bridge)]
storage {
l1_gateway: b256 = 0x00000000000000000000000059F2f1fCfE2474fD5F0b9BA1E73ca90b143Eb8d0,
asset_to_sub_id: StorageMap<AssetId, SubId> = StorageMap {},
asset_to_token_id: StorageMap<AssetId, b256> = StorageMap {},
refund_amounts: StorageMap<b256, StorageMap<b256, u256>> = StorageMap {},
Expand Down Expand Up @@ -161,8 +163,9 @@ impl Bridge for Contract {
});
}

#[storage(read)]
fn bridged_token_gateway() -> b256 {
BRIDGED_TOKEN_GATEWAY
storage.l1_gateway.try_read().unwrap_or(0x00000000000000000000000059F2f1fCfE2474fD5F0b9BA1E73ca90b143Eb8d0)
}

#[storage(read)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ abi Bridge {
fn withdraw(to: b256);

/// Get the address of the gateway that holds the bridged tokens
#[storage(read)]
fn bridged_token_gateway() -> b256;

// Recovers the sub_id used to generate an asset_id (= sha256(contract_id, sub_id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl Bridge for Contract {
run_external(TARGET)
}

#[storage(read)]
fn bridged_token_gateway() -> b256 {
run_external(TARGET)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ mod success {

assert_eq!(proxy_double_value, (42 * 2));

// Works
let impl_bridged_token_gateway = implementation.methods()
.bridged_token_gateway()
.call().await.unwrap().value;
assert_eq!(impl_bridged_token_gateway, Bits256::from_hex_str(message_sender).unwrap());

// Does not work
let proxy_bridged_token_gateway = bridge.methods()
.bridged_token_gateway()
.with_contract_ids(&[target_id.clone().into()])
Expand Down

0 comments on commit dddecf4

Please sign in to comment.