Skip to content

Commit

Permalink
Migrate ramm-sui (not tests) to use Move 2024 (alpha)
Browse files Browse the repository at this point in the history
  • Loading branch information
rockbmb committed Mar 1, 2024
1 parent f40d28b commit bb6d223
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 91 deletions.
7 changes: 6 additions & 1 deletion ramm-sui/Move.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[move]
version = 0
manifest_digest = "C38B0A789416AADBCC8558671B942576B831C3E0D0837DEB1A19A250FA0F15AA"
manifest_digest = "A58C4DBBBBFB6082AB1CA78C64AAB0617451D817CFCF4CA6EDCDEDC14002E878"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"

dependencies = [
Expand Down Expand Up @@ -31,3 +31,8 @@ dependencies = [
{ name = "MoveStdlib" },
{ name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.19.1"
edition = "legacy"
flavor = "sui"
1 change: 1 addition & 0 deletions ramm-sui/Move.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "ramm_sui"
version = "0.0.1"
edition = "2024.alpha"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "testnet" }
Expand Down
16 changes: 8 additions & 8 deletions ramm-sui/sources/events.move
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module ramm_sui::events {
As such, they are defined here.
*/

struct PoolStateEvent has copy, drop {
public struct PoolStateEvent has copy, drop {
ramm_id: ID,
sender: address,
asset_types: vector<TypeName>,
Expand All @@ -54,16 +54,16 @@ module ramm_sui::events {
}

/// Phantom type to mark a `TradeEvent` as the result of `trade_amount_in`
struct TradeIn {}
public struct TradeIn {}
/// Phantom type to mark a `TradeEvent` as the result of `trade_amount_out`
struct TradeOut {}
public struct TradeOut {}

/// Datatype used to emit, to the Sui blockchain, information on a successful trade.
///
/// A phantom type is used to mark whether it's the result of a call to `trade_amount_in`
/// (selling an exact amount of an asset to the RAMM), or to `trade_amount_out` (buying
/// an exact amount of an asset from the RAMM).
struct TradeEvent<phantom TradeType> has copy, drop {
public struct TradeEvent<phantom TradeType> has copy, drop {
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand Down Expand Up @@ -105,7 +105,7 @@ module ramm_sui::events {
/// A phantom type is used to mark whether it's the result of a call to `trade_amount_in`
/// (selling an exact amount of an asset to the RAMM), or to `trade_amount_out` (buying
/// an exact amount of an asset from the RAMM).
struct TradeFailure<phantom TradeType> has copy, drop {
public struct TradeFailure<phantom TradeType> has copy, drop {
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand Down Expand Up @@ -137,7 +137,7 @@ module ramm_sui::events {
}

/// Datatype used to emit, to the Sui blockchain, information on a successful liquidity deposit.
struct LiquidityDepositEvent has copy, drop {
public struct LiquidityDepositEvent has copy, drop {
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand Down Expand Up @@ -166,7 +166,7 @@ module ramm_sui::events {
}

/// Datatype describing a Sui event for a given RAMM's liquidity withdrawal.
struct LiquidityWithdrawalEvent has copy, drop {
public struct LiquidityWithdrawalEvent has copy, drop {
ramm_id: ID,
trader: address,
token_out: TypeName,
Expand Down Expand Up @@ -198,7 +198,7 @@ module ramm_sui::events {
}

/// Datatype describing a Sui event for a given RAMM's fee collection.
struct FeeCollectionEvent has copy, drop {
public struct FeeCollectionEvent has copy, drop {
ramm_id: ID,
admin: address,
fee_collector: address,
Expand Down
40 changes: 20 additions & 20 deletions ramm-sui/sources/interface2.move
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ module ramm_sui::interface2 {
ramm::check_trade_amount_in<AssetIn>(self, (coin::value(&amount_in) as u256));

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -159,7 +159,7 @@ module ramm_sui::interface2 {
let amount_out_u64: u64 = (amount_out_u256 as u64);
if (ramm::execute(&trade)) {
if (amount_out_u64 >= min_ao) {
let amount_in: Balance<AssetIn> = coin::into_balance(amount_in);
let mut amount_in: Balance<AssetIn> = coin::into_balance(amount_in);

let fee: u64 = (ramm::protocol_fee(&trade) as u64);
let fee_bal: Balance<AssetIn> = balance::split(&mut amount_in, fee);
Expand Down Expand Up @@ -230,9 +230,9 @@ module ramm_sui::interface2 {
ramm::check_trade_amount_out<AssetOut>(self, (amount_out as u256));

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -305,8 +305,8 @@ module ramm_sui::interface2 {
let max_ai_u64: u64 = coin::value(&max_ai);
if (ramm::execute(&trade)) {
if (trade_amount <= max_ai_u64) {
let max_ai: Balance<AssetIn> = coin::into_balance(max_ai);
let amount_in: Balance<AssetIn> = balance::split(&mut max_ai, trade_amount);
let mut max_ai: Balance<AssetIn> = coin::into_balance(max_ai);
let mut amount_in: Balance<AssetIn> = balance::split(&mut max_ai, trade_amount);
let remainder = max_ai;

let fee: u64 = (ramm::protocol_fee(&trade) as u64);
Expand Down Expand Up @@ -375,9 +375,9 @@ module ramm_sui::interface2 {
let oth = ramm::get_asset_index<Other>(self);

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -493,9 +493,9 @@ module ramm_sui::interface2 {
let o = ramm::get_asset_index<AssetOut>(self);

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -526,7 +526,7 @@ module ramm_sui::interface2 {
self, snd, *vec_map::get(&new_prices, &snd), *vec_map::get(&new_price_timestamps, &snd)
);

let volatility_fees: VecMap<u8, u256> = vec_map::empty();
let mut volatility_fees: VecMap<u8, u256> = vec_map::empty();
vec_map::insert(&mut volatility_fees, fst, fst_vol_fee);
vec_map::insert(&mut volatility_fees, snd, snd_vol_fee);
/*
Expand Down Expand Up @@ -581,7 +581,7 @@ module ramm_sui::interface2 {
};

let burn_amount: u64 = (*lpt_amount as u64);
let lp_token: Balance<LP<AssetOut>> = coin::into_balance(lp_token);
let mut lp_token: Balance<LP<AssetOut>> = coin::into_balance(lp_token);
let burn_tokens: Balance<LP<AssetOut>> = balance::split(&mut lp_token, burn_amount);
// Update RAMM's untyped count of LP tokens for outgoing asset
ramm::decr_lptokens_issued<AssetOut>(self, burn_amount);
Expand Down Expand Up @@ -621,8 +621,8 @@ module ramm_sui::interface2 {

// Build required data structures for liquidity withdrawal event emission.

let amounts_out_u64: VecMap<TypeName, u64> = vec_map::empty();
let fees_u64: VecMap<TypeName, u64> = vec_map::empty();
let mut amounts_out_u64: VecMap<TypeName, u64> = vec_map::empty();
let mut fees_u64: VecMap<TypeName, u64> = vec_map::empty();
vec_map::insert(&mut amounts_out_u64, type_name::get<Asset1>(), (*vec_map::get(&amounts_out, &fst) as u64));
vec_map::insert(&mut fees_u64, type_name::get<Asset1>(), (*vec_map::get(&fees, &fst) as u64));
if (vec_map::contains(&amounts_out, &snd)) {
Expand Down Expand Up @@ -667,7 +667,7 @@ module ramm_sui::interface2 {
let value_fst: u64 = coin::value(&fst);
let value_snd: u64 = coin::value(&snd);

let collected_fees: VecMap<TypeName, u64> = vec_map::empty();
let mut collected_fees: VecMap<TypeName, u64> = vec_map::empty();
vec_map::insert(&mut collected_fees, type_name::get<Asset1>(), value_fst);
vec_map::insert(&mut collected_fees, type_name::get<Asset2>(), value_snd);

Expand Down
41 changes: 21 additions & 20 deletions ramm-sui/sources/interface3.move
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module ramm_sui::interface3 {
const EInvalidWithdrawal: u64 = 12;

/// Trading function for a RAMM with three (3) assets.
///
/// Used to deposit a given amount of asset `T_i`, in exchange for asset `T_o`.
///
/// # Aborts
Expand Down Expand Up @@ -79,9 +80,9 @@ module ramm_sui::interface3 {
let oth = ramm::get_asset_index<Other>(self);

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -182,7 +183,7 @@ module ramm_sui::interface3 {
let amount_out_u64: u64 = (amount_out_u256 as u64);
if (ramm::execute(&trade)) {
if (amount_out_u64 >= min_ao) {
let amount_in: Balance<AssetIn> = coin::into_balance(amount_in);
let mut amount_in: Balance<AssetIn> = coin::into_balance(amount_in);

let fee: u64 = (ramm::protocol_fee(&trade) as u64);
let fee_bal: Balance<AssetIn> = balance::split(&mut amount_in, fee);
Expand Down Expand Up @@ -257,9 +258,9 @@ module ramm_sui::interface3 {
ramm::check_trade_amount_out<AssetOut>(self, (amount_out as u256));

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -359,8 +360,8 @@ module ramm_sui::interface3 {
let max_ai_u64: u64 = coin::value(&max_ai);
if (ramm::execute(&trade)) {
if (trade_amount <= max_ai_u64) {
let max_ai: Balance<AssetIn> = coin::into_balance(max_ai);
let amount_in: Balance<AssetIn> = balance::split(&mut max_ai, trade_amount);
let mut max_ai: Balance<AssetIn> = coin::into_balance(max_ai);
let mut amount_in: Balance<AssetIn> = balance::split(&mut max_ai, trade_amount);
let remainder = max_ai;

let fee: u64 = (ramm::protocol_fee(&trade) as u64);
Expand Down Expand Up @@ -431,9 +432,9 @@ module ramm_sui::interface3 {
let anoth = ramm::get_asset_index<Another>(self);

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -579,9 +580,9 @@ module ramm_sui::interface3 {
let o = ramm::get_asset_index<AssetOut>(self);

let current_timestamp: u64 = clock::timestamp_ms(clock);
let new_prices = vec_map::empty<u8, u256>();
let factors_for_prices = vec_map::empty<u8, u256>();
let new_price_timestamps = vec_map::empty<u8, u64>();
let mut new_prices = vec_map::empty<u8, u256>();
let mut factors_for_prices = vec_map::empty<u8, u256>();
let mut new_price_timestamps = vec_map::empty<u8, u64>();
ramm::check_feed_and_get_price_data(
self,
current_timestamp,
Expand Down Expand Up @@ -624,7 +625,7 @@ module ramm_sui::interface3 {
self, trd, *vec_map::get(&new_prices, &trd), *vec_map::get(&new_price_timestamps, &trd)
);

let volatility_fees: VecMap<u8, u256> = vec_map::empty();
let mut volatility_fees: VecMap<u8, u256> = vec_map::empty();
vec_map::insert(&mut volatility_fees, fst, fst_vol_fee);
vec_map::insert(&mut volatility_fees, snd, snd_vol_fee);
vec_map::insert(&mut volatility_fees, trd, trd_vol_fee);
Expand Down Expand Up @@ -686,7 +687,7 @@ module ramm_sui::interface3 {
};

let burn_amount: u64 = (*lpt_amount as u64);
let lp_token: Balance<LP<AssetOut>> = coin::into_balance(lp_token);
let mut lp_token: Balance<LP<AssetOut>> = coin::into_balance(lp_token);
let burn_tokens: Balance<LP<AssetOut>> = balance::split(&mut lp_token, burn_amount);
// Update RAMM's untyped count of LP tokens for outgoing asset
ramm::decr_lptokens_issued<AssetOut>(self, burn_amount);
Expand Down Expand Up @@ -734,8 +735,8 @@ module ramm_sui::interface3 {

// Build required data structures for liquidity withdrawal event emission.

let amounts_out_u64: VecMap<TypeName, u64> = vec_map::empty();
let fees_u64: VecMap<TypeName, u64> = vec_map::empty();
let mut amounts_out_u64: VecMap<TypeName, u64> = vec_map::empty();
let mut fees_u64: VecMap<TypeName, u64> = vec_map::empty();
vec_map::insert(&mut amounts_out_u64, type_name::get<Asset1>(), (*vec_map::get(&amounts_out, &fst) as u64));
vec_map::insert(&mut fees_u64, type_name::get<Asset1>(), (*vec_map::get(&fees, &fst) as u64));
if (vec_map::contains(&amounts_out, &snd)) {
Expand Down Expand Up @@ -788,7 +789,7 @@ module ramm_sui::interface3 {
let value_snd: u64 = coin::value(&snd);
let value_trd: u64 = coin::value(&trd);

let collected_fees: VecMap<TypeName, u64> = vec_map::empty();
let mut collected_fees: VecMap<TypeName, u64> = vec_map::empty();
vec_map::insert(&mut collected_fees, type_name::get<Asset1>(), value_fst);
vec_map::insert(&mut collected_fees, type_name::get<Asset2>(), value_snd);
vec_map::insert(&mut collected_fees, type_name::get<Asset3>(), value_trd);
Expand Down
Loading

0 comments on commit bb6d223

Please sign in to comment.