Stored conversion rate updater (#1005)

* update conversion rate: initial commit

* Rialto=Polkadot && Millau=Kusama + actually update conversion rates

* update deployment scripts and readme

* allow non-zero difference between stored and real rates

* dummy commit

* Revert "dummy commit"

This reverts commit a438198180a8385feeaaca60c9d2da0950465215.

* clippy

* #[allow(clippy::float_cmp)] in conversion rate update

* dummy

* Revert "dummy"

This reverts commit 90cd6e47cda56f655e94dbef76138e6cc58d664a.

* spell

* shared_value_ref() -> get()

* Revert "shared_value_ref() -> get()"

This reverts commit 20aa30de6a59b2099cfba3e9676e71200b7bb468.
This commit is contained in:
Svyatoslav Nikolsky
2021-09-01 11:51:57 +03:00
committed by Bastian Köcher
parent fc9363619a
commit 3ef4574594
13 changed files with 464 additions and 24 deletions
@@ -245,3 +245,33 @@ pub(crate) fn add_standalone_metrics(
)),
)
}
/// Update Rialto -> Millau conversion rate, stored in Millau runtime storage.
pub(crate) async fn update_rialto_to_millau_conversion_rate(
client: Client<Millau>,
signer: <Millau as TransactionSignScheme>::AccountKeyPair,
updated_rate: f64,
) -> anyhow::Result<()> {
let genesis_hash = *client.genesis_hash();
let signer_id = (*signer.public().as_array_ref()).into();
client
.submit_signed_extrinsic(signer_id, move |transaction_nonce| {
Bytes(
Millau::sign_transaction(
genesis_hash,
&signer,
transaction_nonce,
millau_runtime::MessagesCall::update_pallet_parameter(
millau_runtime::rialto_messages::MillauToRialtoMessagesParameter::RialtoToMillauConversionRate(
sp_runtime::FixedU128::from_float(updated_rate),
),
)
.into(),
)
.encode(),
)
})
.await
.map(drop)
.map_err(|err| anyhow::format_err!("{:?}", err))
}
@@ -37,9 +37,9 @@ mod wococo;
// Rialto as BTC and Millau as wBTC (only in relayer).
/// The identifier of token, which value is associated with Rialto token value by relayer.
pub(crate) const RIALTO_ASSOCIATED_TOKEN_ID: &str = "bitcoin";
pub(crate) const RIALTO_ASSOCIATED_TOKEN_ID: &str = "polkadot";
/// The identifier of token, which value is associated with Millau token value by relayer.
pub(crate) const MILLAU_ASSOCIATED_TOKEN_ID: &str = "wrapped-bitcoin";
pub(crate) const MILLAU_ASSOCIATED_TOKEN_ID: &str = "kusama";
use relay_utils::metrics::MetricsParams;
@@ -244,3 +244,33 @@ pub(crate) fn add_standalone_metrics(
)),
)
}
/// Update Millau -> Rialto conversion rate, stored in Rialto runtime storage.
pub(crate) async fn update_millau_to_rialto_conversion_rate(
client: Client<Rialto>,
signer: <Rialto as TransactionSignScheme>::AccountKeyPair,
updated_rate: f64,
) -> anyhow::Result<()> {
let genesis_hash = *client.genesis_hash();
let signer_id = (*signer.public().as_array_ref()).into();
client
.submit_signed_extrinsic(signer_id, move |transaction_nonce| {
Bytes(
Rialto::sign_transaction(
genesis_hash,
&signer,
transaction_nonce,
rialto_runtime::MessagesCall::update_pallet_parameter(
rialto_runtime::millau_messages::RialtoToMillauMessagesParameter::MillauToRialtoConversionRate(
sp_runtime::FixedU128::from_float(updated_rate),
),
)
.into(),
)
.encode(),
)
})
.await
.map(drop)
.map_err(|err| anyhow::format_err!("{:?}", err))
}