Skip to content

Commit d1df0f9

Browse files
committed
feat: add BondExtra variant to TransactionIntent
Add staking.bond_extra call encoding support for DOT transactions. This enables the WASM path to handle bond_extra intents (adding more stake to an existing bond) alongside the existing bond/unbond support. - Add BondExtra { amount: u64 } variant to TransactionIntent enum - Add staking_bond_extra() encoder function in calls.rs - Wire up BondExtra in encode_call() match arm - Add BondExtraIntent interface to TypeScript types - Add deserialization test Ticket: BTC-3119
1 parent 0dd2e40 commit d1df0f9

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

packages/wasm-dot/js/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export type TransactionIntent =
9898
| TransferIntent
9999
| TransferAllIntent
100100
| StakeIntent
101+
| BondExtraIntent
101102
| UnstakeIntent
102103
| WithdrawUnbondedIntent
103104
| ChillIntent
@@ -137,6 +138,12 @@ export type StakePayee =
137138
| { type: "controller" }
138139
| { type: "account"; address: string };
139140

141+
export interface BondExtraIntent {
142+
type: "bondExtra";
143+
/** Additional amount to bond in planck */
144+
amount: bigint;
145+
}
146+
140147
export interface UnstakeIntent {
141148
type: "unstake";
142149
/** Amount to unstake in planck */

packages/wasm-dot/src/builder/calls.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn encode_call(
3131
}
3232
TransactionIntent::TransferAll { to, keep_alive } => transfer_all(to, *keep_alive)?,
3333
TransactionIntent::Stake { amount, payee } => staking_bond(*amount, payee)?,
34+
TransactionIntent::BondExtra { amount } => staking_bond_extra(*amount),
3435
TransactionIntent::Unstake { amount } => staking_unbond(*amount),
3536
TransactionIntent::WithdrawUnbonded { slashing_spans } => {
3637
staking_withdraw_unbonded(*slashing_spans)
@@ -116,6 +117,14 @@ fn staking_bond(
116117
))
117118
}
118119

120+
fn staking_bond_extra(amount: u64) -> subxt_core::tx::payload::DynamicPayload {
121+
dynamic(
122+
"Staking",
123+
"bond_extra",
124+
named([("max_additional", Value::u128(amount as u128))]),
125+
)
126+
}
127+
119128
fn staking_unbond(amount: u64) -> subxt_core::tx::payload::DynamicPayload {
120129
dynamic(
121130
"Staking",

packages/wasm-dot/src/builder/types.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ pub enum TransactionIntent {
4040
#[serde(default)]
4141
payee: StakePayee,
4242
},
43+
/// Bond extra DOT to existing stake
44+
BondExtra {
45+
/// Additional amount to bond in planck (accepts JS BigInt natively)
46+
amount: u64,
47+
},
4348
/// Unstake (unbond) DOT
4449
Unstake {
4550
/// Amount to unstake in planck (accepts JS BigInt natively)
@@ -173,6 +178,22 @@ mod tests {
173178
}
174179
}
175180

181+
#[test]
182+
fn test_deserialize_bond_extra_intent() {
183+
let json = r#"{
184+
"type": "bondExtra",
185+
"amount": 2000000000000
186+
}"#;
187+
188+
let intent: TransactionIntent = serde_json::from_str(json).unwrap();
189+
match intent {
190+
TransactionIntent::BondExtra { amount } => {
191+
assert_eq!(amount, 2_000_000_000_000);
192+
}
193+
_ => panic!("Expected BondExtra"),
194+
}
195+
}
196+
176197
#[test]
177198
fn test_deserialize_batch_intent() {
178199
let json = r#"{

0 commit comments

Comments
 (0)