Add optional unsweep amount

This commit is contained in:
root
2026-05-30 18:08:27 +00:00
parent faf7770220
commit 33266b3c14
2 changed files with 23 additions and 7 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ A PHP-based Telegram tip bot for the Salvium (Monero fork) cryptocurrency.
## Commands
- `/withdraw <address> <amount>` withdraws `SAL1`
- `/withdraw <asset> <address> <amount>` withdraws `SAL1` or a token asset, for example `CULT`/`salCULT`
- `/unsweep <asset> <outputs>` admin-only command that self-transfers unlocked wallet funds into multiple smaller outputs
- `/unsweep <asset> <outputs> [amount]` admin-only command that self-transfers unlocked wallet funds into multiple smaller outputs
## Withdrawal fees
- `WITHDRAWAL_FEE` is charged in `SAL1` for `SAL1` withdrawals.
+22 -6
View File
@@ -266,9 +266,9 @@ class SalviumTipBotCommands {
}
try {
[$assetType, $outputCount] = $this->parseUnsweepArgs($args);
[$assetType, $outputCount, $requestedAmountAtomic] = $this->parseUnsweepArgs($args);
} catch (Throwable $e) {
return "Usage: /unsweep <asset> <outputs>";
return "Usage: /unsweep <asset> <outputs> [amount]";
}
$maxOutputs = max(2, (int)($this->config['MAX_UNSWEEP_OUTPUTS'] ?? 100));
@@ -315,7 +315,11 @@ class SalviumTipBotCommands {
$reserveAtomic = $this->humanToAtomic($this->config['UNSWEEP_SAL1_FEE_RESERVE'] ?? 0.5);
}
$spendableAtomic = $unlockedAtomic - $reserveAtomic;
$spendableAtomic = $requestedAmountAtomic ?? ($unlockedAtomic - $reserveAtomic);
if ($requestedAmountAtomic !== null && $spendableAtomic > ($unlockedAtomic - $reserveAtomic)) {
return "Requested amount exceeds spendable unlocked {$assetType}. Max is " . $this->atomicToHuman(max(0, $unlockedAtomic - $reserveAtomic)) . " {$assetType}.";
}
if ($spendableAtomic <= 0) {
return "No spendable {$assetType} after fee reserve of " . $this->atomicToHuman($reserveAtomic) . " {$assetType}.";
}
@@ -346,8 +350,9 @@ class SalviumTipBotCommands {
$totalAtomic = $amountPerOutputAtomic * $outputCount;
$reserveText = $reserveAtomic > 0 ? " Reserved " . $this->atomicToHuman($reserveAtomic) . " {$assetType} for fee/change." : "";
$sourceText = $requestedAmountAtomic !== null ? " Requested " . $this->atomicToHuman($requestedAmountAtomic) . " {$assetType}." : "";
return "Unswept " . $this->atomicToHuman($totalAtomic) . " {$assetType} into {$outputCount} outputs of "
. $this->atomicToHuman($amountPerOutputAtomic) . " {$assetType}.{$reserveText} "
. $this->atomicToHuman($amountPerOutputAtomic) . " {$assetType}.{$sourceText}{$reserveText} "
. $this->formatTxids($txids);
}
@@ -492,7 +497,7 @@ class SalviumTipBotCommands {
}
private function parseUnsweepArgs(array $args): array {
if (count($args) !== 3 || !$this->looksLikeAssetType($args[1]) || !ctype_digit((string)$args[2])) {
if (!in_array(count($args), [3, 4], true) || !$this->looksLikeAssetType($args[1]) || !ctype_digit((string)$args[2])) {
throw new InvalidArgumentException("Invalid /unsweep arguments");
}
@@ -501,7 +506,18 @@ class SalviumTipBotCommands {
throw new InvalidArgumentException("Invalid /unsweep output count");
}
return [$this->parseAssetType($args[1]), $outputCount];
$requestedAmountAtomic = null;
if (count($args) === 4) {
if (!is_numeric($args[3]) || (float)$args[3] <= 0) {
throw new InvalidArgumentException("Invalid /unsweep amount");
}
$requestedAmountAtomic = $this->humanToAtomic($args[3]);
if ($requestedAmountAtomic <= 0) {
throw new InvalidArgumentException("Invalid /unsweep amount");
}
}
return [$this->parseAssetType($args[1]), $outputCount, $requestedAmountAtomic];
}
private function atomicSubtractNonNegative(string $left, string $right): string {