Skip to content

Commit

Permalink
final interactions added
Browse files Browse the repository at this point in the history
  • Loading branch information
RaveenaBhasin committed Dec 9, 2023
1 parent 4231708 commit 2f40d51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 63 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ pub unsafe fn load_bytes32(key: U256) -> B256;
pub unsafe fn store_bytes32(key: U256, data: B256);
```

### Current conract Addresses
Proxy:
counter_v1:
counter_v2:
### Current contract Addresses
Proxy: 0x1D16b2c1311540093c63Ab271c80331bC3C70902
counter_v1: 0x31973Bc79631b05a3c030745391e44A9dce4B536
counter_v2: 0x9232F290277C97947F09B1965b207621e19a5258

### Contribution
Contributions to this project are welcome! Feel free to open issues for suggestions, bugs, or enhancements.
Expand Down
71 changes: 16 additions & 55 deletions examples/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
//! Example on how to interact with a deployed stylus-hello-world program using defaults.
//! This example uses ethers-rs to instantiate the program using a Solidity ABI.
//! Then, it attempts to check the current counter value, increment it via a tx,
//! and check the value again. The deployed program is fully written in Rust and compiled to WASM
//! but with Stylus, it is accessible just as a normal Solidity smart contract is via an ABI.
use dotenv::dotenv;
use ethers::{
core::types::TransactionReceipt,
Expand All @@ -23,7 +17,7 @@ fn log_relayed_data(relay_data: Option<TransactionReceipt>) {
match relay_data {
Some(data) => {
let data_logs_data: Bytes = data.logs[0].data.clone();
println!("Log Data {:?}", data_logs_data);
println!("Data = {:?}", data_logs_data);
}
None => {
println!("No data returned");
Expand All @@ -35,9 +29,9 @@ fn log_relayed_data(relay_data: Option<TransactionReceipt>) {
async fn main() -> eyre::Result<()> {
dotenv().ok();
let priv_key = env::var("ENV_PRIV_KEY_PATH").expect("You've not set the Pvt key");
let proxy_contract_address = "0x117693Ba99250A53BBFdC1720Ebe9C4F06fDfa9c";
let counter_v1_address: Address = ("0x280D5a75ca406c9C427aE2c3b999f8dd4C57D119").parse()?;
let counter_v2_address: Address = ("0xF58D20905CAb2A7CdB7ceb4FD829E1C0F36C7262").parse()?;
let proxy_contract_address = "0x1D16b2c1311540093c63Ab271c80331bC3C70902";
let counter_v1_address: Address = ("0x31973Bc79631b05a3c030745391e44A9dce4B536").parse()?;
let counter_v2_address: Address = ("0x9232F290277C97947F09B1965b207621e19a5258").parse()?;

let rpc_url = "https://stylus-testnet.arbitrum.io/rpc";
abigen!(
Expand All @@ -57,7 +51,7 @@ async fn main() -> eyre::Result<()> {
function setNumber(uint256 new_number) external
function increment() external
event NumberSet(uint256 number)
]"#
]"#
);

abigen!(
Expand Down Expand Up @@ -85,12 +79,6 @@ async fn main() -> eyre::Result<()> {
// proxy.init(_owner_address).send().await?.await?;
// println!("Init successful");

let implementation_address: Address = proxy.get_implementation().call().await?;
println!(
"Current implementation address: {:?}",
implementation_address
);

proxy
.set_implementation(counter_v1_address)
.send()
Expand All @@ -105,7 +93,7 @@ async fn main() -> eyre::Result<()> {
updated_implementation_address
);

let number = U256::from(10u64);
let number = U256::from(5u64);
let hashed_bytes1 = keccak256("setNumber(uint256)");
let data1 = [&hashed_bytes1[..4], &number.to_be_bytes::<32>()].concat();
let relay_data1 = proxy.relay_to_implementation(data1).send().await?.await?;
Expand All @@ -117,17 +105,17 @@ async fn main() -> eyre::Result<()> {
let relay_data2 = proxy.relay_to_implementation(data2).send().await?.await?;
println!("Relayed data from increment()");
log_relayed_data(relay_data2);

let hashed_bytes_3 = keccak256("number()");
let hashed_bytes_3 = keccak256("increment()");
let data_3 = [&hashed_bytes_3[..4]].concat();
let relayed_data_number = proxy.relay_to_implementation(data_3).send().await?.await?;
println!("Relayed data from number(), {:?}", relayed_data_number);
// log_relayed_data(relayed_data_number);
let relay_data3 = proxy.relay_to_implementation(data_3).send().await?.await?;
println!("Relayed data from increment()");
log_relayed_data(relay_data3);


let new_implementation_address_v2: Address =
("0xF58D20905CAb2A7CdB7ceb4FD829E1C0F36C7262").parse()?;
// Updating the Implementation to CounterV2
proxy
.set_implementation(new_implementation_address_v2)
.set_implementation(counter_v2_address)
.send()
.await?
.await?;
Expand All @@ -140,39 +128,12 @@ async fn main() -> eyre::Result<()> {
updated_implementation_address_v2
);

// let number = U256::from(20u64);
// let v2_hashed_bytes_set = keccak256("setNumber(uint256)");
// let data_set = [&v2_hashed_bytes_set[..4], &number.to_be_bytes::<32>()].concat();
// let relayed_data_v2_set = proxy.relay_to_implementation(data_set).send().await?.await?;
// println!("Relayed data from set_number for v2");
// log_relayed_data(relayed_data_v2_set);

let v2_hashed_bytes = keccak256("decrement()");
let v2_data = [&v2_hashed_bytes[..4]].concat();
let relayed_data_v2_dec = proxy.relay_to_implementation(v2_data).send().await?.await?;
println!("Relayed data decrement for v2");
println!("Relayed data from decrement() in v2");
log_relayed_data(relayed_data_v2_dec);

// Read event
// let filter = Filter::new().address(address).event("NumberSet(uint256)");
// let logs = client.get_logs(&filter).await?;
// println!("Event log {:?}", logs);

// let log_data_int = u64::from_be_bytes(logs[0].data.as_ref().try_into()?);
// println!("Event log data {:?}", log_data_int);

proxy
.set_implementation(counter_v2_address)
.send()
.await?
.await?;
println!("Called Set implementation successfully");

let updated_implementation_address = proxy.get_implementation().call().await?;
println!(
"Updated implementation address: {:?}",
updated_implementation_address
);


Ok(())
}
8 changes: 4 additions & 4 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ implementation_interaction() {
cd -
}

deployProxy
deployCounter
deployCounterV2
# proxy_interaction
# deployProxy
# deployCounter
# deployCounterV2
proxy_interaction
# implementation_interaction

0 comments on commit 2f40d51

Please sign in to comment.