Skip to content

Commit

Permalink
Merge pull request #23 from aldrin-labs/migrate-2024-beta
Browse files Browse the repository at this point in the history
Migrate to Sui Move 2024 (beta)
  • Loading branch information
rockbmb authored Apr 20, 2024
2 parents b840445 + c86bfdb commit c350b31
Show file tree
Hide file tree
Showing 27 changed files with 515 additions and 512 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ build/
*.bpl

# cargo stuff
target/
target/

# Sui Move migration artifacts
*.patch
7 changes: 3 additions & 4 deletions ramm-misc/Move.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 0
manifest_digest = "5A89B8E8F764B52614AE57B04BAE162EFD7C96F2E8074906D90E7309A04DCC14"
version = 1
manifest_digest = "B60B9767384B4488DCEB014F8CD337366AD318F3A833A3074496141AF33EC065"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"

dependencies = [
{ name = "MoveStdlib" },
{ name = "Sui" },
Expand Down Expand Up @@ -33,6 +32,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.19.1"
compiler-version = "1.22.0"
edition = "legacy"
flavor = "sui"
3 changes: 2 additions & 1 deletion ramm-misc/Move.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "ramm_misc"
version = "0.0.1"
edition = "2024.beta"

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "testnet" }
Expand All @@ -11,4 +12,4 @@ SwitchboardStdLib = { git = "https://github.com/switchboard-xyz/sbv2-sui.git", s
ramm_misc = "0x0"
std = "0x1"
sui = "0x2"
switchboard = "0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e"
switchboard = "0x98670585b87e06628ef2d7f7cb1e7bee8ada65b43b82997935225a7e6e21d18e"
2 changes: 1 addition & 1 deletion ramm-misc/sources/switchboard_feed_parser.move
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module ramm_misc::switchboard_feed_parser {
where decimal = neg * value * 10^(-1 * dec)
*/
struct AggregatorInfo has store, key {
public struct AggregatorInfo has store, key {
id: UID,
aggregator_addr: address,
latest_result: u128,
Expand Down
2 changes: 1 addition & 1 deletion ramm-misc/sources/test_coin_faucet.move
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module ramm_misc::test_coin_faucet {

const ENonexistentCoinType: u64 = 0;

struct Faucet has key {
public struct Faucet has key {
id: UID,
coins: Bag,
creator: address,
Expand Down
20 changes: 10 additions & 10 deletions ramm-misc/sources/test_coins.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ module ramm_misc::test_coins {
use sui::balance;
use sui::tx_context::TxContext;

friend ramm_misc::test_coin_faucet;
/* friend ramm_misc::test_coin_faucet; */

// These coins below are the only ones for which a Switchboard Testnet feed exists
// as of 2024-01-22.
struct USDT has drop {}
struct USDC has drop {}
struct ETH has drop {}
struct BTC has drop {}
struct SOL has drop {}
struct DOT has drop {}
struct ADA has drop {}
public struct USDT has drop {}
public struct USDC has drop {}
public struct ETH has drop {}
public struct BTC has drop {}
public struct SOL has drop {}
public struct DOT has drop {}
public struct ADA has drop {}
//struct SUI has drop {}

/// For every currently available `Aggregator` in the Sui testnet, create a `Supply` for it,
/// control of which will belong to this package's publisher. See `ramm_misc::faucet::init()`.
public(friend) fun create_test_coin_suplies(ctx: &mut TxContext): Bag {
let coins = bag::new(ctx);
public(package) fun create_test_coin_suplies(ctx: &mut TxContext): Bag {
let mut coins = bag::new(ctx);

bag::add(&mut coins, (type_name::get<USDT>()), balance::create_supply(USDT {}));
bag::add(&mut coins, (type_name::get<USDC>()), balance::create_supply(USDC {}));
Expand Down
6 changes: 3 additions & 3 deletions ramm-misc/tests/coin_bag.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module ramm_misc::coin_bag {

#[test]
fun test_bag() {
let new_scenario = test_scenario::begin(ADDRESS);
let mut new_scenario = test_scenario::begin(ADDRESS);
let scenario = &mut new_scenario;
let ctx = test_scenario::ctx(scenario);

Expand All @@ -31,15 +31,15 @@ module ramm_misc::coin_bag {
let usdc = coin::mint_for_testing<USDC>(amount * 3, ctx);
let eth = coin::mint_for_testing<ETH>(amount * 4, ctx);

let bag = bag::new(ctx);
let mut bag = bag::new(ctx);
test_scenario::next_tx(scenario, ADDRESS);

bag::add<u64, Coin<BTC>>(&mut bag, 0, btc);
bag::add<u64, Coin<SOL>>(&mut bag, 1, sol);
bag::add<u64, Coin<ETH>>(&mut bag, 2, eth);
bag::add<u64, Coin<USDC>>(&mut bag, 3, usdc);

let amnt: u64 = 0;
let mut amnt: u64 = 0;

let btc = bag::remove<u64, Coin<BTC>>(&mut bag, 0);
amnt = amnt + coin::burn_for_testing(btc);
Expand Down
7 changes: 3 additions & 4 deletions ramm-sui/Move.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 0
manifest_digest = "E78137C746596EC13830EFFA68C134750EAE0456EF877CBFE762ED8E55D2DD64"
version = 1
manifest_digest = "DEB875FBA47B190BDFA78409585FBEF193587B3C4165F49EA7519C7C45116102"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"

dependencies = [
{ name = "MoveStdlib" },
{ name = "Sui" },
Expand Down Expand Up @@ -33,6 +32,6 @@ dependencies = [
]

[move.toolchain-version]
compiler-version = "1.21.1"
compiler-version = "1.22.0"
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.beta"
# First version of package published in testnet with ID:
#published-at = "0xd3283fa556731370cd2a7f389b3e35c630184118b5af416ce9e57edfce751496"
# Upgraded to ID:
Expand Down
38 changes: 19 additions & 19 deletions ramm-sui/sources/events.move
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module ramm_sui::events {
use sui::object::ID;
use sui::vec_map::VecMap;

friend ramm_sui::ramm;
friend ramm_sui::interface2;
friend ramm_sui::interface3;
/* friend ramm_sui::ramm; */
/* friend ramm_sui::interface2; */
/* friend ramm_sui::interface3; */

/// ---------
/// IMPORTANT
Expand All @@ -26,15 +26,15 @@ 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>,
asset_balances: vector<u256>,
asset_lpt_issued: vector<u256>,
}

public(friend) fun pool_state_event(
public(package) fun pool_state_event(
ramm_id: ID,
sender: address,
asset_types: vector<TypeName>,
Expand All @@ -53,16 +53,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 All @@ -74,7 +74,7 @@ module ramm_sui::events {

/// Given all the information necessary to identify a given RAMM's trade event,
/// emit it.
public(friend) fun trade_event<TradeType>(
public(package) fun trade_event<TradeType>(
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand All @@ -96,7 +96,7 @@ module ramm_sui::events {
)
}

struct PriceEstimationEvent has copy, drop {
public struct PriceEstimationEvent has copy, drop {
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand All @@ -111,7 +111,7 @@ module ramm_sui::events {
/// Note that no changes are made to the RAMM's state when estimating prices,
/// and that the price is not guaranteed to be the same when the trade is
/// executed.
public(friend) fun price_estimation_event(
public(package) fun price_estimation_event(
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand All @@ -134,7 +134,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 All @@ -144,7 +144,7 @@ module ramm_sui::events {

/// Given all the information necessary to identify a given RAMM's liquidity deposit event,
/// emit it.
public(friend) fun liquidity_deposit_event(
public(package) fun liquidity_deposit_event(
ramm_id: ID,
trader: address,
token_in: TypeName,
Expand All @@ -163,7 +163,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 All @@ -174,7 +174,7 @@ module ramm_sui::events {

/// Given all the information necessary to identify a given RAMM's liquidity withdrawal event,
/// emit it.
public(friend) fun liquidity_withdrawal_event(
public(package) fun liquidity_withdrawal_event(
ramm_id: ID,
trader: address,
token_out: TypeName,
Expand All @@ -200,14 +200,14 @@ module ramm_sui::events {
/// * its keys are each of the RAMM asset's `TypeName`s
/// * its values are the imbalance ratios for each of the RAMM's assets, represented with
/// as `u64`s with `PRECISION_DECIMAL_PLACES`
struct ImbalanceRatioEvent has copy, drop {
public struct ImbalanceRatioEvent has copy, drop {
ramm_id: ID,
requester: address,
imb_ratios: VecMap<TypeName, u64>,
}

/// Given the required data, emit an event with a RAMM's imbalance ratios.
public(friend) fun imbalance_ratios_event(
public(package) fun imbalance_ratios_event(
ramm_id: ID,
requester: address,
imb_ratios: VecMap<TypeName, u64>,
Expand All @@ -222,7 +222,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 All @@ -231,7 +231,7 @@ module ramm_sui::events {

/// Given all the information necessary to identify a given RAMM's fee collection event,
/// emit it.
public(friend) fun fee_collection_event(
public(package) fun fee_collection_event(
ramm_id: ID,
admin: address,
fee_collector: address,
Expand Down
Loading

0 comments on commit c350b31

Please sign in to comment.