Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yun-yeo committed Aug 10, 2021
2 parents 0fc85c1 + 4dbce30 commit e8ddbee
Show file tree
Hide file tree
Showing 23 changed files with 396 additions and 1,782 deletions.
8 changes: 8 additions & 0 deletions contracts/mirror_collateral_oracle/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
"properties": {
"asset": {
"type": "string"
},
"block_height": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions contracts/mirror_collateral_oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ pub fn query<S: Storage, A: Api, Q: Querier>(
) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => to_binary(&query_config(deps)?),
QueryMsg::CollateralPrice { asset } => to_binary(&query_collateral_price(deps, asset)?),
QueryMsg::CollateralPrice {
asset,
block_height,
} => to_binary(&query_collateral_price(deps, asset, block_height)?),
QueryMsg::CollateralAssetInfo { asset } => to_binary(&query_collateral_info(deps, asset)?),
QueryMsg::CollateralAssetInfos {} => to_binary(&query_collateral_infos(deps)?),
}
Expand All @@ -260,6 +263,7 @@ pub fn query_config<S: Storage, A: Api, Q: Querier>(
pub fn query_collateral_price<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
quote_asset: String,
block_height: Option<u64>,
) -> StdResult<CollateralPriceResponse> {
let config: Config = read_config(&deps.storage)?;

Expand All @@ -270,8 +274,13 @@ pub fn query_collateral_price<S: Storage, A: Api, Q: Querier>(
return Err(StdError::generic_err("Collateral asset not found"));
};

let (price, last_updated): (Decimal, u64) =
query_price(deps, &config, &quote_asset, &collateral.price_source)?;
let (price, last_updated): (Decimal, u64) = query_price(
deps,
&config,
&quote_asset,
block_height,
&collateral.price_source,
)?;

Ok(CollateralPriceResponse {
asset: collateral.asset,
Expand Down
3 changes: 2 additions & 1 deletion contracts/mirror_collateral_oracle/src/querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn query_price<S: Storage, A: Api, Q: Querier>(
deps: &Extern<S, A, Q>,
config: &Config,
asset: &String,
block_height: Option<u64>,
price_source: &SourceType,
) -> StdResult<(Decimal, u64)> {
match price_source {
Expand Down Expand Up @@ -149,7 +150,7 @@ pub fn query_price<S: Storage, A: Api, Q: Querier>(
deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart {
contract_addr: HumanAddr::from(anchor_market_addr),
msg: to_binary(&SourceQueryMsg::EpochState {
block_heigth: None,
block_heigth: block_height,
distributed_interest: None,
})
.unwrap(),
Expand Down
18 changes: 9 additions & 9 deletions contracts/mirror_collateral_oracle/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fn get_oracle_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "mTSLA".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "mTSLA".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -362,7 +362,7 @@ fn get_terraswap_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "anc0000".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "anc0000".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -390,7 +390,7 @@ fn get_terraswap_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "bluna0000".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "bluna0000".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -433,7 +433,7 @@ fn get_fixed_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "aUST".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "aUST".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -474,7 +474,7 @@ fn get_band_oracle_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "uluna".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "uluna".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -517,7 +517,7 @@ fn get_anchor_market_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "aust0000".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "aust0000".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -560,7 +560,7 @@ fn get_native_price() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "uluna".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "uluna".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -603,7 +603,7 @@ fn revoke_collateral() {
let _res = handle(&mut deps, env, msg).unwrap();

// attempt to query price
let query_res = query_collateral_price(&deps, "aUST".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "aUST".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down Expand Up @@ -645,7 +645,7 @@ fn revoke_collateral() {
);

// attempt to query price of revoked asset
let query_res = query_collateral_price(&deps, "aUST".to_string()).unwrap();
let query_res = query_collateral_price(&deps, "aUST".to_string(), None).unwrap();
assert_eq!(
query_res,
CollateralPriceResponse {
Expand Down
24 changes: 22 additions & 2 deletions contracts/mirror_gov/schema/handle_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,17 @@
],
"properties": {
"withdraw_voting_rewards": {
"type": "object"
"type": "object",
"properties": {
"poll_id": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
Expand All @@ -178,7 +188,17 @@
],
"properties": {
"stake_voting_rewards": {
"type": "object"
"type": "object",
"properties": {
"poll_id": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
Expand Down
65 changes: 1 addition & 64 deletions contracts/mirror_gov/schema/migrate_msg.json
Original file line number Diff line number Diff line change
@@ -1,68 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "MigrateMsg",
"type": "object",
"required": [
"network"
],
"properties": {
"effective_delay": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"expiration_period": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"network": {
"$ref": "#/definitions/Network"
},
"snapshot_period": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"voter_weight": {
"anyOf": [
{
"$ref": "#/definitions/Decimal"
},
{
"type": "null"
}
]
},
"voting_period": {
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
}
},
"definitions": {
"Decimal": {
"description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)",
"type": "string"
},
"Network": {
"type": "string",
"enum": [
"mainnet",
"testnet"
]
}
}
"type": "object"
}
25 changes: 25 additions & 0 deletions contracts/mirror_gov/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,31 @@
}
}
},
{
"type": "object",
"required": [
"voter"
],
"properties": {
"voter": {
"type": "object",
"required": [
"address",
"poll_id"
],
"properties": {
"address": {
"$ref": "#/definitions/HumanAddr"
},
"poll_id": {
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
}
}
}
},
{
"type": "object",
"required": [
Expand Down
Loading

0 comments on commit e8ddbee

Please sign in to comment.