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 Sui breaking changes #27

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
789b46b
fix sui breaking changes (not finished yet)
Sep 18, 2022
4451e69
fix one-time-witness / info errors
Sep 18, 2022
6edd17c
fix errors to new format in some modules..
maomove Sep 19, 2022
f45c42b
refactor error codes to reflect std lib
maomove Sep 20, 2022
b22c243
fix excplicit deref
maomove Sep 20, 2022
1602a97
update version to 1.2.0
maomove Sep 20, 2022
55c5219
Merge pull request #1 from Origin-Byte/develop
maomove Sep 20, 2022
bb83776
Update to devnet-0.14.0
Suficio Nov 8, 2022
331ad4b
Merge pull request #2 from Origin-Byte/devnet-0.14.0
Suficio Nov 10, 2022
03cb373
Update Sui to 0.15.1
Suficio Nov 14, 2022
d268c53
Merge pull request #3 from Origin-Byte/0.15.1
Suficio Nov 14, 2022
ba4b408
Adding critbit implementation which supports keys as u64
porkbrain Nov 16, 2022
8b5e80b
Fixing one failing test which assumed still u128
porkbrain Nov 16, 2022
4fe200f
Merge pull request #4 from Origin-Byte/module/crit-bit-u64
porkbrain Nov 17, 2022
173e6b8
Update Sui Move version
nmboavida Nov 17, 2022
cd2f07a
Merge pull request #5 from Origin-Byte/beekeeping/sui-0.15.2
nmboavida Nov 17, 2022
fec6c98
Published package
nmboavida Nov 17, 2022
4bc1827
Upgrading movemate to Sui 0.16.0
porkbrain Nov 18, 2022
abb5e27
Merge pull request #6 from Origin-Byte/beekeeping/sui-0.16.0
porkbrain Nov 18, 2022
df7e3de
Republish
Suficio Nov 23, 2022
cfe98c1
Merge pull request #7 from Origin-Byte/republish
porkbrain Nov 23, 2022
2f3b672
Upgrading to latest sui
porkbrain Dec 2, 2022
7cae189
Merge pull request #8 from Origin-Byte/beekeeping/sui-0.17.0
porkbrain Dec 2, 2022
95a45e7
Update to Sui 0.18.0
Suficio Dec 9, 2022
d40f28c
No test
Suficio Dec 9, 2022
816c838
Publish
Suficio Dec 9, 2022
603ccd8
Merge pull request #9 from Origin-Byte/beekeeping/sui-0.18.0
Suficio Dec 9, 2022
78f3aaa
Deploying v0.19.0
porkbrain Dec 19, 2022
115d56b
Merge pull request #10 from Origin-Byte/beekeeping/sui-0.19.0
porkbrain Dec 19, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sui/build/
sui.log.*
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,34 @@ Movemate provides an advanced standard library of common modules in the Move eco

## Modules

