Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move shared interfaces in preparation of ownership trait extraction #96

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions contracts/axelar-gas-service/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ use crate::error::ContractError;
use crate::event;
use crate::interface::AxelarGasServiceInterface;
use crate::storage_types::DataKey;
use axelar_soroban_std::shared_interfaces::{
migrate, MigratableInterface, OwnableInterface, UpgradableInterface,
};
use axelar_soroban_std::{ensure, shared_interfaces, types::Token};
use axelar_soroban_std::interfaces::{MigratableInterface, OwnableInterface, UpgradableInterface};
use axelar_soroban_std::{ensure, interfaces, types::Token};

#[contract]
pub struct AxelarGasService;
Expand All @@ -16,7 +14,7 @@ pub struct AxelarGasService;
impl AxelarGasService {
/// Initialize the gas service contract with a gas_collector address.
pub fn __constructor(env: Env, owner: Address, gas_collector: Address) {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);
env.storage()
.instance()
.set(&DataKey::GasCollector, &gas_collector);
Expand All @@ -34,7 +32,7 @@ impl MigratableInterface for AxelarGasService {
type Error = ContractError;

fn migrate(env: &Env, migration_data: ()) -> Result<(), ContractError> {
migrate::<Self>(env, || Self::run_migration(env, migration_data))
interfaces::migrate::<Self>(env, || Self::run_migration(env, migration_data))
.map_err(|_| ContractError::MigrationNotAllowed)
}
}
Expand All @@ -46,15 +44,15 @@ impl UpgradableInterface for AxelarGasService {
}

fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
shared_interfaces::upgrade::<Self>(env, new_wasm_hash);
interfaces::upgrade::<Self>(env, new_wasm_hash);
}
}

#[contractimpl]
impl OwnableInterface for AxelarGasService {
// boilerplate necessary for the contractimpl macro to include function in the generated client
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}

Expand Down
15 changes: 8 additions & 7 deletions contracts/axelar-gateway/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::messaging_interface::AxelarGatewayMessagingInterface;
use crate::storage_types::{DataKey, MessageApprovalKey, MessageApprovalValue};
use crate::types::{CommandType, Message, Proof, WeightedSigners};
use crate::{auth, event};
use axelar_soroban_std::shared_interfaces::{migrate, UpgradableInterface};
use axelar_soroban_std::shared_interfaces::{MigratableInterface, OwnableInterface};
use axelar_soroban_std::interfaces::{
migrate, MigratableInterface, OwnableInterface, UpgradableInterface,
};
use axelar_soroban_std::ttl::{INSTANCE_TTL_EXTEND_TO, INSTANCE_TTL_THRESHOLD};
use axelar_soroban_std::{ensure, shared_interfaces};
use axelar_soroban_std::{ensure, interfaces};
use soroban_sdk::xdr::ToXdr;
use soroban_sdk::{contract, contractimpl, Address, Bytes, BytesN, Env, String, Vec};

Expand Down Expand Up @@ -35,15 +36,15 @@ impl UpgradableInterface for AxelarGateway {

// boilerplate necessary for the contractimpl macro to include function in the generated client
fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
shared_interfaces::upgrade::<Self>(env, new_wasm_hash);
interfaces::upgrade::<Self>(env, new_wasm_hash);
}
}

#[contractimpl]
impl OwnableInterface for AxelarGateway {
// boilerplate necessary for the contractimpl macro to include function in the generated client
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}

Expand All @@ -59,7 +60,7 @@ impl AxelarGateway {
previous_signers_retention: u64,
initial_signers: Vec<WeightedSigners>,
) -> Result<(), ContractError> {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);
env.storage().instance().set(&DataKey::Operator, &operator);

auth::initialize_auth(
Expand Down Expand Up @@ -254,7 +255,7 @@ impl AxelarGatewayInterface for AxelarGateway {
let owner: Address = Self::owner(&env);
owner.require_auth();

shared_interfaces::set_owner(&env, &new_owner);
interfaces::set_owner(&env, &new_owner);

event::transfer_ownership(&env, owner, new_owner);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/axelar-gateway/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
types::{Message, Proof, WeightedSigners},
AxelarGatewayMessagingInterface,
};
use axelar_soroban_std::shared_interfaces::UpgradableInterface;
use axelar_soroban_std::interfaces::UpgradableInterface;
use soroban_sdk::{contractclient, Address, BytesN, Env, Vec};

#[contractclient(name = "AxelarGatewayClient")]
Expand Down
15 changes: 7 additions & 8 deletions contracts/axelar-operators/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::error::ContractError;
use crate::event;
use crate::storage_types::DataKey;
use axelar_soroban_std::shared_interfaces::{migrate, UpgradableInterface};
use axelar_soroban_std::shared_interfaces::{MigratableInterface, OwnableInterface};
use axelar_soroban_std::{ensure, shared_interfaces};
use axelar_soroban_std::interfaces::{MigratableInterface, OwnableInterface, UpgradableInterface};
use axelar_soroban_std::{ensure, interfaces};
use soroban_sdk::{contract, contractimpl, Address, BytesN, Env, String, Symbol, Val, Vec};

#[contract]
Expand All @@ -12,15 +11,15 @@ pub struct AxelarOperators;
#[contractimpl]
impl AxelarOperators {
pub fn __constructor(env: Env, owner: Address) {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);
}

pub fn transfer_ownership(env: Env, new_owner: Address) -> Result<(), ContractError> {
let owner: Address = Self::owner(&env);

owner.require_auth();

shared_interfaces::set_owner(&env, &new_owner);
interfaces::set_owner(&env, &new_owner);

event::transfer_ownership(&env, owner, new_owner);

Expand Down Expand Up @@ -106,7 +105,7 @@ impl MigratableInterface for AxelarOperators {
type Error = ContractError;

fn migrate(env: &Env, migration_data: ()) -> Result<(), ContractError> {
migrate::<Self>(env, || Self::run_migration(env, migration_data))
interfaces::migrate::<Self>(env, || Self::run_migration(env, migration_data))
.map_err(|_| ContractError::MigrationNotAllowed)
}
}
Expand All @@ -118,14 +117,14 @@ impl UpgradableInterface for AxelarOperators {
}

fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
shared_interfaces::upgrade::<Self>(env, new_wasm_hash);
interfaces::upgrade::<Self>(env, new_wasm_hash);
}
}

