|
| 1 | +import * as t from 'io-ts'; |
| 2 | +import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; |
| 3 | +import { BitgoExpressError } from '../../schemas/error'; |
| 4 | + |
| 5 | +/** |
| 6 | + * Path parameters for wallet sweep operation. |
| 7 | + * @property coin - Ticker or identifier of the coin (e.g. 'btc', 'eth'). |
| 8 | + * @property id - Wallet ID |
| 9 | + */ |
| 10 | +export const SweepRequestParams = { |
| 11 | + /** Coin ticker / chain identifier */ |
| 12 | + coin: t.string, |
| 13 | + /** Wallet ID */ |
| 14 | + id: t.string, |
| 15 | +}; |
| 16 | + |
| 17 | +/** |
| 18 | + * Request body for wallet sweep operation. |
| 19 | + * |
| 20 | + * @property address - The address to sweep funds to |
| 21 | + * @property walletPassphrase - Wallet passphrase for signing |
| 22 | + * @property xprv - Extended private key (alternative to walletPassphrase) |
| 23 | + * @property otp - One-time password for 2FA |
| 24 | + * @property feeRate - Fee rate in satoshis per kilobyte |
| 25 | + * @property maxFeeRate - Maximum fee rate in satoshis per kilobyte |
| 26 | + * @property feeTxConfirmTarget - Number of blocks to target for confirmation |
| 27 | + * @property allowPartialSweep - Whether to allow partial sweep if full sweep fails |
| 28 | + */ |
| 29 | +export const SweepRequestBody = { |
| 30 | + /** Address to sweep funds to */ |
| 31 | + address: optional(t.string), |
| 32 | + /** Wallet passphrase for signing the transaction */ |
| 33 | + walletPassphrase: optional(t.string), |
| 34 | + /** Extended private key (alternative to walletPassphrase) */ |
| 35 | + xprv: optional(t.string), |
| 36 | + /** One-time password for 2FA */ |
| 37 | + otp: optional(t.string), |
| 38 | + /** Fee rate in satoshis per kilobyte */ |
| 39 | + feeRate: optional(t.number), |
| 40 | + /** Maximum fee rate in satoshis per kilobyte */ |
| 41 | + maxFeeRate: optional(t.number), |
| 42 | + /** Number of blocks to target for confirmation */ |
| 43 | + feeTxConfirmTarget: optional(t.number), |
| 44 | + /** Whether to allow partial sweep if full sweep fails */ |
| 45 | + allowPartialSweep: optional(t.boolean), |
| 46 | +}; |
| 47 | + |
| 48 | +/** |
| 49 | + * Sweep wallet |
| 50 | + * |
| 51 | + * Sweep all funds from a wallet to a specified address. |
| 52 | + * This operation consolidates all unspent outputs in the wallet and sends them to the target address. |
| 53 | + * |
| 54 | + * @operationId express.v2.wallet.sweep |
| 55 | + */ |
| 56 | +export const PostSweep = httpRoute({ |
| 57 | + path: '/api/v2/{coin}/wallet/{id}/sweep', |
| 58 | + method: 'POST', |
| 59 | + request: httpRequest({ |
| 60 | + params: SweepRequestParams, |
| 61 | + body: SweepRequestBody, |
| 62 | + }), |
| 63 | + response: { |
| 64 | + /** Successful sweep transaction */ |
| 65 | + 200: t.unknown, // The actual response varies by coin type |
| 66 | + /** Invalid request parameters */ |
| 67 | + 400: BitgoExpressError, |
| 68 | + /** Wallet not found */ |
| 69 | + 404: BitgoExpressError, |
| 70 | + }, |
| 71 | +}); |
0 commit comments