-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathxbtc.move
85 lines (75 loc) · 2.09 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
/// Copyright 2022 OmniBTC Authors. Licensed under Apache-2.0 License.
module owner::xbtc {
use std::string::utf8;
use aptos_framework::coin::{
Self, BurnCapability, FreezeCapability, MintCapability
};
friend owner::bridge;
/// XBTC define
////////////////////////
struct XBTC {}
////////////////////////
/// Capabilities resource storing mint and burn capabilities.
/// The resource is stored on the account that initialized coin `CoinType`.
struct Capabilities has key {
burn_cap: BurnCapability<XBTC>,
freeze_cap: FreezeCapability<XBTC>,
mint_cap: MintCapability<XBTC>,
}
/// A helper function
public fun has_capabilities(
account: address
):bool {
exists<Capabilities>(account)
}
/// Issue XBTC
/// Call by bridge
public(friend) fun issue(
account: &signer,
) {
let (burn_cap, freeze_cap, mint_cap) = coin::initialize<XBTC>(
account,
utf8(b"XBTC"),
utf8(b"XBTC"),
8,
true, // always monitor supply
);
move_to(
account,
Capabilities {
burn_cap,
freeze_cap,
mint_cap,
}
);
}
/// Mint XBTC to receiver
/// Call by bridge
public(friend) fun deposit(
admin: address,
receiver: address,
amount: u64,
) acquires Capabilities {
let capabilities = borrow_global<Capabilities>(admin);
let coins_minted = coin::mint(amount, &capabilities.mint_cap);
coin::deposit(receiver, coins_minted);
}
/// Register XBTC account
/// The same as 0x1::manged_coin::register
/// Call by user
public entry fun register(
account: &signer
) {
coin::register<XBTC>(account);
}
/// Transfer XBTC
/// The same as 0x1::coin::transfer
/// Call by user
public entry fun transfer(
sender: &signer,
receiver: address,
amount: u64,
){
coin::transfer<XBTC>(sender, receiver, amount)
}
}