#[contractimpl]
impl OwnableInterface for AxelarOperators {
// boilerplate necessary for the contractimpl macro to include function in the generated client
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}
16 changes: 7 additions & 9 deletions contracts/interchain-token-service/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axelar_soroban_std::types::Token;
use axelar_soroban_std::{ensure, shared_interfaces};
use axelar_soroban_std::{ensure, interfaces};
use soroban_sdk::{bytes, contract, contractimpl, Address, Bytes, BytesN, Env, FromVal, String};

use crate::error::ContractError;
Expand All @@ -12,17 +12,15 @@ use axelar_gas_service::AxelarGasServiceClient;
use axelar_gateway::AxelarGatewayMessagingClient;

use axelar_gateway::executable::AxelarExecutableInterface;
use axelar_soroban_std::shared_interfaces::{
migrate, MigratableInterface, OwnableInterface, UpgradableInterface,
};
use axelar_soroban_std::interfaces::{MigratableInterface, OwnableInterface, UpgradableInterface};

#[contract]
pub struct InterchainTokenService;

#[contractimpl]
impl InterchainTokenService {
pub fn __constructor(env: Env, owner: Address, gateway: Address, gas_service: Address) {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);
env.storage().instance().set(&DataKey::Gateway, &gateway);
env.storage()
.instance()
Expand Down Expand Up @@ -101,7 +99,7 @@ impl InterchainTokenServiceInterface for InterchainTokenService {
let owner = Self::owner(env);
owner.require_auth();

shared_interfaces::set_owner(env, &new_owner);
interfaces::set_owner(env, &new_owner);

event::transfer_ownership(env, owner, new_owner);
}
Expand Down Expand Up @@ -246,7 +244,7 @@ impl MigratableInterface for InterchainTokenService {
type Error = axelar_gateway::error::ContractError;

fn migrate(env: &Env, migration_data: ()) -> Result<(), axelar_gateway::error::ContractError> {
migrate::<Self>(env, || Self::run_migration(env, migration_data))
interfaces::migrate::<Self>(env, || Self::run_migration(env, migration_data))
.map_err(|_| axelar_gateway::error::ContractError::MigrationNotAllowed)
}
}
Expand All @@ -258,14 +256,14 @@ impl UpgradableInterface for InterchainTokenService {
}

fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
shared_interfaces::upgrade::<Self>(env, new_wasm_hash);
interfaces::upgrade::<Self>(env, new_wasm_hash);
}
}

#[contractimpl]
impl OwnableInterface for InterchainTokenService {
// boilerplate necessary for the contractimpl macro to include function in the generated client
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}
16 changes: 7 additions & 9 deletions contracts/interchain-token/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ use crate::storage_types::DataKey;

use crate::interface::InterchainTokenInterface;
use crate::storage_types::{AllowanceDataKey, AllowanceValue};
use axelar_soroban_std::shared_interfaces::{
migrate, MigratableInterface, OwnableInterface, UpgradableInterface,
};
use axelar_soroban_std::{ensure, shared_interfaces};
use axelar_soroban_std::interfaces::{MigratableInterface, OwnableInterface, UpgradableInterface};
use axelar_soroban_std::{ensure, interfaces};
use soroban_sdk::token::TokenInterface;

use soroban_sdk::{assert_with_error, contract, contractimpl, token, Address, BytesN, Env, String};
Expand All @@ -31,7 +29,7 @@ impl InterchainToken {
token_id: BytesN<32>,
token_meta_data: TokenMetadata,
) -> Result<(), ContractError> {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);

Self::validate_token_metadata(token_meta_data.clone())?;

