Skip to content

Commit

Permalink
Merge pull request #215 from securesecrets/dev
Browse files Browse the repository at this point in the history
[RC] Shade Bonds + Updates
  • Loading branch information
FloppyDisck authored Jul 1, 2022
2 parents 7eeaaf2 + 9448f45 commit 69d3532
Show file tree
Hide file tree
Showing 331 changed files with 49,586 additions and 6,221 deletions.
56 changes: 49 additions & 7 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ env:
CARGO_TERM_COLOR: always

jobs:
find_contracts: # Job that list subdirectories
find-contracts: # Job that list subdirectories
runs-on: ubuntu-latest
outputs:
dir: ${{ steps.set-dirs.outputs.dir }}
Expand All @@ -15,14 +15,43 @@ jobs:
- id: set-dirs
run: echo "::set-output name=dir::$(find ./contracts/ -name Cargo.toml | jq -R -s -c 'split("\n")[:-1]')"

build:
build-contracts:
runs-on: ubuntu-latest
needs: [find_contracts] # Depends on previous job
needs: [find-contracts] # Depends on previous job
strategy:
matrix:
dir: ${{fromJson(needs.find_contracts.outputs.dir)}} # List matrix strategy from directories dynamically
dir: ${{fromJson(needs.find-contracts.outputs.dir)}} # List matrix strategy from directories dynamically
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown

- uses: actions-rs/[email protected]
with:
command: build
args: --release --target wasm32-unknown-unknown --manifest-path=${{matrix.dir}}

find-packages: # Job that list subdirectories
runs-on: ubuntu-latest
outputs:
dir: ${{ steps.set-dirs.outputs.dir }}
steps:
- uses: actions/checkout@v2
- id: set-dirs
run: echo "::set-output name=dir::$(find ./packages/ -name Cargo.toml | jq -R -s -c 'split("\n")[:-1]')"

build-packages:
runs-on: ubuntu-latest
needs: [find-packages] # Depends on previous job
strategy:
matrix:
dir: ${{fromJson(needs.find-packages.outputs.dir)}} # List matrix strategy from directories dynamically
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
Expand All @@ -32,12 +61,25 @@ jobs:
toolchain: stable
target: wasm32-unknown-unknown

- uses: actions-rs/[email protected].1
- uses: actions-rs/[email protected].3
with:
command: build
args: --release --target wasm32-unknown-unknown --manifest-path=${{matrix.dir}}

- uses: actions-rs/[email protected]
test-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown

- uses: actions-rs/[email protected]
with:
command: test
args: --manifest-path=${{matrix.dir}}
args: --manifest-path=Cargo.toml

9 changes: 6 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

# Build results
target/
# this is moved to vm/testdata, others are present locally
contracts/hackatom/contract.wasm
contracts/hackatom/hash.txt

# Testing configs
*.json

# Code coverage stuff
*.profraw

# IDEs
.vscode/
Expand Down
5 changes: 3 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "contracts/snip20"]
path = contracts/snip20
[submodule "contracts/snip20-reference-impl"]
path = contracts/snip20-reference-impl
url = https://github.com/scrtlabs/snip20-reference-impl.git
branch = master
31 changes: 25 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
[workspace]
members = [
# Packages
"packages/network_integration",
"packages/cosmwasm_math_compat",
"packages/shade_protocol",
"packages/secretcli",
"packages/contract_harness",

# Network setups
"contracts/initializer",
"contracts/airdrop",

# Protocol contracts
"contracts/snip20",
"contracts/governance",
"contracts/staking",
"contracts/bonds",
"contracts/mint",
"contracts/mint_router",
"contracts/treasury",
"contracts/oracle",
"contracts/snip20",
"contracts/sky",
"contracts/query_auth",

"contracts/snip20-reference-impl",

# DAO
# - Core
"contracts/treasury",
"contracts/treasury_manager",
# - Adapters
"contracts/scrt_staking",
"contracts/rewards_emission",
"contracts/lp_shade_swap",

"contracts/snip20_staking",

# Mock contracts
"contracts/mock_band",
"contracts/mock_secretswap_pair",
"contracts/mock_sienna_pair",

# Tools
"tools/doc2book"
"tools/doc2book",

#"packages/network_integration"
]

