Skip to content

Commit

Permalink
Merge pull request #2038 from StarryDeserts/main
Browse files Browse the repository at this point in the history
完成task5, 6, 7, 8
  • Loading branch information
Sifotd authored Nov 30, 2024
2 parents 5aa13fb + 76ade1d commit 63077b2
Show file tree
Hide file tree
Showing 35 changed files with 10,707 additions and 25 deletions.
34 changes: 34 additions & 0 deletions mover/StarryDeserts/code/task5/starrydesert_swap/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 = "3372AAA79A795030CB3B12FDA5EC278FC69C9F8981E0E8833940E9C90ED91EF2"
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.3"
edition = "2024.beta"
flavor = "sui"

[env]

[env.mainnet]
chain-id = "35834a8a"
original-published-id = "0x1c1c72e45be1507bfdf20d8c5eead4e14da8062d6ccbc319d9d54b520af076e9"
latest-published-id = "0x1c1c72e45be1507bfdf20d8c5eead4e14da8062d6ccbc319d9d54b520af076e9"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/StarryDeserts/code/task5/starrydesert_swap/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "starrydesert_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 ([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" }

# 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]
starrydesert_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"

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module starrydesert_swap::sd_coin {
use sui::coin::{Self, Coin, TreasuryCap};
use sui::url::{Self, Url};

public struct SD_COIN has drop {}

fun init(
witness: SD_COIN,
ctx: &mut TxContext
) {
let (treasury_cap, metadata) = coin::create_currency<SD_COIN>(
witness,
9,
b"SD",
b"SD_COIN",
b"StarryDesert Coin",
option::some<Url>(
url::new_unsafe_from_bytes(
b"https://avatars.githubusercontent.com/u/86464159"
)
),
ctx
);
transfer::public_freeze_object(metadata);
transfer::public_transfer(
treasury_cap,
tx_context::sender(ctx)
)
}

public entry fun mint(
treasury_cap: &mut TreasuryCap<SD_COIN>,
amount: u64,
recipient: address,
ctx: &mut TxContext
) {
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

public fun burn(
treasury_cap: &mut TreasuryCap<SD_COIN>,
coin: Coin<SD_COIN>
) {
coin::burn(treasury_cap, coin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module starrydesert_swap::sd_faucet_coin {
use sui::coin::{Self, Coin, TreasuryCap};
use sui::url::{Self, Url};

public struct SD_FAUCET_COIN has drop {}

public struct TreasuryCapHolder has key {
id: UID,
treasury_cap: TreasuryCap<SD_FAUCET_COIN>,
}

fun init(
witness: SD_FAUCET_COIN,
ctx: &mut TxContext
) {
let (treasury_cap, metadata) = coin::create_currency<SD_FAUCET_COIN>(
witness,
9,
b"SDF",
b"SD_FAUCET_COIN",
b"StarryDesert Faucet Coin",
option::some<Url>(
url::new_unsafe_from_bytes(
b"https://avatars.githubusercontent.com/u/86464159"
)
),
ctx
);
transfer::public_freeze_object(metadata);

let treasury_cap_holder = TreasuryCapHolder {
id: object::new(ctx),
treasury_cap,
};
transfer::share_object(treasury_cap_holder);
}

public entry fun mint(
treasury_cap_holder: &mut TreasuryCapHolder,
amount: u64,
recipient: address,
ctx: &mut TxContext
) {
let treasury_cap = &mut treasury_cap_holder.treasury_cap;
coin::mint_and_transfer(treasury_cap, amount, recipient, ctx);
}

public fun burn(
treasury_cap: &mut TreasuryCap<SD_FAUCET_COIN>,
coin: Coin<SD_FAUCET_COIN>
) {
coin::burn(treasury_cap, coin);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module starrydesert_swap::swap {
use sui::coin::{Self, Coin};
use starrydesert_swap::sd_coin::SD_COIN;
use starrydesert_swap::sd_faucet_coin::SD_FAUCET_COIN;
use sui::balance::{Self, Balance};

const EInsufficientBalance: u64 = 1000;

public struct Pool has key {
id: UID,
coin_balance: Balance<SD_COIN>,
faucet_balance: Balance<SD_FAUCET_COIN>,
}

fun init(ctx: &mut TxContext) {
let pool = Pool {
id: object::new(ctx),
coin_balance: balance::zero(),
faucet_balance: balance::zero()
};
transfer::share_object(pool);
}

// 填充资金池
public entry fun deposit(
pool: &mut Pool,
coin: &mut Coin<SD_COIN>,
faucet: &mut Coin<SD_FAUCET_COIN>,
coin_amount: u64,
faucet_amount: u64

) {
let split_coin_balance = coin::balance_mut(coin).split(coin_amount);
pool.coin_balance.join(split_coin_balance);
let split_faucet_balance = coin::balance_mut(faucet).split(faucet_amount);
pool.faucet_balance.join(split_faucet_balance);
}

public entry fun swap_coin_to_faucet(
pool: &mut Pool,
coin: &mut Coin<SD_COIN>,
amount: u64,
ctx: &mut TxContext
) {
assert!(
pool.faucet_balance.value() >= amount,
EInsufficientBalance
);
let split_coin_balance = coin::balance_mut(coin).split(amount);
pool.coin_balance.join(split_coin_balance);
let faucet = coin::take(
&mut pool.faucet_balance,
amount,
ctx
);
transfer::public_transfer(faucet, ctx.sender());
}

public entry fun swap_faucet_to_coin(
pool: &mut Pool,
faucet: &mut Coin<SD_FAUCET_COIN>,
amount: u64,
ctx: &mut TxContext
) {
assert!(
pool.coin_balance.value() >= amount,
EInsufficientBalance
);
let split_faucet_balance = coin::balance_mut(faucet).split(amount);
pool.faucet_balance.join(split_faucet_balance);
let coin = coin::take(&mut pool.coin_balance, amount, ctx);
transfer::public_transfer(coin, ctx.sender());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
#[test_only]
module starrydesert_swap::starrydesert_swap_tests;
// uncomment this line to import the module
// use starrydesert_swap::starrydesert_swap;
const ENotImplemented: u64 = 0;
#[test]
fun test_starrydesert_swap() {
// pass
}
#[test, expected_failure(abort_code = ::starrydesert_swap::starrydesert_swap_tests::ENotImplemented)]
fun test_starrydesert_swap_fail() {
abort ENotImplemented
}
*/
1 change: 1 addition & 0 deletions mover/StarryDeserts/code/task6/navi-interacting/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_NETWORK=mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["next/core-web-vitals", "next/typescript"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type": "module"}
3 changes: 3 additions & 0 deletions mover/StarryDeserts/code/task6/navi-interacting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# navi-interacting

This is a Next.js Sui dApp project...
Binary file not shown.
13 changes: 13 additions & 0 deletions mover/StarryDeserts/code/task6/navi-interacting/app/fonts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import localFont from "next/font/local";

export const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
weight: "100 900",
});

export const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
weight: "100 900",
});
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

body {
font-family: Arial, Helvetica, sans-serif;
}
23 changes: 23 additions & 0 deletions mover/StarryDeserts/code/task6/navi-interacting/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Metadata } from "next";
import "./globals.css";
import { geistSans, geistMono } from "./fonts";
import { Providers } from "./providers";

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`${geistSans.variable} ${geistMono.variable} antialiased`}>
<Providers>{children}</Providers>
</body>
</html>
);
}
27 changes: 27 additions & 0 deletions mover/StarryDeserts/code/task6/navi-interacting/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ConnectButton, useCurrentAccount } from "@mysten/dapp-kit";
import { Box, Flex, Heading } from "@radix-ui/themes";
import NaviPage from "../components/navi";
export default function Home() {
useCurrentAccount();
return (
<>
<Flex
position="sticky"
px="4"
py="2"
justify="between"
style={{
borderBottom: "1px solid var(--gray-a2)",
}}
>
<Box>
<Heading>Generated by create next dApp Starter Template</Heading>
</Box>
<Box>
<ConnectButton />
</Box>
</Flex>
<NaviPage />
</>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use client'

import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { SuiClientProvider, WalletProvider } from "@mysten/dapp-kit";
import { networkConfig, network } from "@/config"
import "@mysten/dapp-kit/dist/index.css";

const queryClient = new QueryClient();

export function Providers({ children }: { children: React.ReactNode }) {
return (
<QueryClientProvider client={queryClient}>
<SuiClientProvider networks={networkConfig} defaultNetwork={network}>
<WalletProvider>
{children}
</WalletProvider>
</SuiClientProvider>
</QueryClientProvider>
);
}
Loading

0 comments on commit 63077b2

Please sign in to comment.