* `acl`: Multi-role access control list (ACL).
* `bcd`: Binary canonical DEserialization. Convert `vector<u8>` to `u64` and `u128`.
* `bloom_filter`: Space-efficient probabilistic data structure for checking if an element is part of a set.
* `box`: On Aptos, send objects without the recipient having to set up a store for themselves beforehand. On Sui, transfer objects with the `store` ability but not the `key` ability.
* `crit_bit`: [Crit-bit trees](https://cr.yp.to/critbit.html) data structure. (Thanks to Econia.)
* `date`: Date conversion library in Move.
* `escrow` (Sui only): Very basic object escrow module on Sui.
* `escrow_shared` (Sui only): Basic object escrow module with refunds and arbitration on Sui.
* `governance`: On-chain coinholder governance (store coins and other objects; on Aptos, retrieve a `signer` for special actions like upgrading packages).
* `i64`: Signed 64-bit integers.
* `i128`: Signed 128-bit integers.
* `linear_vesting`: Linear vesting of coins for a given beneficiary.
* `math`: Standard math utilities missing in the Move language (for `u64`).
* `math_safe_precise`: `mul_div` for `u64`s while avoiding overflow and a more precise `quadratic` function.
* `math_u128`: Standard math utilities missing in the Move language (for `u128`).
* `merkle_proof`: Merkle proof verification utilities.
* `pseudorandom`: Pseudorandom number generator.
* `to_string`: `u128` to `String` conversion utilities.
* `u256`: Unsigned 256-bit integer implementation in Move. (Thanks to Pontem.) Includes bitwise operations and `vector<u8>` conversion.
* `vectors`: Vector utilities--specifically, comparison operators and a binary search function.
* `virtual_block`: Replace latency auctions with gas auctions (with control over MEV rewards) via virtual blocks.
- `acl`: Multi-role access control list (ACL).
- `bcd`: Binary canonical DEserialization. Convert `vector<u8>` to `u64` and `u128`.
- `bloom_filter`: Space-efficient probabilistic data structure for checking if an element is part of a set.
- `box`: On Aptos, send objects without the recipient having to set up a store for themselves beforehand. On Sui, transfer objects with the `store` ability but not the `key` ability.
- `crit_bit`: [Crit-bit trees](https://cr.yp.to/critbit.html) data structure. (Thanks to Econia.)
- `crit_bit_u64`: [Crit-bit trees](https://cr.yp.to/critbit.html) data structure. (Thanks to Econia.) Uses `u64` keys.
- `date`: Date conversion library in Move.
- `escrow` (Sui only): Very basic object escrow module on Sui.
- `escrow_shared` (Sui only): Basic object escrow module with refunds and arbitration on Sui.
- `governance`: On-chain coinholder governance (store coins and other objects; on Aptos, retrieve a `signer` for special actions like upgrading packages).
- `i64`: Signed 64-bit integers.
- `i128`: Signed 128-bit integers.
- `linear_vesting`: Linear vesting of coins for a given beneficiary.
- `math`: Standard math utilities missing in the Move language (for `u64`).
- `math_safe_precise`: `mul_div` for `u64`s while avoiding overflow and a more precise `quadratic` function.
- `math_u128`: Standard math utilities missing in the Move language (for `u128`).
- `merkle_proof`: Merkle proof verification utilities.
- `pseudorandom`: Pseudorandom number generator.
- `to_string`: `u128` to `String` conversion utilities.
- `u256`: Unsigned 256-bit integer implementation in Move. (Thanks to Pontem.) Includes bitwise operations and `vector<u8>` conversion.
- `vectors`: Vector utilities--specifically, comparison operators and a binary search function.
- `virtual_block`: Replace latency auctions with gas auctions (with control over MEV rewards) via virtual blocks.

### Outside the repo

* [`multisig_wallet`: Multisignature wallet for coins and arbitrary objects.](https://github.com/pentagonxyz/multisig-wallet-move)
* [`oracle_factory` (Sui only): Create and share custom oracles, aggregating data across validator sets.](https://github.com/pentagonxyz/move-oracles)
* [`xyk_amm`: Constant product (XY=K) AMM (like Uniswap V2).](https://github.com/pentagonxyz/xyk-amm-move)
- [`multisig_wallet`: Multisignature wallet for coins and arbitrary objects.](https://github.com/pentagonxyz/multisig-wallet-move)
- [`oracle_factory` (Sui only): Create and share custom oracles, aggregating data across validator sets.](https://github.com/pentagonxyz/move-oracles)
- [`xyk_amm`: Constant product (XY=K) AMM (like Uniswap V2).](https://github.com/pentagonxyz/xyk-amm-move)

## Usage

Expand Down
14 changes: 4 additions & 10 deletions sui/Move.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
[package]
name = "Movemate"
version = "1.0.0"
version = "1.7.0"
authors = ["David Lucid <[email protected]>"]

[addresses]
std = "0x1"
sui = "0x2"
movemate = "0x0"

[dependencies.MoveStdlib]
git = "https://github.com/MystenLabs/sui.git"
subdir = "crates/sui-framework/deps/move-stdlib"
rev = "fa973184a13579108a45965f7ff0fc3f2e2dc753"
movemate = "0x7a5fd49ad5d7e7b8e4611a3876d73a55868a4ad9"

[dependencies.Sui]
git = "https://github.com/MystenLabs/sui.git"
subdir = "crates/sui-framework"
rev = "fa973184a13579108a45965f7ff0fc3f2e2dc753"
# devnet-0.19.0
rev = "a8af20d94e951ecfb6d0cd47c23cf6393013d8a8"
17 changes: 7 additions & 10 deletions sui/sources/acl.move → sui/sources/acl_module.move
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
/// @title acl
/// @notice Multi-role access control list (ACL).
/// @dev Maps addresses to `u128`s with each bit representing the presence of (or lack of) each role.
module movemate::acl {
use std::errors;

module movemate::acl_module {
use sui::vec_map::{Self, VecMap};

/// @dev When attempting to add/remove a role >= 128.
const EROLE_NUMBER_TOO_LARGE: u64 = 0;
const EROLE_NUMBER_TOO_LARGE: u64 = 0x10000;

/// @dev Maps addresses to `u128`s with each bit representing the presence of (or lack of) each role.
struct ACL has store {
Expand All @@ -23,7 +21,7 @@ module movemate::acl {

/// @notice Check if a member has a role in the ACL.
public fun has_role(acl: &ACL, member: address, role: u8): bool {
assert!(role < 128, errors::invalid_argument(EROLE_NUMBER_TOO_LARGE));
assert!(role < 128, EROLE_NUMBER_TOO_LARGE);
vec_map::contains(&acl.permissions, &member) && *vec_map::get(&acl.permissions, &member) & (1 << role) > 0
}

Expand All @@ -36,7 +34,7 @@ module movemate::acl {

/// @notice Add a role for a member in the ACL.
public fun add_role(acl: &mut ACL, member: address, role: u8) {
assert!(role < 128, errors::invalid_argument(EROLE_NUMBER_TOO_LARGE));
assert!(role < 128, EROLE_NUMBER_TOO_LARGE);
if (vec_map::contains(&acl.permissions, &member)) {
let perms = vec_map::get_mut(&mut acl.permissions, &member);
*perms = *perms | (1 << role);
Expand All @@ -47,15 +45,15 @@ module movemate::acl {

/// @notice Revoke a role for a member in the ACL.
public fun remove_role(acl: &mut ACL, member: address, role: u8) {
assert!(role < 128, errors::invalid_argument(EROLE_NUMBER_TOO_LARGE));
assert!(role < 128, EROLE_NUMBER_TOO_LARGE);
if (vec_map::contains(&acl.permissions, &member)) {
let perms = vec_map::get_mut(&mut acl.permissions, &member);
*perms = *perms - (1 << role);
}
}

#[test_only]
struct TestACL has key {
struct TestACL has store {
acl: ACL
}

Expand All @@ -79,7 +77,6 @@ module movemate::acl {
i = i + 1;
};

// can't drop so must store
sui::transfer::share_object(TestACL { acl });
let ACL { permissions: _ } = acl;
}
}
25 changes: 12 additions & 13 deletions sui/sources/bloom_filter.move
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
/// @title bloom_filter
/// @dev Probabilistic data structure for checking if an element is part of a set.
module movemate::bloom_filter {
use std::errors;
use std::hash;
use std::vector;

use movemate::u256::{Self, U256};
use movemate::u256_type::{Self, U256};

const EHASH_COUNT_IS_ZERO: u64 = 0;
const EVECTOR_LENGTH_NOT_32: u64 = 1;
const EHASH_COUNT_IS_ZERO: u64 = 0x10000;
const EVECTOR_LENGTH_NOT_32: u64 = 0x10001;

struct Filter has copy, drop, store {
bitmap: U256,
Expand All @@ -30,15 +29,15 @@ module movemate::bloom_filter {
/// @param _hash_count How many times to hash. You should use the same value with the one which is used for the original bitmap.
/// @param _item Hash value of an item
public fun add_to_bitmap(_bitmap: U256, _hash_count: u8, _item: vector<u8>): U256 {
assert!(_hash_count > 0, errors::invalid_argument(EHASH_COUNT_IS_ZERO));
assert!(vector::length(&_item) == 32, errors::invalid_argument(EVECTOR_LENGTH_NOT_32));
assert!(_hash_count > 0, EHASH_COUNT_IS_ZERO);
assert!(vector::length(&_item) == 32, EVECTOR_LENGTH_NOT_32);
let i: u8 = 0;
vector::push_back(&mut _item, 0);
while (i < _hash_count) {
*vector::borrow_mut(&mut _item, 32) = i;
let position = vector::pop_back(&mut hash::sha2_256(_item));
let digest = u256::shl(u256::from_u128(1), position);
_bitmap = u256::or(&_bitmap, &digest);
let digest = u256_type::shl(u256_type::from_u128(1), position);
_bitmap = u256_type::or(&_bitmap, &digest);
i = i + 1;
};
_bitmap
Expand All @@ -49,15 +48,15 @@ module movemate::bloom_filter {
/// @param _hash_count How many times to hash. You should use the same value with the one which is used for the original bitmap.
/// @param _item Hash value of an item
public fun false_positive(_bitmap: U256, _hash_count: u8, _item: vector<u8>): bool {
assert!(_hash_count > 0, errors::invalid_argument(EHASH_COUNT_IS_ZERO));
assert!(vector::length(&_item) == 32, errors::invalid_argument(EVECTOR_LENGTH_NOT_32));
assert!(_hash_count > 0, EHASH_COUNT_IS_ZERO);
assert!(vector::length(&_item) == 32, EVECTOR_LENGTH_NOT_32);
let i: u8 = 0;
vector::push_back(&mut _item, 0);
while (i < _hash_count) {
*vector::borrow_mut(&mut _item, 32) = i;
let position = vector::pop_back(&mut hash::sha2_256(_item));
let digest = u256::shl(u256::from_u128(1), position);
if (_bitmap != u256::or(&_bitmap, &digest)) return false;
let digest = u256_type::shl(u256_type::from_u128(1), position);
if (_bitmap != u256_type::or(&_bitmap, &digest)) return false;
i = i + 1;
};
true
Expand All @@ -67,7 +66,7 @@ module movemate::bloom_filter {
/// @param _itemNum Expected number of items to be added
public fun new(_item_num: u64): Filter {
Filter {
bitmap: u256::zero(),
bitmap: u256_type::zero(),
hash_count: get_hash_count(_item_num)
}
}
Expand Down
18 changes: 9 additions & 9 deletions sui/sources/box.move
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/// @title box
/// @notice Generalized box for transferring objects that only have `store` but not `key`.
module movemate::box {
use sui::object::{Self, Info};
use sui::object::{Self, UID};
use sui::transfer;
use sui::tx_context::{Self, TxContext};

struct Box<T: store> has key, store {
info: Info,
id: UID,
obj: T
}

struct PrivateBox<T: store> has key, store {
info: Info,
id: UID,
obj: T,
sender: address
}
Expand All @@ -20,7 +20,7 @@ module movemate::box {
/// @param recipient The destination address of the box object.
public entry fun box<T: store>(recipient: address, obj_in: T, ctx: &mut TxContext) {
let box = Box<T> {
info: object::new(ctx),
id: object::new(ctx),
obj: obj_in
};
transfer::transfer(box, recipient);
Expand All @@ -29,18 +29,18 @@ module movemate::box {
/// @dev Unboxes the object inside the box.
public fun unbox<T: store>(box: Box<T>): T {
let Box {
info: info,
id: id,
obj: obj,
} = box;
object::delete(info);
object::delete(id);
obj
}

/// @dev Stores the sent object in a private box object. (Private box = stores the sender in the sender property.)
/// @param recipient The destination address of the box object.
public entry fun box_private<T: store>(recipient: address, obj_in: T, ctx: &mut TxContext) {
let box = PrivateBox<T> {
info: object::new(ctx),
id: object::new(ctx),
obj: obj_in,
sender: tx_context::sender(ctx)
};
Expand All @@ -50,11 +50,11 @@ module movemate::box {
/// @dev Unboxes the object inside the private box. (Private box = stores the sender in the sender property.)
public fun unbox_private<T: store>(box: PrivateBox<T>): T {
let PrivateBox {
info: info,
id: id,
obj: obj,
sender: _
} = box;
object::delete(info);
object::delete(id);
obj
}
}
Loading