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

task5 #2120

Merged
merged 3 commits into from
Dec 9, 2024
Merged

task5 #2120

Show file tree
Hide file tree
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
58 changes: 58 additions & 0 deletions mover/krypton/code/task5/sources/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# @generated by Move, please check-in and do not edit manually.

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

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

[[move.package]]
id = "Sui"
source = { git = "https://gitee.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.37.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0xde9a45b9e568c4c687bada719f26de89da8a114ae72b17f8c278a88e520afdcd"
latest-published-id = "0xde9a45b9e568c4c687bada719f26de89da8a114ae72b17f8c278a88e520afdcd"
published-version = "1"

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

[dependencies]
Sui = { git = "https://gitee.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]
swap = "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"

100 changes: 100 additions & 0 deletions mover/krypton/code/task5/sources/swap.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module swap::swap;

use faucetcoin::krypton_faucet_coin::KRYPTON_FAUCET_COIN;
use mycoin::krypton_coin::KRYPTON_COIN;
use sui::balance::{Self,Balance};
use sui::transfer::{transfer,share_object,public_transfer};
use sui::coin::{Self,Coin};
// 定义管理员能力
public struct AdminCap has key{
id: UID
}

// 定义银行结构体
public struct Bank has key{
id: UID,
krypton:Balance<KRYPTON_COIN>,
krypton_faucet_coin:Balance<KRYPTON_FAUCET_COIN>
}

fun init(ctx:&mut TxContext){
let bank = Bank {
id:object::new(ctx),
krypton:balance::zero<KRYPTON_COIN>(),
krypton_faucet_coin:balance::zero<KRYPTON_FAUCET_COIN>()
};
share_object(bank);
let admin_cap = AdminCap { id:object::new(ctx) };
transfer(admin_cap,ctx.sender());
}

public entry fun deposit(
_:&AdminCap,
bank:&mut Bank,
krypton:Coin<KRYPTON_COIN>,
_:&mut TxContext
){
let krypton_balance = coin::into_balance(krypton);
balance::join(&mut bank.krypton, krypton_balance);
}

public entry fun deposit_faucet(
_:&AdminCap,
bank:&mut Bank,
krypton_faucet_coin:Coin<KRYPTON_FAUCET_COIN>,
_:&mut TxContext
){
let krypton_faucet_balance = coin::into_balance(krypton_faucet_coin);
balance::join(&mut bank.krypton_faucet_coin, krypton_faucet_balance);
}

public entry fun withdraw(
_:&AdminCap,
bank:&mut Bank,
amount:u64,
ctx:&mut TxContext
){
let krypton_balance = balance::split(&mut bank.krypton, amount);
let krypton= coin::from_balance(krypton_balance, ctx);
public_transfer(krypton,ctx.sender());
}

public entry fun withdraw_krypton_faucet(
_:&AdminCap,
bank:&mut Bank,
amount:u64,
ctx:&mut TxContext
){
let krypton_faucet_balance = balance::split(&mut bank.krypton_faucet_coin, amount);
let krypton_faucet_coin= coin::from_balance(krypton_faucet_balance, ctx);
public_transfer(krypton_faucet_coin,ctx.sender());
}

public entry fun swap_a_to_b(
bank:&mut Bank,
krypton:Coin<KRYPTON_COIN>,
ctx:&mut TxContext
){
let amount = coin::value(&krypton);
balance::join(&mut bank.krypton, coin::into_balance(krypton));

let amount_end = amount * 2;
let faucet = balance::split(&mut bank.krypton_faucet_coin, amount_end);
public_transfer(coin::from_balance(faucet, ctx), ctx.sender());

}


public entry fun swap_b_to_a(
bank:&mut Bank,
krypton_faucet_coin:Coin<KRYPTON_FAUCET_COIN>,
ctx:&mut TxContext
){
let amount = coin::value(&krypton_faucet_coin);
balance::join(&mut bank.krypton_faucet_coin, coin::into_balance(krypton_faucet_coin));

let amount_end = amount / 2;
let krypton = balance::split(&mut bank.krypton, amount_end);
public_transfer(coin::from_balance(krypton, ctx), ctx.sender());

}
102 changes: 102 additions & 0 deletions mover/krypton/code/task6/my-first-sui-dapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Sui dApp Starter Template

This dApp was created using `@mysten/create-dapp` that sets up a basic React
Client dApp using the following tools:

- [React](https://react.dev/) as the UI framework
- [TypeScript](https://www.typescriptlang.org/) for type checking
- [Vite](https://vitejs.dev/) for build tooling
- [Radix UI](https://www.radix-ui.com/) for pre-built UI components
- [ESLint](https://eslint.org/) for linting
- [`@mysten/dapp-kit`](https://sdk.mystenlabs.com/dapp-kit) for connecting to
wallets and loading data
- [pnpm](https://pnpm.io/) for package management

For a full guide on how to build this dApp from scratch, visit this
[guide](http://docs.sui.io/guides/developer/app-examples/e2e-counter#frontend).

## Deploying your Move code

### Install Sui cli

Before deploying your move code, ensure that you have installed the Sui CLI. You
can follow the [Sui installation instruction](https://docs.sui.io/build/install)
to get everything set up.

This template uses `testnet` by default, so we'll need to set up a testnet
environment in the CLI:

```bash
sui client new-env --alias testnet --rpc https://fullnode.testnet.sui.io:443
sui client switch --env testnet
```

If you haven't set up an address in the sui client yet, you can use the
following command to get a new address:

```bash
sui client new-address secp256k1
```

This well generate a new address and recover phrase for you. You can mark a
newly created address as you active address by running the following command
with your new address:

```bash
sui client switch --address 0xYOUR_ADDRESS...
```

We can ensure we have some Sui in our new wallet by requesting Sui from the
faucet (make sure to replace the address with your address):

```bash
curl --location --request POST 'https://faucet.testnet.sui.io/gas' \
--header 'Content-Type: application/json' \
--data-raw '{
"FixedAmountRequest": {
"recipient": "<YOUR_ADDRESS>"
}
}'
```

### Publishing the move package

The move code for this template is located in the `move` directory. To publish
it, you can enter the `move` directory, and publish it with the Sui CLI:

```bash
cd move
sui client publish --gas-budget 100000000 counter
```

In the output there will be an object with a `"packageId"` property. You'll want
to save that package ID to the `src/constants.ts` file as `PACKAGE_ID`:

```ts
export const TESTNET_COUNTER_PACKAGE_ID = "<YOUR_PACKAGE_ID>";
```

Now that we have published the move code, and update the package ID, we can
start the app.

## Starting your dApp

To install dependencies you can run

```bash
pnpm install
```

To start your dApp in development mode run

```bash
pnpm dev
```

## Building

To build your app for deployment you can run

```bash
pnpm build
```
59 changes: 59 additions & 0 deletions mover/krypton/code/task6/my-first-sui-dapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!doctype html>
<html lang="en" class="dark-theme" style="color-scheme: dark">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sui dApp Starter</title>

<style>
/*
Josh's Custom CSS Reset
https://www.joshwcomeau.com/css/custom-css-reset/
*/
*,
*::before,
*::after {
box-sizing: border-box;
}
* {
margin: 0;
}
body {
line-height: 1.5;
-webkit-font-smoothing: antialiased;
}
img,
picture,
video,
canvas,
svg {
display: block;
max-width: 100%;
}
input,
button,
textarea,
select {
font: inherit;
}
p,
h1,
h2,
h3,
h4,
h5,
h6 {
overflow-wrap: break-word;
}
#root,
#__next {
isolation: isolate;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions mover/krypton/code/task6/my-first-sui-dapp/move/counter/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "3700BE3663FD5EAE7AF34BC8B36CFF2AA9C8D280DDEE9324B30BE9F9BFDDD64D"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

[[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.toolchain-version]
compiler-version = "1.37.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0xbbb65cbb84a0bcc7cebedee7ed1c64f268553c29dc8d23127a68dd35b7fb1093"
latest-published-id = "0xbbb65cbb84a0bcc7cebedee7ed1c64f268553c29dc8d23127a68dd35b7fb1093"
published-version = "1"
Loading
Loading