Expand Down Expand Up @@ -114,7 +112,7 @@ impl InterchainTokenInterface for InterchainToken {

owner.require_auth();

shared_interfaces::set_owner(&env, &new_owner);
interfaces::set_owner(&env, &new_owner);

TokenUtils::new(&env)
.events()
Expand Down Expand Up @@ -366,7 +364,7 @@ impl MigratableInterface for InterchainToken {
type Error = ContractError;

fn migrate(env: &Env, migration_data: ()) -> Result<(), ContractError> {
migrate::<Self>(env, || Self::run_migration(env, migration_data))
interfaces::migrate::<Self>(env, || Self::run_migration(env, migration_data))
.map_err(|_| ContractError::MigrationNotAllowed)
}
}
Expand All @@ -378,14 +376,14 @@ impl UpgradableInterface for InterchainToken {
}

fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
shared_interfaces::upgrade::<Self>(env, new_wasm_hash);
interfaces::upgrade::<Self>(env, new_wasm_hash);
}
}

#[contractimpl]
impl OwnableInterface for InterchainToken {
// boilerplate necessary for the contractimpl macro to include function in the generated client
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}
2 changes: 1 addition & 1 deletion contracts/upgrader/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::ContractError;
use axelar_soroban_std::ensure;
use axelar_soroban_std::shared_interfaces::UpgradableClient;
use axelar_soroban_std::interfaces::UpgradableClient;
use soroban_sdk::{
contract, contractimpl, symbol_short, Address, BytesN, Env, String, Symbol, Val,
};
Expand Down
8 changes: 4 additions & 4 deletions contracts/upgrader/tests/utils/dummy_contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Dummy contract to test the [crate::Upgrader]

use axelar_soroban_std::shared_interfaces;
use axelar_soroban_std::shared_interfaces::{OwnableInterface, UpgradableInterface};
use axelar_soroban_std::interfaces;
use axelar_soroban_std::interfaces::{OwnableInterface, UpgradableInterface};
use soroban_sdk::{contract, contracterror, contractimpl, contracttype, Address, BytesN, Env};

#[contract]
Expand All @@ -23,14 +23,14 @@ impl UpgradableInterface for DummyContract {
#[contractimpl]
impl OwnableInterface for DummyContract {
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}

#[contractimpl]
impl DummyContract {
pub fn __constructor(env: Env, owner: Address) {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Base for the dummy.wasm file. This is the dummy contract after upgrade.

use axelar_soroban_std::shared_interfaces;
use axelar_soroban_std::shared_interfaces::{OwnableInterface, UpgradableInterface};
use axelar_soroban_std::interfaces;
use axelar_soroban_std::interfaces::{OwnableInterface, UpgradableInterface};
use soroban_sdk::{contract, contracterror, contractimpl, contracttype, Address, BytesN, Env};

#[contract]
Expand All @@ -23,14 +23,14 @@ impl UpgradableInterface for DummyContract {
#[contractimpl]
impl OwnableInterface for DummyContract {
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
interfaces::owner(env)
}
}

#[contractimpl]
impl DummyContract {
pub fn __constructor(env: Env, owner: Address) {
shared_interfaces::set_owner(&env, &owner);
interfaces::set_owner(&env, &owner);
}

pub fn migrate(env: Env, migration_data: soroban_sdk::String) -> Result<(), ContractError> {
Expand Down
2 changes: 1 addition & 1 deletion packages/axelar-soroban-std/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ mod test {
struct Contract;

#[test]
fn test_format_last_emitted_event() {
fn format_last_emitted_event() {
let env = Env::default();
let expected = TestEvent {
topic1: Symbol::new(&env, "topic1"),
Expand Down
5 changes: 5 additions & 0 deletions packages/axelar-soroban-std/src/interfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[cfg(test)]
mod testdata;
mod upgradable;

pub use upgradable::*;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::shared_interfaces;
use crate::shared_interfaces::{MigratableInterface, OwnableInterface, UpgradableInterface};
use crate::interfaces::{upgradable, MigratableInterface, OwnableInterface, UpgradableInterface};
use soroban_sdk::testutils::arbitrary::std;
use soroban_sdk::{
contract, contracterror, contractimpl, contracttype, Address, BytesN, Env, String,
Expand Down Expand Up @@ -29,15 +28,15 @@ impl MigratableInterface for Contract {
type Error = ContractError;

fn migrate(env: &Env, migration_data: ()) -> Result<(), ContractError> {
shared_interfaces::migrate::<Self>(env, || Self::run_migration(env, migration_data))
upgradable::migrate::<Self>(env, || Self::run_migration(env, migration_data))
.map_err(|_| ContractError::SomeFailure)
}
}

#[contractimpl]
impl OwnableInterface for Contract {
fn owner(env: &Env) -> Address {
shared_interfaces::owner(env)
upgradable::owner(env)
}
}

Expand All @@ -48,7 +47,7 @@ impl UpgradableInterface for Contract {
}

fn upgrade(env: &Env, new_wasm_hash: BytesN<32>) {
shared_interfaces::upgrade::<Self>(env, new_wasm_hash);
upgradable::upgrade::<Self>(env, new_wasm_hash);
}
}

Expand Down
Loading
Loading