Skip to content

Commit 6c2c4f2

Browse files
authored
Merge pull request #3 from baedrik/config_functionality
Adding ability to configure deposit, redeem, mint, and burn functionality during instantiation
2 parents ba682c3 + e029dc3 commit 6c2c4f2

File tree

9 files changed

+1199
-362
lines changed

9 files changed

+1199
-362
lines changed

Cargo.lock

+270-268
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+27-28
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,55 @@
1-
# Secret-SCRT - Privacy coin backed by SCRT
1+
# SNIP-20 Reference Implementation
22

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
49

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.
610

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.
1212

1313
## Usage examples:
1414

15-
To deposit: ***(This is public)***
15+
To create a new token:
1616

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>```
1818

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`.
2020

21-
```./secretcli tx compute execute <contract-address> '{"transfer": {"recipient": "<destination_address>", "amount": "<amount_to_send>"}}' --from <account>```
21+
To deposit: ***(This is public)***
2222

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>```
2424

25-
```./secretcli tx compute execute <contract-address> '{"balance": {}}' --from <account>```
25+
To send SSCRT:
2626

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>```
2828

29-
To withdraw: ***(This is public)***
29+
To set your viewing key:
3030

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>```
3232

33-
To set your viewing key:
33+
To check your balance:
3434

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"}}'```
3636

37-
This transaction will be expensive, so set your gas limit to about 3M with `--gas 3000000`
37+
To view your transaction history:
3838

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>}}'```
4040

41-
```./secretcli q compute tx <returned tx-hash>```
41+
To withdraw: ***(This is public)***
4242

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>```
4444

45-
To use your viewing key, you can query your balance or the transaction history:
45+
To view the token contract's configuration:
4646

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": {}}'```
4848

49-
```./secretcli q compute query <contract-address> '{"transfers": {"address": "<your_address>", "viewing_key": "<your_viewing_key>"}}'```
49+
To view the deposit/redeem exchange rate:
5050

51-
## Play with it on testnet
51+
```secretcli q compute query <contract-address> '{"exchange_rate": {}}'```
5252

53-
The deployed SSCRT contract address on the testnet is `secret1umwqjum7f4zmp9alr2kpmq4y5j4hyxlam896r3` and label `sscrt`
5453

5554
## Troubleshooting
5655

schema/init_msg.json

+28
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,34 @@
6565
"description": "This type represents optional configuration values which can be overridden. All values are optional and have defaults which are more private by default, but can be overridden if necessary",
6666
"type": "object",
6767
"properties": {
68+
"enable_burn": {
69+
"description": "Indicates whether burn functionality should be enabled default: False",
70+
"type": [
71+
"boolean",
72+
"null"
73+
]
74+
},
75+
"enable_deposit": {
76+
"description": "Indicates whether deposit functionality should be enabled default: False",
77+
"type": [
78+
"boolean",
79+
"null"
80+
]
81+
},
82+
"enable_mint": {
83+
"description": "Indicates whether mint functionality should be enabled default: False",
84+
"type": [
85+
"boolean",
86+
"null"
87+
]
88+
},
89+
"enable_redeem": {
90+
"description": "Indicates whether redeem functionality should be enabled default: False",
91+
"type": [
92+
"boolean",
93+
"null"
94+
]
95+
},
6896
"public_total_supply": {
6997
"description": "Indicates whether the total supply is public or should be kept secret. default: False",
7098
"type": [

schema/query_answer.json

+35
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@
4141
}
4242
}
4343
},
44+
{
45+
"type": "object",
46+
"required": [
47+
"token_config"
48+
],
49+
"properties": {
50+
"token_config": {
51+
"type": "object",
52+
"required": [
53+
"burn_enabled",
54+
"deposit_enabled",
55+
"mint_enabled",
56+
"public_total_supply",
57+
"redeem_enabled"
58+
],
59+
"properties": {
60+
"burn_enabled": {
61+
"type": "boolean"
62+
},
63+
"deposit_enabled": {
64+
"type": "boolean"
65+
},
66+
"mint_enabled": {
67+
"type": "boolean"
68+
},
69+
"public_total_supply": {
70+
"type": "boolean"
71+
},
72+
"redeem_enabled": {
73+
"type": "boolean"
74+
}
75+
}
76+
}
77+
}
78+
},
4479
{
4580
"type": "object",
4681
"required": [

schema/query_msg.json

+11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
}
1414
}
1515
},
16+
{
17+
"type": "object",
18+
"required": [
19+
"token_config"
20+
],
21+
"properties": {
22+
"token_config": {
23+
"type": "object"
24+
}
25+
}
26+
},
1627
{
1728
"type": "object",
1829
"required": [

0 commit comments

Comments
 (0)