-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathxbtc.move
92 lines (82 loc) · 2.2 KB
/
xbtc.move
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/// Copyright 2022 OmniBTC Authors. Licensed under Apache-2.0 License.
module owner::xbtc {
use std::string::{utf8, String};
use sui::coin::{Self, Coin, TreasuryCap};
use sui::tx_context::{Self, TxContext};
use sui::object::{Self, UID};
use sui::transfer;
use sui::pay;
friend owner::bridge;
/// XBTC define
////////////////////////
struct XBTC has drop {}
////////////////////////
/// XBTC meta info
struct XBTCInfo has key {
id: UID,
name: String,
symbol: String,
decimals: u8,
}
/// Register XBTC while publishing
/// Call by bridge
fun init(
ctx: &mut TxContext
) {
let treasury_cap = coin::create_currency<XBTC>(XBTC{}, 8, ctx);
transfer::transfer(treasury_cap, tx_context::sender(ctx));
transfer::freeze_object(
XBTCInfo {
id: object::new(ctx),
name: utf8(b"XBTC"),
symbol: utf8(b"XBTC"),
decimals: 8
}
);
}
/// Mint XBTC to receiver
/// Call by bridge
public(friend) fun deposit(
treasury_cap: &mut TreasuryCap<XBTC>,
receiver: address,
amount: u64,
ctx: &mut TxContext
) {
let coins_minted = coin::mint<XBTC>(treasury_cap, amount, ctx);
transfer::transfer(coins_minted, receiver)
}
/// Join XBTC in `coins` with `self`
/// The same as coin::join_vec
/// Call by user
public entry fun join_vec(
self: &mut Coin<XBTC>,
coins: vector<Coin<XBTC>>
) {
pay::join_vec(self, coins)
}
/// Consume XBTC and add its value to `self`.
/// The same as coin::join
/// Call by user
public entry fun join(
self: &mut Coin<XBTC>,
coin: Coin<XBTC>
) {
coin::join(self, coin)
}
/// Send XBTC to receiver
/// The same as coin::split_and_transfer
/// Call by user
public entry fun split_and_transfer(
xbtc: &mut Coin<XBTC>,
amount: u64,
receiver: address,
ctx: &mut TxContext
) {
pay::split_and_transfer(
xbtc,
amount,
receiver,
ctx
)
}
}