8000 Oracle sienna by DrPresident · Pull Request #193 · securesecrets/shade · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Oracle sienna #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a6970e5
started sienna integration
DrPresident Feb 3, 2022
07aadeb
Merge remote-tracking branch 'origin/dev' into oracle-sienna
DrPresident Feb 3, 2022
355457c
not much
DrPresident Feb 4, 2022
6806081
Merge remote-tracking branch 'origin/dev' into oracle-sienna
DrPresident Feb 18, 2022
2107bc8
merged dev
DrPresident Feb 18, 2022
2e67590
roughed out a little further, still not building
DrPresident Feb 18, 2022
e65078c
building, needs testing
DrPresident Feb 23, 2022
d837f43
touch ups on a few things, should be working
DrPresident Feb 25, 2022
a56f1f7
fixed denominator
DrPresident Feb 25, 2022
da8a533
mid-transition to dex_pairs
DrPresident Feb 25, 2022
c66e6bd
warning fixes
DrPresident Mar 1, 2022
8806473
added check to stop registering dex pairs that override indexes
DrPresident Mar 1, 2022
2232995
removed old pair storage
DrPresident Mar 1, 2022
54d0c6a
updates to oracle index
DrPreside 8000 nt Mar 1, 2022
1f21a17
removed some comments
DrPresident Mar 1, 2022
6f20ed9
changes to reduce nesting
DrPresident Mar 1, 2022
b47416e
mock pairs building, needs testing
DrPresident Mar 4, 2022
23da3d5
mock dex pair contracts
DrPresident Mar 4, 2022
6d03f70
mock pairs setup
DrPresident Mar 7, 2022
a647357
finally working, fixed the goof needs a little more testing though
DrPresident Mar 7, 2022
36146aa
fixed some clerical errors in responses
DrPresident Mar 9, 2022
e9bbc30
reworked some things to avoid overflow, need to move back to weighted…
DrPresident Mar 9, 2022
fd93176
working with pool weights & math-compat uint512
DrPresident Mar 11, 2022
c4bc3c2
removed old comment block
DrPresident Mar 11, 2022
0e0fc78
adjusted some things in contractlib
DrPresident Mar 11, 2022
85c3b8b
moved normalize/translate into price.rs and moved tests over
DrPresident Mar 22, 2022
c50c9c6
Merge branch 'dev' into oracle-sienna
DrPresident Mar 24, 2022
1c5bcd2
fixed tests
DrPresident Mar 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ members = [

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

# Tools
"tools/doc2book"
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 }

2 changes: 1 addition & 1 deletion contractlib/mintlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, label, native_asset, oracle, treasury=None,
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
8 changes: 4 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 = '100000'


def run_command(command):
Expand Down Expand Up @@ -135,7 +135,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 +161,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
5 changes: 4 additions & 1 deletion contracts/mint/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ pub mod tests {
Extern, StdError, Uint128, HumanAddr,
};
use mockall_double::double;
use shade_protocol::mint::{HandleMsg, InitMsg, QueryAnswer, QueryMsg};
use shade_protocol::{
mint::{HandleMsg, InitMsg, QueryAnswer, QueryMsg},
utils::price::{normalize_price, translate_price},
};

