diff --git a/Cargo.lock b/Cargo.lock index 0b9f767f..99c3a365 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,7 +337,6 @@ version = "0.1.0" dependencies = [ "amm", "ink", - "openbrush 3.1.1", "pair_contract", "parity-scale-codec", "scale-info", diff --git a/Cargo.toml b/Cargo.toml index dd3af93a..c28a9d80 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,7 @@ [workspace] + +resolver = "2" + members = ["amm/contracts/**", "farm/contracts"] exclude = ["e2e-tests", "amm/logics"] diff --git a/amm/contracts/factory/Cargo.toml b/amm/contracts/factory/Cargo.toml index 7e3ca381..7743f7f8 100644 --- a/amm/contracts/factory/Cargo.toml +++ b/amm/contracts/factory/Cargo.toml @@ -17,7 +17,6 @@ scale-info = { version = "2.3", default-features = false, features = [ pair_contract = { path = "../pair", default-features = false, features = [ "ink-as-dependency", ] } -openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", tag = "3.1.1", default-features = false } amm = { path = "../../logics", default-features = false } [lib] @@ -30,14 +29,7 @@ std = [ "ink/std", "scale/std", "scale-info/std", - "openbrush/std", "amm/std", "pair_contract/std", ] ink-as-dependency = [] - -[profile.dev] -overflow-checks = false - -[profile.release] -overflow-checks = false diff --git a/amm/contracts/factory/lib.rs b/amm/contracts/factory/lib.rs index 3bc07bd2..8626ada1 100644 --- a/amm/contracts/factory/lib.rs +++ b/amm/contracts/factory/lib.rs @@ -1,34 +1,21 @@ #![cfg_attr(not(feature = "std"), no_std, no_main)] -#![feature(min_specialization)] -#[openbrush::contract] +#[ink::contract] pub mod factory { use amm::{ ensure, - impls::factory::{ - factory::{ - only_fee_setter, - Internal, - }, - *, + helpers::ZERO_ADDRESS, + traits::factory::{ + Factory, + FactoryError, }, - traits::factory::*, }; use ink::{ - codegen::{ - EmitEvent, - Env, - }, + codegen::EmitEvent, env::hash::Blake2x256, + storage::Mapping, ToAccountId, }; - use openbrush::{ - modifiers, - traits::{ - AccountIdExt, - Storage, - }, - }; use pair_contract::pair::PairContractRef; #[ink(event)] @@ -42,26 +29,29 @@ pub mod factory { } #[ink(storage)] - #[derive(Default, Storage)] pub struct FactoryContract { - #[storage_field] - factory: data::Data, + get_pair: Mapping<(AccountId, AccountId), AccountId>, + all_pairs: Mapping, + all_pairs_length: u64, + pair_contract_code_hash: Hash, + fee_to: AccountId, + fee_to_setter: AccountId, } impl Factory for FactoryContract { #[ink(message)] fn all_pairs(&self, pid: u64) -> Option { - self.factory.all_pairs.get(&pid) + self.all_pairs.get(pid) } #[ink(message)] fn all_pairs_length(&self) -> u64 { - self.factory.all_pairs_length + self.all_pairs_length } #[ink(message)] fn pair_contract_code_hash(&self) -> Hash { - self.factory.pair_contract_code_hash + self.pair_contract_code_hash } #[ink(message)] @@ -76,9 +66,8 @@ pub mod factory { } else { (token_b, token_a) }; - ensure!(!token_pair.0.is_zero(), FactoryError::ZeroAddress); ensure!( - self.factory.get_pair.get(&token_pair).is_none(), + self.get_pair.get(token_pair).is_none(), FactoryError::PairExists ); @@ -86,12 +75,10 @@ pub mod factory { let pair_contract = self._instantiate_pair(salt.as_ref(), token_pair.0, token_pair.1)?; - self.factory - .get_pair - .insert(&(token_pair.0, token_pair.1), &pair_contract); - self.factory - .get_pair - .insert(&(token_pair.1, token_pair.0), &pair_contract); + self.get_pair + .insert((token_pair.0, token_pair.1), &pair_contract); + self.get_pair + .insert((token_pair.1, token_pair.0), &pair_contract); self._add_new_pair(pair_contract); @@ -105,44 +92,59 @@ pub mod factory { Ok(pair_contract) } - #[modifiers(only_fee_setter)] #[ink(message)] fn set_fee_to(&mut self, fee_to: AccountId) -> Result<(), FactoryError> { - self.factory.fee_to = fee_to; + self._only_fee_setter()?; + self.fee_to = fee_to; Ok(()) } - #[modifiers(only_fee_setter)] #[ink(message)] fn set_fee_to_setter(&mut self, fee_to_setter: AccountId) -> Result<(), FactoryError> { - self.factory.fee_to_setter = fee_to_setter; + self._only_fee_setter()?; + self.fee_to_setter = fee_to_setter; Ok(()) } #[ink(message)] fn fee_to(&self) -> AccountId { - self.factory.fee_to + self.fee_to } #[ink(message)] fn fee_to_setter(&self) -> AccountId { - self.factory.fee_to_setter + self.fee_to_setter } #[ink(message)] fn get_pair(&self, token_a: AccountId, token_b: AccountId) -> Option { - self.factory.get_pair.get(&(token_a, token_b)) + self.get_pair.get((token_a, token_b)) } } - impl factory::Internal for FactoryContract { + impl FactoryContract { + #[ink(constructor)] + pub fn new(fee_to_setter: AccountId, pair_code_hash: Hash) -> Self { + let mut instance = Self { + get_pair: Default::default(), + all_pairs: Default::default(), + all_pairs_length: 0, + pair_contract_code_hash: Default::default(), + fee_to: ZERO_ADDRESS.into(), + fee_to_setter: ZERO_ADDRESS.into(), + }; + instance.pair_contract_code_hash = pair_code_hash; + instance.fee_to_setter = fee_to_setter; + instance + } + fn _instantiate_pair( &mut self, salt_bytes: &[u8], token_0: AccountId, token_1: AccountId, ) -> Result { - let pair_hash = self.factory.pair_contract_code_hash; + let pair_hash = self.pair_contract_code_hash; let pair = match PairContractRef::new(token_0, token_1) .endowment(0) .code_hash(pair_hash) @@ -174,21 +176,19 @@ pub mod factory { } fn _add_new_pair(&mut self, pair: AccountId) { - let pair_len = self.factory.all_pairs_length; - self.factory.all_pairs.insert(&pair_len, &pair); - self.factory.all_pairs_length += 1; + let pair_len = self.all_pairs_length; + self.all_pairs.insert(pair_len, &pair); + self.all_pairs_length += 1; } - } - impl FactoryContract { - #[ink(constructor)] - pub fn new(fee_to_setter: AccountId, pair_code_hash: Hash) -> Self { - let mut instance = Self::default(); - instance.factory.pair_contract_code_hash = pair_code_hash; - instance.factory.fee_to_setter = fee_to_setter; - instance + fn _only_fee_setter(&self) -> Result<(), FactoryError> { + if self.env().caller() != self.fee_to_setter { + return Err(FactoryError::CallerIsNotFeeSetter) + } + Ok(()) } } + #[cfg(test)] mod tests { use ink::{ @@ -202,7 +202,7 @@ pub mod factory { fn initialize_works() { let accounts = default_accounts::(); let factory = FactoryContract::new(accounts.alice, Hash::default()); - assert_eq!(factory.factory.fee_to, amm::helpers::ZERO_ADDRESS.into()); + assert_eq!(factory.fee_to, amm::helpers::ZERO_ADDRESS.into()); } } } diff --git a/amm/contracts/pair/Cargo.toml b/amm/contracts/pair/Cargo.toml index 6474df82..9f585f2f 100644 --- a/amm/contracts/pair/Cargo.toml +++ b/amm/contracts/pair/Cargo.toml @@ -33,9 +33,3 @@ doctest = false default = ["std"] std = ["ink/std", "scale/std", "scale-info/std", "openbrush/std", "amm/std"] ink-as-dependency = [] - -[profile.dev] -overflow-checks = false - -[profile.release] -overflow-checks = false diff --git a/amm/contracts/router/Cargo.toml b/amm/contracts/router/Cargo.toml index 5f51e8de..5ca2a21b 100755 --- a/amm/contracts/router/Cargo.toml +++ b/amm/contracts/router/Cargo.toml @@ -37,9 +37,3 @@ std = [ "amm/std", ] ink-as-dependency = [] - -[profile.dev] -overflow-checks = false - -[profile.release] -overflow-checks = false diff --git a/amm/contracts/wnative/Cargo.toml b/amm/contracts/wnative/Cargo.toml index 4bf937ff..bee06634 100644 --- a/amm/contracts/wnative/Cargo.toml +++ b/amm/contracts/wnative/Cargo.toml @@ -34,9 +34,3 @@ std = [ "amm/std", ] ink-as-dependency = [] - -[profile.dev] -overflow-checks = false - -[profile.release] -overflow-checks = false diff --git a/amm/logics/Cargo.lock b/amm/logics/Cargo.lock index d84fd5c5..09f7326e 100644 --- a/amm/logics/Cargo.lock +++ b/amm/logics/Cargo.lock @@ -11,6 +11,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "amm" +version = "0.2.0" +dependencies = [ + "curve25519-dalek", + "ink", + "ink_metadata", + "openbrush", + "parity-scale-codec", + "primitive-types", + "scale-info", + "sha2", + "sp-arithmetic", +] + [[package]] name = "array-init" version = "2.1.0" @@ -461,9 +476,9 @@ dependencies = [ [[package]] name = "ink" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b374fcb3c9b91f8293bdc93d69292e2ec6ea19e97e00725806d79bf563fa5e55" +checksum = "e9fd4f77d66c94aa7f27a7cf41cd2edbc2229afe34ec475c3f32b6e8fdf561a0" dependencies = [ "derive_more", "ink_env", @@ -477,18 +492,18 @@ dependencies = [ [[package]] name = "ink_allocator" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cdc9dbbc38d0e0cd7b053068112ca8ab8140b8ece33b9e197af5544ed3d97e1" +checksum = "870914970470fd77a3f42d3c5d1918b562817af127fd063ee8b1d9fbf59aa1fe" dependencies = [ "cfg-if", ] [[package]] name = "ink_codegen" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "251e64f2dd74e98329a05812f067f34e2b494a7b1325e538165e481378a72747" +checksum = "22d79057b2565df31a10af6510a44b161093f110c5f9c22ad02c20af9cea4c29" dependencies = [ "blake2 0.10.6", "derive_more", @@ -510,9 +525,9 @@ dependencies = [ [[package]] name = "ink_engine" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77c4af49e092a93e65d1161ce31d23c2e57d724462c96a8944acd647a52787f0" +checksum = "722ec3a5eb557124b001c60ff8f961079f6d566af643edea579f152b15822fe5" dependencies = [ "blake2 0.10.6", "derive_more", @@ -525,9 +540,9 @@ dependencies = [ [[package]] name = "ink_env" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5e1505c5deb7280743e4d7df72a91f52bbf4cb063f464c73f89dce00c70f92" +checksum = "584e73bc0982f6f1a067bb63ebc75262f6dc54ed2a17060efa73eaba84dc9308" dependencies = [ "arrayref", "blake2 0.10.6", @@ -553,9 +568,9 @@ dependencies = [ [[package]] name = "ink_ir" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c0e2d96fc6e5b5cb1696b8057e72958315076dbe3f427e8f7722a346344f27a" +checksum = "5b529c941518e8f450395fab9fe8ebba0a7acbb18778fc7e0a87f6248286ec72" dependencies = [ "blake2 0.10.6", "either", @@ -567,9 +582,9 @@ dependencies = [ [[package]] name = "ink_macro" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15abf802e89909c65b6c15d0c655beb3c7ab86309626effb5d9b330d97308114" +checksum = "8579576c995ca9baa032584beca19155cbd63b6739570aa9da4d35a0415f4be8" dependencies = [ "ink_codegen", "ink_ir", @@ -583,9 +598,9 @@ dependencies = [ [[package]] name = "ink_metadata" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4af082b4c2eb246d27b358411ef950811f851c1099aa507ba4bcdd7214d40ccd" +checksum = "3fddff95ce3e01f42002fdaf96edda691dbccb08c9ae76d7101daa1fa634e601" dependencies = [ "derive_more", "impl-serde", @@ -597,18 +612,18 @@ dependencies = [ [[package]] name = "ink_prelude" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d0662ba1d4aa26f0fea36ce6ef9ef1e510e24c900597d703b148c8c23b675b9" +checksum = "d8cfdf91d2b442f08efb34dd3780fd6fbd3d033f63b42f62684fe47534948ef6" dependencies = [ "cfg-if", ] [[package]] name = "ink_primitives" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52693c5e74600f5bd4c0f6d447ba9c4e491e4edf685eaf9f9f347a3cb1cde66b" +checksum = "6414bcad12ebf0c3abbbb192a09e4d06e22f662cf3e19545204e1b0684be12a1" dependencies = [ "derive_more", "ink_prelude", @@ -621,9 +636,9 @@ dependencies = [ [[package]] name = "ink_storage" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e02d898d2ff85c88126d284854e1198771be94282d44a5d77fdc8a9bce43e398" +checksum = "bd728409de235de0489f71ee2d1beb320613fdb50dda9fa1c564825f4ad06daa" dependencies = [ "array-init", "cfg-if", @@ -639,9 +654,9 @@ dependencies = [ [[package]] name = "ink_storage_traits" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec58d70937c1e1490a00b84e2eb9a799f1a5331dd0e5cc68d550de1dbf6a8f4" +checksum = "a8dcb50f70377ac35c28d63b06383a0a3cbb79542ea4cdc5b00e3e2b3de4a549" dependencies = [ "ink_metadata", "ink_prelude", @@ -799,7 +814,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#73783af2f887eeb1fb3ebb4a012d5f3ff4598b56" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "ink", "openbrush_contracts", @@ -811,7 +826,7 @@ dependencies = [ [[package]] name = "openbrush_contracts" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#73783af2f887eeb1fb3ebb4a012d5f3ff4598b56" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "ink", "openbrush_lang", @@ -823,7 +838,7 @@ dependencies = [ [[package]] name = "openbrush_lang" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#73783af2f887eeb1fb3ebb4a012d5f3ff4598b56" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "const_format", "ink", @@ -836,7 +851,7 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#73783af2f887eeb1fb3ebb4a012d5f3ff4598b56" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -856,7 +871,7 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#73783af2f887eeb1fb3ebb4a012d5f3ff4598b56" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -1066,9 +1081,9 @@ checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "scale-bits" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd7aca73785181cc41f0bbe017263e682b585ca660540ba569133901d013ecf" +checksum = "036575c29af9b6e4866ffb7fa055dbf623fe7a9cc159b33786de6013a6969d89" dependencies = [ "parity-scale-codec", "scale-info", @@ -1076,22 +1091,23 @@ dependencies = [ [[package]] name = "scale-decode" -version = "0.5.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e5527e4b3bf079d4c0b2f253418598c380722ba37ef20fac9088081407f2b6" +checksum = "7789f5728e4e954aaa20cadcc370b99096fb8645fca3c9333ace44bb18f30095" dependencies = [ + "derive_more", "parity-scale-codec", "scale-bits", "scale-decode-derive", "scale-info", - "thiserror", + "smallvec", ] [[package]] name = "scale-decode-derive" -version = "0.5.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b38741b2f78e4391b94eac6b102af0f6ea2b0f7fe65adb55d7f4004f507854db" +checksum = "27873eb6005868f8cc72dcfe109fae664cf51223d35387bc2f28be4c28d94c47" dependencies = [ "darling", "proc-macro-crate", @@ -1102,21 +1118,22 @@ dependencies = [ [[package]] name = "scale-encode" -version = "0.1.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15546e5efbb45f0fc2291f7e202dee8623274c5d8bbfdf9c6886cc8b44a7ced3" +checksum = "6d70cb4b29360105483fac1ed567ff95d65224a14dd275b6303ed0a654c78de5" dependencies = [ + "derive_more", "parity-scale-codec", "scale-encode-derive", "scale-info", - "thiserror", + "smallvec", ] [[package]] name = "scale-encode-derive" -version = "0.1.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd983cf0a9effd76138554ead18a6de542d1af175ac12fd5e91836c5c0268082" +checksum = "995491f110efdc6bea96d6a746140e32bfceb4ea47510750a5467295a4707a25" dependencies = [ "darling", "proc-macro-crate", @@ -1240,6 +1257,12 @@ dependencies = [ "keccak", ] +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + [[package]] name = "sp-arithmetic" version = "6.0.0" @@ -1427,21 +1450,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "uniswap_v2" -version = "0.1.0" -dependencies = [ - "curve25519-dalek", - "ink", - "ink_metadata", - "openbrush", - "parity-scale-codec", - "primitive-types", - "scale-info", - "sha2", - "sp-arithmetic", -] - [[package]] name = "unwrap" version = "1.2.1" diff --git a/amm/logics/helpers/helper.rs b/amm/logics/helpers/helper.rs index 4b87fc2c..efd050ae 100644 --- a/amm/logics/helpers/helper.rs +++ b/amm/logics/helpers/helper.rs @@ -1,7 +1,10 @@ use crate::{ helpers::math::casted_mul, traits::{ - factory::FactoryRef, + factory::{ + Factory, + FactoryRef, + }, pair::PairRef, }, }; @@ -49,7 +52,8 @@ pub fn pair_for_on_chain( token_a: AccountId, token_b: AccountId, ) -> Option { - FactoryRef::get_pair(factory, token_a, token_b) + let factory_ref: FactoryRef = (*factory).into(); + factory_ref.get_pair(token_a, token_b) } /// Returns balances of token reserves for particular `Factory` instance. diff --git a/amm/logics/impls/factory/data.rs b/amm/logics/impls/factory/data.rs deleted file mode 100644 index 658a9a4e..00000000 --- a/amm/logics/impls/factory/data.rs +++ /dev/null @@ -1,33 +0,0 @@ -use ink::primitives::Hash; -use openbrush::{ - storage::Mapping, - traits::AccountId, -}; - -use crate::helpers::ZERO_ADDRESS; - -pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data); - -#[derive(Debug)] -#[openbrush::upgradeable_storage(STORAGE_KEY)] -pub struct Data { - pub fee_to: AccountId, - pub fee_to_setter: AccountId, - pub get_pair: Mapping<(AccountId, AccountId), AccountId>, - pub all_pairs: Mapping, - pub all_pairs_length: u64, - pub pair_contract_code_hash: Hash, -} - -impl Default for Data { - fn default() -> Self { - Self { - fee_to: ZERO_ADDRESS.into(), - fee_to_setter: ZERO_ADDRESS.into(), - get_pair: Default::default(), - all_pairs: Mapping::default(), - all_pairs_length: 0, - pair_contract_code_hash: Default::default(), - } - } -} diff --git a/amm/logics/impls/factory/factory.rs b/amm/logics/impls/factory/factory.rs deleted file mode 100644 index 6ea56cb6..00000000 --- a/amm/logics/impls/factory/factory.rs +++ /dev/null @@ -1,45 +0,0 @@ -pub use crate::{ - impls::factory::*, - traits::factory::*, -}; -use openbrush::{ - modifier_definition, - traits::{ - AccountId, - Storage, - }, -}; - -pub trait Internal { - fn _emit_create_pair_event( - &self, - _token_0: AccountId, - _token_1: AccountId, - _pair: AccountId, - _pair_len: u64, - ); - - /// Creates an instance of the `Pair` contract. - fn _instantiate_pair( - &mut self, - salt_bytes: &[u8], - token_0: AccountId, - token_1: AccountId, - ) -> Result; - - /// Adds a new pair to the contract's storage. - fn _add_new_pair(&mut self, pair: AccountId); -} - -#[modifier_definition] -pub fn only_fee_setter(instance: &mut T, body: F) -> Result -where - T: Storage, - F: FnOnce(&mut T) -> Result, - E: From, -{ - if instance.data().fee_to_setter != T::env().caller() { - return Err(From::from(FactoryError::CallerIsNotFeeSetter)) - } - body(instance) -} diff --git a/amm/logics/impls/factory/mod.rs b/amm/logics/impls/factory/mod.rs deleted file mode 100644 index ddeb9e91..00000000 --- a/amm/logics/impls/factory/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod data; -pub mod factory; diff --git a/amm/logics/impls/mod.rs b/amm/logics/impls/mod.rs index 9b922ed4..20d2f674 100644 --- a/amm/logics/impls/mod.rs +++ b/amm/logics/impls/mod.rs @@ -1,3 +1,2 @@ -pub mod factory; pub mod pair; pub mod router; diff --git a/amm/logics/impls/pair/pair.rs b/amm/logics/impls/pair/pair.rs index 0d56448d..5b3a747d 100644 --- a/amm/logics/impls/pair/pair.rs +++ b/amm/logics/impls/pair/pair.rs @@ -2,7 +2,10 @@ use crate::{ ensure, helpers::math::casted_mul, traits::{ - factory::FactoryRef, + factory::{ + Factory, + FactoryRef, + }, types::WrappedU256, }, }; @@ -100,7 +103,8 @@ impl + Storage> Internal for T { reserve_0: Balance, reserve_1: Balance, ) -> Result { - let fee_to = FactoryRef::fee_to(&self.data::().factory); + let factory_ref: FactoryRef = self.data::().factory.into(); + let fee_to = factory_ref.fee_to(); let fee_on = !fee_to.is_zero(); let k_last: U256 = self.data::().k_last.into(); if fee_on { diff --git a/amm/logics/impls/router/router.rs b/amm/logics/impls/router/router.rs index e0b480b8..7eee9cf9 100644 --- a/amm/logics/impls/router/router.rs +++ b/amm/logics/impls/router/router.rs @@ -7,7 +7,10 @@ use crate::{ sort_tokens, }, traits::{ - factory::FactoryRef, + factory::{ + Factory, + FactoryRef, + }, pair::PairRef, }, }; @@ -60,7 +63,8 @@ impl> Internal for T { ) -> Result<(Balance, Balance), RouterError> { let factory = self.data().factory; if pair_for_on_chain(&factory, token_a, token_b).is_none() { - FactoryRef::create_pair(&factory, token_a, token_b)?; + let mut factory_ref: FactoryRef = factory.into(); + factory_ref.create_pair(token_a, token_b)?; }; let (reserve_a, reserve_b) = get_reserves(&factory, token_a, token_b)?; diff --git a/amm/logics/traits/factory.rs b/amm/logics/traits/factory.rs index d18513c4..43eb12d8 100644 --- a/amm/logics/traits/factory.rs +++ b/amm/logics/traits/factory.rs @@ -1,14 +1,19 @@ use crate::traits::pair::PairError; -use ink::primitives::Hash; -use openbrush::traits::AccountId; +use ink::{ + contract_ref, + env::DefaultEnvironment, + primitives::{ + AccountId, + Hash, + }, +}; -#[openbrush::wrapper] -pub type FactoryRef = dyn Factory; +pub type FactoryRef = contract_ref!(Factory, DefaultEnvironment); /// Factory trait for tracking all pairs within the UniswapV2 DEX. /// Creates new, unique instances of `Pair` smart contract per token pairs. /// Contains the logic to turn on the protocol charge. -#[openbrush::trait_definition] +#[ink::trait_definition] pub trait Factory { /// Returns address of the pair contract identified by `pid` id. #[ink(message)] @@ -49,7 +54,7 @@ pub trait Factory { #[ink(message)] fn fee_to_setter(&self) -> AccountId; - /// Returns addres of `Pair` contract instance (if any) for `(token_a, token_b)` pair. + /// Returns address of `Pair` contract instance (if any) for `(token_a, token_b)` pair. #[ink(message)] fn get_pair(&self, token_a: AccountId, token_b: AccountId) -> Option; } diff --git a/e2e-tests/Cargo.lock b/e2e-tests/Cargo.lock index f5267e64..c46bcfd4 100644 --- a/e2e-tests/Cargo.lock +++ b/e2e-tests/Cargo.lock @@ -68,6 +68,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "amm" +version = "0.2.0" +dependencies = [ + "ink", + "ink_metadata", + "openbrush", + "parity-scale-codec", + "primitive-types 0.11.1", + "scale-info", + "sp-arithmetic 6.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37)", +] + [[package]] name = "android-tzdata" version = "0.1.1" @@ -663,6 +676,7 @@ name = "e2e-tests" version = "0.1.0" dependencies = [ "aleph_client", + "amm", "anyhow", "assert2", "async-trait", @@ -672,7 +686,6 @@ dependencies = [ "parity-scale-codec", "rand 0.8.5", "tokio", - "uniswap_v2", ] [[package]] @@ -1268,9 +1281,9 @@ dependencies = [ [[package]] name = "ink" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "311a988dada2242dc748834b86f330bb37ff25482ceef8767104f512a3c465a7" +checksum = "e9fd4f77d66c94aa7f27a7cf41cd2edbc2229afe34ec475c3f32b6e8fdf561a0" dependencies = [ "derive_more", "ink_env", @@ -1299,18 +1312,18 @@ dependencies = [ [[package]] name = "ink_allocator" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cb3178f207f6a37c3512142c8c6c2561a2aac61d60baa934d08d1e55a67d4a8" +checksum = "870914970470fd77a3f42d3c5d1918b562817af127fd063ee8b1d9fbf59aa1fe" dependencies = [ "cfg-if", ] [[package]] name = "ink_codegen" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b22c0517e5c249d7997cb20e7bd6fbf2076708d39e7b114465c2cb9c1d5c9c" +checksum = "22d79057b2565df31a10af6510a44b161093f110c5f9c22ad02c20af9cea4c29" dependencies = [ "blake2 0.10.6", "derive_more", @@ -1332,9 +1345,9 @@ dependencies = [ [[package]] name = "ink_engine" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c9abc50b932893113e782761ac719c46214ecd10c423a3f626dce30a0c61b45" +checksum = "722ec3a5eb557124b001c60ff8f961079f6d566af643edea579f152b15822fe5" dependencies = [ "blake2 0.10.6", "derive_more", @@ -1347,9 +1360,9 @@ dependencies = [ [[package]] name = "ink_env" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aef653137381ff5f37ce2ff9130d11dd1b25f6e9734d97d687c3b953dee4d14f" +checksum = "584e73bc0982f6f1a067bb63ebc75262f6dc54ed2a17060efa73eaba84dc9308" dependencies = [ "arrayref", "blake2 0.10.6", @@ -1364,7 +1377,7 @@ dependencies = [ "parity-scale-codec", "paste", "rlibc", - "scale-decode 0.5.0", + "scale-decode 0.9.0", "scale-encode", "scale-info", "secp256k1 0.27.0", @@ -1375,9 +1388,9 @@ dependencies = [ [[package]] name = "ink_ir" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb9a2826cae9617d8ed2d547ed6e595deb334c1b69ff0a579abd86a76e48c30" +checksum = "5b529c941518e8f450395fab9fe8ebba0a7acbb18778fc7e0a87f6248286ec72" dependencies = [ "blake2 0.10.6", "either", @@ -1389,9 +1402,9 @@ dependencies = [ [[package]] name = "ink_macro" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0399b6423e892efb4d39eb76ed9286e4e93fab8141f89b4f4348ee77065b81d" +checksum = "8579576c995ca9baa032584beca19155cbd63b6739570aa9da4d35a0415f4be8" dependencies = [ "ink_codegen", "ink_ir", @@ -1405,9 +1418,9 @@ dependencies = [ [[package]] name = "ink_metadata" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5fb2b5ad83f725a6d0c8886ca737964d0013a193ca2d21c7e514fd427672416" +checksum = "3fddff95ce3e01f42002fdaf96edda691dbccb08c9ae76d7101daa1fa634e601" dependencies = [ "derive_more", "impl-serde", @@ -1419,23 +1432,23 @@ dependencies = [ [[package]] name = "ink_prelude" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6f174d742ff929abe66716ad8159f324441b4ff5161a3b0e282f416afbbac1" +checksum = "d8cfdf91d2b442f08efb34dd3780fd6fbd3d033f63b42f62684fe47534948ef6" dependencies = [ "cfg-if", ] [[package]] name = "ink_primitives" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b4e4772e1b9384233103c1f488df9854d24b3c16168bcf23613b7d98fb363f" +checksum = "6414bcad12ebf0c3abbbb192a09e4d06e22f662cf3e19545204e1b0684be12a1" dependencies = [ "derive_more", "ink_prelude", "parity-scale-codec", - "scale-decode 0.5.0", + "scale-decode 0.9.0", "scale-encode", "scale-info", "xxhash-rust", @@ -1443,9 +1456,9 @@ dependencies = [ [[package]] name = "ink_storage" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a0f0858c90d5660dc6ec76d31388919a9609aab74723262ccf893d81aafd06c" +checksum = "bd728409de235de0489f71ee2d1beb320613fdb50dda9fa1c564825f4ad06daa" dependencies = [ "array-init", "cfg-if", @@ -1461,9 +1474,9 @@ dependencies = [ [[package]] name = "ink_storage_traits" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4179f00b052e5955ab7535c1a69042a468771217e9db6a12de2cdbfcb03c861" +checksum = "a8dcb50f70377ac35c28d63b06383a0a3cbb79542ea4cdc5b00e3e2b3de4a549" dependencies = [ "ink_metadata", "ink_prelude", @@ -1956,7 +1969,7 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openbrush" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#8fc50483a911218271e764633c9b63f9dde5dbf6" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "ink", "openbrush_contracts", @@ -1968,7 +1981,7 @@ dependencies = [ [[package]] name = "openbrush_contracts" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#8fc50483a911218271e764633c9b63f9dde5dbf6" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "ink", "openbrush_lang", @@ -1980,7 +1993,7 @@ dependencies = [ [[package]] name = "openbrush_lang" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#8fc50483a911218271e764633c9b63f9dde5dbf6" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "const_format", "ink", @@ -1993,7 +2006,7 @@ dependencies = [ [[package]] name = "openbrush_lang_codegen" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#8fc50483a911218271e764633c9b63f9dde5dbf6" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "blake2 0.9.2", "cargo_metadata", @@ -2013,7 +2026,7 @@ dependencies = [ [[package]] name = "openbrush_lang_macro" version = "3.1.1" -source = "git+https://github.com/727-Ventures/openbrush-contracts#8fc50483a911218271e764633c9b63f9dde5dbf6" +source = "git+https://github.com/727-Ventures/openbrush-contracts?tag=3.1.1#13e82f3f02e8ea65a95ea02c381106ea738e1fb8" dependencies = [ "openbrush_lang_codegen", "proc-macro2", @@ -2554,6 +2567,16 @@ dependencies = [ "serde", ] +[[package]] +name = "scale-bits" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "036575c29af9b6e4866ffb7fa055dbf623fe7a9cc159b33786de6013a6969d89" +dependencies = [ + "parity-scale-codec", + "scale-info", +] + [[package]] name = "scale-decode" version = "0.4.0" @@ -2561,29 +2584,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d823d4be477fc33321f93d08fb6c2698273d044f01362dc27573a750deb7c233" dependencies = [ "parity-scale-codec", - "scale-bits", + "scale-bits 0.3.0", "scale-info", "thiserror", ] [[package]] name = "scale-decode" -version = "0.5.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e5527e4b3bf079d4c0b2f253418598c380722ba37ef20fac9088081407f2b6" +checksum = "7789f5728e4e954aaa20cadcc370b99096fb8645fca3c9333ace44bb18f30095" dependencies = [ + "derive_more", "parity-scale-codec", - "scale-bits", + "scale-bits 0.4.0", "scale-decode-derive", "scale-info", - "thiserror", + "smallvec", ] [[package]] name = "scale-decode-derive" -version = "0.5.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b38741b2f78e4391b94eac6b102af0f6ea2b0f7fe65adb55d7f4004f507854db" +checksum = "27873eb6005868f8cc72dcfe109fae664cf51223d35387bc2f28be4c28d94c47" dependencies = [ "darling", "proc-macro-crate", @@ -2594,21 +2618,22 @@ dependencies = [ [[package]] name = "scale-encode" -version = "0.1.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15546e5efbb45f0fc2291f7e202dee8623274c5d8bbfdf9c6886cc8b44a7ced3" +checksum = "6d70cb4b29360105483fac1ed567ff95d65224a14dd275b6303ed0a654c78de5" dependencies = [ + "derive_more", "parity-scale-codec", "scale-encode-derive", "scale-info", - "thiserror", + "smallvec", ] [[package]] name = "scale-encode-derive" -version = "0.1.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd983cf0a9effd76138554ead18a6de542d1af175ac12fd5e91836c5c0268082" +checksum = "995491f110efdc6bea96d6a746140e32bfceb4ea47510750a5467295a4707a25" dependencies = [ "darling", "proc-macro-crate", @@ -2652,7 +2677,7 @@ dependencies = [ "either", "frame-metadata", "parity-scale-codec", - "scale-bits", + "scale-bits 0.3.0", "scale-decode 0.4.0", "scale-info", "serde", @@ -3803,19 +3828,6 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" -[[package]] -name = "uniswap_v2" -version = "0.1.0" -dependencies = [ - "ink", - "ink_metadata", - "openbrush", - "parity-scale-codec", - "primitive-types 0.11.1", - "scale-info", - "sp-arithmetic 6.0.0 (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.37)", -] - [[package]] name = "untrusted" version = "0.7.1"