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

feat: squid changes #27

Merged
merged 17 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
43 changes: 43 additions & 0 deletions .github/workflows/codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Code Coverage
on: pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
coverage:
runs-on: ubuntu-latest

steps:
- name: Setup Dependencies for Sui Binary
run: sudo apt-get update && sudo apt-get install -y libpq-dev

- name: Download and Install Sui
env:
SUI_VERSION: devnet-v1.24.0
run: |
wget https://github.com/MystenLabs/sui/releases/download/${SUI_VERSION}/sui-${SUI_VERSION}-ubuntu-x86_64.tgz
tar -xvf sui-${SUI_VERSION}-ubuntu-x86_64.tgz
sudo mv ./sui-test-validator /usr/local/bin/sui-test-validator
sudo mv ./sui /usr/local/bin/sui
rm -rf sui-${SUI_VERSION}-ubuntu-x86_64.tgz

- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Test
timeout-minutes: 60
run: npm run test --coverage
milapsheth marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions move/abi/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "Abi"
version = "0.0.1"
published-at = "0xe716e153ada17d39bf0e2325658d5969d885c2c548cd55f2068f29831be1d42a"
published-at = "0x77b52c722425e0943f6e820aa7be91c7a5310b6d4942fb6f56c323ed84c69dc8"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }

[addresses]
abi = "0xe716e153ada17d39bf0e2325658d5969d885c2c548cd55f2068f29831be1d42a"
abi = "0x77b52c722425e0943f6e820aa7be91c7a5310b6d4942fb6f56c323ed84c69dc8"
4 changes: 2 additions & 2 deletions move/axelar/Move.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "Axelar"
version = "0.0.1"
published-at = "0x4c1b0c036766f48f5d067200fe2c2418f4455970470ec8931a3ab338a7249adc"
published-at = "0xc965b7fa1340121091a81274d415c8f737f922e2a1e4e8fe93ab86a517e4014e"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }

[addresses]
axelar = "0x4c1b0c036766f48f5d067200fe2c2418f4455970470ec8931a3ab338a7249adc"
axelar = "0xc965b7fa1340121091a81274d415c8f737f922e2a1e4e8fe93ab86a517e4014e"
4 changes: 2 additions & 2 deletions move/gas_service/Move.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "Governance"
version = "0.0.1"
published-at = "0x578987b18d4d60ba54533ebf578cb724e4e892bebb9eb35b354e159953995b57"
published-at = "0xdaed1c78f684a1d38caeb8e84e084085493e5c954b0cf12cbe597a40b5d0bab8"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/mainnet" }
Axelar = { local = "../axelar" }

[addresses]
gas_service = "0x578987b18d4d60ba54533ebf578cb724e4e892bebb9eb35b354e159953995b57"
gas_service = "0xdaed1c78f684a1d38caeb8e84e084085493e5c954b0cf12cbe597a40b5d0bab8"
4 changes: 2 additions & 2 deletions move/governance/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "Governance"
version = "0.0.1"
published-at = "0x26de81e805d4608df54b89477e160c2b19e5c222adb0a0cc57e63647a7b3f5d1"
published-at = "0xdc367d99a163b08219b5887567e1d87f95b239ef36f2b3a748123bd1a832b17c"
edition = "2024.beta"

[dependencies]
Expand All @@ -10,4 +10,4 @@ Axelar = { local = "../axelar" }
Abi = { local = "../abi" }

