Skip to content

Commit

Permalink
Merge pull request #2158 from mickvandijke/evm-dev-smart-contract-rem…
Browse files Browse the repository at this point in the history
…ove-royalties

feat: removed royalties from the smart contract
  • Loading branch information
mickvandijke authored Oct 1, 2024
2 parents 43ce3d2 + bdf95ca commit 693000a
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 76 deletions.
8 changes: 4 additions & 4 deletions autonomi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ autonomi = { path = "../autonomi", version = "0.1.0" }
2. Run a local EVM node:

```sh
cargo run --bin evm_testnet -- --royalties-wallet <ETHEREUM_ADDRESS>
cargo run --bin evm_testnet
```

Take note of the console output for the next step (`RPC URL`, `Payment token address` & `Chunk payments address`).
Expand Down Expand Up @@ -57,9 +57,9 @@ cargo run --bin=safenode-manager --features=local-discovery -- local run --build
payment tokens on the network (in this case Arbitrum One):

```sh
$ EVM_NETWORK=arbitrum-one PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local
$ EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local
# Or with logs
$ RUST_LOG=autonomi EVM_NETWORK=arbitrum-one PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local -- --nocapture
$ RUST_LOG=autonomi EVM_NETWORK=arbitrum-one EVM_PRIVATE_KEY=<PRIVATE_KEY> cargo test --package=autonomi --features=local -- --nocapture
```

## Faucet (local)
Expand Down Expand Up @@ -92,7 +92,7 @@ Alternatively, you can provide the wallet address that should own all the gas an
startup command using the `--genesis-wallet` flag:

```sh
cargo run --bin evm_testnet -- --royalties-wallet <ETHEREUM_ADDRESS> --genesis-wallet <ETHEREUM_ADDRESS>
cargo run --bin evm_testnet -- --genesis-wallet <ETHEREUM_ADDRESS>
```

