From 21d0566afa8e7e6dc0e9bd4610affc98893c130a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dino=20Pa=C4=8Dandi?=
 <3002868+Dinonard@users.noreply.github.com>
Date: Thu, 13 Jul 2023 09:37:32 +0200
Subject: [PATCH] FreeBalance as default dapp-staking reward destination (#975)

* FreeBalance as default dapp-staking reward destination

* Fix some tests

* Formatting

* fix benchmarks issue

* Formatting
---
 Cargo.lock                                | 10 +++++-----
 bin/collator/Cargo.toml                   |  2 +-
 pallets/dapps-staking/Cargo.toml          |  2 +-
 pallets/dapps-staking/src/benchmarking.rs |  2 +-
 pallets/dapps-staking/src/lib.rs          |  3 +--
 pallets/dapps-staking/src/tests.rs        | 19 ++++++++++++++++++-
 runtime/astar/Cargo.toml                  |  2 +-
 runtime/astar/src/lib.rs                  |  2 +-
 runtime/shibuya/Cargo.toml                |  2 +-
 runtime/shibuya/src/lib.rs                |  2 +-
 runtime/shiden/Cargo.toml                 |  2 +-
 runtime/shiden/src/lib.rs                 |  2 +-
 tests/xcm-simulator/src/tests/general.rs  |  4 ++++
 13 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 6c6832c167..b1bb1c6543 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -410,7 +410,7 @@ dependencies = [
 
 [[package]]
 name = "astar-collator"
-version = "5.12.0"
+version = "5.13.0"
 dependencies = [
  "astar-primitives",
  "astar-runtime",
@@ -533,7 +533,7 @@ dependencies = [
 
 [[package]]
 name = "astar-runtime"
-version = "5.12.0"
+version = "5.13.0"
 dependencies = [
  "array-bytes 6.1.0",
  "astar-primitives",
@@ -6917,7 +6917,7 @@ dependencies = [
 
 [[package]]
 name = "pallet-dapps-staking"
-version = "3.9.0"
+version = "3.10.0"
 dependencies = [
  "astar-primitives",
  "frame-benchmarking",
@@ -12018,7 +12018,7 @@ dependencies = [
 
 [[package]]
 name = "shibuya-runtime"
-version = "5.12.0"
+version = "5.13.0"
 dependencies = [
  "array-bytes 6.1.0",
  "astar-primitives",
@@ -12126,7 +12126,7 @@ dependencies = [
 
 [[package]]
 name = "shiden-runtime"
-version = "5.12.0"
+version = "5.13.0"
 dependencies = [
  "array-bytes 6.1.0",
  "astar-primitives",
diff --git a/bin/collator/Cargo.toml b/bin/collator/Cargo.toml
index efb2e2ecf5..52e73779c2 100644
--- a/bin/collator/Cargo.toml
+++ b/bin/collator/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "astar-collator"
-version = "5.12.0"
+version = "5.13.0"
 description = "Astar collator implementation in Rust."
 build = "build.rs"
 default-run = "astar-collator"
diff --git a/pallets/dapps-staking/Cargo.toml b/pallets/dapps-staking/Cargo.toml
index c06c1400bf..ecbf8ca1ed 100644
--- a/pallets/dapps-staking/Cargo.toml
+++ b/pallets/dapps-staking/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "pallet-dapps-staking"
-version = "3.9.0"
+version = "3.10.0"
 description = "FRAME pallet to staking for dapps"
 authors.workspace = true
 edition.workspace = true
diff --git a/pallets/dapps-staking/src/benchmarking.rs b/pallets/dapps-staking/src/benchmarking.rs
index aad7705064..ce259ad217 100644
--- a/pallets/dapps-staking/src/benchmarking.rs
+++ b/pallets/dapps-staking/src/benchmarking.rs
@@ -22,7 +22,7 @@ use super::*;
 use crate::Pallet as DappsStaking;
 
 use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelisted_caller};
-use frame_support::traits::{Get, OnFinalize, OnInitialize};
+use frame_support::traits::{Currency, Get, OnFinalize, OnInitialize};
 use frame_system::{Pallet as System, RawOrigin};
 use sp_runtime::traits::{One, TrailingZeroInput};
 
diff --git a/pallets/dapps-staking/src/lib.rs b/pallets/dapps-staking/src/lib.rs
index 1530ba5f24..d9da78d259 100644
--- a/pallets/dapps-staking/src/lib.rs
+++ b/pallets/dapps-staking/src/lib.rs
@@ -67,7 +67,6 @@
 #![cfg_attr(not(feature = "std"), no_std)]
 
 use astar_primitives::Balance;
-use frame_support::traits::Currency;
 use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
 use scale_info::TypeInfo;
 use sp_runtime::{traits::Zero, RuntimeDebug};
@@ -541,7 +540,7 @@ pub enum RewardDestination {
 
 impl Default for RewardDestination {
     fn default() -> Self {
-        RewardDestination::StakeBalance
+        RewardDestination::FreeBalance
     }
 }
 
diff --git a/pallets/dapps-staking/src/tests.rs b/pallets/dapps-staking/src/tests.rs
index 23ca758304..761251b74e 100644
--- a/pallets/dapps-staking/src/tests.rs
+++ b/pallets/dapps-staking/src/tests.rs
@@ -17,7 +17,11 @@
 // along with Astar. If not, see <http://www.gnu.org/licenses/>.
 
 use super::{pallet::pallet::Error, pallet::pallet::Event, *};
-use frame_support::{assert_noop, assert_ok, traits::OnInitialize, weights::Weight};
+use frame_support::{
+    assert_noop, assert_ok,
+    traits::{Currency, OnInitialize},
+    weights::Weight,
+};
 use mock::{Balance, Balances, MockSmartContract, *};
 use sp_core::H160;
 use sp_runtime::{
@@ -1911,6 +1915,19 @@ fn changing_reward_destination_for_empty_ledger_is_not_ok() {
     });
 }
 
+#[test]
+fn default_reward_destination_is_free_balance() {
+    ExternalityBuilder::build().execute_with(|| {
+        initialize_first_block();
+
+        let staker = 1;
+        assert_eq!(
+            DappsStaking::ledger(&staker).reward_destination,
+            RewardDestination::FreeBalance
+        );
+    });
+}
+
 #[test]
 fn claim_dapp_with_zero_stake_periods_is_ok() {
     ExternalityBuilder::build().execute_with(|| {
diff --git a/runtime/astar/Cargo.toml b/runtime/astar/Cargo.toml
index 61d0bbd046..2ff481ed93 100644
--- a/runtime/astar/Cargo.toml
+++ b/runtime/astar/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "astar-runtime"
-version = "5.12.0"
+version = "5.13.0"
 build = "build.rs"
 authors.workspace = true
 edition.workspace = true
diff --git a/runtime/astar/src/lib.rs b/runtime/astar/src/lib.rs
index 73ddde3a42..40584ecfe4 100644
--- a/runtime/astar/src/lib.rs
+++ b/runtime/astar/src/lib.rs
@@ -141,7 +141,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("astar"),
     impl_name: create_runtime_str!("astar"),
     authoring_version: 1,
-    spec_version: 62,
+    spec_version: 63,
     impl_version: 0,
     apis: RUNTIME_API_VERSIONS,
     transaction_version: 2,
diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml
index dba6eccc14..8007acacf5 100644
--- a/runtime/shibuya/Cargo.toml
+++ b/runtime/shibuya/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "shibuya-runtime"
-version = "5.12.0"
+version = "5.13.0"
 build = "build.rs"
 authors.workspace = true
 edition.workspace = true
diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs
index 6bf8fa53f9..02edb7692c 100644
--- a/runtime/shibuya/src/lib.rs
+++ b/runtime/shibuya/src/lib.rs
@@ -164,7 +164,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("shibuya"),
     impl_name: create_runtime_str!("shibuya"),
     authoring_version: 1,
-    spec_version: 102,
+    spec_version: 103,
     impl_version: 0,
     apis: RUNTIME_API_VERSIONS,
     transaction_version: 2,
diff --git a/runtime/shiden/Cargo.toml b/runtime/shiden/Cargo.toml
index d07bccc4f1..65499074c7 100644
--- a/runtime/shiden/Cargo.toml
+++ b/runtime/shiden/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "shiden-runtime"
-version = "5.12.0"
+version = "5.13.0"
 build = "build.rs"
 authors.workspace = true
 edition.workspace = true
diff --git a/runtime/shiden/src/lib.rs b/runtime/shiden/src/lib.rs
index cd4e5dd052..3ea2c58424 100644
--- a/runtime/shiden/src/lib.rs
+++ b/runtime/shiden/src/lib.rs
@@ -143,7 +143,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
     spec_name: create_runtime_str!("shiden"),
     impl_name: create_runtime_str!("shiden"),
     authoring_version: 1,
-    spec_version: 102,
+    spec_version: 103,
     impl_version: 0,
     apis: RUNTIME_API_VERSIONS,
     transaction_version: 2,
diff --git a/tests/xcm-simulator/src/tests/general.rs b/tests/xcm-simulator/src/tests/general.rs
index 8449acaec4..1931f5d069 100644
--- a/tests/xcm-simulator/src/tests/general.rs
+++ b/tests/xcm-simulator/src/tests/general.rs
@@ -207,6 +207,10 @@ fn remote_dapps_staking_staker_claim() {
             smart_contract.clone(),
             stake_amount,
         ));
+        assert_ok!(parachain::DappsStaking::set_reward_destination(
+            parachain::RuntimeOrigin::signed(ALICE),
+            pallet_dapps_staking::RewardDestination::StakeBalance,
+        ));
 
         // advance enough blocks so we at least get to era 4
         advance_parachain_block_to(20);