Skip to content

Commit 794a60b

Browse files
authored
allow withdrawing only relayer fees in pallet hyperbridge (#491)
1 parent 98ffbd5 commit 794a60b

File tree

2 files changed

+4
-50
lines changed

2 files changed

+4
-50
lines changed

modules/pallets/hyperbridge/src/lib.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ pub mod pallet {
155155
/// The withdrawal beneficiary
156156
account: T::AccountId,
157157
},
158-
/// Hyperbridge has withdrawn it's protocol revenue
159-
ProtocolRevenueWithdrawn {
160-
/// The amount that was withdrawn
161-
amount: <T as pallet_ismp::Config>::Balance,
162-
/// The withdrawal beneficiary
163-
account: T::AccountId,
164-
},
165158
}
166159

167160
// Errors encountered by pallet-hyperbridge
@@ -213,7 +206,7 @@ where
213206
if fees != 0 {
214207
T::Currency::transfer(
215208
&fee.payer,
216-
&PALLET_HYPERBRIDGE.into_account_truncating(),
209+
&RELAYER_FEE_ACCOUNT.into_account_truncating(),
217210
fees.into(),
218211
Preservation::Expendable,
219212
)
@@ -258,7 +251,7 @@ where
258251
if fees != 0 {
259252
T::Currency::transfer(
260253
&fee.payer,
261-
&PALLET_HYPERBRIDGE.into_account_truncating(),
254+
&RELAYER_FEE_ACCOUNT.into_account_truncating(),
262255
fees.into(),
263256
Preservation::Expendable,
264257
)
@@ -292,8 +285,6 @@ pub struct WithdrawalRequest<Account, Amount> {
292285
pub enum Message<Account, Balance> {
293286
/// Set some new host params
294287
UpdateHostParams(VersionedHostParams<Balance>),
295-
/// Withdraw the hyperbridge protocol reveneue
296-
WithdrawProtocolFees(WithdrawalRequest<Account, Balance>),
297288
/// Withdraw the fees owed to a relayer
298289
WithdrawRelayerFees(WithdrawalRequest<Account, Balance>),
299290
}
@@ -322,20 +313,6 @@ where
322313
Self::deposit_event(Event::<T>::HostParamsUpdated { old, new });
323314
T::DbWeight::get().reads_writes(0, 0)
324315
},
325-
Message::WithdrawProtocolFees(WithdrawalRequest { account, amount }) => {
326-
T::Currency::transfer(
327-
&PALLET_HYPERBRIDGE.into_account_truncating(),
328-
&account,
329-
amount,
330-
Preservation::Expendable,
331-
)
332-
.map_err(|err| {
333-
ismp::Error::Custom(format!("Error withdrawing protocol fees: {err:?}"))
334-
})?;
335-
336-
Self::deposit_event(Event::<T>::ProtocolRevenueWithdrawn { account, amount });
337-
T::DbWeight::get().reads_writes(0, 0)
338-
},
339316
Message::WithdrawRelayerFees(WithdrawalRequest { account, amount }) => {
340317
T::Currency::transfer(
341318
&RELAYER_FEE_ACCOUNT.into_account_truncating(),

modules/pallets/testsuite/src/tests/pallet_hyperbridge.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ fn test_dispatch_fees() {
9999
assert_eq!(Balances::balance(&account), Default::default());
100100

101101
// now pallet-ismp has it
102-
assert_eq!(Balances::balance(&RELAYER_FEE_ACCOUNT.into_account_truncating()), 10 * UNIT);
103-
// and pallet-hyperbridge
104-
assert_eq!(
105-
Balances::balance(&PALLET_HYPERBRIDGE.into_account_truncating()),
106-
64 * 10 * UNIT
107-
);
102+
assert_eq!(Balances::balance(&RELAYER_FEE_ACCOUNT.into_account_truncating()), 65 * 10 * UNIT);
108103
});
109104
}
110105

@@ -115,29 +110,11 @@ fn test_can_withdraw_relayer_and_protocol_revenue() {
115110
let hyperbridge = Hyperbridge::default();
116111

117112
ext.execute_with(|| {
118-
// init the balances
119-
Balances::mint_into(&PALLET_HYPERBRIDGE.into_account_truncating(), 65 * 10 * UNIT).unwrap();
120113
Balances::mint_into(&RELAYER_FEE_ACCOUNT.into_account_truncating(), 65 * 10 * UNIT)
121114
.unwrap();
122115

123116
let withdrawal = WithdrawalRequest { amount: 65 * 10 * UNIT, account: account.clone() };
124117

125-
let data = Message::<AccountId32, u128>::WithdrawProtocolFees(withdrawal.clone()).encode();
126-
hyperbridge
127-
.on_accept(PostRequest {
128-
source: Coprocessor::get().unwrap(),
129-
dest: StateMachine::Polkadot(2001),
130-
nonce: 0,
131-
from: vec![],
132-
to: vec![],
133-
timeout_timestamp: 0,
134-
body: data,
135-
})
136-
.unwrap();
137-
138-
// protocol fees withdrawn
139-
assert_eq!(Balances::balance(&account), 65 * 10 * UNIT);
140-
141118
let data = Message::<AccountId32, u128>::WithdrawRelayerFees(withdrawal.clone()).encode();
142119
hyperbridge
143120
.on_accept(PostRequest {
@@ -152,6 +129,6 @@ fn test_can_withdraw_relayer_and_protocol_revenue() {
152129
.unwrap();
153130

154131
// relayer fees withdrawn
155-
assert_eq!(Balances::balance(&account), 130 * 10 * UNIT);
132+
assert_eq!(Balances::balance(&account), 65 * 10 * UNIT);
156133
});
157134
}

0 commit comments

Comments
 (0)