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

[examples] Adds example of a pool + removes entry fun #4544

Merged
merged 1 commit into from
Sep 9, 2022
Merged
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
33 changes: 18 additions & 15 deletions sui_programmability/examples/defi/sources/pool.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
/// - Fees are customizable per Pool.
/// - Max stored value for both tokens is: U64_MAX / 10_000
///
/// To publish a new pool, a type is required. Eg:
/// ```
/// module me::my_pool {
/// use defi::pool;
///
/// struct POOL_TEAM has drop {}
///
/// entry fun create_pool<T>(
/// token: Coin<T>,
/// sui: Coin<SUI>,
/// fee_percent: u64,
/// ctx: &mut TxContext
/// ) {
/// pool::create_pool(POOL_TEAM {}, token, sui, fee_percent, ctx)
/// }
/// }
/// ```
///
/// This solution is rather simple and is based on the example from the Move repo:
/// https://github.com/move-language/move/blob/main/language/documentation/examples/experimental/coin-swap/sources/CoinSwap.move
module defi::pool {
Expand Down Expand Up @@ -68,21 +86,6 @@ module defi::pool {
/// to create a type which will mark LSPs.
fun init(_: &mut TxContext) {}

/// Entrypoint for the `create_pool` method.
entry fun create_pool_<P: drop, T>(
witness: P,
token: Coin<T>,
sui: Coin<SUI>,
// share: u64,
fee_percent: u64,
ctx: &mut TxContext
) {
transfer::transfer(
create_pool(witness, token, sui, /* share, */ fee_percent, ctx),
tx_context::sender(ctx)
)
}

/// Create new `Pool` for token `T`. Each Pool holds a `Coin<T>`
/// and a `Coin<SUI>`. Swaps are available in both directions.
///
Expand Down