Skip to content

Commit

Permalink
update to ink! 4 rc
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreOssun committed Feb 13, 2023
1 parent 66082e0 commit 88acf58
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 25 deletions.
4 changes: 2 additions & 2 deletions uniswap-v2/contracts/factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ authors = ["Stake Technologies <[email protected]>"]
edition = "2021"

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

pair_contract = { path = "../pair", default-features = false, features = ["ink-as-dependency"] }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.0.0-beta.1", default-features = false }
uniswap_v2 = { path = "../../logics", default-features = false }

[lib]
Expand Down
8 changes: 5 additions & 3 deletions uniswap-v2/contracts/factory/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ pub mod factory {
impl factory::Internal for FactoryContract {
fn _instantiate_pair(&mut self, salt_bytes: &[u8]) -> Result<AccountId, FactoryError> {
let pair_hash = self.factory.pair_contract_code_hash;
let pair = PairContractRef::new()
let pair = match PairContractRef::new()
.endowment(0)
.code_hash(pair_hash)
.salt_bytes(&salt_bytes[..4])
.instantiate()
.map_err(|_| FactoryError::PairInstantiationFailed)?;
.try_instantiate() {
Ok(Ok(res)) => Ok(res),
_ => Err(FactoryError::PairInstantiationFailed),
}?;
Ok(pair.to_account_id())
}

Expand Down
4 changes: 2 additions & 2 deletions uniswap-v2/contracts/pair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ authors = ["Stake Technologies <[email protected]>"]
edition = "2021"

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22", "ownable", "reentrancy_guard"] }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.0.0-beta.1", default-features = false, features = ["psp22", "ownable", "reentrancy_guard"] }
uniswap_v2 = { path = "../../logics", default-features = false }

[lib]
Expand Down
4 changes: 2 additions & 2 deletions uniswap-v2/contracts/psp22/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ authors = ["Supercolony <[email protected]>"]
edition = "2021"

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22"] }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.0.0-beta.1", default-features = false, features = ["psp22"] }

[lib]
name = "psp22_token"
Expand Down
4 changes: 2 additions & 2 deletions uniswap-v2/contracts/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"

[dependencies]
primitive-types = { version = "0.11.1", default-features = false, features = ["num-traits"] }
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22"] }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.0.0-beta.1", default-features = false, features = ["psp22"] }
uniswap_v2 = { path = "../../logics", default-features = false }

[lib]
Expand Down
5 changes: 2 additions & 3 deletions uniswap-v2/contracts/wnative/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ authors = ["Stake Technologies <[email protected]>"]
edition = "2021"

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink = { version = "~4.0.0-rc", default-features = false}

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }


openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22"] }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.0.0-beta.1", default-features = false, features = ["psp22"] }
uniswap_v2 = { path = "../../logics", default-features = false }

[lib]
Expand Down
6 changes: 3 additions & 3 deletions uniswap-v2/logics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ authors = ["Stake Technologies <[email protected]>"]
edition = "2021"

[dependencies]
ink = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", default-features = false}
ink_metadata = { git = "https://github.com/paritytech/ink", rev = "4655a8b4413cb50cbc38d1b7c173ad426ab06cde", features = ["derive"], optional = true }
ink = { version = "~4.0.0-rc", default-features = false}
ink_metadata = { version = "~4.0.0-rc", features = ["derive"], optional = true }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", default-features = false, features = ["psp22", "ownable", "reentrancy_guard"] }
openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.0.0-beta.1", default-features = false, features = ["psp22", "ownable", "reentrancy_guard"] }
primitive-types = { version = "0.11.1", default-features = false, features = ["codec"] }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.33"}

Expand Down
2 changes: 1 addition & 1 deletion uniswap-v2/logics/helpers/transfer_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn safe_transfer_from(
pub fn wrap(wnative: &AccountId, value: Balance) -> Result<(), PSP22Error> {
match WnativeRef::deposit_builder(wnative)
.transferred_value(value)
.fire()
.try_invoke()
{
Ok(res) => {
match res {
Expand Down
17 changes: 15 additions & 2 deletions uniswap-v2/logics/impls/factory/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use ink::{
};
use openbrush::{
storage::Mapping,
traits::AccountId,
traits::{AccountId, ZERO_ADDRESS}
};

pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);

#[derive(Default, Debug)]
#[derive(Debug)]
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
pub fee_to: AccountId,
Expand All @@ -18,3 +18,16 @@ pub struct Data {
pub all_pairs: Vec<AccountId>,
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: Vec::new(),
pair_contract_code_hash: Default::default(),
}
}
}
19 changes: 18 additions & 1 deletion uniswap-v2/logics/impls/pair/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use openbrush::traits::{
AccountId,
Balance,
Timestamp,
ZERO_ADDRESS
};

pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);

#[derive(Default, Debug)]
#[derive(Debug)]
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
pub factory: AccountId,
Expand All @@ -20,3 +21,19 @@ pub struct Data {
pub price_1_cumulative_last: WrappedU256,
pub k_last: WrappedU256,
}

impl Default for Data {
fn default() -> Self {
Self {
factory: ZERO_ADDRESS.into(),
token_0: ZERO_ADDRESS.into(),
token_1: ZERO_ADDRESS.into(),
reserve_0: 0,
reserve_1: 0,
block_timestamp_last: 0,
price_0_cumulative_last: Default::default(),
price_1_cumulative_last: Default::default(),
k_last: Default::default(),
}
}
}
14 changes: 12 additions & 2 deletions uniswap-v2/logics/impls/router/data.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
use ink::primitives::Hash;
use openbrush::traits::AccountId;
use openbrush::traits::{AccountId, ZERO_ADDRESS};

pub const STORAGE_KEY: u32 = openbrush::storage_unique_key!(Data);

#[derive(Default, Debug)]
#[derive(Debug)]
#[openbrush::upgradeable_storage(STORAGE_KEY)]
pub struct Data {
pub factory: AccountId,
pub wnative: AccountId,
pub pair_code_hash: Hash,
}

impl Default for Data {
fn default() -> Self {
Self {
factory: ZERO_ADDRESS.into(),
wnative: ZERO_ADDRESS.into(),
pair_code_hash: Default::default(),
}
}
}
4 changes: 2 additions & 2 deletions uniswap-v2/logics/impls/router/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<T: Storage<data::Data>> Router for T {

let (amount_0, amount_1) = match PairRef::burn_builder(&pair_contract, to)
.call_flags(CallFlags::default().set_allow_reentry(true))
.fire()
.try_invoke()
{
Ok(res) => {
match res {
Expand Down Expand Up @@ -545,7 +545,7 @@ impl<T: Storage<data::Data>> Internal for T {
to,
)
.call_flags(CallFlags::default().set_allow_reentry(true))
.fire()
.try_invoke()
{
Ok(res) => {
match res {
Expand Down

0 comments on commit 88acf58

Please sign in to comment.