From 09f52d0f57f9e8b84333ab5b8386f8943115b998 Mon Sep 17 00:00:00 2001 From: bigben-7 Date: Sat, 30 May 2026 22:45:34 +0100 Subject: [PATCH] fix: enable transfers, testutils feature, AccountStatus ordering, scaffold native_transfer - Issue #42: uncomment `mod transfers` in sweep_controller and replace the dead-commented transfer block with a proper loop over `info.payments` using `transfers::TransferContext` - Issue #43: add `[features] testutils = ["soroban-sdk/testutils"]` to bridgelet-shared, and add `bridgelet-shared = { features = ["testutils"] }` to dev-dependencies in ephemeral_account, sweep_controller, and reserve_contract - Issue #44: add `PartialOrd, Ord` to AccountStatus derive so contracts can do ordered comparisons against the `#[repr(u32)]` state progression - Issue #48: scaffold contracts/native_transfer with Cargo.toml, src/lib.rs, src/errors.rs, and src/events.rs matching the existing contract pattern; registered in workspace Cargo.toml Closes #42Closes #43Closes #44Closes #48 --- Cargo.toml | 1 + contracts/ephemeral_account/Cargo.toml | 1 + contracts/native_transfer/Cargo.toml | 18 ++++++++++++++++++ contracts/native_transfer/src/errors.rs | 8 ++++++++ contracts/native_transfer/src/events.rs | 14 ++++++++++++++ contracts/native_transfer/src/lib.rs | 17 +++++++++++++++++ contracts/reserve_contract/Cargo.toml | 1 + contracts/shared/Cargo.toml | 3 +++ contracts/shared/src/types.rs | 2 +- contracts/sweep_controller/Cargo.toml | 1 + contracts/sweep_controller/src/lib.rs | 21 +++++++++++---------- 11 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 contracts/native_transfer/Cargo.toml create mode 100644 contracts/native_transfer/src/errors.rs create mode 100644 contracts/native_transfer/src/events.rs create mode 100644 contracts/native_transfer/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 9859e32..5b7cdaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ members = [ "contracts/sweep_controller", "contracts/shared", "contracts/reserve_contract", + "contracts/native_transfer", ] diff --git a/contracts/ephemeral_account/Cargo.toml b/contracts/ephemeral_account/Cargo.toml index 062d946..9077776 100644 --- a/contracts/ephemeral_account/Cargo.toml +++ b/contracts/ephemeral_account/Cargo.toml @@ -13,6 +13,7 @@ bridgelet-shared = { path = "../shared", version = "0.1.0" } [dev-dependencies] soroban-sdk = { version = "22.0.0", features = ["testutils"] } +bridgelet-shared = { path = "../shared", features = ["testutils"] } [profile.release] opt-level = "z" diff --git a/contracts/native_transfer/Cargo.toml b/contracts/native_transfer/Cargo.toml new file mode 100644 index 0000000..7ca7b6f --- /dev/null +++ b/contracts/native_transfer/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "native-transfer" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["rlib", "cdylib"] + +[dependencies] +soroban-sdk = "22.0.0" +bridgelet-shared = { path = "../shared" } + +[dev-dependencies] +soroban-sdk = { version = "22.0.0", features = ["testutils"] } +bridgelet-shared = { path = "../shared", features = ["testutils"] } + +[features] +testutils = ["soroban-sdk/testutils"] diff --git a/contracts/native_transfer/src/errors.rs b/contracts/native_transfer/src/errors.rs new file mode 100644 index 0000000..a3bf0e6 --- /dev/null +++ b/contracts/native_transfer/src/errors.rs @@ -0,0 +1,8 @@ +use soroban_sdk::contracterror; + +#[contracterror] +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +pub enum Error { + InvalidAmount = 1, + TransferFailed = 2, +} diff --git a/contracts/native_transfer/src/events.rs b/contracts/native_transfer/src/events.rs new file mode 100644 index 0000000..96e1694 --- /dev/null +++ b/contracts/native_transfer/src/events.rs @@ -0,0 +1,14 @@ +use soroban_sdk::{contracttype, symbol_short, Address, Env}; + +#[contracttype] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct NativeTransferExecuted { + pub from: Address, + pub to: Address, + pub amount: i128, +} + +pub fn emit_native_transfer_executed(env: &Env, from: Address, to: Address, amount: i128) { + let event = NativeTransferExecuted { from, to, amount }; + env.events().publish((symbol_short!("native_tx"),), event); +} diff --git a/contracts/native_transfer/src/lib.rs b/contracts/native_transfer/src/lib.rs new file mode 100644 index 0000000..7303357 --- /dev/null +++ b/contracts/native_transfer/src/lib.rs @@ -0,0 +1,17 @@ +#![no_std] + +mod errors; +mod events; + +use soroban_sdk::{contract, contractimpl, Env}; + +pub use errors::Error; +pub use events::NativeTransferExecuted; + +#[contract] +pub struct NativeTransferContract; + +#[contractimpl] +impl NativeTransferContract { + // Implementation coming in a future issue +} diff --git a/contracts/reserve_contract/Cargo.toml b/contracts/reserve_contract/Cargo.toml index 555be97..66ef143 100644 --- a/contracts/reserve_contract/Cargo.toml +++ b/contracts/reserve_contract/Cargo.toml @@ -11,6 +11,7 @@ soroban-sdk = "22.0.0" [dev-dependencies] soroban-sdk = { version = "22.0.0", features = ["testutils"] } +bridgelet-shared = { path = "../shared", features = ["testutils"] } [profile.release] opt-level = "z" diff --git a/contracts/shared/Cargo.toml b/contracts/shared/Cargo.toml index e219632..0727337 100644 --- a/contracts/shared/Cargo.toml +++ b/contracts/shared/Cargo.toml @@ -6,5 +6,8 @@ edition = "2021" [dependencies] soroban-sdk = "22.0.0" +[features] +testutils = ["soroban-sdk/testutils"] + [lib] crate-type = ["rlib"] diff --git a/contracts/shared/src/types.rs b/contracts/shared/src/types.rs index 6e2387d..7abc7a1 100644 --- a/contracts/shared/src/types.rs +++ b/contracts/shared/src/types.rs @@ -10,7 +10,7 @@ pub struct Payment { } // The current status of an ephemeral account. #[contracttype] -#[derive(Clone, Debug, Eq, PartialEq, Copy)] +#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Copy)] #[repr(u32)] pub enum AccountStatus { Active = 0, diff --git a/contracts/sweep_controller/Cargo.toml b/contracts/sweep_controller/Cargo.toml index 4319bab..f5c4b97 100644 --- a/contracts/sweep_controller/Cargo.toml +++ b/contracts/sweep_controller/Cargo.toml @@ -15,6 +15,7 @@ soroban-token-sdk = "22.0.0" [dev-dependencies] soroban-sdk = { version = "22.0.0", features = ["testutils"] } +bridgelet-shared = { path = "../shared", features = ["testutils"] } [profile.release] diff --git a/contracts/sweep_controller/src/lib.rs b/contracts/sweep_controller/src/lib.rs index 8c556a0..068dcb6 100644 --- a/contracts/sweep_controller/src/lib.rs +++ b/contracts/sweep_controller/src/lib.rs @@ -3,7 +3,7 @@ mod authorization; mod errors; mod storage; -// mod transfers; +mod transfers; use ephemeral_account::EphemeralAccountContractClient as EphemeralAccountClient; use soroban_sdk::{contract, contractimpl, contracttype, Address, BytesN, Env}; @@ -115,15 +115,16 @@ impl SweepController { return Err(Error::AccountNotReady); } - // Execute the actual token transfer - // Note: In production, the ephemeral account would need to authorize this transfer - // let transfer_ctx = TransferContext::new( - // info.payment_asset, - // ephemeral_account.clone(), - // destination.clone(), - // amount, - // ); - // transfer_ctx.execute(&env)?; + // Execute the actual token transfer for each payment asset + for payment in info.payments.iter() { + let transfer_ctx = transfers::TransferContext::new( + payment.asset.clone(), + ephemeral_account.clone(), + destination.clone(), + payment.amount, + ); + transfer_ctx.execute(&env)?; + } // Emit sweep executed event emit_sweep_completed(&env, ephemeral_account, destination, amount);