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

Fix lints + format #50

Merged
merged 6 commits into from
Feb 5, 2025
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
3 changes: 3 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ jobs:
- name: install git
run: apt-get install -y git

- name: build
run: cd contracts/suilend && sui move build

- name: test
run: cd contracts/suilend && sui move test
4 changes: 2 additions & 2 deletions contracts/suilend/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 3
manifest_digest = "E1B32CD02102E7B9E19A5E7293F67188F052E87A415F5A3936C826988518BBBE"
manifest_digest = "E25F888B3CC57B28D0C772334DD30911CD5A1F9E4F24D8EC7733F5B434BF5012"
deps_digest = "F9B494B64F0615AED0E98FC12A85B85ECD2BC5185C22D30E7F67786BB52E507C"
dependencies = [
{ id = "Pyth", name = "Pyth" },
Expand Down Expand Up @@ -67,6 +67,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.39.4"
compiler-version = "1.35.3"
edition = "2024.beta"
flavor = "sui"
4 changes: 1 addition & 3 deletions contracts/suilend/sources/cell.move
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module suilend::cell {
use std::option::{Self, Option};

public struct Cell<Element> has store {
element: Option<Element>
element: Option<Element>,
}

public fun new<Element>(element: Element): Cell<Element> {
Expand Down
45 changes: 32 additions & 13 deletions contracts/suilend/sources/decimal.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ module suilend::decimal {
const WAD: u256 = 1000000000000000000;
const U64_MAX: u256 = 18446744073709551615;

public struct Decimal has copy, store, drop {
value: u256
public struct Decimal has copy, drop, store {
value: u256,
}

public fun from(v: u64): Decimal {
Decimal {
value: (v as u256) * WAD
value: (v as u256) * WAD,
}
}

public fun from_percent(v: u8): Decimal {
Decimal {
value: (v as u256) * WAD / 100
value: (v as u256) * WAD / 100,
}
}

public fun from_percent_u64(v: u64): Decimal {
Decimal {
value: (v as u256) * WAD / 100
value: (v as u256) * WAD / 100,
}
}

public fun from_bps(v: u64): Decimal {
Decimal {
value: (v as u256) * WAD / 10_000
value: (v as u256) * WAD / 10_000,
}
}

public fun from_scaled_val(v: u256): Decimal {
Decimal {
value: v
value: v,
}
}

Expand All @@ -44,13 +44,13 @@ module suilend::decimal {

public fun add(a: Decimal, b: Decimal): Decimal {
Decimal {
value: a.value + b.value
value: a.value + b.value,
}
}

public fun sub(a: Decimal, b: Decimal): Decimal {
Decimal {
value: a.value - b.value
value: a.value - b.value,
}
}

Expand All @@ -64,13 +64,13 @@ module suilend::decimal {

public fun mul(a: Decimal, b: Decimal): Decimal {
Decimal {
value: (a.value * b.value) / WAD
value: (a.value * b.value) / WAD,
}
}

public fun div(a: Decimal, b: Decimal): Decimal {
Decimal {
value: (a.value * WAD) / b.value
value: (a.value * WAD) / b.value,
}
}

Expand Down Expand Up @@ -144,7 +144,23 @@ module suilend::decimal {

#[test_only]
module suilend::decimal_tests {
use suilend::decimal::{add, sub, mul, div, floor, ceil, pow, lt, gt, le, ge, from, from_percent, saturating_sub, saturating_floor};
use suilend::decimal::{
add,
sub,
mul,
div,
floor,
ceil,
pow,
lt,
gt,
le,
ge,
from,
from_percent,
saturating_sub,
saturating_floor
};

#[test]
fun test_basic() {
Expand All @@ -164,7 +180,10 @@ module suilend::decimal_tests {
assert!(saturating_sub(a, b) == from(0), 0);
assert!(saturating_sub(b, a) == from(1), 0);
assert!(saturating_floor(from(18446744073709551615)) == 18446744073709551615, 0);
assert!(saturating_floor(add(from(18446744073709551615), from(1))) == 18446744073709551615, 0);
assert!(
saturating_floor(add(from(18446744073709551615), from(1))) == 18446744073709551615,
0,
);
}

#[test]
Expand Down
Loading