Skip to content

Commit 6358083

Browse files
committed
docs(root): rename variables and add jsdoc
BTC-1864 TICKET: BTC-0
1 parent 27be3c8 commit 6358083

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

examples/ts/btc/omni/index.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,39 @@ import * as utxolib from '@bitgo/utxo-lib';
1010

1111
const RECEIVE_ADDRESS = '';
1212
const SEND_ADDRESS = '';
13-
const AMOUNT = 729100000n;
1413
const ASSET_ID = 31;
1514

1615
async function getWallet() {
1716
return await omniConfig.sdk.coin(omniConfig.coin).wallets().get({ id: omniConfig.walletId });
1817
}
1918

19+
/**
20+
* Send an omni asset to a receiver. This function is used when you have sent an omni asset to a BitGo BTC wallet
21+
* and need to manually recover it
22+
* This function assumes that:
23+
* - Your address has a single unspent that is large enough to cover the transaction
24+
* - The receiver address is a legacy address, otherwise the transaction will not be recognized by the omni explorer
25+
* @param wallet - The wallet to send the omni asset from.
26+
* @param receiver - The address to send the omni asset to (legacy address required).
27+
* @param sender - The address to send the omni asset from (legacy address required).
28+
* @param omniBaseAmount - The amount of the omni asset to send
29+
* with respect to its smallest unit (e.g., microcents for USDT).
30+
* Can be found at https://api.omniexplorer.info/v1/transaction/tx/{prev_txid}
31+
* by multiplying `amount` by 10e8 if `divisible` is true.
32+
* If `divisible` is false, `amount` is the amount of the omni asset to send
33+
* @param assetId - The id of the omni asset to send.
34+
* Can be found at https://api.omniexplorer.info/v1/transaction/tx/{prev_txid}
35+
* by looking at the `propertyid` field.
36+
* This is 31 for USDT.
37+
* @param feeRateSatPerKB - The fee rate to use for the transaction, in satoshis per kilobyte.
38+
*/
2039
async function sendOmniAsset(
2140
wallet: Wallet,
2241
receiver: string,
2342
sender: string,
24-
amountMicroCents: bigint,
43+
omniBaseAmount: bigint,
2544
assetId = 31,
26-
feeRate = 20_000
45+
feeRateSatPerKB = 20_000
2746
) {
2847
if (!['1', 'n', 'm'].includes(receiver.slice(0, 1))) {
2948
throw new Error(
@@ -40,7 +59,7 @@ async function sendOmniAsset(
4059
const assetHex = Buffer.alloc(4);
4160
assetHex.writeUInt32BE(assetId);
4261
const amountHex = Buffer.alloc(8);
43-
amountHex.writeBigUInt64BE(amountMicroCents);
62+
amountHex.writeBigUInt64BE(omniBaseAmount);
4463
const omniScript = Buffer.concat([omniConfig.OMNI_PREFIX, transactionType, assetHex, amountHex]);
4564
const output = utxolib.payments.embed({ data: [omniScript], network: omniConfig.network }).output;
4665
if (!output) {
@@ -63,7 +82,7 @@ async function sendOmniAsset(
6382
},
6483
],
6584
isReplaceableByFee: true,
66-
feeRate,
85+
feeRate: feeRateSatPerKB,
6786
walletPassphrase: omniConfig.walletPassphrase,
6887
// we must send change to our input address to ensure that omni won't
6988
// accidentally send our asset to the change address instead of the recipient
@@ -84,7 +103,7 @@ async function main() {
84103

85104
const wallet = await getWallet();
86105
// we multiply feeRate by 1000 because mempool returns sat/vB and BitGo uses sat/kvB
87-
await sendOmniAsset(wallet, RECEIVE_ADDRESS, SEND_ADDRESS, AMOUNT, ASSET_ID, feeRate * 1000);
106+
await sendOmniAsset(wallet, RECEIVE_ADDRESS, SEND_ADDRESS, 729100000n, ASSET_ID, feeRate * 1000);
88107
}
89108

90109
main().catch((e) => {

0 commit comments

Comments
 (0)