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

split transfer tx #3297

Merged
merged 21 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e5cef4c
replace the single `Transfer` struct with 4 distinct ones
tzemanovic May 22, 2024
9c1f993
move most of core IBC types into IBC crate
tzemanovic May 23, 2024
ca84daa
wasm: rename `tx_transfer` to `tx_transparent_transfer`
tzemanovic May 28, 2024
006d469
wasm/tx_transparent_transfer: remove the shielded section
tzemanovic May 28, 2024
efc30ac
wasm: add shielded, shielding and unshielding transfer
tzemanovic May 28, 2024
0f6da0c
sdk: update for split-up transfer tx
tzemanovic May 29, 2024
b082958
namada: update ibc path imports
tzemanovic May 29, 2024
6ba3be7
namada/protocol: rm dead code
tzemanovic May 29, 2024
6893bf9
light_sdk: update for split-up transfer tx
tzemanovic May 29, 2024
96dc992
apps_lib: update for split-up transfer tx
tzemanovic May 29, 2024
733afa1
apps: update for split-up transfer tx
tzemanovic May 29, 2024
b445329
node/bench_utils: update for split-up transfer tx
tzemanovic May 29, 2024
e6c62b5
tests: update for split-up transfer tx
tzemanovic May 29, 2024
9b02a03
encoding_spec: update for split-up transfer tx
tzemanovic May 29, 2024
bf5bc5b
benches: update for split-up transfer tx
tzemanovic May 29, 2024
ac881db
wasm/tx_ibc: update the shielded transfer
tzemanovic May 29, 2024
8a921ca
wasm_for_tests: update Cargo.lock
tzemanovic May 29, 2024
cc4ed7a
sdk/tx: fix the display of insufficient funds for non-native token
tzemanovic May 30, 2024
ebadb8d
changelog: add #3297
tzemanovic May 30, 2024
748f440
ShieldingTransfer for IBC messages
yito88 May 30, 2024
ff29e1c
update hermes
yito88 May 30, 2024
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
Next Next commit
replace the single Transfer struct with 4 distinct ones
  • Loading branch information
tzemanovic committed May 29, 2024
commit e5cef4cc83c71b8f469fa961eb4138e8b3a1f687
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 0 additions & 51 deletions crates/core/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ use namada_migrations::*;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::address::Address;
use crate::arith::{self, checked, CheckedAdd, CheckedSub};
use crate::dec::{Dec, POS_DECIMAL_PRECISION};
use crate::hash::Hash;
use crate::ibc::apps::transfer::types::Amount as IbcAmount;
use crate::storage;
use crate::storage::{DbKeySeg, KeySeg};
Expand Down Expand Up @@ -950,34 +948,6 @@ impl From<DenominatedAmount> for IbcAmount {
}
}

/// A simple bilateral token transfer
#[derive(
Debug,
Clone,
PartialEq,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
Hash,
Eq,
PartialOrd,
Serialize,
Deserialize,
)]
pub struct Transfer {
/// Source address will spend the tokens
pub source: Address,
/// Target address will receive the tokens
pub target: Address,
/// Token's address
pub token: Address,
/// The amount of tokens
pub amount: DenominatedAmount,
/// Shielded transaction part
pub shielded: Option<Hash>,
}

#[allow(missing_docs)]
#[derive(Error, Debug)]
pub enum AmountError {
Expand All @@ -994,9 +964,6 @@ pub mod testing {
use proptest::prelude::*;

use super::*;
use crate::address::testing::{
arb_established_address, arb_non_internal_address,
};

impl std::ops::Add for Amount {
type Output = Self;
Expand Down Expand Up @@ -1078,24 +1045,6 @@ pub mod testing {
}
}

prop_compose! {
/// Generate a transfer
pub fn arb_transfer()(
source in arb_non_internal_address(),
target in arb_non_internal_address(),
token in arb_established_address().prop_map(Address::Established),
amount in arb_denominated_amount(),
) -> Transfer {
Transfer {
source,
target,
token,
amount,
shielded: None,
}
}
}

/// Generate an arbitrary token amount
pub fn arb_amount() -> impl Strategy<Value = Amount> {
any::<u64>().prop_map(|val| Amount::from_uint(val, 0).unwrap())
Expand Down
9 changes: 8 additions & 1 deletion crates/token/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ version.workspace = true
[features]
default = []
multicore = ["namada_shielded_token/multicore"]
testing = ["namada_core/testing"]
testing = ["namada_core/testing", "proptest"]

[dependencies]
namada_core = { path = "../core" }
namada_events = { path = "../events", default-features = false }
namada_macros = { path = "../macros" }
namada_shielded_token = { path = "../shielded_token" }
namada_storage = { path = "../storage" }
namada_trans_token = { path = "../trans_token" }

borsh.workspace = true
proptest = { workspace = true, optional = true }
serde.workspace = true

[dev-dependencies]
namada_core = { path = "../core", features = ["testing"] }

proptest.workspace = true
137 changes: 135 additions & 2 deletions crates/token/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
clippy::print_stderr
)]

use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
use namada_core::hash::Hash;
use namada_macros::BorshDeserializer;
pub use namada_shielded_token::*;
pub use namada_trans_token::*;
use serde::{Deserialize, Serialize};

/// Token storage keys
pub mod storage_key {
Expand All @@ -28,8 +32,6 @@ pub mod storage_key {
}

use namada_core::address::Address;
#[cfg(any(test, feature = "testing"))]
pub use namada_core::token::testing;
use namada_events::EmitEvents;
use namada_storage::{Result, StorageRead, StorageWrite};

Expand Down Expand Up @@ -64,3 +66,134 @@ where
}
Ok(())
}

