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

Add GitHub Action to publish package and remove unstable features #7

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Publish package

on:
release:
types: [ published ]

env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

jobs:
cargo_publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Publish to crates.io
run: cargo publish
7 changes: 0 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ jobs:
restore-keys: |
${{ runner.os }}-cargo-registry-

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true

- name: Build
run: cargo build

Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ anyhow = "1.0"
#aperture-lens = { git = "https://github.com/Aperture-Finance/Aperture-Lens", branch = "main" }
ethers = { version = "2.0", features = ["default"] }
num-bigint = "0.4.4"
num-integer = "0.1.45"
num-traits = "0.2.17"
once_cell = "1.19.0"
ruint = "1.11.1"
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(int_roundings)]
#![feature(is_sorted)]
//! # uniswap-v3-sdk
//!
//! A Rust SDK for building applications on top of Uniswap V3.
Expand Down
9 changes: 5 additions & 4 deletions src/utils/nearest_usable_tick.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::tick_math::{MAX_TICK, MIN_TICK};
use num_integer::Integer;

/// Returns the closest tick that is nearest a given tick and usable for the given tick spacing
///
Expand All @@ -9,11 +10,11 @@ use super::tick_math::{MAX_TICK, MIN_TICK};
///
/// returns: i32
///
pub const fn nearest_usable_tick(tick: i32, tick_spacing: i32) -> i32 {
pub fn nearest_usable_tick(tick: i32, tick_spacing: i32) -> i32 {
assert!(tick_spacing > 0, "TICK_SPACING");
assert!(tick >= MIN_TICK && tick <= MAX_TICK, "TICK_BOUND");
let rounded = tick.div_floor(tick_spacing) * tick_spacing;
let rounded = rounded + (tick - rounded + tick_spacing / 2) / tick_spacing * tick_spacing;
assert!((MIN_TICK..=MAX_TICK).contains(&tick), "TICK_BOUND");
let (quotient, remainder) = tick.div_mod_floor(&tick_spacing);
let rounded = (quotient + (remainder + tick_spacing / 2) / tick_spacing) * tick_spacing;
if rounded < MIN_TICK {
rounded + tick_spacing
} else if rounded > MAX_TICK {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/tick_list.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::entities::TickTrait;
use num_integer::Integer;

/// Utility methods for interacting with sorted lists of self
pub trait TickList<T: TickTrait> {
Expand Down Expand Up @@ -37,7 +38,11 @@ impl<T: TickTrait> TickList<T> for [T] {
self.iter().all(|x| x.index() % tick_spacing == 0),
"TICK_SPACING"
);
assert!(self.is_sorted(), "SORTED");
for i in 1..self.len() {
if self[i] < self[i - 1] {
panic!("SORTED");
}
}
assert_eq!(
self.iter().fold(0, |acc, x| acc + x.liquidity_net()),
0,
Expand Down Expand Up @@ -107,7 +112,7 @@ impl<T: TickTrait> TickList<T> for [T] {
lte: bool,
tick_spacing: i32,
) -> (i32, bool) {
let compressed = tick.div_floor(tick_spacing);
let (compressed, _) = tick.div_mod_floor(&tick_spacing);
if lte {
let word_pos = compressed >> 8;
let minimum = (word_pos << 8) * tick_spacing;
Expand Down
Loading