use crate::{
contract::{handle, init, query},
Expand Down
5 changes: 5 additions & 0 deletions contracts/mock_secretswap_pair/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib --features backtraces"
integration-test = "test --test integration"
schema = "run --example schema"
52 changes: 52 additions & 0 deletions contracts/mock_secretswap_pair/.circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: 2.1

jobs:
build:
docker:
- image: rust:1.43.1
steps:
- checkout
- run:
name: Version information
command: rustc --version; cargo --version; rustup --version
- restore_cache:
keys:
- v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
- run:
name: Add wasm32 target
command: rustup target add wasm32-unknown-unknown
- run:
name: Build
command: cargo wasm --locked
- run:
name: Unit tests
env: RUST_BACKTRACE=1
command: cargo unit-test --locked
- run:
name: Integration tests
command: cargo integration-test --locked
- run:
name: Format source code
command: cargo fmt
- run:
name: Build and run schema generator
command: cargo schema --locked
- run:
name: Ensure checked-in source code and schemas are up-to-date
command: |
CHANGES_IN_REPO=$(git status --porcelain)
if [[ -n "$CHANGES_IN_REPO" ]]; then
echo "Repository is dirty. Showing 'git status' and 'git --no-pager diff' for debugging now:"
git status && git --no-pager diff
exit 1
fi
- save_cache:
paths:
- /usr/local/cargo/registry
- target/debug/.fingerprint
- target/debug/build
- target/debug/deps
- target/wasm32-unknown-unknown/release/.fingerprint
- target/wasm32-unknown-unknown/release/build
- target/wasm32-unknown-unknown/release/deps
key: v4-cargo-cache-{{ arch }}-{{ checksum "Cargo.lock" }}
34 changes: 34 additions & 0 deletions contracts/mock_secretswap_pair/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "mock_secretswap_pair"
version = "0.1.0"
authors = ["Jack Swenson <jacksonswenson22@gmail.com>"]
edition = "2018"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
default = []
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
debug-print = ["cosmwasm-std/debug-print"]

[dependencies]
bincode = "1.3.1"
cosmwasm-std = { version = "0.10", 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" }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
snafu = { version = "0.6.3" }
68 changes: 68 additions & 0 deletions contracts/mock_secretswap_pair/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.PHONY: check
check:
cargo check

.PHONY: clippy
clippy:
cargo clippy

PHONY: test
test: unit-test

.PHONY: unit-test
unit-test:
cargo test

# This is a local build with debug-prints activated. Debug prints only show up
# in the local development chain (see the `start-server` command below)
# and mainnet won't accept contracts built with the feature enabled.
.PHONY: build _build
build: _build compress-wasm
_build:
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown --features="debug-print"

# This is a build suitable for uploading to mainnet.
# Calls to `debug_print` get removed by the compiler.
.PHONY: build-mainnet _build-mainnet
build-mainnet: _build-mainnet compress-wasm
_build-mainnet:
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown

# like build-mainnet, but slower and more deterministic
.PHONY: build-mainnet-reproducible
build-mainnet-reproducible:
docker run --rm -v "$$(pwd)":/contract \
--mount type=volume,source="$$(basename "$$(pwd)")_cache",target=/contract/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
enigmampc/secret-contract-optimizer:1.0.3

.PHONY: compress-wasm
compress-wasm:
cp ./target/wasm32-unknown-unknown/release/*.wasm ./contract.wasm
@## The following line is not necessary, may work only on linux (extra size optimization)
@# wasm-opt -Os ./contract.wasm -o ./contract.wasm
cat ./contract.wasm | gzip -9 > ./contract.wasm.gz

.PHONY: schema
schema:
cargo run --example schema

# Run local development chain with four funded accounts (named a, b, c, and d)
.PHONY: start-server
start-server: # CTRL+C to stop
docker run -it --rm \
-p 26657:26657 -p 26656:26656 -p 1317:1317 \
-v $$(pwd):/root/code \
--name secretdev enigmampc/secret-network-sw-dev:v1.0.4-3

# This relies on running `start-server` in another console
# You can run other commands on the secretcli inside the dev image
# by using `docker exec secretdev secretcli`.
.PHONY: store-contract-local
store-contract-local:
docker exec secretdev secretcli tx compute store -y --from a --gas 1000000 /root/code/contract.wasm.gz

.PHONY: clean
clean:
cargo clean
-rm -f ./contract.wasm ./contract.wasm.gz
21 changes: 21 additions & 0 deletions contracts/mock_secretswap_pair/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Mock Band Contract
* [Introduction](#Introduction)
* [Sections](#Sections)
* [User](#User)
* Queries
* [GetReferenceData](#GetReferenceData)
# Introduction
The Mocked Band contract is used to test locally when there is no official band contract available

### Queries

#### GetReferenceData
Get a hardcoded sample from an ETH query for testing locally
##### Response
```json
{
"rate": "3119154999999000000000",
"last_updated_base": 1628548483,
"last_updated_quote": 3377610
}
```
Loading
0