Skip to content

Commit b423b3f

Browse files
authored
Add stellar tx new begin-sponsoring-future-reserves and stellar tx new end-sponsoring-future-reserves. (#2213)
1 parent 96a3a82 commit b423b3f

9 files changed

Lines changed: 343 additions & 0 deletions

File tree

FULL_HELP_DOCS.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,7 @@ Create a new transaction
17061706
###### **Subcommands:**
17071707

17081708
* `account-merge` — Transfer XLM balance to another account and remove source account
1709+
* `begin-sponsoring-future-reserves` — Begin sponsoring future reserves for another account
17091710
* `bump-sequence` — Bump sequence number to invalidate older transactions
17101711
* `change-trust` — Create, update, or delete a trustline
17111712
* `claim-claimable-balance` — Claim a claimable balance by its balance ID
@@ -1714,6 +1715,7 @@ Create a new transaction
17141715
* `create-account` — Create and fund a new account
17151716
* `create-claimable-balance` — Create a claimable balance that can be claimed by specified accounts
17161717
* `create-passive-sell-offer` — Create a passive sell offer on the Stellar DEX
1718+
* `end-sponsoring-future-reserves` — End sponsoring future reserves
17171719
* `liquidity-pool-deposit` — Deposit assets into a liquidity pool
17181720
* `liquidity-pool-withdraw` — Withdraw assets from a liquidity pool
17191721
* `manage-buy-offer` — Create, update, or delete a buy offer
@@ -1756,6 +1758,35 @@ Transfer XLM balance to another account and remove source account
17561758

17571759

17581760

1761+
## `stellar tx new begin-sponsoring-future-reserves`
1762+
1763+
Begin sponsoring future reserves for another account
1764+
1765+
**Usage:** `stellar tx new begin-sponsoring-future-reserves [OPTIONS] --source-account <SOURCE_ACCOUNT> --sponsored-id <SPONSORED_ID>`
1766+
1767+
###### **Options:**
1768+
1769+
* `--fee <FEE>` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm
1770+
1771+
Default value: `100`
1772+
* `--cost` — Output the cost execution to stderr
1773+
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
1774+
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
1775+
* `--rpc-url <RPC_URL>` — RPC server endpoint
1776+
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
1777+
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
1778+
* `-n`, `--network <NETWORK>` — Name of network to use from config
1779+
* `-s`, `--source-account <SOURCE_ACCOUNT>` [alias: `source`] — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail
1780+
* `--global` — ⚠️ Deprecated: global config is always on
1781+
* `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings
1782+
* `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key or key saved in OS secure storage. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
1783+
* `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
1784+
* `--sign-with-lab` — Sign with https://lab.stellar.org
1785+
* `--sign-with-ledger` — Sign with a ledger wallet
1786+
* `--sponsored-id <SPONSORED_ID>` — Account that will be sponsored
1787+
1788+
1789+
17591790
## `stellar tx new bump-sequence`
17601791

17611792
Bump sequence number to invalidate older transactions
@@ -2007,6 +2038,34 @@ Create a passive sell offer on the Stellar DEX
20072038

20082039

20092040

2041+
## `stellar tx new end-sponsoring-future-reserves`
2042+
2043+
End sponsoring future reserves
2044+
2045+
**Usage:** `stellar tx new end-sponsoring-future-reserves [OPTIONS] --source-account <SOURCE_ACCOUNT>`
2046+
2047+
###### **Options:**
2048+
2049+
* `--fee <FEE>` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm
2050+
2051+
Default value: `100`
2052+
* `--cost` — Output the cost execution to stderr
2053+
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
2054+
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
2055+
* `--rpc-url <RPC_URL>` — RPC server endpoint
2056+
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
2057+
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
2058+
* `-n`, `--network <NETWORK>` — Name of network to use from config
2059+
* `-s`, `--source-account <SOURCE_ACCOUNT>` [alias: `source`] — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail
2060+
* `--global` — ⚠️ Deprecated: global config is always on
2061+
* `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings
2062+
* `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key or key saved in OS secure storage. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
2063+
* `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
2064+
* `--sign-with-lab` — Sign with https://lab.stellar.org
2065+
* `--sign-with-ledger` — Sign with a ledger wallet
2066+
2067+
2068+
20102069
## `stellar tx new liquidity-pool-deposit`
20112070

20122071
Deposit assets into a liquidity pool
@@ -2380,6 +2439,7 @@ Add Operation to a transaction
23802439
###### **Subcommands:**
23812440

23822441
* `account-merge` — Transfer XLM balance to another account and remove source account
2442+
* `begin-sponsoring-future-reserves` — Begin sponsoring future reserves for another account
23832443
* `bump-sequence` — Bump sequence number to invalidate older transactions
23842444
* `change-trust` — Create, update, or delete a trustline
23852445
* `claim-claimable-balance` — Claim a claimable balance by its balance ID
@@ -2388,6 +2448,7 @@ Add Operation to a transaction
23882448
* `create-account` — Create and fund a new account
23892449
* `create-claimable-balance` — Create a claimable balance that can be claimed by specified accounts
23902450
* `create-passive-sell-offer` — Create a passive sell offer on the Stellar DEX
2451+
* `end-sponsoring-future-reserves` — End sponsoring future reserves
23912452
* `liquidity-pool-deposit` — Deposit assets into a liquidity pool
23922453
* `liquidity-pool-withdraw` — Withdraw assets from a liquidity pool
23932454
* `manage-buy-offer` — Create, update, or delete a buy offer
@@ -2435,6 +2496,40 @@ Transfer XLM balance to another account and remove source account
24352496

24362497

24372498

2499+
## `stellar tx operation add begin-sponsoring-future-reserves`
2500+
2501+
Begin sponsoring future reserves for another account
2502+
2503+
**Usage:** `stellar tx operation add begin-sponsoring-future-reserves [OPTIONS] --source-account <SOURCE_ACCOUNT> --sponsored-id <SPONSORED_ID> [TX_XDR]`
2504+
2505+
###### **Arguments:**
2506+
2507+
* `<TX_XDR>` — Base-64 transaction envelope XDR or file containing XDR to decode, or stdin if empty
2508+
2509+
###### **Options:**
2510+
2511+
* `--operation-source-account <OPERATION_SOURCE_ACCOUNT>` [alias: `op-source`] — Source account used for the operation
2512+
* `--fee <FEE>` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm
2513+
2514+
Default value: `100`
2515+
* `--cost` — Output the cost execution to stderr
2516+
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
2517+
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
2518+
* `--rpc-url <RPC_URL>` — RPC server endpoint
2519+
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
2520+
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
2521+
* `-n`, `--network <NETWORK>` — Name of network to use from config
2522+
* `-s`, `--source-account <SOURCE_ACCOUNT>` [alias: `source`] — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail
2523+
* `--global` — ⚠️ Deprecated: global config is always on
2524+
* `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings
2525+
* `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key or key saved in OS secure storage. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
2526+
* `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
2527+
* `--sign-with-lab` — Sign with https://lab.stellar.org
2528+
* `--sign-with-ledger` — Sign with a ledger wallet
2529+
* `--sponsored-id <SPONSORED_ID>` — Account that will be sponsored
2530+
2531+
2532+
24382533
## `stellar tx operation add bump-sequence`
24392534

24402535
Bump sequence number to invalidate older transactions
@@ -2726,6 +2821,39 @@ Create a passive sell offer on the Stellar DEX
27262821

27272822

27282823

2824+
## `stellar tx operation add end-sponsoring-future-reserves`
2825+
2826+
End sponsoring future reserves
2827+
2828+
**Usage:** `stellar tx operation add end-sponsoring-future-reserves [OPTIONS] --source-account <SOURCE_ACCOUNT> [TX_XDR]`
2829+
2830+
###### **Arguments:**
2831+
2832+
* `<TX_XDR>` — Base-64 transaction envelope XDR or file containing XDR to decode, or stdin if empty
2833+
2834+
###### **Options:**
2835+
2836+
* `--operation-source-account <OPERATION_SOURCE_ACCOUNT>` [alias: `op-source`] — Source account used for the operation
2837+
* `--fee <FEE>` — fee amount for transaction, in stroops. 1 stroop = 0.0000001 xlm
2838+
2839+
Default value: `100`
2840+
* `--cost` — Output the cost execution to stderr
2841+
* `--instructions <INSTRUCTIONS>` — Number of instructions to simulate
2842+
* `--build-only` — Build the transaction and only write the base64 xdr to stdout
2843+
* `--rpc-url <RPC_URL>` — RPC server endpoint
2844+
* `--rpc-header <RPC_HEADERS>` — RPC Header(s) to include in requests to the RPC provider
2845+
* `--network-passphrase <NETWORK_PASSPHRASE>` — Network passphrase to sign the transaction sent to the rpc server
2846+
* `-n`, `--network <NETWORK>` — Name of network to use from config
2847+
* `-s`, `--source-account <SOURCE_ACCOUNT>` [alias: `source`] — Account that where transaction originates from. Alias `source`. Can be an identity (--source alice), a public key (--source GDKW...), a muxed account (--source MDA…), a secret key (--source SC36…), or a seed phrase (--source "kite urban…"). If `--build-only` or `--sim-only` flags were NOT provided, this key will also be used to sign the final transaction. In that case, trying to sign with public key will fail
2848+
* `--global` — ⚠️ Deprecated: global config is always on
2849+
* `--config-dir <CONFIG_DIR>` — Location of config directory. By default, it uses `$XDG_CONFIG_HOME/stellar` if set, falling back to `~/.config/stellar` otherwise. Contains configuration files, aliases, and other persistent settings
2850+
* `--sign-with-key <SIGN_WITH_KEY>` — Sign with a local key or key saved in OS secure storage. Can be an identity (--sign-with-key alice), a secret key (--sign-with-key SC36…), or a seed phrase (--sign-with-key "kite urban…"). If using seed phrase, `--hd-path` defaults to the `0` path
2851+
* `--hd-path <HD_PATH>` — If using a seed phrase to sign, sets which hierarchical deterministic path to use, e.g. `m/44'/148'/{hd_path}`. Example: `--hd-path 1`. Default: `0`
2852+
* `--sign-with-lab` — Sign with https://lab.stellar.org
2853+
* `--sign-with-ledger` — Sign with a ledger wallet
2854+
2855+
2856+
27292857
## `stellar tx operation add liquidity-pool-deposit`
27302858

27312859
Deposit assets into a liquidity pool

cmd/crates/soroban-test/tests/it/integration/tx/operations.rs

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,3 +1580,106 @@ async fn clawback() {
15801580
.assert()
15811581
.failure();
15821582
}
1583+
1584+
#[tokio::test]
1585+
async fn begin_sponsoring_future_reserves() {
1586+
let sandbox = &TestEnv::new();
1587+
let client = sandbox.network.rpc_client().unwrap();
1588+
1589+
// Create sponsor account (use test account as sponsor)
1590+
let sponsor = test_address(sandbox);
1591+
1592+
// Create a new account to sponsor (but don't fund it)
1593+
let sponsored_account = gen_account_no_fund(sandbox, "sponsored");
1594+
1595+
let sponsor_balance_before = client.get_account(&sponsor).await.unwrap().balance;
1596+
1597+
let sponsor_tx = sandbox
1598+
.new_assert_cmd("tx")
1599+
.args([
1600+
"new",
1601+
"begin-sponsoring-future-reserves",
1602+
"--source-account",
1603+
"test",
1604+
"--sponsored-id",
1605+
&sponsored_account,
1606+
"--fee",
1607+
"1000000", // Higher fee for sponsoring operations
1608+
"--build-only",
1609+
])
1610+
.assert()
1611+
.success()
1612+
.stdout_as_str();
1613+
1614+
// Add create account operation with sponsor as operation source
1615+
let create_account_tx = sandbox
1616+
.new_assert_cmd("tx")
1617+
.args([
1618+
"op",
1619+
"add",
1620+
"create-account",
1621+
"--destination",
1622+
&sponsored_account,
1623+
"--starting-balance",
1624+
"50000000",
1625+
"--operation-source-account",
1626+
"test", // sponsor account
1627+
])
1628+
.write_stdin(sponsor_tx.as_bytes())
1629+
.assert()
1630+
.success()
1631+
.stdout_as_str();
1632+
1633+
// Add end sponsoring future reserves operation with sponsored account as operation source
1634+
let complete_tx = sandbox
1635+
.new_assert_cmd("tx")
1636+
.args([
1637+
"op",
1638+
"add",
1639+
"end-sponsoring-future-reserves",
1640+
"--operation-source-account",
1641+
"sponsored",
1642+
])
1643+
.write_stdin(create_account_tx.as_bytes())
1644+
.assert()
1645+
.success()
1646+
.stdout_as_str();
1647+
1648+
// Sign with sponsor first
1649+
let sponsor_signed_tx = sandbox
1650+
.new_assert_cmd("tx")
1651+
.args(["sign", "--sign-with-key=test"])
1652+
.write_stdin(complete_tx.as_bytes())
1653+
.assert()
1654+
.success()
1655+
.stdout_as_str();
1656+
1657+
// Sign with sponsored account second
1658+
let fully_signed_tx = sandbox
1659+
.new_assert_cmd("tx")
1660+
.args(["sign", "--sign-with-key=sponsored"])
1661+
.write_stdin(sponsor_signed_tx.as_bytes())
1662+
.assert()
1663+
.success()
1664+
.stdout_as_str();
1665+
1666+
// Submit the transaction
1667+
sandbox
1668+
.new_assert_cmd("tx")
1669+
.arg("send")
1670+
.write_stdin(fully_signed_tx.as_bytes())
1671+
.assert()
1672+
.success();
1673+
1674+
let sponsor_balance_after = client.get_account(&sponsor).await.unwrap().balance;
1675+
1676+
// The sponsored account should exist
1677+
let sponsored_account_info = client.get_account(&sponsored_account).await.unwrap();
1678+
assert_eq!(sponsored_account_info.balance, 50000000);
1679+
1680+
// The sponsor account balance should be lower due to sponsoring the reserves
1681+
assert!(
1682+
sponsor_balance_after < sponsor_balance_before,
1683+
"Sponsor account should have paid for the sponsored account reserves"
1684+
);
1685+
}

cmd/soroban-cli/src/commands/tx/help.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ pub const PATH_PAYMENT_STRICT_RECEIVE: &str =
2020
pub const PAYMENT: &str = "Send asset to destination account";
2121
pub const SET_OPTIONS: &str = "Set account options like flags, signers, and home domain";
2222
pub const SET_TRUSTLINE_FLAGS: &str = "Configure authorization and trustline flags for an asset";
23+
pub const BEGIN_SPONSORING_FUTURE_RESERVES: &str =
24+
"Begin sponsoring future reserves for another account";
25+
pub const END_SPONSORING_FUTURE_RESERVES: &str = "End sponsoring future reserves";
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use clap::{command, Parser};
2+
3+
use crate::{commands::tx, config::address, xdr};
4+
5+
#[derive(Parser, Debug, Clone)]
6+
#[group(skip)]
7+
pub struct Cmd {
8+
#[command(flatten)]
9+
pub tx: tx::Args,
10+
#[clap(flatten)]
11+
pub op: Args,
12+
}
13+
14+
#[derive(Debug, clap::Args, Clone)]
15+
pub struct Args {
16+
/// Account that will be sponsored
17+
#[arg(long)]
18+
pub sponsored_id: address::UnresolvedMuxedAccount,
19+
}
20+
21+
impl TryFrom<&Cmd> for xdr::OperationBody {
22+
type Error = tx::args::Error;
23+
fn try_from(
24+
Cmd {
25+
tx,
26+
op: Args { sponsored_id },
27+
}: &Cmd,
28+
) -> Result<Self, Self::Error> {
29+
Ok(xdr::OperationBody::BeginSponsoringFutureReserves(
30+
xdr::BeginSponsoringFutureReservesOp {
31+
sponsored_id: tx.resolve_account_id(sponsored_id)?,
32+
},
33+
))
34+
}
35+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use clap::{command, Parser};
2+
3+
use crate::{commands::tx, xdr};
4+
5+
#[derive(Parser, Debug, Clone)]
6+
#[group(skip)]
7+
pub struct Cmd {
8+
#[command(flatten)]
9+
pub tx: tx::Args,
10+
#[clap(flatten)]
11+
pub op: Args,
12+
}
13+
14+
#[derive(Debug, clap::Args, Clone)]
15+
pub struct Args {
16+
// EndSponsoringFutureReserves has no parameters
17+
}
18+
19+
impl From<&Cmd> for xdr::OperationBody {
20+
fn from(_cmd: &Cmd) -> Self {
21+
xdr::OperationBody::EndSponsoringFutureReserves
22+
}
23+
}

0 commit comments

Comments
 (0)