From 6ef9e55651beeabe2b48a16e1d968e36df026b66 Mon Sep 17 00:00:00 2001 From: David Craven Date: Sat, 8 Feb 2025 18:49:46 +0100 Subject: [PATCH 1/6] Evm key (#1521) --- Cargo.lock | 33 +++++++++--------- gmp/evm/Cargo.toml | 1 - gmp/evm/factory/additional_config.json | 3 +- gmp/evm/src/lib.rs | 47 +++++--------------------- 4 files changed, 25 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e5457950c..8a578a3ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5596,7 +5596,6 @@ dependencies = [ "hex", "reqwest", "rosetta-client", - "rosetta-crypto", "rosetta-ethereum-backend", "rosetta-ethereum-types", "rosetta-server", @@ -14159,7 +14158,7 @@ dependencies = [ [[package]] name = "rosetta-client" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14190,7 +14189,7 @@ dependencies = [ [[package]] name = "rosetta-config-astar" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "rosetta-core", @@ -14200,7 +14199,7 @@ dependencies = [ [[package]] name = "rosetta-config-ethereum" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "const-hex", @@ -14220,7 +14219,7 @@ dependencies = [ [[package]] name = "rosetta-config-polkadot" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "rosetta-core", @@ -14231,7 +14230,7 @@ dependencies = [ [[package]] name = "rosetta-core" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14248,7 +14247,7 @@ dependencies = [ [[package]] name = "rosetta-crypto" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "bech32", @@ -14274,7 +14273,7 @@ dependencies = [ [[package]] name = "rosetta-ethereum-backend" version = "0.1.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "async-trait", "auto_impl", @@ -14290,7 +14289,7 @@ dependencies = [ [[package]] name = "rosetta-ethereum-types" version = "0.2.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "bytes", "const-hex", @@ -14324,7 +14323,7 @@ dependencies = [ [[package]] name = "rosetta-server" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14347,7 +14346,7 @@ dependencies = [ [[package]] name = "rosetta-server-astar" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14371,7 +14370,7 @@ dependencies = [ [[package]] name = "rosetta-server-ethereum" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14400,7 +14399,7 @@ dependencies = [ [[package]] name = "rosetta-server-polkadot" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14421,7 +14420,7 @@ dependencies = [ [[package]] name = "rosetta-tx-ethereum" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "rosetta-config-ethereum", @@ -14432,7 +14431,7 @@ dependencies = [ [[package]] name = "rosetta-tx-polkadot" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "blake2-rfc", @@ -14446,7 +14445,7 @@ dependencies = [ [[package]] name = "rosetta-types" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "serde", "serde_json", @@ -14455,7 +14454,7 @@ dependencies = [ [[package]] name = "rosetta-utils" version = "0.1.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#e345337a7135cc9678d9faf6e47bc06f0bb59203" +source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "bytes", "futures-timer", diff --git a/gmp/evm/Cargo.toml b/gmp/evm/Cargo.toml index 7682cf896..f8276ea47 100644 --- a/gmp/evm/Cargo.toml +++ b/gmp/evm/Cargo.toml @@ -17,7 +17,6 @@ futures.workspace = true hex.workspace = true reqwest = { version = "0.12.7", default-features = false, features = ["json", "rustls-tls-native-roots"] } rosetta-client = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } -rosetta-crypto = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } rosetta-server = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } rosetta-server-ethereum = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } rosetta-ethereum-backend = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } diff --git a/gmp/evm/factory/additional_config.json b/gmp/evm/factory/additional_config.json index ab77686b2..5cb21bd4c 100644 --- a/gmp/evm/factory/additional_config.json +++ b/gmp/evm/factory/additional_config.json @@ -3,6 +3,5 @@ "factory_address": "0x0000000000001c4bf962df86e38f0c10c7972c6e", "raw_tx": "0xf909a98085174876e800839896808080b909565f195f555f196001555f196002555f19600355756d34600c573d3d3d3d47335af15b003d52600e6012f35f526016600a47f050610915806100416080396080f3fe3033146108c4575f3560e01c63d0496d6a811461069f577d1b0000001e00000000000000000000000000000000001f1c1d0000001a00601f82161a9065838363634343821a7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc81015f5236119063ffffffff772af25238b9aaf526d2a8169ace40d339ac049de28778391e6420406080a0851a1c1614161561069b576503070105000460806101805f80306107d0fa91821561063e575b1a9060031b175f51906024356004810135916024820160c0528260e0526024604435926001831695600485013594600185368689850101111562400000891083366023870112878711680100000000000000008810861616161616161616809481920102950295856101005286610120526024600160643560048101359088831c9183833687848601011115680100000000000000008410366023870112607f871168010000000000000000881016161616161680958193010261014052026101605216151793881517928115159268010000000000000000366024858501011115931091680100000000000000003660238301129282119110161616161616161561063a57607f6101805160031c16607e811161062d5760010160a052344710344718029182341893808261020037610200209015150260605260e051918260c0516102003774ff0000000000000000000000000000000000000000301790815f526004359384602052610200208060405273ffffffffffffffffffffffffffffffffffffffff6055600b201692335f52856020526034600c206020525f527f0281a97663cf81306691f0800b13a91c4d335e1d772539f127389adae654ffc66040526055600b2074ffffffffffffffffffffffffffffffffffffffff008160081b1676d694000000000000000000000000000000000000000001175f528373ffffffffffffffffffffffffffffffffffffffff60176009201660018760021c1695869118021893157f0281a97663cf81306691f0800b13a91c4d335e1d772539f127389adae654ffc683141680853b1761060f57509073ffffffffffffffffffffffffffffffffffffffff869392855f5216602052604052610100516006610120518215158335029987878c84610140519463ffffffff610160519660a051998a97169b3414158c17971515903560e01c029360801c160260161b1760201b1760a01b1760071b1760031b17997fffffffffffffffffffffffff000000000000000000000000000000000000000033911617600888169a8a8c5f146105aa575090601092915f5d60015d8560025d8960035d830192019060401b905b828110610590575050505b600484161561056a575050505f5190602051335f52836020526034600c206b60203d3d733d526030601bf3600c527f763318602e57363d3d37363d47f080915215602e57f35bfd602b5233601452645f52602c5f80f5925f526030833b14908314161561055d575f602091610200825194600260e0519316158802905af1905f5118901517610550575b81610140516101605190818161020037816102002093604051905f51956060519060a05191602052873f604052841515026060526080528460a05233918660a06020a4835f5261050a575b505050610180516101a051906101c051926101e051945f146104e157505f5d60015d60025d60035d60205ff35b91939281155f038095818094175f5517600155176002556105015760205ff35b1760035560205ff35b6102005f939284935af115610521575f81816104b4565b6330b9b6dd5f52602080523d6040525f3d606001523d5f60603e604467ffffffffffffffe0601f3d011601601cfd5b6308fde50a5f526004601cfd5b6308fde50a5f526004601cfd5b9091925061020060e05191158602f5801591181715610469576304a5b3ee5f526004601cfd5b600191929394508060209135845d019101869392916103d4565b91815f556001558618600255610606575b601081116105cc575b5050506103df565b6001601060605192850194019260401b82815501915b8381106105ef57506105c4565b8035821883558895506001909201916020016105e2565b886003556105bb565b8481637dd8f3ba0263b8bcb0c9185f526020521560051b600401601cfd5b6341f739de5f526004601cfd5b5f80fd5b5f547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811861066e575b506100b6565b806001916101805281546101a0526002546101c0521661068f575b5f610668565b6003546101e052610689565b5f80fd5b610bb85a1034176108c05760806101805f80306107d0fa8015610861575b610180516101a051916101c051926101e05193623fffff8460ca1c169460205f5273ffffffffffffffffffffffffffffffffffffffff85600a1c1660205273ffffffffffffffffffffffffffffffffffffffff8316604052607f8560031c1660605260018560021c16608052600185811c1660a0527fffffffff000000000000000000000000000000000000000000000000000000008560361b1660c05260e05261010052610120805283610140527fffffffffffffffffffffffff000000000000000000000000000000000000000073ffffffff000000000000000000000000000000008460601c16911617610160525f1461080557610160820190603d1b687f0000000000000000166101705b8281106107f357505050601f67ffffffffffffffe0915b5f8161016001520116610160015ff35b6020600191835c8152019101906107cc565b60108211610820575b50601f67ffffffffffffffe0916107e3565b603d1b687f0000000000000000168054610160830191600101906101705b83811061084d5750505061080e565b60206001918385541881520192019161083e565b5f547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8118610891575b506106bd565b806001916101805281546101a05280600254186101c052166108b4575b8161088b565b6003546101e0526108ae565b5f80fd5b5f5c5f5260015c60205260025c60405260035c60605260805ff3fea2646970667358221220c08668cd0244953158d248e1677b7e7572d7cbf75dc8e9487789fd51dba84e2d64736f6c634300081b00331ba0853af0eb51d22d61a49788cf13a49149ad25a70524cf23fcbca72cee9d9a89aca02526c0ed486078ef863bf89351fb67e18812dd242036280d39eb1aec47d065ba", "required_balance": 51000000000000000000, - "deployment_salt": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - "proxy_admin_sk": "owner word vocal dose decline sunset battle example forget excite gentle waste" + "deployment_salt": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] } diff --git a/gmp/evm/src/lib.rs b/gmp/evm/src/lib.rs index 46666fc2f..d322440b6 100644 --- a/gmp/evm/src/lib.rs +++ b/gmp/evm/src/lib.rs @@ -6,9 +6,8 @@ use futures::Stream; use reqwest::Client; use rosetta_client::{ query::GetLogs, types::AccountIdentifier, AtBlock, CallResult, FilterBlockOption, - GetTransactionCount, Signer, SubmitResult, TransactionReceipt, Wallet, + GetTransactionCount, SubmitResult, TransactionReceipt, Wallet, }; -use rosetta_crypto::{bip44::ChildNumber, SecretKey}; use rosetta_ethereum_backend::{jsonrpsee::Adapter, EthereumRpc}; use rosetta_server::ws::{default_client, DefaultClient}; use rosetta_server_ethereum::utils::{ @@ -206,12 +205,8 @@ impl Connector { Ok(gateway_address) } - fn compute_proxy_address( - &self, - config: &DeploymentConfig, - admin: AlloyAddress, - proxy: &[u8], - ) -> Result<[u8; 20]> { + fn compute_proxy_address(&self, config: &DeploymentConfig, proxy: &[u8]) -> Result<[u8; 20]> { + let admin = a_addr(self.address()); let factory_address = a_addr(self.parse_address(&config.factory_address)?).0 .0; let proxy_constructor = sol::GatewayProxy::constructorCall { admin }; let proxy_bytecode = get_contract_from_slice(proxy)?; @@ -229,30 +224,14 @@ impl Connector { Ok(computed_proxy_address) } - fn get_proxy_admin_creds(&self, config: &DeploymentConfig) -> Result<(SecretKey, [u8; 20])> { - let signer = Signer::new(&config.proxy_admin_sk.parse()?, "")?; - let proxy_admin_sk = signer - .bip44_account(self.wallet.config().algorithm, self.wallet.config().coin, 0)? - .derive(ChildNumber::non_hardened_from_u32(0))?; - - let proxy_admin_pk = proxy_admin_sk - .public_key() - .to_address(rosetta_crypto::address::AddressFormat::Eip55); - - let proxy_admin_address = a_addr(self.parse_address(proxy_admin_pk.address())?).0 .0; - let proxy_admin_sk = proxy_admin_sk.secret_key(); - Ok((proxy_admin_sk.clone(), proxy_admin_address)) - } - async fn deploy_proxy( &self, config: &DeploymentConfig, proxy_addr: AlloyAddress, gateway_address: AlloyAddress, proxy_bytes: &[u8], - admin_sk: SecretKey, - admin: AlloyAddress, ) -> Result<(AlloyAddress, u64)> { + let admin = a_addr(self.address()); let factory_address = a_addr(self.parse_address(&config.factory_address)?).0 .0; let deployment_salt = config.deployment_salt; @@ -269,7 +248,7 @@ impl Connector { } .abi_encode(); let payload: [u8; 32] = Keccak256::digest(digest).into(); - let signature = admin_sk.sign_prehashed(&payload)?; + let signature = self.wallet.sign_prehashed(&payload)?; let (v, r, s) = extract_signature_bytes(signature.to_bytes())?; let arguments = ProxyContext { // Ethereum verification uses 27,28 instead of 0,1 for recovery id @@ -636,8 +615,7 @@ impl IConnectorAdmin for Connector { } // proxy address computation - let (admin_sk, admin) = self.get_proxy_admin_creds(&config)?; - let proxy_addr = self.compute_proxy_address(&config, admin.into(), proxy)?; + let proxy_addr = self.compute_proxy_address(&config, proxy)?; // check if proxy is deployed let is_proxy_deployed = self @@ -654,16 +632,8 @@ impl IConnectorAdmin for Connector { let gateway_address = self.deploy_gateway(&config, proxy_addr, gateway).await?; // compute proxy arguments - let (proxy_address, block) = self - .deploy_proxy( - &config, - proxy_addr.into(), - gateway_address, - proxy, - admin_sk, - admin.into(), - ) - .await?; + let (proxy_address, block) = + self.deploy_proxy(&config, proxy_addr.into(), gateway_address, proxy).await?; Ok((t_addr(proxy_address), block)) } @@ -890,7 +860,6 @@ pub struct DeploymentConfig { pub raw_tx: String, pub factory_address: String, pub deployment_salt: [u8; 32], - pub proxy_admin_sk: String, } #[derive(Deserialize)] From cdaa009c4c6751ca427670f64ed8a20a1cbd1a49 Mon Sep 17 00:00:00 2001 From: Amar Singh Date: Sun, 9 Feb 2025 01:53:32 -0500 Subject: [PATCH 2/6] SORA bridge mainnet (#1514) Co-authored-by: David Craven --- node/src/service.rs | 165 ++++++++++++++++------------------ runtime/src/apis.rs | 5 -- runtime/src/configs/bridge.rs | 11 ++- runtime/src/configs/mod.rs | 1 - runtime/src/lib.rs | 8 ++ 5 files changed, 94 insertions(+), 96 deletions(-) diff --git a/node/src/service.rs b/node/src/service.rs index c3edd869f..2af8d9d7c 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -9,6 +9,12 @@ use std::{path::Path, sync::Arc}; use polkadot_sdk::*; +use eth_bridge::common; +use eth_bridge::PeerConfig; +use eth_bridge::STORAGE_ETH_NODE_PARAMS; +use eth_bridge::STORAGE_NETWORK_IDS_KEY; +use eth_bridge::STORAGE_PEER_SECRET_KEY; +use eth_bridge::STORAGE_SUB_NODE_URL_KEY; use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE; use sc_client_api::{Backend, BlockBackend}; use sc_consensus_babe::{self, SlotProportion}; @@ -19,7 +25,16 @@ use sc_network_sync::{strategy::warp::WarpSyncParams, SyncingService}; use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager}; use sc_telemetry::{Telemetry, TelemetryWorker}; use sc_transaction_pool_api::OffchainTransactionPoolFactory; +use scale_codec::Encode; +use sp_core::offchain::OffchainStorage; +use sp_core::ByteArray; +use sp_core::Pair; +use sp_runtime::offchain::STORAGE_PREFIX; use sp_runtime::traits::Block as BlockT; +use sp_runtime::traits::IdentifyAccount; +use sp_std::collections::btree_set::BTreeSet; +use std::fs::File; +use timechain_runtime::Runtime; use time_primitives::{AccountId, Balance, Block, Nonce}; @@ -117,96 +132,74 @@ where let client = Arc::new(client); // HASHI Bridge support - #[cfg(feature = "testnet")] + let mut bridge_peer_secret_key = None; + + if let Some(first_pk_raw) = keystore_container + .keystore() + .keys(eth_bridge::KEY_TYPE) + .unwrap() + .first() + .cloned() { - use eth_bridge::common; - use eth_bridge::PeerConfig; - use eth_bridge::STORAGE_ETH_NODE_PARAMS; - use eth_bridge::STORAGE_NETWORK_IDS_KEY; - use eth_bridge::STORAGE_PEER_SECRET_KEY; - use eth_bridge::STORAGE_SUB_NODE_URL_KEY; - use scale_codec::Encode; - use sp_core::offchain::OffchainStorage; - use sp_core::ByteArray; - use sp_core::Pair; - use sp_runtime::offchain::STORAGE_PREFIX; - use sp_runtime::traits::IdentifyAccount; - use sp_std::collections::btree_set::BTreeSet; - use std::fs::File; - use timechain_runtime::Runtime; - let mut bridge_peer_secret_key = None; - - if let Some(first_pk_raw) = keystore_container - .keystore() - .keys(eth_bridge::KEY_TYPE) - .unwrap() - .first() - .cloned() - { - let pk = eth_bridge::offchain::crypto::Public::from_slice(&first_pk_raw[..]) - .expect("should have correct size"); - let sub_public = sp_core::ecdsa::Public::from(pk.clone()); - let public = secp256k1::PublicKey::parse_compressed(&sub_public.0).unwrap(); - let address = common::eth::public_key_to_eth_address(&public); - let account = sp_runtime::MultiSigner::Ecdsa(sub_public).into_account(); - log::warn!( - "Peer info: address: {:?}, account: {:?}, {}, public: {:?}", - address, - account, - account, - sub_public - ); - let keystore = keystore_container.local_keystore(); - if let Ok(Some(kep)) = keystore.key_pair::(&pk) { - let seed = kep.to_raw_vec(); - bridge_peer_secret_key = Some(seed); - } - } else { - log::debug!("Ethereum bridge peer key not found.") + let pk = eth_bridge::offchain::crypto::Public::from_slice(&first_pk_raw[..]) + .expect("should have correct size"); + let sub_public = sp_core::ecdsa::Public::from(pk.clone()); + let public = secp256k1::PublicKey::parse_compressed(&sub_public.0).unwrap(); + let address = common::eth::public_key_to_eth_address(&public); + let account = sp_runtime::MultiSigner::Ecdsa(sub_public).into_account(); + log::warn!( + "Peer info: address: {:?}, account: {:?}, {}, public: {:?}", + address, + account, + account, + sub_public + ); + let keystore = keystore_container.local_keystore(); + if let Ok(Some(kep)) = keystore.key_pair::(&pk) { + let seed = kep.to_raw_vec(); + bridge_peer_secret_key = Some(seed); } + } else { + log::debug!("Ethereum bridge peer key not found.") + } - if let Some(sk) = bridge_peer_secret_key { - let mut storage = backend.offchain_storage().unwrap(); - storage.set(STORAGE_PREFIX, STORAGE_PEER_SECRET_KEY, &sk.encode()); - - let path = config - .network - .net_config_path - .clone() - .or(config.database.path().map(|x| x.to_owned())) - .expect("Expected network or database path."); - let bridge_path = path - .ancestors() - .nth(1) - .map(|x| { - let mut x = x.to_owned(); - x.push("bridge/eth.json"); - x - }) - .unwrap(); - let file = File::open(&bridge_path).map_err(|_| { - ServiceError::Other(format!( - "Ethereum bridge node config not found. Expected path: {:?}", - bridge_path - )) - })?; - let peer_config: PeerConfig<::NetworkId> = - serde_json::from_reader(&file).expect("Invalid ethereum bridge node config."); - let mut network_ids = BTreeSet::new(); - for (net_id, params) in peer_config.networks { - let string = format!("{}-{:?}", STORAGE_ETH_NODE_PARAMS, net_id); - storage.set(STORAGE_PREFIX, string.as_bytes(), ¶ms.encode()); - network_ids.insert(net_id); - } - storage.set(STORAGE_PREFIX, STORAGE_NETWORK_IDS_KEY, &network_ids.encode()); - let addr = config.rpc_addr.unwrap_or_else(|| ([127, 0, 0, 1], config.rpc_port).into()); - log::warn!("RPC Address: {addr}"); - storage.set( - STORAGE_PREFIX, - STORAGE_SUB_NODE_URL_KEY, - &format!("http://{}", addr).encode(), - ); + if let Some(sk) = bridge_peer_secret_key { + let mut storage = backend.offchain_storage().unwrap(); + storage.set(STORAGE_PREFIX, STORAGE_PEER_SECRET_KEY, &sk.encode()); + + let path = config + .network + .net_config_path + .clone() + .or(config.database.path().map(|x| x.to_owned())) + .expect("Expected network or database path."); + let bridge_path = path + .ancestors() + .nth(1) + .map(|x| { + let mut x = x.to_owned(); + x.push("bridge/eth.json"); + x + }) + .unwrap(); + let file = File::open(&bridge_path).map_err(|_| { + ServiceError::Other(format!( + "Ethereum bridge node config not found. Expected path: {:?}", + bridge_path + )) + })?; + let peer_config: PeerConfig<::NetworkId> = + serde_json::from_reader(&file).expect("Invalid ethereum bridge node config."); + let mut network_ids = BTreeSet::new(); + for (net_id, params) in peer_config.networks { + let string = format!("{}-{:?}", STORAGE_ETH_NODE_PARAMS, net_id); + storage.set(STORAGE_PREFIX, string.as_bytes(), ¶ms.encode()); + network_ids.insert(net_id); } + storage.set(STORAGE_PREFIX, STORAGE_NETWORK_IDS_KEY, &network_ids.encode()); + let addr = config.rpc_addr.unwrap_or_else(|| ([127, 0, 0, 1], config.rpc_port).into()); + log::warn!("RPC Address: {addr}"); + storage.set(STORAGE_PREFIX, STORAGE_SUB_NODE_URL_KEY, &format!("http://{}", addr).encode()); } let telemetry = telemetry.map(|(worker, telemetry)| { diff --git a/runtime/src/apis.rs b/runtime/src/apis.rs index 74908b74c..8765e452f 100644 --- a/runtime/src/apis.rs +++ b/runtime/src/apis.rs @@ -44,11 +44,8 @@ use crate::RuntimeGenesisConfig; use crate::{Members, Networks, Shards, Staking, Tasks}; // HASHI Bridge -#[cfg(feature = "testnet")] use crate::configs::bridge::NetworkId as BridgeNetworkId; -#[cfg(feature = "testnet")] use crate::EthBridge; -#[cfg(feature = "testnet")] use eth_bridge::{ common::{AssetId as BridgeAssetId, BalancePrecision as BridgeBalancePrecision}, offchain::SignatureParams as BridgeSignatureParams, @@ -57,7 +54,6 @@ use eth_bridge::{ RequestStatus as BridgeRequestStatus, }, }; -#[cfg(feature = "testnet")] use sp_runtime::DispatchError; // Original Author: ntn-x2 @ KILTprotocol @@ -377,7 +373,6 @@ impl_runtime_apis! { } } - #[cfg(feature = "testnet")] impl eth_bridge_runtime_api::EthBridgeRuntimeApi< Block, diff --git a/runtime/src/configs/bridge.rs b/runtime/src/configs/bridge.rs index dc11e7b9b..e119d0321 100644 --- a/runtime/src/configs/bridge.rs +++ b/runtime/src/configs/bridge.rs @@ -3,7 +3,7 @@ use polkadot_sdk::*; use frame_support::parameter_types; // Local module imports -use crate::{Balances, Runtime, RuntimeCall, RuntimeEvent}; +use crate::{deposit, Balance, Balances, Runtime, RuntimeCall, RuntimeEvent}; pub type NetworkId = u32; @@ -31,8 +31,11 @@ impl eth_bridge::Config for Runtime { } parameter_types! { - pub const DepositBase: u64 = 1; - pub const DepositFactor: u64 = 1; + /// Base deposit required for storing a multisig execution, covering the cost of a single storage item. + // One storage item; key size is 32; value is size 4+4(block number)+16(balance)+32(account ID) bytes = 56 bytes. + pub const DepositBase: Balance = deposit(1, 88); + // Additional storage item size of 32 bytes. + pub const DepositFactor: Balance = deposit(0, 32); pub const MaxSignatories: u16 = 100; } @@ -43,5 +46,5 @@ impl bridge_multisig::Config for Runtime { type DepositBase = DepositBase; type DepositFactor = DepositFactor; type MaxSignatories = MaxSignatories; - type WeightInfo = (); + type WeightInfo = bridge_multisig::weights::SubstrateWeight; } diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index 1ef2a5e92..ec931ea4c 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -10,7 +10,6 @@ pub mod staking; pub mod tokenomics; pub mod utilities; -#[cfg(feature = "testnet")] pub mod bridge; #[cfg(feature = "testnet")] pub mod custom; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3f83eff78..6e28e79fb 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -480,6 +480,14 @@ mod runtime { #[runtime::pallet_index(43)] pub type Launch = pallet_launch; + + // HASHI Bridge + + #[runtime::pallet_index(50)] + pub type EthBridge = eth_bridge; + + #[runtime::pallet_index(51)] + pub type BridgeMultisig = bridge_multisig; } /// Testnet and develop runtime assembly From 7e11e3159198eaca39cc24afd426a6669b4e6bf7 Mon Sep 17 00:00:00 2001 From: David Craven Date: Sun, 9 Feb 2025 08:10:45 +0100 Subject: [PATCH 3/6] Add integration env. (#1522) --- .github/workflows/merge-srtool-runtime.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/merge-srtool-runtime.yaml b/.github/workflows/merge-srtool-runtime.yaml index 6fe9a66ca..e44ec8c3c 100644 --- a/.github/workflows/merge-srtool-runtime.yaml +++ b/.github/workflows/merge-srtool-runtime.yaml @@ -23,6 +23,7 @@ on: type: choice options: - development + - integration thread: description: "Slack thread id" required: false From ddae285b25ba0d00507410a24dd6dde273e46f6f Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Sun, 9 Feb 2025 12:22:51 +0100 Subject: [PATCH 4/6] runtime: add reward pool and re-enable rewards (#1513) --- node/src/chain_spec.rs | 73 ++++++++++++++---------------- node/src/chains/internal.keys.json | 3 +- pallets/launch/src/data/mod.rs | 1 + pallets/launch/src/data/v19.rs | 6 +++ pallets/launch/src/lib.rs | 8 +++- pallets/launch/src/tests.rs | 1 + runtime/src/configs/staking.rs | 52 +++++++++++++++++---- runtime/src/configs/tokenomics.rs | 13 +++--- runtime/src/lib.rs | 5 ++ 9 files changed, 105 insertions(+), 57 deletions(-) create mode 100644 pallets/launch/src/data/v19.rs diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 734551c8a..d435b2b25 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -17,18 +17,14 @@ use time_primitives::{AccountId, Balance, Block, BlockNumber, ANLOG, SS58_PREFIX use timechain_runtime::{RUNTIME_VARIANT, WASM_BINARY}; /// Stash and float for validators -const PER_VALIDATOR_STASH: Balance = ANLOG * 500_000; -const PER_VALIDATOR_UNLOCKED: Balance = ANLOG * 20_000; +const PER_VALIDATOR_STASH: Balance = ANLOG * 1_001_000; +const PER_VALIDATOR_UNLOCKED: Balance = ANLOG * 1_000; /// Stash and float for chronicles const PER_CHRONICLE_STASH: Balance = ANLOG * 100_000; /// Token supply for prefunded admin accounts -const CONTROLLER_SUPPLY: Balance = ANLOG * 50_000; -const PER_COUNCIL_STASH: Balance = ANLOG * 50_000; - -/// Minimum needed validators, currently lowered for testing environments -const MIN_VALIDATOR_COUNT: u32 = 1; +const PER_COUNCIL_STASH: Balance = ANLOG * 100_000; /// Default telemetry server for all networks const DEFAULT_TELEMETRY_URL: &str = "wss://telemetry.analog.one/submit"; @@ -64,8 +60,6 @@ pub struct GenesisKeysConfig { /// Stashes to be used for chronicles, balances controlled by PER_CHRONICLE_STASH #[allow(dead_code)] chronicles: Vec, - /// Optional controller account that will control all nominates stakes - controller: Option, /// Additional endowed accounts and their balance in ANLOG. endowments: Vec<(AccountId, Balance)>, /// Stashes intended to be used to run validators. @@ -88,8 +82,6 @@ impl Default for GenesisKeysConfig { Alice.to_raw_public().unchecked_into(), )], chronicles: vec![], - // TODO: Would be better to assign individual controllers - controller: None, endowments: vec![], stakes: vec![Alice.into(), Bob.into(), Charlie.into(), Dave.into()], } @@ -185,11 +177,6 @@ impl GenesisKeysConfig { .collect::>(), ); - // Endow controller if necessary - if let Some(controller) = self.controller.as_ref() { - endowments.push((controller.clone(), CONTROLLER_SUPPLY)); - } - // Endow council members and validators endowments.append( &mut self.admins.iter().map(|x| (x.clone(), PER_COUNCIL_STASH)).collect::>(), @@ -210,7 +197,7 @@ impl GenesisKeysConfig { .enumerate() .map(|(i, x)| { ( - self.controller.clone().unwrap_or(self.stakes[i].clone()), + self.stakes[i].clone(), self.stakes[i].clone(), timechain_runtime::SessionKeys { babe: x.0.clone(), @@ -222,6 +209,21 @@ impl GenesisKeysConfig { }) .collect(); + // Self-stake all authorities + let locked = PER_VALIDATOR_STASH - PER_VALIDATOR_UNLOCKED; + let min_count = if chain_type == ChainType::Local { 1 } else { 4 }; + let stakers = authorities + .iter() + .map(|x| { + ( + x.1.clone(), + x.0.clone(), // Ignored + locked, + timechain_runtime::StakerStatus::::Validator, + ) + }) + .collect::>(); + let mut genesis_patch = serde_json::json!({ "balances": { "balances": endowments, @@ -229,42 +231,37 @@ impl GenesisKeysConfig { "babe": { "epochConfig": timechain_runtime::BABE_GENESIS_EPOCH_CONFIG, }, + "nominationPools": { + "minJoinBond": ANLOG, + "minCreateBond": 100_000 * ANLOG, + "maxPools": Some(0), + "maxMembersPerPool": None::, + "maxMembers": None::, + }, "session": { "keys": authorities, }, + "staking": { + "validatorCount": authorities.len() as u32, + "minimumValidatorCount": min_count, + "invulnerables": authorities.iter().map(|x| x.1.clone()).collect::>(), + "slashRewardFraction": sp_runtime::Perbill::from_percent(10), + "stakers": stakers, + "minNominatorBond": 100_000 * ANLOG, + "minValidatorBond": 1_000_000 * ANLOG, + }, "technicalCommittee": { "members": Some(self.admins.clone()), }, }); if cfg!(feature = "testnet") { - // Self-stake all authorities - let locked = PER_VALIDATOR_STASH - PER_VALIDATOR_UNLOCKED; - let stakers = authorities - .iter() - .map(|x| { - ( - x.1.clone(), - x.0.clone(), - locked, - timechain_runtime::StakerStatus::::Validator, - ) - }) - .collect::>(); - json_merge( &mut genesis_patch, serde_json::json!({ "networks": { "networks": [], }, - "staking": { - "validatorCount": authorities.len() as u32, - "minimumValidatorCount": MIN_VALIDATOR_COUNT, - "invulnerables": authorities.iter().map(|x| x.1.clone()).collect::>(), - "slashRewardFraction": sp_runtime::Perbill::from_percent(10), - "stakers": stakers - }, }), ); } diff --git a/node/src/chains/internal.keys.json b/node/src/chains/internal.keys.json index c66c7dc32..3474da3f4 100644 --- a/node/src/chains/internal.keys.json +++ b/node/src/chains/internal.keys.json @@ -123,13 +123,12 @@ "an7Xpup8pGMQAyVs1KFfbtVtZTHau2RwVv7ii5CNFmb1s8dCg", "anBH2gEs72QEAc4ufppmXBjHSDrj995UHpattE956aUAYXFGJ" ], - "controller": "anAFMd7NCCekftTGrkhv9oymmZ4biPrmbMGj5mtvfXqeqkSST", "endowments": [ ["an5xJhYKVepTVKH3JqeRc126R4iAzV8As9DuXLW9EQkyzhgFf", 100000], ["an8MGkKQtjYr2KKPcP1EoNsUwQ6uwEJikZrTXHJ2f1gy8TV1N", 1000000], ["an9kSckzNGEy9eA9tAs9dPNfYEXf8LJCFBrVDchZVTfjcpxE7", 50000], ["anAW8EGrNU6bA6uMGnoXvr86YTFkB5hxtRitW2WePUv4p2986", 50000], - ["anAkNQdVkbM5XgzFxtS6auRRBCv74R2gFhXoYSHi7pQAW74vG", 1440000] + ["anAkNQdVkbM5XgzFxtS6auRRBCv74R2gFhXoYSHi7pQAW74vG", 100000000] ], "stakes": [ "anAjuQVafzzr1PkHkJNq2WAu9LFE2iQwAtgEXc2VXbAyDBW85", diff --git a/pallets/launch/src/data/mod.rs b/pallets/launch/src/data/mod.rs index 415205da4..7888a6b89 100644 --- a/pallets/launch/src/data/mod.rs +++ b/pallets/launch/src/data/mod.rs @@ -1 +1,2 @@ // Add underlying data for stage here +pub mod v19; diff --git a/pallets/launch/src/data/v19.rs b/pallets/launch/src/data/v19.rs new file mode 100644 index 000000000..b849e7b3f --- /dev/null +++ b/pallets/launch/src/data/v19.rs @@ -0,0 +1,6 @@ +use crate::deposits::RawDepositStage; + +use time_primitives::ANLOG; + +pub const DEPOSIT_REWARD_POOL: RawDepositStage = + &[("an83ePjroFcSy8v7zBkaKXydhni4H88F3PG7w8vpVHfhb6Gof", 60_386_473 * ANLOG, None)]; diff --git a/pallets/launch/src/lib.rs b/pallets/launch/src/lib.rs index b93b41db1..3b37cc005 100644 --- a/pallets/launch/src/lib.rs +++ b/pallets/launch/src/lib.rs @@ -52,7 +52,7 @@ pub mod pallet { use sp_std::{vec, vec::Vec}; /// Updating this number will automatically execute the next launch stages on update - pub const LAUNCH_VERSION: u16 = 18; + pub const LAUNCH_VERSION: u16 = 19; /// Wrapped version to support substrate interface as well pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(LAUNCH_VERSION); @@ -94,6 +94,12 @@ pub mod pallet { (17, 0, Stage::Retired), // Prelaunch Deposit 4 (18, 3_636_364 * ANLOG, Stage::Retired), + // Bootstaking Month 1 + ( + 19, + 60_386_473 * ANLOG, + Stage::DepositFromVirtual(b"initiatives", data::v19::DEPOSIT_REWARD_POOL), + ), ]; /// TODO: Difference to go to treasury: diff --git a/pallets/launch/src/tests.rs b/pallets/launch/src/tests.rs index 6f3b40e9f..c22c39bb1 100644 --- a/pallets/launch/src/tests.rs +++ b/pallets/launch/src/tests.rs @@ -31,6 +31,7 @@ fn launch_ledger_validation() { // Mint necessary virtual funds mint_virtual(b"airdrop", 1_336_147_462_613_682_971); + mint_virtual(b"initiatives", 60_386_473 * ANLOG); mint_virtual(b"ecosystem", 3_636_364 * ANLOG); // Start new block to collect events diff --git a/runtime/src/configs/staking.rs b/runtime/src/configs/staking.rs index d2612246a..1bf821cba 100644 --- a/runtime/src/configs/staking.rs +++ b/runtime/src/configs/staking.rs @@ -13,13 +13,14 @@ use frame_support::{ pallet_prelude::Get, parameter_types, //traits::tokens::imbalance::ResolveTo, - traits::ConstU32, + traits::{ConstU32, Currency, ExistenceRequirement, OnUnbalanced, WithdrawReasons}, weights::Weight, PalletId, }; use sp_runtime::{ - curve::PiecewiseLinear, transaction_validity::TransactionPriority, FixedU128, Perbill, Percent, + curve::PiecewiseLinear, traits::AccountIdConversion, transaction_validity::TransactionPriority, + FixedU128, Perbill, Percent, }; use sp_std::prelude::*; @@ -30,9 +31,9 @@ use time_primitives::BlockNumber; use crate::{ deposit, weights, AccountId, Balance, Balances, BlockExecutionWeight, BondingDuration, DelegatedStaking, ElectionProviderMultiPhase, EnsureRootOrHalfTechnical, EpochDuration, - NominationPools, Runtime, RuntimeBlockLength, RuntimeBlockWeights, RuntimeEvent, - RuntimeFreezeReason, RuntimeHoldReason, Session, SessionsPerEra, Staking, Timestamp, - TransactionPayment, VoterList, ANLOG, + NegativeImbalance, NominationPools, PositiveImbalance, Runtime, RuntimeBlockLength, + RuntimeBlockWeights, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, Session, + SessionsPerEra, Staking, Timestamp, TransactionPayment, VoterList, ANLOG, }; parameter_types! { @@ -214,9 +215,39 @@ impl pallet_election_provider_multi_phase::Config for Runtime { type WeightInfo = pallet_election_provider_multi_phase::weights::SubstrateWeight; } +/// Virtual reward pool wallet +pub struct RewardPool; +impl RewardPool { + /// Return internal virtual wallet id + fn account_id() -> AccountId { + PalletId(*b"timerwrd").into_account_truncating() + } +} + +impl OnUnbalanced for RewardPool { + /// Take rewards from special rewards wallet, otherwise mint it via drop + fn on_nonzero_unbalanced(imbalance: PositiveImbalance) { + let _ = Balances::settle( + &Self::account_id(), + imbalance, + WithdrawReasons::TRANSFER, + ExistenceRequirement::AllowDeath, + ); + } +} + +/// Additional wrapper around reward pool to return funds +pub struct ToRewardPool; +impl OnUnbalanced for ToRewardPool { + /// Return unspent reward to reward pool + fn on_nonzero_unbalanced(imbalance: NegativeImbalance) { + Balances::resolve_creating(&RewardPool::account_id(), imbalance); + } +} + pallet_staking_reward_curve::build! { const REWARD_CURVE: PiecewiseLinear<'static> = curve!( - min_inflation: 0_020_000, + min_inflation: 0_030_000, max_inflation: 0_080_000, ideal_stake: 0_600_000, falloff: 0_050_000, @@ -254,6 +285,7 @@ parameter_types! { /// Upper limit on the number of NPOS nominations. const MAX_QUOTA_NOMINATIONS: u32 = 16; +/// Configuration of benchmarking bounds pub struct StakingBenchmarkingConfig; impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig { type MaxNominators = ConstU32<1000>; @@ -268,17 +300,19 @@ impl pallet_staking::Config for Runtime { type CurrencyBalance = Balance; type UnixTime = Timestamp; type CurrencyToVote = sp_staking::currency_to_vote::U128CurrencyToVote; - type RewardRemainder = (); //Treasury; + type RewardRemainder = ToRewardPool; type RuntimeEvent = RuntimeEvent; type Slash = (); //Treasury; // send the slashed funds to the treasury. - type Reward = (); // rewards are minted from the void + /// Pay rewards from reward pool, otherwise mint them. + type Reward = RewardPool; type SessionsPerEra = SessionsPerEra; type BondingDuration = BondingDuration; type SlashDeferDuration = SlashDeferDuration; /// A majority of the council can cancel the slash. type AdminOrigin = EnsureRootOrHalfTechnical; type SessionInterface = Self; - type EraPayout = (); //pallet_staking::ConvertCurve; + /// Inflation curve that optimizes returned rewards + type EraPayout = pallet_staking::ConvertCurve; type MaxExposurePageSize = ConstU32<256>; type NextNewSession = Session; type ElectionProvider = ElectionProviderMultiPhase; diff --git a/runtime/src/configs/tokenomics.rs b/runtime/src/configs/tokenomics.rs index 0b6715d5d..1c5bcff94 100644 --- a/runtime/src/configs/tokenomics.rs +++ b/runtime/src/configs/tokenomics.rs @@ -31,7 +31,7 @@ use crate::{ RuntimeHoldReason, System, ANLOG, MAX_BLOCK_LENGTH, }; #[cfg(feature = "testnet")] -use crate::{AccountId, Authorship, Treasury}; +use crate::{Authorship, NegativeImbalance, Treasury}; #[cfg(feature = "testnet")] use frame_support::traits::Currency; use time_primitives::{MICROANLOG, MILLIANLOG}; @@ -61,9 +61,10 @@ pub const MAXIMUM_BLOCK_WEIGHT_SECONDS: u64 = 2; impl WeightToFeePolynomial for WeightToFee { type Balance = Balance; fn polynomial() -> WeightToFeeCoefficients { + // Quadratic term maps max weight to max quadratic fee let q_2: Balance = MAX_QUADRATIC_WEIGHT_FEE * MAX_QUADRATIC_WEIGHT_FEE; let p_2 = WEIGHT_REF_TIME_PER_SECOND.saturating_mul(MAXIMUM_BLOCK_WEIGHT_SECONDS) as u128; - // in Timechain, extrinsic base weight (smallest non-zero weight) is mapped to MILLIANLOG: + // Linear term map linear minimum to base weight let p_1 = MIN_LINEAR_WEIGHT_FEE; let q_1 = Balance::from(ExtrinsicBaseWeight::get().ref_time()); smallvec![ @@ -90,11 +91,12 @@ pub struct LengthToFee; impl WeightToFeePolynomial for LengthToFee { type Balance = Balance; fn polynomial() -> WeightToFeeCoefficients { + // Quadratic term maps max weight to max quadratic fee let q_2 = MAX_QUADRATIC_LENGTH_FEE * MAX_QUADRATIC_WEIGHT_FEE; let p_2 = MAX_BLOCK_LENGTH as u128; - // in Timechain, extrinsic base weight (smallest non-zero weight) is mapped to MILLIANLOG: + // Linear minimum is mapped to size of smallest transaction let p_1 = MIN_LINEAR_LENGTH_FEE; - let q_1 = Balance::from(ExtrinsicBaseWeight::get().ref_time()); + let q_1 = 2; smallvec![ WeightToFeeCoefficient { degree: 2, @@ -134,9 +136,6 @@ impl OnUnbalanced for Author { } } -#[cfg(feature = "testnet")] -type NegativeImbalance = >::NegativeImbalance; - pub struct DealWithFees; #[cfg(feature = "testnet")] impl OnUnbalanced for DealWithFees { diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6e28e79fb..3d5f4d6f6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -131,6 +131,7 @@ use polkadot_sdk::*; use frame_support::{ parameter_types, + traits::Currency, weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, }; use pallet_session::historical as pallet_session_historical; @@ -220,6 +221,10 @@ pub type Executive = frame_executive::Executive< Migrations, >; +// Useful types when handeling currency +pub type NegativeImbalance = >::NegativeImbalance; +pub type PositiveImbalance = >::PositiveImbalance; + /// Max size for serialized extrinsic params for this testing runtime. /// This is a quite arbitrary but empirically battle tested value. #[cfg(test)] From 3881112659db6c1e007ee40905c75b2a617f4385 Mon Sep 17 00:00:00 2001 From: David Craven Date: Sun, 9 Feb 2025 13:18:59 +0100 Subject: [PATCH 5/6] Fix deps (#1525) --- Cargo.lock | 36 ++++++++++++++++++------------------ gmp/evm/Cargo.toml | 10 +++++----- tc-cli/Cargo.toml | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a578a3ae..87ba68d6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14158,7 +14158,7 @@ dependencies = [ [[package]] name = "rosetta-client" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14189,7 +14189,7 @@ dependencies = [ [[package]] name = "rosetta-config-astar" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "rosetta-core", @@ -14199,7 +14199,7 @@ dependencies = [ [[package]] name = "rosetta-config-ethereum" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "const-hex", @@ -14219,7 +14219,7 @@ dependencies = [ [[package]] name = "rosetta-config-polkadot" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "rosetta-core", @@ -14230,7 +14230,7 @@ dependencies = [ [[package]] name = "rosetta-core" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14247,7 +14247,7 @@ dependencies = [ [[package]] name = "rosetta-crypto" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "bech32", @@ -14273,7 +14273,7 @@ dependencies = [ [[package]] name = "rosetta-ethereum-backend" version = "0.1.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "async-trait", "auto_impl", @@ -14289,7 +14289,7 @@ dependencies = [ [[package]] name = "rosetta-ethereum-types" version = "0.2.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "bytes", "const-hex", @@ -14323,7 +14323,7 @@ dependencies = [ [[package]] name = "rosetta-server" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14346,7 +14346,7 @@ dependencies = [ [[package]] name = "rosetta-server-astar" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14370,7 +14370,7 @@ dependencies = [ [[package]] name = "rosetta-server-ethereum" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14399,7 +14399,7 @@ dependencies = [ [[package]] name = "rosetta-server-polkadot" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "async-trait", @@ -14420,7 +14420,7 @@ dependencies = [ [[package]] name = "rosetta-tx-ethereum" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "rosetta-config-ethereum", @@ -14431,7 +14431,7 @@ dependencies = [ [[package]] name = "rosetta-tx-polkadot" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "anyhow", "blake2-rfc", @@ -14445,7 +14445,7 @@ dependencies = [ [[package]] name = "rosetta-types" version = "0.6.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "serde", "serde_json", @@ -14454,7 +14454,7 @@ dependencies = [ [[package]] name = "rosetta-utils" version = "0.1.0" -source = "git+https://github.com/analog-labs/chain-connectors?branch=gmp-api#37e2cd13b9a958542137a6674ea26314f39e59d7" +source = "git+https://github.com/analog-labs/chain-connectors?rev=37e2cd1#37e2cd13b9a958542137a6674ea26314f39e59d7" dependencies = [ "bytes", "futures-timer", @@ -17121,7 +17121,7 @@ dependencies = [ [[package]] name = "slack-morphism" version = "2.9.0" -source = "git+https://github.com/dvc94ch/slack-morphism-rust?branch=files-delete#f33ead88a58e1f13af007eb51a36d0be0f45386a" +source = "git+https://github.com/abdolence/slack-morphism-rust#babc68bfed9490545d7e721a58e95d78a71fc171" dependencies = [ "async-recursion", "async-trait", @@ -20021,7 +20021,7 @@ dependencies = [ "serde", "serde_json", "serde_yaml", - "slack-morphism 2.9.0 (git+https://github.com/dvc94ch/slack-morphism-rust?branch=files-delete)", + "slack-morphism 2.9.0 (git+https://github.com/abdolence/slack-morphism-rust)", "tabled 0.16.0", "tc-subxt", "time-primitives", diff --git a/gmp/evm/Cargo.toml b/gmp/evm/Cargo.toml index f8276ea47..d698910fd 100644 --- a/gmp/evm/Cargo.toml +++ b/gmp/evm/Cargo.toml @@ -16,11 +16,11 @@ async-trait.workspace = true futures.workspace = true hex.workspace = true reqwest = { version = "0.12.7", default-features = false, features = ["json", "rustls-tls-native-roots"] } -rosetta-client = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } -rosetta-server = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } -rosetta-server-ethereum = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } -rosetta-ethereum-backend = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } -rosetta-ethereum-types = { git = "https://github.com/analog-labs/chain-connectors", branch = "gmp-api" } +rosetta-client = { git = "https://github.com/analog-labs/chain-connectors", rev = "37e2cd1" } +rosetta-server = { git = "https://github.com/analog-labs/chain-connectors", rev = "37e2cd1" } +rosetta-server-ethereum = { git = "https://github.com/analog-labs/chain-connectors", rev = "37e2cd1" } +rosetta-ethereum-backend = { git = "https://github.com/analog-labs/chain-connectors", rev = "37e2cd1" } +rosetta-ethereum-types = { git = "https://github.com/analog-labs/chain-connectors", rev = "37e2cd1" } sha3 = { version = "0.10", default-features = false } serde.workspace = true serde_json = "1.0.127" diff --git a/tc-cli/Cargo.toml b/tc-cli/Cargo.toml index 74e1581b3..3e610dab6 100644 --- a/tc-cli/Cargo.toml +++ b/tc-cli/Cargo.toml @@ -28,7 +28,7 @@ scale-codec.workspace = true serde = { workspace = true, features = ["derive"] } serde_json = "1.0.138" serde_yaml = "0.9.34" -slack-morphism = { version = "2.8.0", features = ["hyper"], git = "https://github.com/dvc94ch/slack-morphism-rust", branch = "files-delete" } +slack-morphism = { version = "2.8.0", features = ["hyper"], git = "https://github.com/abdolence/slack-morphism-rust" } tabled = "0.16.0" tc-subxt.workspace = true time-primitives = { workspace = true, default-features = true } From 325a67970b14474533831753c2b650d4ccd3ecdf Mon Sep 17 00:00:00 2001 From: Florian Franzen Date: Sun, 9 Feb 2025 16:40:15 +0100 Subject: [PATCH 6/6] launch: add deposit of fjord presale tokens to claim backend (#1526) --- pallets/launch/src/data/mod.rs | 1 + pallets/launch/src/data/v20.rs | 6 ++++++ pallets/launch/src/lib.rs | 8 +++++++- pallets/launch/src/tests.rs | 2 +- runtime/src/apis.rs | 6 ++++++ runtime/src/configs/mod.rs | 1 + runtime/src/configs/staking.rs | 25 +++++++++---------------- runtime/src/lib.rs | 8 ++++---- 8 files changed, 35 insertions(+), 22 deletions(-) create mode 100644 pallets/launch/src/data/v20.rs diff --git a/pallets/launch/src/data/mod.rs b/pallets/launch/src/data/mod.rs index 7888a6b89..5e46dbade 100644 --- a/pallets/launch/src/data/mod.rs +++ b/pallets/launch/src/data/mod.rs @@ -1,2 +1,3 @@ // Add underlying data for stage here pub mod v19; +pub mod v20; diff --git a/pallets/launch/src/data/v20.rs b/pallets/launch/src/data/v20.rs new file mode 100644 index 000000000..85daef88d --- /dev/null +++ b/pallets/launch/src/data/v20.rs @@ -0,0 +1,6 @@ +use crate::deposits::RawDepositStage; + +use time_primitives::ANLOG; + +pub const DEPOSIT_FJORD_SALE: RawDepositStage = + &[("5ECGU5tc6gcFyoxAXgmgde8b2aGPNNadwHqVNCcZEJRaHQEf", 116_163_163 * ANLOG, None)]; diff --git a/pallets/launch/src/lib.rs b/pallets/launch/src/lib.rs index 3b37cc005..7aa6b6429 100644 --- a/pallets/launch/src/lib.rs +++ b/pallets/launch/src/lib.rs @@ -52,7 +52,7 @@ pub mod pallet { use sp_std::{vec, vec::Vec}; /// Updating this number will automatically execute the next launch stages on update - pub const LAUNCH_VERSION: u16 = 19; + pub const LAUNCH_VERSION: u16 = 20; /// Wrapped version to support substrate interface as well pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(LAUNCH_VERSION); @@ -86,6 +86,7 @@ pub mod pallet { (13, 113_204_200 * ANLOG, Stage::Retired), // Virtual Token Genesis Event (14, 8_166_845_674 * ANLOG, Stage::Retired), + // FIXME: Minting stopped here: Toke ledger should check virtual wallets, not issuance. // Retry failed mints in stage 11 (15, 6_062_296 * ANLOG, Stage::Retired), // Airdrop Snapshot 4 @@ -100,6 +101,11 @@ pub mod pallet { 60_386_473 * ANLOG, Stage::DepositFromVirtual(b"initiatives", data::v19::DEPOSIT_REWARD_POOL), ), + ( + 20, + 116_163_163 * ANLOG, + Stage::DepositFromVirtual(b"ecosystem", data::v20::DEPOSIT_FJORD_SALE), + ), ]; /// TODO: Difference to go to treasury: diff --git a/pallets/launch/src/tests.rs b/pallets/launch/src/tests.rs index c22c39bb1..9c60b241c 100644 --- a/pallets/launch/src/tests.rs +++ b/pallets/launch/src/tests.rs @@ -32,7 +32,7 @@ fn launch_ledger_validation() { // Mint necessary virtual funds mint_virtual(b"airdrop", 1_336_147_462_613_682_971); mint_virtual(b"initiatives", 60_386_473 * ANLOG); - mint_virtual(b"ecosystem", 3_636_364 * ANLOG); + mint_virtual(b"ecosystem", 119_799_527 * ANLOG); // Start new block to collect events System::set_block_number(1); diff --git a/runtime/src/apis.rs b/runtime/src/apis.rs index 8765e452f..5fdd76a4d 100644 --- a/runtime/src/apis.rs +++ b/runtime/src/apis.rs @@ -44,8 +44,11 @@ use crate::RuntimeGenesisConfig; use crate::{Members, Networks, Shards, Staking, Tasks}; // HASHI Bridge +#[cfg(feature = "testnet")] use crate::configs::bridge::NetworkId as BridgeNetworkId; +#[cfg(feature = "testnet")] use crate::EthBridge; +#[cfg(feature = "testnet")] use eth_bridge::{ common::{AssetId as BridgeAssetId, BalancePrecision as BridgeBalancePrecision}, offchain::SignatureParams as BridgeSignatureParams, @@ -54,6 +57,7 @@ use eth_bridge::{ RequestStatus as BridgeRequestStatus, }, }; +#[cfg(feature = "testnet")] use sp_runtime::DispatchError; // Original Author: ntn-x2 @ KILTprotocol @@ -373,6 +377,8 @@ impl_runtime_apis! { } } + + #[cfg(feature = "testnet")] impl eth_bridge_runtime_api::EthBridgeRuntimeApi< Block, diff --git a/runtime/src/configs/mod.rs b/runtime/src/configs/mod.rs index ec931ea4c..1ef2a5e92 100644 --- a/runtime/src/configs/mod.rs +++ b/runtime/src/configs/mod.rs @@ -10,6 +10,7 @@ pub mod staking; pub mod tokenomics; pub mod utilities; +#[cfg(feature = "testnet")] pub mod bridge; #[cfg(feature = "testnet")] pub mod custom; diff --git a/runtime/src/configs/staking.rs b/runtime/src/configs/staking.rs index 1bf821cba..ac26261b4 100644 --- a/runtime/src/configs/staking.rs +++ b/runtime/src/configs/staking.rs @@ -13,7 +13,7 @@ use frame_support::{ pallet_prelude::Get, parameter_types, //traits::tokens::imbalance::ResolveTo, - traits::{ConstU32, Currency, ExistenceRequirement, OnUnbalanced, WithdrawReasons}, + traits::{ConstU32, Currency, ExistenceRequirement, Imbalance, OnUnbalanced, WithdrawReasons}, weights::Weight, PalletId, }; @@ -31,9 +31,9 @@ use time_primitives::BlockNumber; use crate::{ deposit, weights, AccountId, Balance, Balances, BlockExecutionWeight, BondingDuration, DelegatedStaking, ElectionProviderMultiPhase, EnsureRootOrHalfTechnical, EpochDuration, - NegativeImbalance, NominationPools, PositiveImbalance, Runtime, RuntimeBlockLength, - RuntimeBlockWeights, RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, Session, - SessionsPerEra, Staking, Timestamp, TransactionPayment, VoterList, ANLOG, + NominationPools, PositiveImbalance, Runtime, RuntimeBlockLength, RuntimeBlockWeights, + RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, Session, SessionsPerEra, Staking, + Timestamp, TransactionPayment, VoterList, ANLOG, }; parameter_types! { @@ -227,21 +227,14 @@ impl RewardPool { impl OnUnbalanced for RewardPool { /// Take rewards from special rewards wallet, otherwise mint it via drop fn on_nonzero_unbalanced(imbalance: PositiveImbalance) { - let _ = Balances::settle( + if let Err(to_mint) = Balances::settle( &Self::account_id(), imbalance, WithdrawReasons::TRANSFER, ExistenceRequirement::AllowDeath, - ); - } -} - -/// Additional wrapper around reward pool to return funds -pub struct ToRewardPool; -impl OnUnbalanced for ToRewardPool { - /// Return unspent reward to reward pool - fn on_nonzero_unbalanced(imbalance: NegativeImbalance) { - Balances::resolve_creating(&RewardPool::account_id(), imbalance); + ) { + log::warn!("💰 Reward pool drained, to be minted instead: {}", to_mint.peek()); + } } } @@ -300,7 +293,7 @@ impl pallet_staking::Config for Runtime { type CurrencyBalance = Balance; type UnixTime = Timestamp; type CurrencyToVote = sp_staking::currency_to_vote::U128CurrencyToVote; - type RewardRemainder = ToRewardPool; + type RewardRemainder = (); type RuntimeEvent = RuntimeEvent; type Slash = (); //Treasury; // send the slashed funds to the treasury. /// Pay rewards from reward pool, otherwise mint them. diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 3d5f4d6f6..1ee4a7cc8 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -488,11 +488,11 @@ mod runtime { // HASHI Bridge - #[runtime::pallet_index(50)] - pub type EthBridge = eth_bridge; + //#[runtime::pallet_index(50)] + //pub type EthBridge = eth_bridge; - #[runtime::pallet_index(51)] - pub type BridgeMultisig = bridge_multisig; + //#[runtime::pallet_index(51)] + //pub type BridgeMultisig = bridge_multisig; } /// Testnet and develop runtime assembly