Skip to content

Commit e179de4

Browse files
fbielejecdeuszxh4nsu
authored
Simple dex (#612)
* implementation sur course * swaps done * add new role * added events * wut * edited events * set AC * give why * docstring * modified docstring * cleanup * Update contracts/simple_dex/lib.rs Co-authored-by: deuszx <[email protected]> * simplified artihmetic * moved roles to own mod * wZERO * dumbed down LP * slippage check * check pool composition * explicitely check swap fee value that is set * change parameter name to avoid confusion, use integer operations could use promils for better precision but meh * not payabale * refactor * ok semver * refactor role check * remove duplicated check * Update contracts/wrapped_azero/lib.rs Co-authored-by: deuszx <[email protected]> * remove unused dep * Update contracts/simple_dex/lib.rs Co-authored-by: Michal Handzlik <[email protected]> * Update contracts/simple_dex/lib.rs Co-authored-by: Michal Handzlik <[email protected]> * added swap pairs * edited docstring Co-authored-by: deuszx <[email protected]> Co-authored-by: Michal Handzlik <[email protected]>
1 parent 20b1c81 commit e179de4

File tree

20 files changed

+3027
-119
lines changed

20 files changed

+3027
-119
lines changed

contracts/access_control/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contracts/access_control/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "access_control"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Cardinal Cryptography"]
55
edition = "2021"
66
publish = false

contracts/access_control/lib.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,27 @@
11
#![cfg_attr(not(feature = "std"), no_std)]
22

33
pub use crate::access_control::{
4-
AccessControlError, Role, ACCESS_CONTROL_PUBKEY, CHECK_ROLE_SELECTOR, HAS_ROLE_SELECTOR,
4+
AccessControlError, ACCESS_CONTROL_PUBKEY, CHECK_ROLE_SELECTOR, HAS_ROLE_SELECTOR,
55
};
6+
pub mod roles;
67
pub mod traits;
78
use ink_lang as ink;
89

910
#[ink::contract]
1011
mod access_control {
1112

1213
use ink_lang::{codegen::EmitEvent, reflect::ContractEventBase};
13-
use ink_storage::{
14-
traits::{PackedLayout, SpreadAllocate, SpreadLayout},
15-
Mapping,
16-
};
14+
use ink_storage::{traits::SpreadAllocate, Mapping};
1715
use scale::{Decode, Encode};
1816

17+
use crate::roles::Role;
18+
1919
// address placeholder, to be set in the bytecode
2020
// 4465614444656144446561444465614444656144446561444465614444656144 => 5DcPEG9AQ4Y9Lo9C5WXuKJDDawens77jWxZ6zGChnm8y8FUX
2121
pub const ACCESS_CONTROL_PUBKEY: [u8; 32] = *b"DeaDDeaDDeaDDeaDDeaDDeaDDeaDDeaD";
2222
pub const HAS_ROLE_SELECTOR: [u8; 4] = [0, 0, 0, 3];
2323
pub const CHECK_ROLE_SELECTOR: [u8; 4] = [0, 0, 0, 5];
2424

25-
#[derive(Debug, Encode, Decode, Clone, Copy, SpreadLayout, PackedLayout, PartialEq, Eq)]
26-
#[cfg_attr(
27-
feature = "std",
28-
derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout)
29-
)]
30-
pub enum Role {
31-
/// Indicates a superuser.
32-
Admin(AccountId),
33-
/// Indicates account can terminate a contract.
34-
Owner(AccountId),
35-
/// Indicates account can initialize a contract from a given code hash.
36-
Initializer(Hash),
37-
}
38-
3925
#[ink(storage)]
4026
#[derive(SpreadAllocate)]
4127
pub struct AccessControl {

contracts/access_control/roles.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use ink_env::{AccountId, Hash};
2+
use ink_storage::traits::{PackedLayout, SpreadLayout};
3+
use scale::{Decode, Encode};
4+
5+
#[derive(Debug, Encode, Decode, Clone, Copy, SpreadLayout, PackedLayout, PartialEq, Eq)]
6+
#[cfg_attr(
7+
feature = "std",
8+
derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout)
9+
)]
10+
pub enum Role {
11+
/// Indicates a superuser.
12+
Admin(AccountId),
13+
/// Indicates account can terminate a contract.
14+
Owner(AccountId),
15+
/// Indicates account can initialize a contract from a given code hash.
16+
Initializer(Hash),
17+
/// Indicates account can add liquidity to a DEX contract (call certain functions)
18+
LiquidityProvider(AccountId),
19+
}

contracts/access_control/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ink_env::{
33
AccountId, DefaultEnvironment, Error as InkEnvError,
44
};
55

6-
use crate::access_control::{Role, HAS_ROLE_SELECTOR};
6+
use crate::{access_control::HAS_ROLE_SELECTOR, roles::Role};
77

88
pub trait AccessControlled {
99
type ContractError;

0 commit comments

Comments
 (0)