Skip to content

Commit

Permalink
add task5
Browse files Browse the repository at this point in the history
  • Loading branch information
brainks committed Nov 22, 2024
1 parent f28d138 commit a3f6a6a
Show file tree
Hide file tree
Showing 7 changed files with 644 additions and 3 deletions.
9 changes: 9 additions & 0 deletions mover/brainsk/code/task5/brainsk/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

deposit_mycoin:
sui client call --package 0x8fce92f5a9044de1b3b19a622c2f2beb74c080321612ca546a8ddfbae089c264 --module brainsk --function deposit_mycoin --args 0x38c79f4b37e56ec98cfdd56c72faea011d4dab9eae0775c399ff975ac003a1c8 0x05f29334ed951b1748ddd65e502056175a83582b077949ad4299670449f3a430
deposit_faucetcoin:
sui client call --package 0x8fce92f5a9044de1b3b19a622c2f2beb74c080321612ca546a8ddfbae089c264 --module brainsk --function deposit_faucetcoin --args 0x38c79f4b37e56ec98cfdd56c72faea011d4dab9eae0775c399ff975ac003a1c8 0xa404c780507a31981dc02c3ed95cf63965f78a66c3963c6065d432ca7b71971f
faucte_swap_my:
sui client call --package 0x8fce92f5a9044de1b3b19a622c2f2beb74c080321612ca546a8ddfbae089c264 --module brainsk --function faucte_swap_my --args 0x38c79f4b37e56ec98cfdd56c72faea011d4dab9eae0775c399ff975ac003a1c8 0xc0b59caa882ecc24c77bb0848c893b0fbfdf419bc52b592329fdb634564a30cb
my_swap_faucet:
sui client call --package 0x8fce92f5a9044de1b3b19a622c2f2beb74c080321612ca546a8ddfbae089c264 --module brainsk --function my_swap_faucet --args 0x38c79f4b37e56ec98cfdd56c72faea011d4dab9eae0775c399ff975ac003a1c8 0xc77d969fdc7b17f7e4fcb609277772c58191ddb53208ce8ded44fab3626d28c5
52 changes: 52 additions & 0 deletions mover/brainsk/code/task5/brainsk/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "7E391F177F35AAA09364D249E82FC27924488069285497FF7FBD9FA8534BC6A6"
deps_digest = "060AD7E57DFB13104F21BE5F5C3759D03F0553FC3229247D9A7A6B45F50D03A3"
dependencies = [
{ id = "Sui", name = "Sui" },
{ id = "faucetcoin", name = "faucetcoin" },
{ id = "mycoin", name = "mycoin" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[[move.package]]
id = "faucetcoin"
source = { local = "../../task2/faucetcoin" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "mycoin"
source = { local = "../../task2/mycoin" }

dependencies = [
{ id = "Sui", name = "Sui" },
]

[move.toolchain-version]
compiler-version = "1.38.0"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x8fce92f5a9044de1b3b19a622c2f2beb74c080321612ca546a8ddfbae089c264"
latest-published-id = "0x8fce92f5a9044de1b3b19a622c2f2beb74c080321612ca546a8ddfbae089c264"
published-version = "1"
38 changes: 38 additions & 0 deletions mover/brainsk/code/task5/brainsk/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
name = "brainsk"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith ([email protected])", "John Snow ([email protected])"]

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }
faucetcoin = { local = "../../task2/faucetcoin" }
mycoin = { local = "../../task2/mycoin" }
# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }

# For local dependencies use `local = path`. Path is relative to the package root
# Local = { local = "../path/to" }

# To resolve a version conflict and force a specific version for dependency
# override use `override = true`
# Override = { local = "../conflicting/version", override = true }

[addresses]
brainsk = "0x0"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
# alice = "0xA11CE"

[dev-dependencies]
# The dev-dependencies section allows overriding dependencies for `--test` and
# `--dev` modes. You can introduce test-only dependencies here.
# Local = { local = "../path/to/dev-build" }

[dev-addresses]
# The dev-addresses section allows overwriting named addresses for the `--test`
# and `--dev` modes.
# alice = "0xB0B"

76 changes: 76 additions & 0 deletions mover/brainsk/code/task5/brainsk/sources/brainsk.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

/// Module: brainsk
module brainsk::brainsk{
use sui::coin::{Self, Coin};
use sui::balance::{Self, Balance};
use sui::transfer::{Self, transfer, share_object, public_transfer};
use mycoin::mycoin::MYCOIN;
use faucetcoin::faucetcoin::FAUCETCOIN;
use sui::tx_context::sender;

public struct BrainskSwapBank has key {
id: UID,
faucetcoin: Balance<FAUCETCOIN>,
mycoin: Balance<MYCOIN>,
mc_prop: u64,
fc_prop: u64
}

public struct AdaminCap has key {
id: UID
}

fun init(ctx: &mut TxContext) {
let bank = BrainskSwapBank {
id: object::new(ctx),
faucetcoin: balance::zero<FAUCETCOIN>(),
mycoin: balance::zero<MYCOIN>(),
mc_prop: 1000,
fc_prop: 7300
};
share_object(bank);
let adamin_cap = AdaminCap {
id: object::new(ctx)
};
transfer(adamin_cap, sender(ctx));
}

public entry fun deposit_mycoin(bank: &mut BrainskSwapBank, mycoin: Coin<MYCOIN>, _ctx: &mut TxContext) {
let balance = coin::into_balance(mycoin);
bank.mycoin.join(balance);
}

public entry fun deposit_faucetcoin(bank: &mut BrainskSwapBank, faucetcoin: Coin<FAUCETCOIN>, _ctx: &mut TxContext) {
let balance = coin::into_balance(faucetcoin);
bank.faucetcoin.join(balance);
}

public entry fun withdraw_mycoin(_: &AdaminCap, bank: &mut BrainskSwapBank, amount: u64, ctx: &mut TxContext) {
let amount = bank.mycoin.split(amount);
let mycoin = coin::from_balance(amount, ctx);
public_transfer(mycoin, sender(ctx));
}

public entry fun withdraw_faucetcoin(_: &AdaminCap, bank: &mut BrainskSwapBank, amount: u64, ctx: &mut TxContext) {
let amount = bank.mycoin.split(amount);
let mycoin = coin::from_balance(amount, ctx);
public_transfer(mycoin, sender(ctx));
}

public entry fun faucte_swap_my(bank: &mut BrainskSwapBank, faucetcoin: Coin<FAUCETCOIN>, ctx: &mut TxContext) {
let fc_balance = faucetcoin.into_balance();
let fc_amt = fc_balance.value();
let mc_amt = bank.mycoin.split(fc_amt * bank.mc_prop / bank.fc_prop);
bank.faucetcoin.join(fc_balance);
public_transfer(coin::from_balance(mc_amt, ctx), sender(ctx));
}

public entry fun my_swap_faucet(bank: &mut BrainskSwapBank, mycoin: Coin<MYCOIN>, ctx: &mut TxContext) {
let mc_balance = mycoin.into_balance();
let mc_amt = mc_balance.value();
let fc_amt = bank.faucetcoin.split(mc_amt * bank.fc_prop / bank.mc_prop);
bank.mycoin.join(mc_balance);
public_transfer(coin::from_balance(fc_amt, ctx), sender(ctx));
}
}

18 changes: 18 additions & 0 deletions mover/brainsk/code/task5/brainsk/tests/brainsk_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module brainsk::brainsk_tests;
// uncomment this line to import the module
// use brainsk::brainsk;
const ENotImplemented: u64 = 0;
#[test]
fun test_brainsk() {
// pass
}
#[test, expected_failure(abort_code = ::brainsk::brainsk_tests::ENotImplemented)]
fun test_brainsk_fail() {
abort ENotImplemented
}
*/
Loading

0 comments on commit a3f6a6a

Please sign in to comment.