Last active
March 4, 2023 15:39
-
-
Save sascha1337/5e924b2c428a4ff59cfabbe5afbd87d4 to your computer and use it in GitHub Desktop.
cw20-base.cwscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract CW20Base { | |
error InvalidZeroAmount() | |
error Unauthorized() | |
event Transfer(sender: Addr, recipient: Addr, amount: u64) | |
event Burn(sender: Addr, amount: u64) | |
event Mint(minter: Addr, recipient: Addr, amount: u64) | |
event Send(sender: Addr, contract: Addr, amount: u64) | |
struct TokenInfo { | |
name: String, | |
symbol: String, | |
decimals: u64, | |
total_supply: u64, | |
} | |
state { | |
token_info: TokenInfo, | |
balances[Addr]: u64 | |
} | |
instantiate( | |
name: String, | |
symbol: String, | |
decimals: u64, | |
initial_balances: struct Cw20Coin { address: Addr, amount: u64 }[], | |
mint?: String | |
) { | |
let total_supply = 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: u64) { | |
// state.balances[msg.sender] = state.balances[msg.sender] + amount | |
// state.balances[recipient] = state.balances[recipient] + amount | |
// // emit Transfer(msg.sender, recipient, amount) | |
// } | |
// exec burn(amount: u64) { | |
// state.balances[msg.sender] = state.balances[msg.sender] - amount | |
// state.token_info.total_supply = state.token_info.total_supply - amount | |
// // emit Burn(msg.sender, amount) | |
// } | |
exec mint(recipient: Addr, amount: u64) | |
{ | |
// state.balances[recipient] = state.balances[recipient] + amount | |
let token_info = state.token_info | |
token_info.total_supply = token_info.total_supply + amount | |
token_info.decimals = 8 | |
state.token_info = token_info | |
emit Mint(recipient, amount) | |
} | |
query balance(address: Addr) -> struct BalanceResponse { balance: u64 } { | |
return BalanceResponse { | |
balance: state.balances[address] | |
} | |
} | |
query token_info() -> struct TokenInfoResponse { token_info: TokenInfo } { | |
return TokenInfoResponse { | |
token_info: state.token_info | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment