diff --git a/cosmwasm/README.md b/cosmwasm/README.md index 27297a2..40d525f 100644 --- a/cosmwasm/README.md +++ b/cosmwasm/README.md @@ -90,9 +90,9 @@ pub struct ReferenceData { // Pair rate e.g. rate of BTC/USD pub rate: Uint256, // Unix time of when the base asset was last updated. e.g. Last update time of BTC in Unix time - pub last_updated_base: Uint64, + pub last_updated_base: Uint256, // Unix time of when the quote asset was last updated. e.g. Last update time of USD in Unix time - pub last_updated_quote: Uint64, + pub last_updated_quote: Uint256, } ``` @@ -194,11 +194,11 @@ bulk variant returns `Vec` ```rust pub struct RefDeviationData { // Deviation Rates of an asset relative to USD - pub rates: Vec, + pub rates: Vec, // The resolve time of the request ID - pub resolve_time: Uint64, + pub resolve_time: Uint256, // The request ID where the rate was derived from - pub request_id: Uint64, + pub request_id: Uint256, } ``` diff --git a/cosmwasm/contracts/price-feed/schema/execute_msg.json b/cosmwasm/contracts/price-feed/schema/execute_msg.json index 330cfed..e7b0722 100644 --- a/cosmwasm/contracts/price-feed/schema/execute_msg.json +++ b/cosmwasm/contracts/price-feed/schema/execute_msg.json @@ -23,6 +23,27 @@ }, "additionalProperties": false }, + { + "type": "object", + "required": [ + "median_status" + ], + "properties": { + "median_status": { + "type": "object", + "required": [ + "status" + ], + "properties": { + "status": { + "type": "boolean" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "type": "object", "required": [ @@ -100,7 +121,97 @@ "type": "string" }, { - "$ref": "#/definitions/Uint64" + "$ref": "#/definitions/Uint256" + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "relay_historical_median" + ], + "properties": { + "relay_historical_median": { + "type": "object", + "required": [ + "request_id", + "resolve_time", + "symbol_rates" + ], + "properties": { + "request_id": { + "$ref": "#/definitions/Uint64" + }, + "resolve_time": { + "$ref": "#/definitions/Uint64" + }, + "symbol_rates": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/Uint256" + } + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "relay_historical_deviation" + ], + "properties": { + "relay_historical_deviation": { + "type": "object", + "required": [ + "request_id", + "resolve_time", + "symbol_rates" + ], + "properties": { + "request_id": { + "$ref": "#/definitions/Uint64" + }, + "resolve_time": { + "$ref": "#/definitions/Uint64" + }, + "symbol_rates": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/Uint256" + } } ], "maxItems": 2, @@ -142,7 +253,97 @@ "type": "string" }, { - "$ref": "#/definitions/Uint64" + "$ref": "#/definitions/Uint256" + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "force_relay_historical_median" + ], + "properties": { + "force_relay_historical_median": { + "type": "object", + "required": [ + "request_id", + "resolve_time", + "symbol_rates" + ], + "properties": { + "request_id": { + "$ref": "#/definitions/Uint64" + }, + "resolve_time": { + "$ref": "#/definitions/Uint64" + }, + "symbol_rates": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/Uint256" + } + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "force_relay_historical_deviation" + ], + "properties": { + "force_relay_historical_deviation": { + "type": "object", + "required": [ + "request_id", + "resolve_time", + "symbol_rates" + ], + "properties": { + "request_id": { + "$ref": "#/definitions/Uint64" + }, + "resolve_time": { + "$ref": "#/definitions/Uint64" + }, + "symbol_rates": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "array", + "items": { + "$ref": "#/definitions/Uint256" + } } ], "maxItems": 2, @@ -157,6 +358,10 @@ } ], "definitions": { + "Uint256": { + "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", + "type": "string" + }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/cosmwasm/contracts/price-feed/schema/query_msg.json b/cosmwasm/contracts/price-feed/schema/query_msg.json index 91d44e1..885ee1a 100644 --- a/cosmwasm/contracts/price-feed/schema/query_msg.json +++ b/cosmwasm/contracts/price-feed/schema/query_msg.json @@ -15,6 +15,19 @@ }, "additionalProperties": false }, + { + "type": "object", + "required": [ + "median_status" + ], + "properties": { + "median_status": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, { "type": "object", "required": [ @@ -121,6 +134,96 @@ } }, "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_median_ref" + ], + "properties": { + "get_median_ref": { + "type": "object", + "required": [ + "symbol" + ], + "properties": { + "symbol": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_median_ref_data_bulk" + ], + "properties": { + "get_median_ref_data_bulk": { + "type": "object", + "required": [ + "symbols" + ], + "properties": { + "symbols": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_deviation_ref" + ], + "properties": { + "get_deviation_ref": { + "type": "object", + "required": [ + "symbol" + ], + "properties": { + "symbol": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "get_deviation_ref_bulk" + ], + "properties": { + "get_deviation_ref_bulk": { + "type": "object", + "required": [ + "symbols" + ], + "properties": { + "symbols": { + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false } ] } diff --git a/cosmwasm/contracts/price-feed/schema/ref_data.json b/cosmwasm/contracts/price-feed/schema/ref_data.json index f69ff09..3e8ec23 100644 --- a/cosmwasm/contracts/price-feed/schema/ref_data.json +++ b/cosmwasm/contracts/price-feed/schema/ref_data.json @@ -9,7 +9,7 @@ ], "properties": { "rate": { - "$ref": "#/definitions/Uint64" + "$ref": "#/definitions/Uint256" }, "request_id": { "$ref": "#/definitions/Uint64" @@ -20,6 +20,10 @@ }, "additionalProperties": false, "definitions": { + "Uint256": { + "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", + "type": "string" + }, "Uint64": { "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", "type": "string" diff --git a/cosmwasm/contracts/price-feed/schema/ref_deviation_data.json b/cosmwasm/contracts/price-feed/schema/ref_deviation_data.json new file mode 100644 index 0000000..97dcfea --- /dev/null +++ b/cosmwasm/contracts/price-feed/schema/ref_deviation_data.json @@ -0,0 +1,35 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "RefDeviationData", + "type": "object", + "required": [ + "rates", + "request_id", + "resolve_time" + ], + "properties": { + "rates": { + "type": "array", + "items": { + "$ref": "#/definitions/Uint256" + } + }, + "request_id": { + "$ref": "#/definitions/Uint64" + }, + "resolve_time": { + "$ref": "#/definitions/Uint64" + } + }, + "additionalProperties": false, + "definitions": { + "Uint256": { + "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", + "type": "string" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/cosmwasm/contracts/price-feed/schema/ref_median_data.json b/cosmwasm/contracts/price-feed/schema/ref_median_data.json new file mode 100644 index 0000000..7a6518e --- /dev/null +++ b/cosmwasm/contracts/price-feed/schema/ref_median_data.json @@ -0,0 +1,35 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "RefMedianData", + "type": "object", + "required": [ + "rates", + "request_id", + "resolve_time" + ], + "properties": { + "rates": { + "type": "array", + "items": { + "$ref": "#/definitions/Uint256" + } + }, + "request_id": { + "$ref": "#/definitions/Uint64" + }, + "resolve_time": { + "$ref": "#/definitions/Uint64" + } + }, + "additionalProperties": false, + "definitions": { + "Uint256": { + "description": "An implementation of u256 that is using strings for JSON encoding/decoding, such that the full u256 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances out of primitive uint types or `new` to provide big endian bytes:\n\n``` # use cosmwasm_std::Uint256; let a = Uint256::from(258u128); let b = Uint256::new([ 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8, 2u8, ]); assert_eq!(a, b); ```", + "type": "string" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + } + } +} diff --git a/cosmwasm/contracts/price-feed/src/contract.rs b/cosmwasm/contracts/price-feed/src/contract.rs index a35dd56..99ae043 100644 --- a/cosmwasm/contracts/price-feed/src/contract.rs +++ b/cosmwasm/contracts/price-feed/src/contract.rs @@ -12,8 +12,7 @@ use crate::state::{ MEDIANSTATUS, REFDATA, RELAYERS, }; -const E0: Uint64 = Uint64::zero(); -const E9: Uint64 = Uint64::new(1_000_000_000u64); +const E0: Uint256 = Uint256::zero(); const E18: Uint256 = Uint256::from_u128(1_000_000_000_000_000_000u128); // Version Info @@ -167,7 +166,7 @@ fn execute_remove_relayers( fn execute_relay( deps: DepsMut, info: MessageInfo, - symbol_rates: Vec<(String, Uint64)>, + symbol_rates: Vec<(String, Uint256)>, resolve_time: Uint64, request_id: Uint64, ) -> Result { @@ -199,7 +198,7 @@ fn execute_relay( fn execute_relay_historical_median( deps: DepsMut, info: MessageInfo, - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, request_id: Uint64, ) -> Result { @@ -236,7 +235,7 @@ fn execute_relay_historical_median( fn execute_force_relay( deps: DepsMut, info: MessageInfo, - symbol_rates: Vec<(String, Uint64)>, + symbol_rates: Vec<(String, Uint256)>, resolve_time: Uint64, request_id: Uint64, ) -> Result { @@ -262,7 +261,7 @@ fn execute_force_relay( fn execute_force_relay_historical_median( deps: DepsMut, info: MessageInfo, - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, request_id: Uint64, ) -> Result { @@ -288,7 +287,7 @@ fn execute_force_relay_historical_median( fn execute_relay_historical_deviation( deps: DepsMut, info: MessageInfo, - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, request_id: Uint64, ) -> Result { @@ -321,7 +320,7 @@ fn execute_relay_historical_deviation( fn execute_force_relay_historical_deviation( deps: DepsMut, info: MessageInfo, - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, request_id: Uint64, ) -> Result { @@ -377,7 +376,7 @@ fn query_is_relayer(deps: Deps, relayer: &Addr) -> StdResult { fn query_ref(deps: Deps, symbol: &str) -> StdResult { if symbol == "USD" { - Ok(RefData::new(E9, Uint64::MAX, Uint64::zero())) + Ok(RefData::new(E18, Uint64::MAX, Uint64::zero())) } else { REFDATA.load(deps.storage, symbol) } @@ -413,7 +412,7 @@ fn query_median_ref(deps: Deps, symbol: &str) -> StdResult { } if symbol == "USD" { - Ok(RefMedianData::new(vec![E9], Uint64::MAX, Uint64::zero())) + Ok(RefMedianData::new(vec![E18], Uint64::MAX, Uint64::zero())) } else { MEDIANREFDATA.load(deps.storage, symbol) } @@ -482,7 +481,7 @@ mod tests { mut deps: DepsMut, sender: &str, relayers: Vec, - symbol_rates: Vec<(String, Uint64)>, + symbol_rates: Vec<(String, Uint256)>, resolve_time: Uint64, request_id: Uint64, ) { @@ -688,12 +687,12 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = Relay { symbol_rates: zip(symbols.clone(), rates.clone()) - .collect::>(), + .collect::>(), resolve_time: Uint64::from(100u64), request_id: Uint64::one(), }; @@ -712,7 +711,7 @@ mod tests { let retrieved_rates = reference_datas .clone() .into_iter() - .map(|rd| rd.rate / Uint256::from(E9)) + .map(|rd| rd.rate) .collect::>(); assert_eq!( retrieved_rates, @@ -739,11 +738,11 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = Relay { symbol_rates: zip(symbols.clone(), rates.clone()) - .collect::>(), + .collect::>(), resolve_time: Uint64::from(100u64), request_id: Uint64::one(), }; @@ -754,10 +753,10 @@ mod tests { let env = mock_env(); let old_rates = [1, 2, 3] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = Relay { - symbol_rates: zip(symbols.clone(), old_rates).collect::>(), + symbol_rates: zip(symbols.clone(), old_rates).collect::>(), resolve_time: Uint64::from(90u64), request_id: Uint64::one(), }; @@ -776,7 +775,7 @@ mod tests { let retrieved_rates = reference_datas .clone() .into_iter() - .map(|rd| rd.rate / Uint256::from(E9)) + .map(|rd| rd.rate) .collect::>(); assert_eq!( retrieved_rates, @@ -803,10 +802,10 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = Relay { - symbol_rates: zip(symbols.clone(), rates).collect::>(), + symbol_rates: zip(symbols.clone(), rates).collect::>(), resolve_time: Uint64::from(10u64), request_id: Uint64::one(), }; @@ -816,7 +815,7 @@ mod tests { let info = mock_info(relayer.as_str(), &[]); let env = mock_env(); let msg = Relay { - symbol_rates: vec![(String::from("AAA"), Uint64::new(99999))], + symbol_rates: vec![(String::from("AAA"), Uint256::from(99999u128))], resolve_time: Uint64::from(20u64), request_id: Uint64::from(3u64), }; @@ -827,10 +826,10 @@ mod tests { let env = mock_env(); let update_rates = [1, 2, 3] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = Relay { - symbol_rates: zip(symbols.clone(), update_rates).collect::>(), + symbol_rates: zip(symbols.clone(), update_rates).collect::>(), resolve_time: Uint64::from(15u64), request_id: Uint64::from(2u64), }; @@ -849,7 +848,7 @@ mod tests { let retrieved_rates = reference_datas .clone() .into_iter() - .map(|rd| rd.rate / Uint256::from(E9)) + .map(|rd| rd.rate) .collect::>(); let expected_rates = vec![99999, 2, 3] .iter() @@ -874,10 +873,10 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); - let symbol_rates: Vec<(String, Vec)> = symbols + let symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(rates.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -906,7 +905,7 @@ mod tests { execute(deps.as_mut(), env.clone(), info, msg).unwrap(); // try executing relay msg - let symbol_rates: Vec<(String, Vec)> = symbols + let symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(rates.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -944,10 +943,10 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); - let symbol_rates: Vec<(String, Vec)> = symbols + let symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(rates.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -967,10 +966,10 @@ mod tests { let forced_rates = [1001, 2001, 3001] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); - let forced_symbol_rates: Vec<(String, Vec)> = symbols + let forced_symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(forced_rates.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -1009,10 +1008,10 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); - let symbol_rates: Vec<(String, Vec)> = symbols + let symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(rates.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -1050,10 +1049,10 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); - let symbol_rates: Vec<(String, Vec)> = symbols + let symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(rates.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -1071,10 +1070,10 @@ mod tests { let env = mock_env(); let forced_deviations = [1001, 2001, 3001] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); - let symbol_rates: Vec<(String, Vec)> = symbols + let symbol_rates: Vec<(String, Vec)> = symbols .iter() .zip(std::iter::repeat(forced_deviations.clone())) .map(|(s, r)| (s.to_owned(), r)) @@ -1111,11 +1110,11 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = Relay { symbol_rates: zip(symbols.clone(), rates.clone()) - .collect::>(), + .collect::>(), resolve_time: Uint64::zero(), request_id: Uint64::zero(), }; @@ -1144,11 +1143,11 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = ForceRelay { symbol_rates: zip(symbols.clone(), rates.clone()) - .collect::>(), + .collect::>(), resolve_time: Uint64::from(100u64), request_id: Uint64::from(2u64), }; @@ -1159,11 +1158,11 @@ mod tests { let env = mock_env(); let forced_rates = [1, 2, 3] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = ForceRelay { symbol_rates: zip(symbols.clone(), forced_rates.clone()) - .collect::>(), + .collect::>(), resolve_time: Uint64::from(90u64), request_id: Uint64::one(), }; @@ -1181,7 +1180,7 @@ mod tests { .unwrap(); let retrieved_rates = reference_datas .into_iter() - .map(|rd| rd.rate / Uint256::from(E9)) + .map(|rd| rd.rate) .collect::>(); assert_eq!( retrieved_rates, @@ -1207,11 +1206,11 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); let msg = ForceRelay { symbol_rates: zip(symbols.clone(), rates.clone()) - .collect::>(), + .collect::>(), resolve_time: Uint64::zero(), request_id: Uint64::zero(), }; @@ -1273,7 +1272,7 @@ mod tests { let mut deps = mock_dependencies(); let relayer = String::from("relayer"); let symbol = vec![String::from("AAA")]; - let rate = vec![Uint64::new(1000)]; + let rate = vec![Uint256::from(1000u128)]; setup_relays( deps.as_mut(), "owner", @@ -1309,7 +1308,7 @@ mod tests { let mut deps = mock_dependencies(); let relayer = String::from("relayer"); let symbol = vec![String::from("AAA")]; - let rate = vec![Uint64::new(1000)]; + let rate = vec![Uint256::from(1000u128)]; setup_relays( deps.as_mut(), "owner", @@ -1328,7 +1327,7 @@ mod tests { assert_eq!( from_binary::(&binary_res).unwrap(), ReferenceData::new( - Uint256::from(rate[0]).mul(Uint256::from(E9)), + Uint256::from(rate[0]), Uint64::from(100u64), Uint64::MAX, ) @@ -1361,8 +1360,8 @@ mod tests { .collect::>(); let rates = [1000, 2000, 3000] .iter() - .map(|r| Uint64::new(*r)) - .collect::>(); + .map(|r| Uint256::from(*r as u128)) + .collect::>(); setup_relays( deps.as_mut(), "owner", @@ -1386,7 +1385,7 @@ mod tests { .iter() .map(|r| { ReferenceData::new( - Uint256::from(*r).mul(Uint256::from(E9)), + Uint256::from(*r), Uint64::from(100u64), Uint64::MAX, ) diff --git a/cosmwasm/contracts/price-feed/src/msg.rs b/cosmwasm/contracts/price-feed/src/msg.rs index 643a155..90f358d 100644 --- a/cosmwasm/contracts/price-feed/src/msg.rs +++ b/cosmwasm/contracts/price-feed/src/msg.rs @@ -1,5 +1,5 @@ use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::Uint64; +use cosmwasm_std::{Uint256, Uint64}; use crate::state::{RefData,RefDeviationData,RefMedianData,ReferenceData}; #[cw_serde] @@ -37,7 +37,7 @@ pub enum ExecuteMsg { // e.g. // BTC = 19,343.34, ETH = 1,348.57 // symbol_rates ≡ <("BTC", 19343340000000), ("ETH", 1348570000000)> - symbol_rates: Vec<(String, Uint64)>, + symbol_rates: Vec<(String, Uint256)>, // Resolve time of request on Ojo in Unix timestamp resolve_time: Uint64, // Request ID of the results on Ojo @@ -50,7 +50,7 @@ pub enum ExecuteMsg { // e.g. // BTC = 19,343.34, ETH = 1,348.57 // symbol_rates ≡ <("BTC", 19343340000000), ("ETH", 1348570000000)> - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, // Resolve time of request on Ojo in Unix timestamp resolve_time: Uint64, // Request ID of the results on Ojo @@ -58,26 +58,26 @@ pub enum ExecuteMsg { }, // Relays a vector of symbols and their corresponding deviation rates RelayHistoricalDeviation { - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, // Request ID of the results on Ojo request_id: Uint64, }, // Same as Relay but without the resolve_time guard ForceRelay { - symbol_rates: Vec<(String, Uint64)>, + symbol_rates: Vec<(String, Uint256)>, resolve_time: Uint64, request_id: Uint64, }, // Same as RelayHistoricalMedian but without the resolve_time guard ForceRelayHistoricalMedian { - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, request_id: Uint64, }, // Same as RelayHistoricalDeviation but without the resolve_time guard ForceRelayHistoricalDeviation { - symbol_rates: Vec<(String, Vec)>, + symbol_rates: Vec<(String, Vec)>, resolve_time: Uint64, // Request ID of the results on Ojo request_id: Uint64, diff --git a/cosmwasm/contracts/price-feed/src/state.rs b/cosmwasm/contracts/price-feed/src/state.rs index b479799..2b00cde 100644 --- a/cosmwasm/contracts/price-feed/src/state.rs +++ b/cosmwasm/contracts/price-feed/src/state.rs @@ -24,7 +24,7 @@ pub const DEVIATIONDATA: Map<&str, RefDeviationData> = Map::new("deviationdata") #[cw_serde] pub struct RefData { // Rate of an asset relative to USD (deviation of assets when used with deviation queries) - pub rate: Uint64, + pub rate: Uint256, // The resolve time of the request ID pub resolve_time: Uint64, // The request ID where the rate was derived from @@ -32,7 +32,7 @@ pub struct RefData { } impl RefData { - pub fn new(rate: Uint64, resolve_time: Uint64, request_id: Uint64) -> Self { + pub fn new(rate: Uint256, resolve_time: Uint64, request_id: Uint64) -> Self { RefData { rate, resolve_time, @@ -44,7 +44,7 @@ impl RefData { #[cw_serde] pub struct RefMedianData { // Median Rates of an asset relative to USD - pub rates: Vec, + pub rates: Vec, // The resolve time of the request ID pub resolve_time: Uint64, // The request ID where the rate was derived from @@ -52,7 +52,7 @@ pub struct RefMedianData { } impl RefMedianData { - pub fn new(rates: Vec, resolve_time: Uint64, request_id: Uint64) -> Self { + pub fn new(rates: Vec, resolve_time: Uint64, request_id: Uint64) -> Self { RefMedianData { rates, resolve_time, @@ -64,7 +64,7 @@ impl RefMedianData { #[cw_serde] pub struct RefDeviationData { // Deviation Rates of an asset relative to USD - pub rates: Vec, + pub rates: Vec, // The resolve time of the request ID pub resolve_time: Uint64, // The request ID where the rate was derived from @@ -72,7 +72,7 @@ pub struct RefDeviationData { } impl RefDeviationData { - pub fn new(rates: Vec, resolve_time: Uint64, request_id: Uint64) -> Self { + pub fn new(rates: Vec, resolve_time: Uint64, request_id: Uint64) -> Self { RefDeviationData { rates, resolve_time, diff --git a/cw-relayer/relayer/relayer.go b/cw-relayer/relayer/relayer.go index 7220905..a604aa2 100644 --- a/cw-relayer/relayer/relayer.go +++ b/cw-relayer/relayer/relayer.go @@ -23,7 +23,7 @@ import ( var ( // RateFactor is used to convert ojo prices to contract-compatible values. - RateFactor = types.NewDec(10).Power(9) + RateFactor = types.NewDec(10).Power(18) noRates = fmt.Errorf("no rates found") noMedians = fmt.Errorf("median deviations empty") noDeviations = fmt.Errorf("deviation deviations empty")