This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw20base.cws
75 lines (62 loc) · 1.99 KB
/
cw20base.cws
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
contract CW20Base {
error InvalidZeroAmount(Hello, There)
error Unauthorized()
event Transfer(sender: Addr, recipient: Addr, amount: Uint128)
event Burn(sender: Addr, amount: Uint128)
event Mint(minter: Addr, recipient: Addr, amount: Uint128)
event Send(sender: Addr, contract: Addr, amount: Uint128)
struct TokenInfo {
name: String,
symbol: String,
decimals: u8,
total_supply: Uint128,
}
state {
token_info: TokenInfo
balances[Addr]: Uint128
}
instantiate(
name: String,
symbol: String,
decimals: u8,
initial_balances: struct Cw20Coin { address: Addr, amount: Uint128 }[],
mint?: String
) {
let total_supply: Uint128 = Uint128(0)
for { address, amount } in initial_balances {
state.balances[address] += amount
total_supply += amount
}
state.token_info = TokenInfo {
name: name,
symbol: symbol,
decimals: decimals,
total_supply: total_supply,
}
}
exec transfer(recipient: Addr, amount: Uint128) {
state.balances[msg.sender] -= amount
state.balances[recipient] += amount
emit Transfer(msg.sender, recipient, amount)
}
exec burn(amount: Uint128) {
state.balances[msg.sender] -= amount
state.token_info.total_supply -= amount
emit Burn(msg.sender, amount)
}
exec send(contract_addr: Addr, amount: Uint128, msg: Binary) {
state.balances[msg.sender] -= amount
state.balances[contract_addr] += amount
emit Send(msg.sender, contract_addr, amount)
}
query balance(address: Addr) -> struct BalanceResponse { balance: Uint128 } {
return _ {
balance: state.balances[address] or 0
}
}
query token_info() -> struct TokenInfoResponse { token_info: TokenInfo } {
return _ {
token_info: state.token_info
}
}
}