|
1 |
| -# Secret-SCRT - Privacy coin backed by SCRT |
| 1 | +# SNIP-20 Reference Implementation |
2 | 2 |
|
3 |
| -This is a PoC of how to create a privacy token on the Secret Network backed by a native coin. |
| 3 | +This is an implementation of a SNIP-20 compliant token contract. At the time of token creation you may configure: |
| 4 | +* Public Total Supply: If you enable this, the token's total supply will be displayed whenever a TokenInfo query is performed. DEFAULT: false |
| 5 | +* Enable Deposit: If you enable this, you will be able to convert from SCRT to the token.* DEFAULT: false |
| 6 | +* Enable Redeem: If you enable this, you will be able to redeem your token for SCRT.* It should be noted that if you have redeem enabled, but deposit disabled, all redeem attempts will fail unless someone has sent SCRT to the token contract. DEFAULT: false |
| 7 | +* Enable Mint: If you enable this, any address in the list of minters will be able to mint new tokens. The admin address is the default minter, but can use the set/add/remove_minters functions to change the list of approved minting addresses. DEFAULT: false |
| 8 | +* Enable Burn: If you enable this, addresses will be able to burn tokens. DEFAULT: false |
4 | 9 |
|
5 |
| -Usage is pretty simple - you deposit SCRT into the contract, and you get SSCRT (or Secret-SCRT), which you can then use with the ERC-20-like functionality that the contract provides including: sending/receiving/allowance and withdrawing back to SCRT. |
6 | 10 |
|
7 |
| -In terms of privacy the deposit & withdrawals are public, as they are transactions on-chain. The rest of the functionality is private (so no one can see if you send SSCRT and to whom, and receiving SSCRT is also hidden). |
8 |
| - |
9 |
| -The code was updated with a new mechanism, which I call viewing keys. This allows a user to generate a key that enables off-chain queries. This way you can perform balance and transaction history queries without waiting for a transaction on-chain. The tranaction to create a viewing key is expensive, to the tune of about 3M gas. This is intended to make queries take a long time to execute to be resistant to brute-force attacks. |
10 |
| - |
11 |
| -The usual disclaimer: Don't use this in production, I take no responsibility for anything anywhere anytime etc. |
| 11 | +\*:The conversion rate will be 1 uscrt for 1 minimum denomination of the token. This means that if your token has 6 decimal places, it will convert 1:1 with SCRT. If your token has 10 decimal places, it will have an exchange rate of 10000 SCRT for 1 token. If your token has 3 decimal places, it will have an exchange rate of 1000 tokens for 1 SCRT. You can use the exchange_rate query to view the exchange rate for the token. The query response will display either how many tokens are worth 1 SCRT, or how many SCRT are worth 1 token. That is, the response lists the symbol of the coin that has less value (either SCRT or the token), and the number of those coins that are worth 1 of the other. |
12 | 12 |
|
13 | 13 | ## Usage examples:
|
14 | 14 |
|
15 |
| -To deposit: ***(This is public)*** |
| 15 | +To create a new token: |
16 | 16 |
|
17 |
| -```./secretcli tx compute execute <contract-address> '{"deposit": {}}' --amount 1000000uscrt --from <account>``` |
| 17 | +```secretcli tx compute instantiate <code-id> '{"name":"<your_token_name>","symbol":"<your_token_symbol>","admin":"<optional_admin_address_defaults_to_the_from_address>","decimals":<number_of_decimals>,"initial_balances":[{"address":"<address1>","amount":"<amount_for_address1>"}],"prng_seed":"<base64_encoded_string>","config":{"public_total_supply":<true_or_false>,"enable_deposit":<true_or_false>,"enable_redeem":<true_or_false>,"enable_mint":<true_or_false>,"enable_burn":<true_or_false>}}' --label <token_label> --from <account>``` |
18 | 18 |
|
19 |
| -To send SSCRT: ***(Only you will be able to see the parameters you send here)*** |
| 19 | +The `admin` field is optional and will default to the "--from" address if you do not specify it. The `initial_balances` field is optional, and you can specify as many addresses/balances as you like. The `config` field as well as every field in the `config` is optional. Any `config` fields not specified will default to `false`. |
20 | 20 |
|
21 |
| -```./secretcli tx compute execute <contract-address> '{"transfer": {"recipient": "<destination_address>", "amount": "<amount_to_send>"}}' --from <account>``` |
| 21 | +To deposit: ***(This is public)*** |
22 | 22 |
|
23 |
| -To check your balance: ***(Only you will be able to see the parameters you send here)*** |
| 23 | +```secretcli tx compute execute <contract-address> '{"deposit": {}}' --amount 1000000uscrt --from <account>``` |
24 | 24 |
|
25 |
| -```./secretcli tx compute execute <contract-address> '{"balance": {}}' --from <account>``` |
| 25 | +To send SSCRT: |
26 | 26 |
|
27 |
| -```./secretcli q compute tx <returned tx-hash> --trust-node``` |
| 27 | +```secretcli tx compute execute <contract-address> '{"transfer": {"recipient": "<destination_address>", "amount": "<amount_to_send>"}}' --from <account>``` |
28 | 28 |
|
29 |
| -To withdraw: ***(This is public)*** |
| 29 | +To set your viewing key: |
30 | 30 |
|
31 |
| -```./secretcli tx compute execute <contract-address> '{"withdraw": {"amount": "<amount in uscrt>"}}' --from <account>``` |
| 31 | +```secretcli tx compute execute <contract-address> '{"create_viewing_key": {"entropy": "<random_phrase>"}}' --from <account>``` |
32 | 32 |
|
33 |
| -To set your viewing key: |
| 33 | +To check your balance: |
34 | 34 |
|
35 |
| -```./secretcli tx compute execute <contract-address> '{"create_viewing_key": {"entropy": "<random_phrase>"}}' --from <account>``` |
| 35 | +```secretcli q compute query <contract-address> '{"balance": {"address":"<your_address>", "key":"your_viewing_key"}}'``` |
36 | 36 |
|
37 |
| -This transaction will be expensive, so set your gas limit to about 3M with `--gas 3000000` |
| 37 | +To view your transaction history: |
38 | 38 |
|
39 |
| -Make your random phrase as long as you want. At least 15 characters are recommended. You do not have to remember it - it will simply be used to randomize your generated viewing key. After this is done you can get your viewing key: |
| 39 | +```secretcli q compute query <contract-address> '{"transfer_history": {"address": "<your_address>", "key": "<your_viewing_key>", "page": <optional_page_number>, "page_size": <number_of_transactions_to_return>}}'``` |
40 | 40 |
|
41 |
| -```./secretcli q compute tx <returned tx-hash>``` |
| 41 | +To withdraw: ***(This is public)*** |
42 | 42 |
|
43 |
| -The key will start with the prefix `api_key_....` |
| 43 | +```secretcli tx compute execute <contract-address> '{"redeem": {"amount": "<amount_in_smallest_denom_of_token>"}}' --from <account>``` |
44 | 44 |
|
45 |
| -To use your viewing key, you can query your balance or the transaction history: |
| 45 | +To view the token contract's configuration: |
46 | 46 |
|
47 |
| -```./secretcli q compute query <contract-address> '{"balance": {"address": "<your_address>", "viewing_key": "<your_viewing_key>"}}'``` |
| 47 | +```secretcli q compute query <contract-address> '{"token_config": {}}'``` |
48 | 48 |
|
49 |
| -```./secretcli q compute query <contract-address> '{"transfers": {"address": "<your_address>", "viewing_key": "<your_viewing_key>"}}'``` |
| 49 | +To view the deposit/redeem exchange rate: |
50 | 50 |
|
51 |
| -## Play with it on testnet |
| 51 | +```secretcli q compute query <contract-address> '{"exchange_rate": {}}'``` |
52 | 52 |
|
53 |
| -The deployed SSCRT contract address on the testnet is `secret1umwqjum7f4zmp9alr2kpmq4y5j4hyxlam896r3` and label `sscrt` |
54 | 53 |
|
55 | 54 | ## Troubleshooting
|
56 | 55 |
|
|
0 commit comments