/// Arguments for a transparent token transfer
#[derive(
Debug,
Clone,
PartialEq,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
Hash,
Eq,
PartialOrd,
Serialize,
Deserialize,
)]
pub struct TransparentTransfer {
/// Source address will spend the tokens
pub source: Address,
/// Target address will receive the tokens
pub target: Address,
/// Token's address
pub token: Address,
/// The amount of tokens
pub amount: DenominatedAmount,
}

/// Arguments for a shielded token transfer
#[derive(
Debug,
Clone,
PartialEq,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
Hash,
Eq,
PartialOrd,
Serialize,
Deserialize,
)]
pub struct ShieldedTransfer {
/// Hash of tx section that contains the MASP transaction
pub section_hash: Hash,
}

/// Arguments for a shielding transfer (from a transparent token to a shielded
/// token)
#[derive(
Debug,
Clone,
PartialEq,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
Hash,
Eq,
PartialOrd,
Serialize,
Deserialize,
)]
pub struct ShieldingTransfer {
/// Source address will spend the tokens
pub source: Address,
/// Token's address
pub token: Address,
/// The amount of tokens
pub amount: DenominatedAmount,
/// Hash of tx section that contains the MASP transaction
pub shielded_section_hash: Hash,
}

/// Arguments for an unshielding transfer (from a shielded token to a
/// transparent token)
#[derive(
Debug,
Clone,
PartialEq,
BorshSerialize,
BorshDeserialize,
BorshDeserializer,
BorshSchema,
Hash,
Eq,
PartialOrd,
Serialize,
Deserialize,
)]
pub struct UnshieldingTransfer {
/// Target address will receive the tokens
pub target: Address,
/// Token's address
pub token: Address,
/// The amount of tokens
pub amount: DenominatedAmount,
/// Hash of tx section that contains the MASP transaction
pub shielded_section_hash: Hash,
}

#[cfg(any(test, feature = "testing"))]
/// Testing helpers and strategies for tokens
pub mod testing {
use namada_core::address::testing::{
arb_established_address, arb_non_internal_address,
};
use namada_core::address::Address;
pub use namada_core::token::*;
pub use namada_trans_token::testing::*;
use proptest::prelude::*;

use super::TransparentTransfer;

prop_compose! {
/// Generate a transparent transfer
pub fn arb_transparent_transfer()(
source in arb_non_internal_address(),
target in arb_non_internal_address(),
token in arb_established_address().prop_map(Address::Established),
amount in arb_denominated_amount(),
) -> TransparentTransfer {
TransparentTransfer {
source,
target,
token,
amount,
}
}
}
}
5 changes: 3 additions & 2 deletions crates/tx_prelude/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ use namada_events::{EmitEvents, EventLevel};
#[cfg(any(test, feature = "testing"))]
pub use namada_token::testing;
pub use namada_token::{
storage_key, utils, Amount, DenominatedAmount, Transfer,
storage_key, utils, Amount, DenominatedAmount, ShieldedTransfer,
ShieldingTransfer, TransparentTransfer, UnshieldingTransfer,
};
use namada_tx_env::TxEnv;

use crate::{Ctx, TxResult};

/// A token transfer that can be used in a transaction.
/// A transparent token transfer that can be used in a transaction.
pub fn transfer(
ctx: &mut Ctx,
src: &Address,
Expand Down