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

Oracle index #143

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 11 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 13 additions & 2 deletions contractlib/oraclelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ def __init__(self, label, band_contract, sscrt, contract='oracle.wasm.gz', admin
super().__init__(contract, init_msg, label, admin, uploader, backend,
instantiated_contract=instantiated_contract, code_id=code_id)

def get_price(self, symbol):
def price(self, symbol):
"""
Get current coin price
:param symbol: Coin ticker
:return:
"""
msg = json.dumps({'get_price': {'symbol': symbol}})
msg = json.dumps({'price': {'symbol': symbol}})

return self.query(msg)

Expand All @@ -40,3 +40,14 @@ def register_sswap_pair(self, pair):
}})

return self.execute(msg)

def register_index(self, symbol, basket: list):
msg = json.dumps({
'register_index': {
'symbol': symbol,
'basket': basket,
}
})
print(msg)

return self.execute(msg)
19 changes: 10 additions & 9 deletions contractlib/secretlib/secretlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time

# Presetup some commands
query_list_code = ['secretcli', 'query', 'compute', 'list-code']
query_list_code = ['secretd', 'query', 'compute', 'list-code']
MAX_TRIES = 30

GAS_METRICS = []
Expand All @@ -18,6 +18,7 @@ def run_command(command):
:param wait: Time to wait for command
:return: Output string
"""
# print('CMD', command)
p = Popen(command, stdout=PIPE, stderr=PIPE, text=True)
output, err = p.communicate()
status = p.wait()
Expand All @@ -36,7 +37,7 @@ def store_contract(contract, user='a', backend='test'):
:return: Contract ID
"""

command = ['secretcli', 'tx', 'compute', 'store', f'./compiled/{contract}',
command = ['secretd', 'tx', 'compute', 'store', f'./compiled/{contract}',
'--from', user, '--gas', STORE_GAS, '-y']

if backend is not None:
Expand All @@ -63,7 +64,7 @@ def instantiate_contract(contract, msg, label, user='a', backend='test'):
:return:
"""

command = ['secretcli', 'tx', 'compute', 'instantiate', contract, msg, '--from',
command = ['secretd', 'tx', 'compute', 'instantiate', contract, msg, '--from',
user, '--label', label, '-y', '--gas', '500000']

if backend is not None:
Expand All @@ -73,19 +74,19 @@ def instantiate_contract(contract, msg, label, user='a', backend='test'):


def list_code():
command = ['secretcli', 'query', 'compute', 'list-code']
command = ['secretd', 'query', 'compute', 'list-code']

return json.loads(run_command(command))


def list_contract_by_code(code):
command = ['secretcli', 'query', 'compute', 'list-contract-by-code', code]
command = ['secretd', 'query', 'compute', 'list-contract-by-code', code]

return json.loads(run_command(command))


def execute_contract(contract, msg, user='a', backend='test', amount=None, compute=True):
command = ['secretcli', 'tx', 'compute', 'execute', contract, json.dumps(msg), '--from', user, '--gas', GAS, '-y']
command = ['secretd', 'tx', 'compute', 'execute', contract, json.dumps(msg), '--from', user, '--gas', GAS, '-y']

if backend is not None:
command += ['--keyring-backend', backend]
Expand All @@ -100,15 +101,15 @@ def execute_contract(contract, msg, user='a', backend='test', amount=None, compu


def query_hash(hash):
return run_command(['secretcli', 'q', 'tx', hash])
return run_command(['secretd', 'q', 'tx', hash])


def compute_hash(hash):
return run_command(['secretcli', 'q', 'compute', 'tx', hash])
return run_command(['secretd', 'q', 'compute', 'tx', hash])


def query_contract(contract, msg):
command = ['secretcli', 'query', 'compute', 'query', contract, json.dumps(msg)]
command = ['secretd', 'query', 'compute', 'query', contract, json.dumps(msg)]
out = run_command(command)
try:
return json.loads(out)
Expand Down
4 changes: 2 additions & 2 deletions contracts/micro_mint/src/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use shade_protocol::{
mint::MintMsgHook,
snip20::{Snip20Asset, token_config_query, TokenConfig},
oracle::{
QueryMsg::GetPrice,
QueryMsg::Price,
},
band::ReferenceData,
asset::Contract,
Expand Down Expand Up @@ -491,7 +491,7 @@ fn oracle<S: Storage, A: Api, Q: Querier>(
) -> StdResult<Uint128> {

let config: Config = config_r(&deps.storage).load()?;
let answer: ReferenceData = GetPrice {
let answer: ReferenceData = Price {
symbol: symbol.to_string()
}.query(&deps.querier,
config.oracle.code_hash,
Expand Down
4 changes: 2 additions & 2 deletions contracts/mint/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use secret_toolkit::{
use shade_protocol::{
mint::{InitMsg, HandleMsg, HandleAnswer, QueryMsg, QueryAnswer, MintConfig, SupportedAsset, SnipMsgHook},
oracle::{
QueryMsg::GetPrice,
QueryMsg::Price,
},
band::ReferenceData,
asset::{Contract},
Expand Down Expand Up @@ -387,7 +387,7 @@ fn call_oracle<S: Storage, A: Api, Q: Querier>(
symbol: String,
) -> StdResult<Uint128> {
let config = config_read(&deps.storage).load()?;
let query_msg = GetPrice { symbol };
let query_msg = Price { symbol };
let answer: ReferenceData = query_msg.query(&deps.querier,
config.oracle.code_hash,
config.oracle.address)?;
Expand Down
71 changes: 54 additions & 17 deletions contracts/mock_band/src/contract.rs