```shell
Expand Down
2 changes: 1 addition & 1 deletion autonomi/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn evm_wallet_from_env_or_default(network: evmlib::Network) -> evmlib::walle
const DEFAULT_WALLET_PRIVATE_KEY: &str =
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80";

let private_key = env::var("PRIVATE_KEY").unwrap_or(DEFAULT_WALLET_PRIVATE_KEY.to_string());
let private_key = env::var("EVM_PRIVATE_KEY").unwrap_or(DEFAULT_WALLET_PRIVATE_KEY.to_string());

evmlib::wallet::Wallet::new_from_private_key(network, &private_key)
.expect("Invalid private key")
Expand Down
2 changes: 1 addition & 1 deletion evm_testnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Tool to run a local Ethereum node that automatically deploys all Autonomi smart
### Usage

```bash
cargo run --bin evm_testnet -- --royalties-wallet <ETHEREUM_ADDRESS> --genesis-wallet <ETHEREUM_ADDRESS>
cargo run --bin evm_testnet -- --genesis-wallet <ETHEREUM_ADDRESS>
```

Example output:
Expand Down
9 changes: 3 additions & 6 deletions evm_testnet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ use std::str::FromStr;
#[derive(Debug, Parser)]
#[clap(version, author, verbatim_doc_comment)]
struct Args {
/// Address that will receive the chunk payments royalties.
#[clap(long, short)]
royalties_wallet: Address,
/// Wallet that will hold ~all gas funds and payment tokens.
#[clap(long, short)]
genesis_wallet: Option<Address>,
Expand All @@ -27,11 +24,11 @@ struct Args {
#[tokio::main]
async fn main() {
let args = Args::parse();
start_node(args.genesis_wallet, args.royalties_wallet).await;
start_node(args.genesis_wallet).await;
}

async fn start_node(genesis_wallet: Option<Address>, royalties_wallet: Address) {
let testnet = Testnet::new(royalties_wallet).await;
async fn start_node(genesis_wallet: Option<Address>) {
let testnet = Testnet::new().await;

println!("*************************");
println!("* Ethereum node started *");
Expand Down
22 changes: 2 additions & 20 deletions evmlib/artifacts/ChunkPayments.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
"internalType": "address",
"name": "_tokenAddress",
"type": "address"
},
{
"internalType": "address",
"name": "_foundationWallet",
"type": "address"
}
],
"stateMutability": "nonpayable",
Expand Down Expand Up @@ -57,19 +52,6 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "ROYALTIES_WALLET",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -101,8 +83,8 @@
"type": "function"
}
],
"bytecode": "0x60c060405234801561001057600080fd5b5060405161075b38038061075b83398101604081905261002f91610130565b6001600160a01b0382166100965760405162461bcd60e51b8152602060048201526024808201527f546f6b656e20616464726573732063616e6e6f74206265207a65726f206164646044820152637265737360e01b60648201526084015b60405180910390fd5b6001600160a01b0381166100fd5760405162461bcd60e51b815260206004820152602860248201527f466f756e646174696f6e2077616c6c65742063616e6e6f74206265207a65726f604482015267206164647265737360c01b606482015260840161008d565b6001600160a01b039182166080521660a052610163565b80516001600160a01b038116811461012b57600080fd5b919050565b6000806040838503121561014357600080fd5b61014c83610114565b915061015a60208401610114565b90509250929050565b60805160a0516105b96101a2600039600081816060015261018401526000818160a3015281816101cf015281816102d101526103d101526105b96000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806305aa488a146100465780631c317b341461005b5780635c0d32861461009e575b600080fd5b610059610054366004610444565b6100c5565b005b6100827f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b6100827f000000000000000000000000000000000000000000000000000000000000000081565b6000805b8281101561017d57368484838181106100e4576100e46104b9565b90506060020190506000600a82602001356100ff91906104cf565b905061010b81856104f1565b93506101283361011e6020850185610518565b84602001356101ae565b60408201356020830180359061013e9085610518565b6001600160a01b03167fa6df5ca64d2adbcdd26949b97238efc4e97dc7e5d23012ea53f92a24f005f95860405160405180910390a450506001016100c9565b506101a9337f0000000000000000000000000000000000000000000000000000000000000000836101ae565b505050565b6040516370a0823160e01b81526001600160a01b03848116600483015282917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa158015610218573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061023c9190610548565b101561029a5760405162461bcd60e51b815260206004820152602260248201527f57616c6c657420646f6573206e6f74206861766520656e6f75676820746f6b656044820152616e7360f01b60648201526084015b60405180910390fd5b6001600160a01b03831630146103a357604051636eb1769f60e11b81526001600160a01b03848116600483015230602483015282917f00000000000000000000000000000000000000000000000000000000000000009091169063dd62ed3e90604401602060405180830381865afa15801561031a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061033e9190610548565b10156103a35760405162461bcd60e51b815260206004820152602e60248201527f436f6e7472616374206973206e6f7420616c6c6f77656420746f207370656e6460448201526d20656e6f75676820746f6b656e7360901b6064820152608401610291565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016020604051808303816000875af115801561041a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043e9190610561565b50505050565b6000806020838503121561045757600080fd5b823567ffffffffffffffff8082111561046f57600080fd5b818501915085601f83011261048357600080fd5b81358181111561049257600080fd5b8660206060830285010111156104a757600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052603260045260246000fd5b6000826104ec57634e487b7160e01b600052601260045260246000fd5b500490565b8082018082111561051257634e487b7160e01b600052601160045260246000fd5b92915050565b60006020828403121561052a57600080fd5b81356001600160a01b038116811461054157600080fd5b9392505050565b60006020828403121561055a57600080fd5b5051919050565b60006020828403121561057357600080fd5b8151801515811461054157600080fdfea264697066735822122094c63e1f2c74507a86a2259c9b1cb5a11238724ae1164198b92142b5386eda6164736f6c63430008180033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100415760003560e01c806305aa488a146100465780631c317b341461005b5780635c0d32861461009e575b600080fd5b610059610054366004610444565b6100c5565b005b6100827f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b6100827f000000000000000000000000000000000000000000000000000000000000000081565b6000805b8281101561017d57368484838181106100e4576100e46104b9565b90506060020190506000600a82602001356100ff91906104cf565b905061010b81856104f1565b93506101283361011e6020850185610518565b84602001356101ae565b60408201356020830180359061013e9085610518565b6001600160a01b03167fa6df5ca64d2adbcdd26949b97238efc4e97dc7e5d23012ea53f92a24f005f95860405160405180910390a450506001016100c9565b506101a9337f0000000000000000000000000000000000000000000000000000000000000000836101ae565b505050565b6040516370a0823160e01b81526001600160a01b03848116600483015282917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa158015610218573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061023c9190610548565b101561029a5760405162461bcd60e51b815260206004820152602260248201527f57616c6c657420646f6573206e6f74206861766520656e6f75676820746f6b656044820152616e7360f01b60648201526084015b60405180910390fd5b6001600160a01b03831630146103a357604051636eb1769f60e11b81526001600160a01b03848116600483015230602483015282917f00000000000000000000000000000000000000000000000000000000000000009091169063dd62ed3e90604401602060405180830381865afa15801561031a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061033e9190610548565b10156103a35760405162461bcd60e51b815260206004820152602e60248201527f436f6e7472616374206973206e6f7420616c6c6f77656420746f207370656e6460448201526d20656e6f75676820746f6b656e7360901b6064820152608401610291565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016020604051808303816000875af115801561041a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061043e9190610561565b50505050565b6000806020838503121561045757600080fd5b823567ffffffffffffffff8082111561046f57600080fd5b818501915085601f83011261048357600080fd5b81358181111561049257600080fd5b8660206060830285010111156104a757600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052603260045260246000fd5b6000826104ec57634e487b7160e01b600052601260045260246000fd5b500490565b8082018082111561051257634e487b7160e01b600052601160045260246000fd5b92915050565b60006020828403121561052a57600080fd5b81356001600160a01b038116811461054157600080fd5b9392505050565b60006020828403121561055a57600080fd5b5051919050565b60006020828403121561057357600080fd5b8151801515811461054157600080fdfea264697066735822122094c63e1f2c74507a86a2259c9b1cb5a11238724ae1164198b92142b5386eda6164736f6c63430008180033",
"bytecode": "0x60a060405234801561001057600080fd5b506040516105f73803806105f783398101604081905261002f916100a6565b6001600160a01b0381166100955760405162461bcd60e51b8152602060048201526024808201527f546f6b656e20616464726573732063616e6e6f74206265207a65726f206164646044820152637265737360e01b606482015260840160405180910390fd5b6001600160a01b03166080526100d6565b6000602082840312156100b857600080fd5b81516001600160a01b03811681146100cf57600080fd5b9392505050565b6080516104f26101056000396000818160550152818161015101528181610253015261035301526104f26000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c806305aa488a1461003b5780635c0d328614610050575b600080fd5b61004e6100493660046103c6565b610093565b005b6100777f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b60005b8181101561012b57368383838181106100b1576100b161043b565b6060029190910191506100d79050336100cd6020840184610451565b8360200135610130565b6040810135602082018035906100ed9084610451565b6001600160a01b03167fa6df5ca64d2adbcdd26949b97238efc4e97dc7e5d23012ea53f92a24f005f95860405160405180910390a450600101610096565b505050565b6040516370a0823160e01b81526001600160a01b03848116600483015282917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa15801561019a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101be9190610481565b101561021c5760405162461bcd60e51b815260206004820152602260248201527f57616c6c657420646f6573206e6f74206861766520656e6f75676820746f6b656044820152616e7360f01b60648201526084015b60405180910390fd5b6001600160a01b038316301461032557604051636eb1769f60e11b81526001600160a01b03848116600483015230602483015282917f00000000000000000000000000000000000000000000000000000000000000009091169063dd62ed3e90604401602060405180830381865afa15801561029c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102c09190610481565b10156103255760405162461bcd60e51b815260206004820152602e60248201527f436f6e7472616374206973206e6f7420616c6c6f77656420746f207370656e6460448201526d20656e6f75676820746f6b656e7360901b6064820152608401610213565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016020604051808303816000875af115801561039c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c0919061049a565b50505050565b600080602083850312156103d957600080fd5b823567ffffffffffffffff808211156103f157600080fd5b818501915085601f83011261040557600080fd5b81358181111561041457600080fd5b86602060608302850101111561042957600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561046357600080fd5b81356001600160a01b038116811461047a57600080fd5b9392505050565b60006020828403121561049357600080fd5b5051919050565b6000602082840312156104ac57600080fd5b8151801515811461047a57600080fdfea2646970667358221220f36a68bc214963ac01148fda122f884402375e68563223e639f0b88bf6a1aaf664736f6c63430008180033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806305aa488a1461003b5780635c0d328614610050575b600080fd5b61004e6100493660046103c6565b610093565b005b6100777f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200160405180910390f35b60005b8181101561012b57368383838181106100b1576100b161043b565b6060029190910191506100d79050336100cd6020840184610451565b8360200135610130565b6040810135602082018035906100ed9084610451565b6001600160a01b03167fa6df5ca64d2adbcdd26949b97238efc4e97dc7e5d23012ea53f92a24f005f95860405160405180910390a450600101610096565b505050565b6040516370a0823160e01b81526001600160a01b03848116600483015282917f0000000000000000000000000000000000000000000000000000000000000000909116906370a0823190602401602060405180830381865afa15801561019a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101be9190610481565b101561021c5760405162461bcd60e51b815260206004820152602260248201527f57616c6c657420646f6573206e6f74206861766520656e6f75676820746f6b656044820152616e7360f01b60648201526084015b60405180910390fd5b6001600160a01b038316301461032557604051636eb1769f60e11b81526001600160a01b03848116600483015230602483015282917f00000000000000000000000000000000000000000000000000000000000000009091169063dd62ed3e90604401602060405180830381865afa15801561029c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102c09190610481565b10156103255760405162461bcd60e51b815260206004820152602e60248201527f436f6e7472616374206973206e6f7420616c6c6f77656420746f207370656e6460448201526d20656e6f75676820746f6b656e7360901b6064820152608401610213565b6040516323b872dd60e01b81526001600160a01b0384811660048301528381166024830152604482018390527f000000000000000000000000000000000000000000000000000000000000000016906323b872dd906064016020604051808303816000875af115801561039c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103c0919061049a565b50505050565b600080602083850312156103d957600080fd5b823567ffffffffffffffff808211156103f157600080fd5b818501915085601f83011261040557600080fd5b81358181111561041457600080fd5b86602060608302850101111561042957600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561046357600080fd5b81356001600160a01b038116811461047a57600080fd5b9392505050565b60006020828403121561049357600080fd5b5051919050565b6000602082840312156104ac57600080fd5b8151801515811461047a57600080fdfea2646970667358221220f36a68bc214963ac01148fda122f884402375e68563223e639f0b88bf6a1aaf664736f6c63430008180033",
"linkReferences": {},
"deployedLinkReferences": {}
}
13 changes: 4 additions & 9 deletions evmlib/src/contract/chunk_payments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,10 @@ where

/// Deploys the ChunkPayments smart contract to the network of the provider.
/// ONLY DO THIS IF YOU KNOW WHAT YOU ARE DOING!
pub async fn deploy(
provider: P,
payment_token_address: Address,
royalties_wallet: Address,
) -> Self {
let contract =
ChunkPaymentsContract::deploy(provider, payment_token_address, royalties_wallet)
.await
.expect("Could not deploy contract");
pub async fn deploy(provider: P, payment_token_address: Address) -> Self {
let contract = ChunkPaymentsContract::deploy(provider, payment_token_address)
.await
.expect("Could not deploy contract");

ChunkPayments { contract }
}
Expand Down
2 changes: 1 addition & 1 deletion evmlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ARBITRUM_ONE_PAYMENT_TOKEN_ADDRESS: Address =

// Should be updated when the smart contract changes!
const ARBITRUM_ONE_CHUNK_PAYMENTS_ADDRESS: Address =
address!("F15BfEA73b6a551C5c2e66026e4eB3b69c1F602c");
address!("708353783756C62818aCdbce914d90E0245F7319");

#[derive(Clone, Debug, PartialEq)]
pub struct CustomNetwork {
Expand Down
13 changes: 4 additions & 9 deletions evmlib/src/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ pub struct Testnet {

impl Testnet {
/// Starts an Anvil node and automatically deploys the network token and chunk payments smart contracts.
pub async fn new(royalties_wallet: Address) -> Self {
pub async fn new() -> Self {
let anvil = start_node();

let network_token = deploy_network_token_contract(&anvil).await;
let chunk_payments = deploy_chunk_payments_contract(
&anvil,
*network_token.contract.address(),
royalties_wallet,
)
.await;
let chunk_payments =
deploy_chunk_payments_contract(&anvil, *network_token.contract.address()).await;

Testnet {
anvil,
Expand Down Expand Up @@ -96,7 +92,6 @@ pub async fn deploy_network_token_contract(
pub async fn deploy_chunk_payments_contract(
anvil: &AnvilInstance,
token_address: Address,
royalties_wallet: Address,
) -> ChunkPayments<
Http<Client>,
FillProvider<
Expand All @@ -119,5 +114,5 @@ pub async fn deploy_chunk_payments_contract(
.on_http(rpc_url);

// Deploy the contract.
ChunkPayments::deploy(provider, token_address, royalties_wallet).await
ChunkPayments::deploy(provider, token_address).await
}
1 change: 0 additions & 1 deletion evmlib/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub async fn verify_chunk_payment(

if let Ok(event) = ChunkPaymentEvent::try_from(log) {
// Check if the event matches what we expect.
// The smart contract handles royalties, so we don't have to check that.
if event.quote_hash == quote_hash
&& event.reward_address == reward_addr
&& event.amount >= amount
Expand Down
7 changes: 1 addition & 6 deletions evmlib/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
use crate::common::{Address, Amount, Hash};
use crate::common::{Address, Hash};
use rand::Rng;

/// Returns the amount of royalties expected for a certain transfer amount.
pub fn calculate_royalties_from_amount(amount: Amount) -> Amount {
amount / Amount::from(10)
}

/// Generate a random Address.
pub fn dummy_address() -> Address {
Address::new(rand::rngs::OsRng.gen())
Expand Down
Loading

0 comments on commit 693000a

Please sign in to comment.