exclude = ["packages/network_integration"]

[profile.release]
opt-level = 3
debug = false
Expand Down
25 changes: 25 additions & 0 deletions contractlib/contractlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ def __init__(self, address, code_hash, code_id):
self.code_hash = code_hash
self.code_id = code_id

def execute(self, msg, sender, 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
"""
return secretlib.execute_contract(self.address, msg, sender, 'test', amount, compute)

def query(self, msg):
"""
Query said msg
:param msg: Query msg
:return: Query
"""
return secretlib.query_contract(self.address, msg)

def as_dict(self):
return {'address': self.address, 'code_hash': self.code_hash }


class Contract:
def __init__(self, contract, initMsg, label, admin='a', uploader='a', backend='test',
Expand Down Expand Up @@ -74,3 +95,7 @@ def print(self):
f"Address: {self.address}\n"
f"Id: {self.code_id}\n"
f"Hash: {self.code_hash}")

def as_dict(self):
return {'address': self.address, 'code_hash': self.code_hash }

7 changes: 2 additions & 5 deletions contractlib/mintlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ def __init__(self, label, native_asset, oracle, treasury=None,
},
}
if treasury:
init_msg['treasury'] = {
'address': treasury.address,
'code_hash': treasury.code_hash,
}
init_msg['treasury'] = treasury.address

if asset_peg:
init_msg['peg'] = asset_peg

print(json.dumps(init_msg, indent=2))
# print(json.dumps(init_msg, indent=2))
init_msg = json.dumps(init_msg)

super().__init__(contract, init_msg, label, admin, uploader, backend,
Expand Down
10 changes: 6 additions & 4 deletions contractlib/secretlib/secretlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
MAX_TRIES = 30

GAS_METRICS = []
STORE_GAS = '10000000'
GAS = '800000'
STORE_GAS = '4000000'
GAS = '4000000'


def run_command(command):
Expand Down Expand Up @@ -123,6 +123,8 @@ def run_command_compute_hash(command):

try:
txhash = json.loads(out)["txhash"]
#print(txhash)

except Exception as e:
# print(out)
raise e
Expand All @@ -135,7 +137,7 @@ def run_command_compute_hash(command):
# querying hash once the hash is computed so we can check gas usage
tx_data = json.loads(query_hash(txhash))
# print(json.dumps(tx_data))
print('gas:', tx_data['gas_used'], '\t/', tx_data['gas_wanted'])
# print('gas:', tx_data['gas_used'], '\t/', tx_data['gas_wanted'])
GAS_METRICS.append({
'want': tx_data['gas_wanted'],
'used': tx_data['gas_used'],
Expand All @@ -161,7 +163,7 @@ def run_command_query_hash(command):
# TODO: Read the gas used and store somewhere for metrics
out = query_hash(txhash)
out = json.loads(out)
print('gas:', out['gas_used'], '\t/', out['gas_wanted'])
# print('gas:', out['gas_used'], '\t/', out['gas_wanted'])
GAS_METRICS.append({
'want': out['gas_wanted'],
'used': out['gas_used'],
Expand Down
3 changes: 2 additions & 1 deletion contractlib/snip20lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class SNIP20(Contract):
def __init__(self, label, name="token", symbol="TKN", decimals=3, seed="cGFzc3dvcmQ=", public_total_supply=False,
enable_deposit=False, enable_redeem=False, enable_mint=False, enable_burn=False,
enable_deposit=False, enable_redeem=False, enable_mint=False, enable_burn=False, initial_balances=[],
contract='snip20.wasm.gz', admin='a', uploader='a', backend='test',
instantiated_contract=None, code_id=None):
self.view_key = ""
Expand All @@ -20,6 +20,7 @@ def __init__(self, label, name="token", symbol="TKN", decimals=3, seed="cGFzc3dv
"symbol": symbol,
"decimals": decimals,
"prng_seed": seed,
"initial_balances": initial_balances,
"config": {
"public_total_supply": public_total_supply,
"enable_deposit": enable_deposit,
Expand Down
14 changes: 8 additions & 6 deletions contracts/airdrop/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
[package]
name = "airdrop"
version = "0.1.0"
authors = [
"Guy Garcia <[email protected]>",
]
authors = ["Guy Garcia <[email protected]>"]
edition = "2018"

exclude = [
Expand All @@ -25,15 +23,19 @@ backtraces = ["cosmwasm-std/backtraces"]
debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
cosmwasm-std = { version = "0.10", package = "secret-cosmwasm-std" }
cosmwasm-std = { version = "0.10.1", package = "secret-cosmwasm-std" }
cosmwasm-storage = { version = "0.10", package = "secret-cosmwasm-storage" }
cosmwasm-schema = "0.10.1"
secret-toolkit = { version = "0.2" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol" }
cosmwasm-math-compat = { path = "../../packages/cosmwasm_math_compat" }
shade-protocol = { version = "0.1.0", path = "../../packages/shade_protocol", features = [
"airdrop",
"math",
] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
rs_merkle = { git = "https://github.com/FloppyDisck/rs-merkle", branch = "node_export" }
mockall = "0.10.2"
mockall_double = "0.2.0"
query-authentication = {git = "https://github.com/securesecrets/query-authentication", tag = "v1.2.0"}
query-authentication = { git = "https://github.com/securesecrets/query-authentication", tag = "v1.3.0" }
2 changes: 0 additions & 2 deletions contracts/airdrop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ Complete that address' tasks for a given user
"status": "success",
"total": "Total airdrop amount",
"claimed": "Claimed amount",
"unclaimed": "Amount available to claim",
"finished_tasks": "All of the finished tasks",
"addresses": ["claimed addresses"]
}
Expand Down Expand Up @@ -191,7 +190,6 @@ Claim the user's available claimable amount
"status": "success",
"total": "Total airdrop amount",
"claimed": "Claimed amount",
"unclaimed": "Amount available to claim",
"finished_tasks": "All of the finished tasks",
"addresses": ["claimed addresses"]
}
Expand Down
35 changes: 28 additions & 7 deletions contracts/airdrop/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
use crate::handle::{try_account, try_set_viewing_key};
use crate::{
handle::{
try_add_tasks, try_claim, try_claim_decay, try_complete_task, try_disable_permit_key,
try_account,
try_add_tasks,
try_claim,
try_claim_decay,
try_complete_task,
try_disable_permit_key,
try_set_viewing_key,
try_update_config,
},
query,
state::{config_w, decay_claimed_w, total_claimed_w},
};
use cosmwasm_math_compat::Uint128;
use cosmwasm_std::{
to_binary, Api, Binary, Env, Extern, HandleResponse, InitResponse, Querier, StdError,
StdResult, Storage, Uint128,
to_binary,
Api,
Binary,
Env,
Extern,
HandleResponse,
InitResponse,
Querier,
StdError,
StdResult,
Storage,
};
use secret_toolkit::utils::{pad_handle_result, pad_query_result};
use shade_protocol::airdrop::errors::{invalid_dates, invalid_task_percentage};
use shade_protocol::airdrop::{claim_info::RequiredTask, Config, HandleMsg, InitMsg, QueryMsg};
use shade_protocol::contract_interfaces::airdrop::{
claim_info::RequiredTask,
errors::{invalid_dates, invalid_task_percentage},
Config,
HandleMsg,
InitMsg,
QueryMsg,
};

// Used to pad up responses for better privacy.
pub const RESPONSE_BLOCK_SIZE: usize = 256;
Expand All @@ -37,7 +58,7 @@ pub fn init<S: Storage, A: Api, Q: Querier>(
count += claim.percent;
}

if count > Uint128(100) {
if count > Uint128::new(100u128) {
return Err(invalid_task_percentage(count.to_string().as_str()));
}

Expand Down
Loading

0 comments on commit 69d3532

Please sign in to comment.