-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from securesecrets/dev
Add Minting and Oracle contract
- Loading branch information
Showing
285 changed files
with
2,910 additions
and
33,658 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,2 @@ | ||
[workspace] | ||
members = ["packages/*", "shade-contracts/*"] | ||
|
||
[profile.release.package.mirror-protocol] | ||
opt-level = 3 | ||
debug = false | ||
debug-assertions = false | ||
codegen-units = 1 | ||
incremental = false | ||
|
||
[profile.release] | ||
rpath = false | ||
lto = true | ||
overflow-checks = true | ||
members = ["contracts/mint","contracts/oracle", "packages/shade_protocol"] |
This file contains 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
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
root_dir=$(git rev-parse --show-toplevel) | ||
contracts_dir="${root_dir}/contracts" | ||
compiled_dir="${contracts_dir}/compiled" | ||
|
||
compile_contract() { | ||
# Run tests | ||
(cd ${contracts_dir}/$1; cargo unit-test) | ||
(cd ${contracts_dir}/$1; cargo integration-test) | ||
(cd ${compiled_dir}; rm $1.wasm.gz) | ||
(cd ${contracts_dir}; cargo build --release --target wasm32-unknown-unknown --locked) | ||
wasm-opt -Oz ./target/wasm32-unknown-unknown/release/$1.wasm -o ./$1.wasm | ||
cat ./$1.wasm | gzip -n -9 > ${compiled_dir}/$1.wasm.gz | ||
rm -f ./$1.wasm | ||
} | ||
|
||
compile_contract "mint" | ||
compile_contract "oracle" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import random | ||
from contractlib.secretlib import secretlib | ||
from contractlib.snip20lib import SNIP20 | ||
from contractlib.mintlib import Mint | ||
from contractlib.oraclelib import Oracle | ||
from contractlib.utils import gen_label | ||
|
||
account_key = 'a' | ||
account = secretlib.run_command(['secretcli', 'keys', 'show', '-a', account_key]).rstrip() | ||
|
||
print("Configuring sSCRT") | ||
sscrt = SNIP20(gen_label(8), decimals=6, public_total_supply=True, enable_deposit=True) | ||
sscrt_password = sscrt.set_view_key(account_key, "password") | ||
sscrt.print() | ||
|
||
sscrt_mint_amount = '100000000000000' | ||
print(f"\tDepositing {sscrt_mint_amount} uSCRT") | ||
sscrt.deposit(account, sscrt_mint_amount + "uscrt") | ||
sscrt_minted = sscrt.get_balance(account, sscrt_password) | ||
print(f"\tReceived {sscrt_minted} usSCRT") | ||
assert sscrt_mint_amount == sscrt_minted, f"Minted {sscrt_minted}; expected {sscrt_mint_amount}" | ||
|
||
print("Configuring silk") | ||
silk = SNIP20(gen_label(8), decimals=6, public_total_supply=True, enable_mint=True) | ||
silk_password = silk.set_view_key(account_key, "password") | ||
|
||
print('Configuring Oracle') | ||
oracle = Oracle(gen_label(8)) | ||
price = int(oracle.get_silk_price()["price"]) | ||
print(price / (10**18)) | ||
|
||
print("Configuring Mint contract") | ||
mint = Mint(gen_label(8), silk, oracle) | ||
silk.set_minters([mint.address]) | ||
mint.register_asset(sscrt) | ||
assets = mint.get_supported_assets()['supported_assets']['assets'][0] | ||
assert sscrt.address == assets, f"Got {assets}; expected {sscrt.address}" | ||
|
||
print("Sending to mint contract") | ||
|
||
total_amount = int(sscrt_mint_amount) | ||
minimum_amount = 1000 | ||
total_tests = 5 | ||
|
||
total_sent = 0 | ||
|
||
for i in range(total_tests): | ||
send_amount = random.randint(minimum_amount, int(total_amount/total_tests)-1) | ||
total_sent += send_amount | ||
|
||
print(f"\tSending {send_amount} usSCRT") | ||
sscrt.send(account_key, mint.address, send_amount) | ||
silk_minted = silk.get_balance(account, silk_password) | ||
#assert total_sent == int(silk_minted), f"Total minted {silk_minted}; expected {total_sent}" | ||
|
||
print(f"\tSilk balance: {silk_minted} uSILK") | ||
burned_amount = mint.get_asset(sscrt)["asset"]["asset"]["burned_tokens"] | ||
print(f"\tTotal burned: {burned_amount} usSCRT\n") | ||
#assert total_sent == int(burned_amount), f"Burnt {burned_amount}; expected {total_sent}" | ||
|
||
print("Testing migration") | ||
new_mint = mint.migrate(gen_label(8), int(mint.contract_id), mint.code_hash) | ||
assert mint.get_supported_assets() == new_mint.get_supported_assets(), "Contracts are not the same" |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from .secretlib import secretlib | ||
|
||
|
||
class PreInstantiatedContract: | ||
def __init__(self, contract_id, address, code_hash): | ||
self.contract_id = contract_id | ||
self.address = address | ||
self.code_hash = code_hash | ||
|
||
|
||
class Contract: | ||
def __init__(self, contract, initMsg, label, admin='a', uploader='a', gas='10000000', backend='test', wait=6, | ||
instantiated_contract=None): | ||
self.label = label | ||
self.admin = admin | ||
self.uploader = uploader | ||
self.gas = gas | ||
self.backend = backend | ||
self.wait = wait | ||
|
||
if instantiated_contract is None: | ||
self.contract_id = secretlib.store_contract(contract, uploader, gas, backend) | ||
initResponse = secretlib.instantiate_contract(str(self.contract_id), initMsg, label, admin, backend) | ||
contracts = secretlib.list_code() | ||
self.code_hash = contracts[int(self.contract_id) - 1]["data_hash"] | ||
for attribute in initResponse["logs"][0]["events"][0]["attributes"]: | ||
if attribute["key"] == "contract_address": | ||
self.address = attribute["value"] | ||
break | ||
|
||
else: | ||
self.contract_id = instantiated_contract.contract_id | ||
self.code_hash = instantiated_contract.code_hash | ||
self.address = instantiated_contract.address | ||
|
||
def execute(self, msg, sender=None, amount=None, compute=True): | ||
""" | ||
Execute said msg | ||
:param msg: Execute msg | ||
:param sender: Who will be sending the message, defaults to contract admin | ||
:param amount: Optional string amount to send along with transaction | ||
:return: Result | ||
""" | ||
signer = sender if sender is not None else self.admin | ||
return secretlib.execute_contract(self.address, msg, signer, self.backend, amount, compute) | ||
|
||
def query(self, msg): | ||
""" | ||
Query said msg | ||
:param msg: Query msg | ||
:return: Query | ||
""" | ||
return secretlib.query_contract(self.address, msg) | ||
|
||
def print(self): | ||
""" | ||
Prints the contract info | ||
:return: | ||
""" | ||
print(f"Label: {self.label}\n" | ||
f"Address: {self.address}\n" | ||
f"Id: {self.contract_id}\n" | ||
f"Hash: {self.code_hash}") |
Oops, something went wrong.