Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/wasm-dot/js/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export type TransactionIntent =
| TransferIntent
| TransferAllIntent
| StakeIntent
| BondExtraIntent
| UnstakeIntent
| WithdrawUnbondedIntent
| ChillIntent
Expand Down Expand Up @@ -137,6 +138,12 @@ export type StakePayee =
| { type: "controller" }
| { type: "account"; address: string };

export interface BondExtraIntent {
type: "bondExtra";
/** Additional amount to bond in planck */
amount: bigint;
}

export interface UnstakeIntent {
type: "unstake";
/** Amount to unstake in planck */
Expand Down
9 changes: 9 additions & 0 deletions packages/wasm-dot/src/builder/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn encode_call(
}
TransactionIntent::TransferAll { to, keep_alive } => transfer_all(to, *keep_alive)?,
TransactionIntent::Stake { amount, payee } => staking_bond(*amount, payee)?,
TransactionIntent::BondExtra { amount } => staking_bond_extra(*amount),
TransactionIntent::Unstake { amount } => staking_unbond(*amount),
TransactionIntent::WithdrawUnbonded { slashing_spans } => {
staking_withdraw_unbonded(*slashing_spans)
Expand Down Expand Up @@ -116,6 +117,14 @@ fn staking_bond(
))
}

fn staking_bond_extra(amount: u64) -> subxt_core::tx::payload::DynamicPayload {
dynamic(
"Staking",
"bond_extra",
named([("max_additional", Value::u128(amount as u128))]),
)
}

fn staking_unbond(amount: u64) -> subxt_core::tx::payload::DynamicPayload {
dynamic(
"Staking",
Expand Down
21 changes: 21 additions & 0 deletions packages/wasm-dot/src/builder/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub enum TransactionIntent {
#[serde(default)]
payee: StakePayee,
},
/// Bond extra DOT to existing stake
BondExtra {
/// Additional amount to bond in planck (accepts JS BigInt natively)
amount: u64,
},
/// Unstake (unbond) DOT
Unstake {
/// Amount to unstake in planck (accepts JS BigInt natively)
Expand Down Expand Up @@ -173,6 +178,22 @@ mod tests {
}
}

#[test]
fn test_deserialize_bond_extra_intent() {
let json = r#"{
"type": "bondExtra",
"amount": 2000000000000
}"#;

let intent: TransactionIntent = serde_json::from_str(json).unwrap();
match intent {
TransactionIntent::BondExtra { amount } => {
assert_eq!(amount, 2_000_000_000_000);
}
_ => panic!("Expected BondExtra"),
}
}

#[test]
fn test_deserialize_batch_intent() {
let json = r#"{
Expand Down