[addresses]
governance = "0x26de81e805d4608df54b89477e160c2b19e5c222adb0a0cc57e63647a7b3f5d1"
governance = "0xdc367d99a163b08219b5887567e1d87f95b239ef36f2b3a748123bd1a832b17c"
16 changes: 8 additions & 8 deletions move/interchain_token/sources/interchain_token.move
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
module interchain_token::tt {
module interchain_token::q {
use sui::coin::{Self};
use sui::url::{Url};

public struct TT has drop {}
public struct Q has drop {}

fun init(witness: TT, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency<TT>(
fun init(witness: Q, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency<Q>(
witness,
6,
b"TT",
b"Test Token",
9,
b"Q",
b"Quote",
b"",
option::none<Url>(),
ctx
);
transfer::public_transfer(treasury, tx_context::sender(ctx));
transfer::public_transfer(metadata, tx_context::sender(ctx));
}
}
}
4 changes: 2 additions & 2 deletions move/its/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ITS"
version = "0.0.1"
published-at = "0x4f54b4023596c4889208ec65243c1a2a93dad567458803d8f469abc861257b98"
published-at = "0x85195d4f7ba958d6ecdc8c80d2ceb0a6927ad3e202a6802b40c192198f931907"
#published-at = "0x996939577aed09e0f9bc6690d85c6bbdb0228353cbe4dbb326b3c2d7f59cbff9"
edition = "2024.beta"

Expand All @@ -11,4 +11,4 @@ Axelar = { local = "../axelar" }
Governance = { local = "../governance" }

[addresses]
its = "0x4f54b4023596c4889208ec65243c1a2a93dad567458803d8f469abc861257b98"
its = "0x85195d4f7ba958d6ecdc8c80d2ceb0a6927ad3e202a6802b40c192198f931907"
4 changes: 2 additions & 2 deletions move/squid/Move.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "Squid"
version = "0.0.1"
published-at = "0x6b3d7de8dda55754c03490d91638c64ac28af14d4fd1c2aab3db6ec9b7b6a32b"
published-at = "0x98e78c0f8a3acb28f9a2dcd7142969ea793cec38c476cfdbaefc8670c92e3c55"
edition = "2024.beta"

[dependencies]
Expand All @@ -11,4 +11,4 @@ Axelar = { local = "../axelar" }
ITS = { local = "../its" }

[addresses]
squid = "0x6b3d7de8dda55754c03490d91638c64ac28af14d4fd1c2aab3db6ec9b7b6a32b"
squid = "0x98e78c0f8a3acb28f9a2dcd7142969ea793cec38c476cfdbaefc8670c92e3c55"
76 changes: 54 additions & 22 deletions move/squid/sources/squid/deepbook_v2.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module squid::deepbook_v2 {
use axelar::discovery::{Self, MoveCall};

use squid::swap_info::{SwapInfo};
use squid::squid::Squid;

const FLOAT_SCALING_U128: u128 = 1_000_000_000;
const FLOAT_SCALING: u64 = 1_000_000_000;
Expand All @@ -22,6 +23,7 @@ module squid::deepbook_v2 {
const EWrongSwapType: u64 = 0;
const EWrongPool: u64 = 1;
const EWrongCoinType: u64 = 2;
const ENotEnoughOutput: u64 = 3;

public fun swap_base<T1, T2>(pool: &mut Pool<T1, T2>, coin: Coin<T1>, clock: &Clock, ctx: &mut TxContext): (Coin<T1>, Coin<T2>) {
let account = clob::create_account(ctx);
Expand Down Expand Up @@ -198,13 +200,17 @@ module squid::deepbook_v2 {
}

public fun estimate<T1, T2>(self: &mut SwapInfo, pool: &Pool<T1, T2>, clock: &Clock) {
let mut bcs = bcs::new(self.get_data_estimating());
let data = self.get_data_estimating();
if(vector::length(&data) == 0) return;

let mut bcs = bcs::new(data);

assert!(bcs.peel_u8() == SWAP_TYPE, EWrongSwapType);

assert!(bcs.peel_address() == object::id_address(pool), EWrongPool);

let has_base = bcs.peel_bool();
let min_output = bcs.peel_u64();

assert!(
&bcs.peel_vec_u8() == &type_name::get<T1>().into_string().into_bytes(),
Expand All @@ -217,14 +223,19 @@ module squid::deepbook_v2 {
);

let lot_size = bcs.peel_u64();
let should_sweep = bcs.peel_bool();
if(has_base) {
let (amount_left, output) = predict_base_for_quote(
pool,
self.coin_bag().get_estimate<T1>(),
lot_size,
clock,
);
self.coin_bag().store_estimate<T1>(amount_left);
if(min_output > output) {
self.skip_swap();
return
};
if(!should_sweep) self.coin_bag().store_estimate<T1>(amount_left);
self.coin_bag().store_estimate<T2>(output);
} else {
let (amount_left, output) = predict_quote_for_base(
Expand All @@ -233,12 +244,16 @@ module squid::deepbook_v2 {
lot_size,
clock,
);
self.coin_bag().store_estimate<T2>(amount_left);
if(min_output > output) {
self.skip_swap();
return
};
if(!should_sweep) self.coin_bag().store_estimate<T2>(amount_left);
self.coin_bag().store_estimate<T1>(output);
}
}

public fun swap<T1, T2>(self: &mut SwapInfo, pool: &mut Pool<T1, T2>, clock: &Clock, ctx: &mut TxContext) {
public fun swap<T1, T2>(self: &mut SwapInfo, pool: &mut Pool<T1, T2>, squid: &mut Squid, clock: &Clock, ctx: &mut TxContext) {
let data = self.get_data_swapping();
if(vector::length(&data) == 0) return;
let mut bcs = bcs::new(data);
Expand All @@ -248,6 +263,7 @@ module squid::deepbook_v2 {
assert!(bcs.peel_address() == object::id_address(pool), EWrongPool);

let has_base = bcs.peel_bool();
let min_output = bcs.peel_u64();

assert!(
&bcs.peel_vec_u8() == &type_name::get<T1>().into_string().into_bytes(),
Expand All @@ -260,20 +276,28 @@ module squid::deepbook_v2 {
);

let lot_size = bcs.peel_u64();
let should_sweep = bcs.peel_bool();
if(has_base) {
let mut base_balance = self.coin_bag().get_balance<T1>().destroy_some();
let leftover = base_balance.value() % lot_size;
if(leftover > 0) {
self.coin_bag().store_balance<T1>(
base_balance.split(leftover),
);
if(should_sweep) {
squid.coin_bag().store_balance<T1>(
base_balance.split(leftover)
);
} else {
self.coin_bag().store_balance<T1>(
base_balance.split(leftover),
);
};
};
let (base_coin, quote_coin) = swap_base(
pool,
coin::from_balance(base_balance, ctx),
clock,
ctx,
);
assert!(min_output <= quote_coin.value(), ENotEnoughOutput);
base_coin.destroy_zero();
self.coin_bag().store_balance<T2>(quote_coin.into_balance());
} else {
Expand All @@ -284,8 +308,13 @@ module squid::deepbook_v2 {
clock,
ctx,
);
assert!(min_output <= base_coin.value(), ENotEnoughOutput);
self.coin_bag().store_balance<T1>(base_coin.into_balance());
self.coin_bag().store_balance<T2>(quote_coin.into_balance());
if(should_sweep) {
squid.coin_bag().store_balance<T2>(quote_coin.into_balance());
} else {
self.coin_bag().store_balance<T2>(quote_coin.into_balance());
};
}
}

Expand All @@ -294,33 +323,35 @@ module squid::deepbook_v2 {
vector::append(&mut pool_arg, bcs.peel_address().to_bytes());

let _has_base = bcs.peel_bool();
let _min_output = bcs.peel_u64();

let type_base = ascii::string(bcs.peel_vec_u8());
let type_quote = ascii::string(bcs.peel_vec_u8());

discovery::new_move_call(
discovery::new_function(
package_id,
ascii::string(b"deepbook_v2"),
ascii::string(b"estimate"),
),
vector[
swap_info_arg,
pool_arg,
vector[0, 6],
],
vector[type_base, type_quote],
)
discovery::new_function(
package_id,
ascii::string(b"deepbook_v2"),
ascii::string(b"estimate"),
),
vector[
swap_info_arg,
pool_arg,
vector[0, 6],
],
vector[type_base, type_quote],
)
}

public(package) fun get_swap_move_call(package_id: address, mut bcs: BCS, swap_info_arg: vector<u8>): MoveCall {
public(package) fun get_swap_move_call(package_id: address, mut bcs: BCS, swap_info_arg: vector<u8>, squid_arg: vector<u8>): MoveCall {
let mut pool_arg = vector[0];
vector::append(&mut pool_arg, bcs.peel_address().to_bytes());

let _has_base = bcs.peel_bool();
let _min_output = bcs.peel_u64();

let type_base = ascii::string(bcs.peel_vec_u8());
let type_quote = ascii::string(bcs.peel_vec_u8());
let type_quote = ascii::string(bcs.peel_vec_u8());

discovery::new_move_call(
discovery::new_function(
Expand All @@ -331,6 +362,7 @@ module squid::deepbook_v2 {
vector[
swap_info_arg,
pool_arg,
squid_arg,
vector[0, 6],
],
vector[type_base, type_quote] ,
Expand Down
Loading
Loading