-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into create-collection-tests
- Loading branch information
Showing
7 changed files
with
532 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Unit and e2e tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
checks: | ||
name: Run clippy and unit tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust toolchain | ||
uses: Cardinal-Cryptography/github-actions/install-rust-toolchain@v1 | ||
# - name: Install Rust toolchain | ||
# run: | | ||
# rustup component add rust-src | ||
|
||
- name: Run cargo fmt | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: fmt | ||
args: --all -- --check | ||
|
||
- name: Run clippy | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: clippy | ||
# args: --all-targets -- --no-deps -D warnings (TODO: fix clippy warnings first) | ||
|
||
# sudo apt update && apt upgrade -y | ||
- name: Install Protobuf | ||
run: | | ||
sudo apt-get install -y protobuf-compiler libprotobuf-dev | ||
- name: Add installing required dependency | ||
run: | | ||
cargo install cargo-dylint dylint-link | ||
- name: Install substrate-contracts-node | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: install | ||
args: --force --locked contracts-node | ||
|
||
# TODO: cache substrate-contracts-node OR downlaod binary from github release | ||
# args: --locked substrate-contracts-node | ||
|
||
- name: Run unit tests | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --features e2e-tests | ||
|
||
build: | ||
name: Build the contract | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Cache Crates | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.cargo | ||
key: ${{ runner.os }}-contract-build-env-${{ hashFiles('rust-toolchain.toml') }} | ||
|
||
- name: Install Rust toolchain | ||
uses: Cardinal-Cryptography/github-actions/install-rust-toolchain@v1 | ||
|
||
- name: Install cargo contract | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: install | ||
args: --locked cargo-contract | ||
|
||
- name: Build contract | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: contract | ||
args: build --release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[toolchain] | ||
channel = "1.72.1" | ||
components = ["rustfmt", "rust-src", "clippy"] | ||
targets = ["wasm32-unknown-unknown"] | ||
profile = "minimal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
use crate::{ | ||
contract::{CalculateSwapResult, Hop}, | ||
contracts::{FeeTier, FeeTierKey, Pool, PoolKey, Position, Tick}, | ||
math::{ | ||
liquidity::Liquidity, percentage::Percentage, sqrt_price::sqrt_price::SqrtPrice, | ||
token_amount::TokenAmount, | ||
}, | ||
InvariantError, | ||
}; | ||
use alloc::vec::Vec; | ||
use ink::primitives::AccountId; | ||
|
||
#[ink::trait_definition] | ||
pub trait Invariant { | ||
#[ink(message)] | ||
fn get_protocol_fee(&self) -> Percentage; | ||
|
||
#[ink(message)] | ||
fn withdraw_protocol_fee(&mut self, pool_key: PoolKey) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn change_protocol_fee(&mut self, protocol_fee: Percentage) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn change_fee_receiver( | ||
&mut self, | ||
pool_key: PoolKey, | ||
fee_receiver: AccountId, | ||
) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn create_position( | ||
&mut self, | ||
pool_key: PoolKey, | ||
lower_tick: i32, | ||
upper_tick: i32, | ||
liquidity_delta: Liquidity, | ||
slippage_limit_lower: SqrtPrice, | ||
slippage_limit_upper: SqrtPrice, | ||
) -> Result<Position, InvariantError>; | ||
|
||
#[ink(message)] | ||
fn swap( | ||
&mut self, | ||
pool_key: PoolKey, | ||
x_to_y: bool, | ||
amount: TokenAmount, | ||
by_amount_in: bool, | ||
sqrt_price_limit: SqrtPrice, | ||
) -> Result<CalculateSwapResult, InvariantError>; | ||
|
||
#[ink(message)] | ||
fn swap_route( | ||
&mut self, | ||
amount_in: TokenAmount, | ||
expected_amount_out: TokenAmount, | ||
slippage: Percentage, | ||
swaps: Vec<Hop>, | ||
) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn quote( | ||
&self, | ||
pool_key: PoolKey, | ||
x_to_y: bool, | ||
amount: TokenAmount, | ||
by_amount_in: bool, | ||
sqrt_price_limit: SqrtPrice, | ||
) -> Result<(TokenAmount, TokenAmount, SqrtPrice, Vec<Tick>), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn quote_route( | ||
&mut self, | ||
amount_in: TokenAmount, | ||
swaps: Vec<Hop>, | ||
) -> Result<TokenAmount, InvariantError>; | ||
|
||
#[ink(message)] | ||
fn transfer_position(&mut self, index: u32, receiver: AccountId) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn get_position(&mut self, index: u32) -> Result<Position, InvariantError>; | ||
|
||
#[ink(message)] | ||
fn get_all_positions(&mut self) -> Vec<Position>; | ||
|
||
#[ink(message)] | ||
fn update_position_seconds_per_liquidity( | ||
&mut self, | ||
index: u32, | ||
pool_key: PoolKey, | ||
) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn claim_fee(&mut self, index: u32) -> Result<(TokenAmount, TokenAmount), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn remove_position(&mut self, index: u32) | ||
-> Result<(TokenAmount, TokenAmount), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn add_fee_tier(&mut self, fee_tier: FeeTier) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn get_fee_tier(&self, key: FeeTierKey) -> Option<()>; | ||
|
||
#[ink(message)] | ||
fn remove_fee_tier(&mut self, key: FeeTierKey); | ||
|
||
#[ink(message)] | ||
fn create_pool( | ||
&mut self, | ||
token_0: AccountId, | ||
token_1: AccountId, | ||
fee_tier: FeeTier, | ||
init_tick: i32, | ||
) -> Result<(), InvariantError>; | ||
|
||
#[ink(message)] | ||
fn get_pool( | ||
&self, | ||
token_0: AccountId, | ||
token_1: AccountId, | ||
fee_tier: FeeTier, | ||
) -> Result<Pool, InvariantError>; | ||
|
||
#[ink(message)] | ||
fn get_tick(&self, key: PoolKey, index: i32) -> Result<Tick, InvariantError>; | ||
|
||
#[ink(message)] | ||
fn get_tickmap_bit(&self, key: PoolKey, index: i32) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
pub mod collections; | ||
pub mod entrypoints; | ||
pub mod logic; | ||
pub mod storage; | ||
|
||
pub use collections::*; | ||
pub use entrypoints::*; | ||
pub use logic::*; | ||
pub use storage::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.