paytaca-cli 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +40 -0
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/swap.d.ts +19 -0
- package/dist/commands/swap.d.ts.map +1 -0
- package/dist/commands/swap.js +129 -0
- package/dist/commands/swap.js.map +1 -0
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/commands/token.js +140 -1
- package/dist/commands/token.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/nostr/store.test.js +12 -4
- package/dist/nostr/store.test.js.map +1 -1
- package/dist/utils/prices.d.ts +46 -0
- package/dist/utils/prices.d.ts.map +1 -0
- package/dist/utils/prices.js +93 -0
- package/dist/utils/prices.js.map +1 -0
- package/dist/utils/prices.test.d.ts +5 -0
- package/dist/utils/prices.test.d.ts.map +1 -0
- package/dist/utils/prices.test.js +62 -0
- package/dist/utils/prices.test.js.map +1 -0
- package/dist/wallet/bch.d.ts +14 -0
- package/dist/wallet/bch.d.ts.map +1 -1
- package/dist/wallet/bch.js +24 -0
- package/dist/wallet/bch.js.map +1 -1
- package/dist/wallet/cauldron/api.d.ts +58 -0
- package/dist/wallet/cauldron/api.d.ts.map +1 -0
- package/dist/wallet/cauldron/api.js +60 -0
- package/dist/wallet/cauldron/api.js.map +1 -0
- package/dist/wallet/cauldron/pools.d.ts +66 -0
- package/dist/wallet/cauldron/pools.d.ts.map +1 -0
- package/dist/wallet/cauldron/pools.js +96 -0
- package/dist/wallet/cauldron/pools.js.map +1 -0
- package/dist/wallet/cauldron/pools.test.d.ts +3 -0
- package/dist/wallet/cauldron/pools.test.d.ts.map +1 -0
- package/dist/wallet/cauldron/pools.test.js +149 -0
- package/dist/wallet/cauldron/pools.test.js.map +1 -0
- package/dist/wallet/cauldron/swap.d.ts +69 -0
- package/dist/wallet/cauldron/swap.d.ts.map +1 -0
- package/dist/wallet/cauldron/swap.js +173 -0
- package/dist/wallet/cauldron/swap.js.map +1 -0
- package/dist/wallet/cauldron/transact.d.ts +98 -0
- package/dist/wallet/cauldron/transact.d.ts.map +1 -0
- package/dist/wallet/cauldron/transact.js +307 -0
- package/dist/wallet/cauldron/transact.js.map +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cauldron swap orchestration: quote estimation and on-chain execution.
|
|
3
|
+
*
|
|
4
|
+
* This is the generic swap primitive (token ⇄ BCH). Higher-level callers
|
|
5
|
+
* (e.g. an MCP payment wrapper) can use estimateSwap() to price a swap and
|
|
6
|
+
* executeSwap() to broadcast it, mirroring the paytaca-app cauldron flow.
|
|
7
|
+
*/
|
|
8
|
+
import { ExchangeLab } from '@cashlab/cauldron';
|
|
9
|
+
import { binToHex } from '@cashlab/common/libauth.js';
|
|
10
|
+
import { LibauthHDWallet } from '../keys.js';
|
|
11
|
+
import { fetchPoolsForToken, fetchTokenData, } from './api.js';
|
|
12
|
+
import { apiPoolToMicroPool, microPoolToPoolV0, parseRate } from './pools.js';
|
|
13
|
+
import { attemptTrade, createInputAndOutput, watchtowerUtxosToSpendableCoins, } from './transact.js';
|
|
14
|
+
/**
|
|
15
|
+
* Estimate a swap: fetch pools + token data and compute the best-rate trade.
|
|
16
|
+
*/
|
|
17
|
+
export async function estimateSwap(opts) {
|
|
18
|
+
const { tokenId, direction, amount } = opts;
|
|
19
|
+
const [tokenData, apiPools] = await Promise.all([
|
|
20
|
+
fetchTokenData(tokenId),
|
|
21
|
+
fetchPoolsForToken(tokenId),
|
|
22
|
+
]);
|
|
23
|
+
if (!tokenData) {
|
|
24
|
+
throw new Error(`No cauldron token data found for ${tokenId}`);
|
|
25
|
+
}
|
|
26
|
+
if (apiPools.length === 0) {
|
|
27
|
+
throw new Error(`No active cauldron pools for token ${tokenId}`);
|
|
28
|
+
}
|
|
29
|
+
const pools = apiPools.map(apiPoolToMicroPool).map(microPoolToPoolV0);
|
|
30
|
+
const isBuyingToken = direction === 'buy';
|
|
31
|
+
const tradeResult = attemptTrade({
|
|
32
|
+
pools,
|
|
33
|
+
isBuyingToken,
|
|
34
|
+
supply: isBuyingToken ? undefined : amount,
|
|
35
|
+
demand: isBuyingToken ? amount : undefined,
|
|
36
|
+
});
|
|
37
|
+
// supply/demand semantics depend on direction:
|
|
38
|
+
// sell: supply=token, demand=BCH
|
|
39
|
+
// buy: supply=BCH, demand=token
|
|
40
|
+
const tokenAmount = isBuyingToken
|
|
41
|
+
? tradeResult.summary.demand
|
|
42
|
+
: tradeResult.summary.supply;
|
|
43
|
+
const bchAmount = isBuyingToken
|
|
44
|
+
? tradeResult.summary.supply
|
|
45
|
+
: tradeResult.summary.demand;
|
|
46
|
+
const decimals = tokenData.bcmr.token.decimals;
|
|
47
|
+
return {
|
|
48
|
+
tokenId,
|
|
49
|
+
tokenData,
|
|
50
|
+
direction,
|
|
51
|
+
isBuyingToken,
|
|
52
|
+
pools,
|
|
53
|
+
tradeResult,
|
|
54
|
+
rate: parseRate(tradeResult.summary.rate, decimals, isBuyingToken),
|
|
55
|
+
tokenAmount,
|
|
56
|
+
bchAmount,
|
|
57
|
+
tradeFee: tradeResult.summary.trade_fee,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Format a SwapQuote for human display.
|
|
62
|
+
*/
|
|
63
|
+
export function formatQuote(quote) {
|
|
64
|
+
const { tokenData, direction, rate, tokenAmount, bchAmount, tradeFee } = quote;
|
|
65
|
+
const decimals = tokenData.bcmr.token.decimals;
|
|
66
|
+
const tokenSymbol = tokenData.bcmr.token.symbol || tokenData.display_symbol;
|
|
67
|
+
const tokenFormatted = (Number(tokenAmount) / 10 ** decimals).toFixed(decimals);
|
|
68
|
+
const bchFormatted = (Number(bchAmount) / 10 ** 8).toFixed(8);
|
|
69
|
+
const feeFormatted = (Number(tradeFee) / 10 ** 8).toFixed(8);
|
|
70
|
+
if (direction === 'sell') {
|
|
71
|
+
// Rate semantics (matches paytaca-app): '1 {demandSymbol} ≈ {rate} {supplySymbol}'.
|
|
72
|
+
// Selling tokens → demand is BCH, rate is tokens-per-BCH.
|
|
73
|
+
return [
|
|
74
|
+
`Sell ${tokenFormatted} ${tokenSymbol} for ${bchFormatted} BCH`,
|
|
75
|
+
`Rate: 1 BCH ≈ ${rate} ${tokenSymbol}`,
|
|
76
|
+
`Trade fee: ~${feeFormatted} BCH`,
|
|
77
|
+
].join('\n');
|
|
78
|
+
}
|
|
79
|
+
// Buying tokens → demand is the token, rate is BCH-per-token.
|
|
80
|
+
return [
|
|
81
|
+
`Buy ${tokenFormatted} ${tokenSymbol} for ${bchFormatted} BCH`,
|
|
82
|
+
`Rate: 1 ${tokenSymbol} ≈ ${rate} BCH`,
|
|
83
|
+
`Trade fee: ~${feeFormatted} BCH`,
|
|
84
|
+
].join('\n');
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Execute a swap: build + sign the trade transaction and broadcast it.
|
|
88
|
+
*/
|
|
89
|
+
export async function executeSwap(opts) {
|
|
90
|
+
const { bchWallet, mnemonic, derivationPath } = opts;
|
|
91
|
+
let quote;
|
|
92
|
+
try {
|
|
93
|
+
quote = await estimateSwap(opts);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
return { success: false, error: err?.message || String(err) };
|
|
97
|
+
}
|
|
98
|
+
let txHex;
|
|
99
|
+
try {
|
|
100
|
+
const tradeTx = await buildSignedTradeTx({
|
|
101
|
+
bchWallet,
|
|
102
|
+
mnemonic,
|
|
103
|
+
derivationPath,
|
|
104
|
+
quote,
|
|
105
|
+
});
|
|
106
|
+
txHex = binToHex(tradeTx.txbin);
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
return { success: false, error: err?.message || String(err), quote };
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const broadcastResponse = await bchWallet.watchtower.BCH._api.post('broadcast/', { transaction: txHex });
|
|
113
|
+
const data = broadcastResponse.data;
|
|
114
|
+
// Mempool test API compatibility
|
|
115
|
+
if (data?.result) {
|
|
116
|
+
data[data.success ? 'txid' : 'error'] = data.result;
|
|
117
|
+
delete data.result;
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
success: Boolean(data?.success),
|
|
121
|
+
txid: data?.txid,
|
|
122
|
+
transaction: txHex,
|
|
123
|
+
error: data?.error,
|
|
124
|
+
quote,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
transaction: txHex,
|
|
131
|
+
error: err?.message || String(err),
|
|
132
|
+
quote,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Build + sign the trade transaction (no broadcast).
|
|
138
|
+
*/
|
|
139
|
+
export async function buildSignedTradeTx(opts) {
|
|
140
|
+
const { bchWallet, mnemonic, derivationPath, quote } = opts;
|
|
141
|
+
const hdWallet = new LibauthHDWallet(mnemonic, derivationPath, bchWallet.isChipnet ? 'chipnet' : 'mainnet');
|
|
142
|
+
const spendableCoins = await collectSpendableCoins({
|
|
143
|
+
bchWallet,
|
|
144
|
+
hdWallet,
|
|
145
|
+
tokenId: quote.tokenId,
|
|
146
|
+
isBuyingToken: quote.isBuyingToken,
|
|
147
|
+
});
|
|
148
|
+
const { inputCoins, payouts } = createInputAndOutput({
|
|
149
|
+
tradeResult: quote.tradeResult,
|
|
150
|
+
spendableCoins,
|
|
151
|
+
});
|
|
152
|
+
const exlab = new ExchangeLab();
|
|
153
|
+
const tradeTx = exlab.createTradeTx(quote.tradeResult.entries, inputCoins, payouts, null, 1n);
|
|
154
|
+
exlab.verifyTradeTx(tradeTx);
|
|
155
|
+
return tradeTx;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Collect the wallet UTXOs needed for the swap as SpendableCoins.
|
|
159
|
+
* Selling needs the token's UTXOs + BCH; buying needs BCH only.
|
|
160
|
+
*/
|
|
161
|
+
async function collectSpendableCoins(opts) {
|
|
162
|
+
const { bchWallet, hdWallet, tokenId, isBuyingToken } = opts;
|
|
163
|
+
// BCH inputs: all UTXOs, filtered client-side to non-token ones so that
|
|
164
|
+
// other token holdings are never accidentally consumed.
|
|
165
|
+
const [allUtxos, tokenUtxos] = await Promise.all([
|
|
166
|
+
bchWallet.getUtxos(),
|
|
167
|
+
isBuyingToken ? Promise.resolve([]) : bchWallet.getUtxos({ category: tokenId }),
|
|
168
|
+
]);
|
|
169
|
+
const bchUtxos = allUtxos.filter((utxo) => !utxo.is_cashtoken);
|
|
170
|
+
const utxos = [...bchUtxos, ...tokenUtxos];
|
|
171
|
+
return watchtowerUtxosToSpendableCoins({ utxos, wallet: hdWallet });
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../../src/wallet/cauldron/swap.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAiC,MAAM,mBAAmB,CAAA;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,EACL,kBAAkB,EAClB,cAAc,GAEf,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC7E,OAAO,EACL,YAAY,EACZ,oBAAoB,EACpB,+BAA+B,GAEhC,MAAM,eAAe,CAAA;AA4CtB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAsB;IAEtB,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;IAE3C,MAAM,CAA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ACH,CAAA;IACD,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAA;IAE5B,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;GAGG;AACH,KAAK,UAAU,qBAAqB,CAAC,IAKpC;IACC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;IAE5D,wEAAwE;IACxE,wDAAwD;IACxD,MAAM,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC/C,SAAS,CAAC,QAAQ,EAAE;QACpB,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAsB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;KACpG,CAAC,CAAA;IAEF,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAoB,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IAC9E,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,EAAE,GAAI,UAA+B,CAAC,CAAA;IAEhE,OAAO,+BAA+B,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAA;AACrE,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cauldron trade transaction building.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from: paytaca-app/src/wallet/cauldron/transact.js.
|
|
5
|
+
*
|
|
6
|
+
* Uses @cashlab/cauldron's ExchangeLab to construct a best-rate trade across
|
|
7
|
+
* the active pools, then createInputAndOutput() selects the wallet coins and
|
|
8
|
+
* payout rules needed to fund and settle it. The final signed transaction is
|
|
9
|
+
* produced by ExchangeLab.createTradeTx() (libauth templates).
|
|
10
|
+
*/
|
|
11
|
+
import { ExchangeLab, type PoolV0, type TradeResult } from '@cashlab/cauldron';
|
|
12
|
+
import { type PayoutRule, type SpendableCoin } from '@cashlab/common';
|
|
13
|
+
import type { LibauthHDWallet } from '../keys.js';
|
|
14
|
+
export interface AttemptTradeOpts {
|
|
15
|
+
exlab?: ExchangeLab;
|
|
16
|
+
pools: PoolV0[];
|
|
17
|
+
isBuyingToken: boolean;
|
|
18
|
+
supply?: bigint;
|
|
19
|
+
demand?: bigint;
|
|
20
|
+
txFeePerByte?: bigint;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Attempt a best-rate trade across the given pools.
|
|
24
|
+
*
|
|
25
|
+
* - Selling token → BCH: pass `supply` (token amount in base units).
|
|
26
|
+
* - Buying token with BCH: pass `demand` (token amount in base units to receive).
|
|
27
|
+
*/
|
|
28
|
+
export declare function attemptTrade(opts: AttemptTradeOpts): TradeResult;
|
|
29
|
+
export interface PlatformFee {
|
|
30
|
+
to: string;
|
|
31
|
+
amount: bigint;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Select the wallet coins and payout rules needed to fund + settle a trade.
|
|
35
|
+
* Mirrors paytaca-app createInputAndOutput().
|
|
36
|
+
*/
|
|
37
|
+
export declare function createInputAndOutput(opts: {
|
|
38
|
+
tradeResult: TradeResult;
|
|
39
|
+
spendableCoins: SpendableCoin[];
|
|
40
|
+
platformFee?: PlatformFee;
|
|
41
|
+
tokenOutputSats?: bigint;
|
|
42
|
+
}): {
|
|
43
|
+
inputCoins: SpendableCoin[];
|
|
44
|
+
payouts: PayoutRule[];
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Sum the on-chain byte sizes of the pool inputs and outputs for a trade.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getEntriesSize(tradeResult: TradeResult): {
|
|
50
|
+
inputFees: number;
|
|
51
|
+
outputFees: number;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Build a signed transaction for a trade using test coins, then optionally
|
|
55
|
+
* verify it. Used to validate a trade before broadcasting.
|
|
56
|
+
*/
|
|
57
|
+
export declare function testTradeResult(opts: {
|
|
58
|
+
exlab?: ExchangeLab;
|
|
59
|
+
tradeResult: TradeResult;
|
|
60
|
+
verify?: boolean;
|
|
61
|
+
}): import("@cashlab/cauldron").TradeTxResult;
|
|
62
|
+
/**
|
|
63
|
+
* Convert watchtower UTXOs into @cashlab/common SpendableCoins.
|
|
64
|
+
* Mirrors paytaca-app watchtowerUtxosToSpendableCoins().
|
|
65
|
+
*/
|
|
66
|
+
export interface WatchtowerUtxo {
|
|
67
|
+
txid: string;
|
|
68
|
+
vout: number;
|
|
69
|
+
value: number;
|
|
70
|
+
tokenid?: string;
|
|
71
|
+
amount?: number;
|
|
72
|
+
address_path: string;
|
|
73
|
+
is_cashtoken?: boolean;
|
|
74
|
+
}
|
|
75
|
+
export declare function watchtowerUtxosToSpendableCoins(opts: {
|
|
76
|
+
utxos: WatchtowerUtxo[];
|
|
77
|
+
wallet: LibauthHDWallet;
|
|
78
|
+
}): SpendableCoin[];
|
|
79
|
+
/**
|
|
80
|
+
* On-chain byte size of a transaction input for a given unlocking script.
|
|
81
|
+
* Mirrors cashscript getInputSize().
|
|
82
|
+
*/
|
|
83
|
+
export declare function getInputSize(inputScript: Uint8Array): number;
|
|
84
|
+
interface SizedOutput {
|
|
85
|
+
to: Uint8Array | string;
|
|
86
|
+
amount: bigint;
|
|
87
|
+
token?: {
|
|
88
|
+
category?: string;
|
|
89
|
+
amount: bigint;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* On-chain byte size of a transaction output.
|
|
94
|
+
* Mirrors cashscript getOutputSize() (string `to` is treated as a CashAddress).
|
|
95
|
+
*/
|
|
96
|
+
export declare function getOutputSize(output: SizedOutput): number;
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=transact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transact.d.ts","sourceRoot":"","sources":["../../../src/wallet/cauldron/transact.ts"],"names":[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CACjB,6CAmEA;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,wBAAgB,+BAA+B,CAAC,IAAI,EAAE;IACpD,KAAK,EAAE,cAAc,EAAE,CAAA;IACvB,MAAM,EAAE,eAAe,CAAA;CACxB,GAAG,aAAa,EAAE,CAmClB;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,UAAU,GAAG,MAAM,CAI5D;AAED,UAAU,WAAW;IACnB,EAAE,EAAE,UAAU,GAAG,MAAM,CAAA;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAC9C;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CA+BzD"}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cauldron trade transaction building.
|
|
3
|
+
*
|
|
4
|
+
* Adapted from: paytaca-app/src/wallet/cauldron/transact.js.
|
|
5
|
+
*
|
|
6
|
+
* Uses @cashlab/cauldron's ExchangeLab to construct a best-rate trade across
|
|
7
|
+
* the active pools, then createInputAndOutput() selects the wallet coins and
|
|
8
|
+
* payout rules needed to fund and settle it. The final signed transaction is
|
|
9
|
+
* produced by ExchangeLab.createTradeTx() (libauth templates).
|
|
10
|
+
*/
|
|
11
|
+
import { ExchangeLab, buildPoolV0UnlockingBytecode, } from '@cashlab/cauldron';
|
|
12
|
+
import { NATIVE_BCH_TOKEN_ID, PayoutAmountRuleType, SpendableCoinType, } from '@cashlab/common';
|
|
13
|
+
import { bigIntToCompactUint, cashAddressToLockingBytecode, compactUintPrefixToLength, decodePrivateKeyWif, hexToBin, privateKeyToP2pkhLockingBytecode, } from '@cashlab/common/libauth.js';
|
|
14
|
+
import { poolTradeToOutput } from './pools.js';
|
|
15
|
+
const PLACEHOLDER_TOKEN_ID_FOR_SIZE_CALC = Array.from({ length: 64 })
|
|
16
|
+
.fill('0')
|
|
17
|
+
.join('');
|
|
18
|
+
/** Estimated on-chain size of a P2PKH input (Schnorr signature). */
|
|
19
|
+
const P2PKH_INPUT_SIZE = 141n;
|
|
20
|
+
/**
|
|
21
|
+
* Attempt a best-rate trade across the given pools.
|
|
22
|
+
*
|
|
23
|
+
* - Selling token → BCH: pass `supply` (token amount in base units).
|
|
24
|
+
* - Buying token with BCH: pass `demand` (token amount in base units to receive).
|
|
25
|
+
*/
|
|
26
|
+
export function attemptTrade(opts) {
|
|
27
|
+
const exlab = opts.exlab ?? new ExchangeLab();
|
|
28
|
+
const { pools, isBuyingToken, supply, demand } = opts;
|
|
29
|
+
const txFeePerByte = opts.txFeePerByte || 1n;
|
|
30
|
+
if (pools.length === 0)
|
|
31
|
+
throw new Error('No pools provided');
|
|
32
|
+
let supplyTokenId = pools[0].output.token.token_id;
|
|
33
|
+
let demandTokenId = NATIVE_BCH_TOKEN_ID;
|
|
34
|
+
if (isBuyingToken) {
|
|
35
|
+
supplyTokenId = NATIVE_BCH_TOKEN_ID;
|
|
36
|
+
demandTokenId = pools[0].output.token.token_id;
|
|
37
|
+
}
|
|
38
|
+
if (demand) {
|
|
39
|
+
return exlab.constructTradeBestRateForTargetDemand(supplyTokenId, demandTokenId, demand, pools, txFeePerByte);
|
|
40
|
+
}
|
|
41
|
+
return exlab.constructTradeBestRateForTargetSupply(supplyTokenId, demandTokenId, supply, pools, txFeePerByte);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Select the wallet coins and payout rules needed to fund + settle a trade.
|
|
45
|
+
* Mirrors paytaca-app createInputAndOutput().
|
|
46
|
+
*/
|
|
47
|
+
export function createInputAndOutput(opts) {
|
|
48
|
+
const { tradeResult, spendableCoins, platformFee } = opts;
|
|
49
|
+
const tokenOutputSats = opts.tokenOutputSats ?? 1000n;
|
|
50
|
+
if (spendableCoins.length === 0) {
|
|
51
|
+
throw new Error('No UTXOs available to fund the trade');
|
|
52
|
+
}
|
|
53
|
+
const privateKey = spendableCoins[0].key;
|
|
54
|
+
const lockingBytecode = privateKeyToP2pkhLockingBytecode({
|
|
55
|
+
privateKey,
|
|
56
|
+
throwErrors: true,
|
|
57
|
+
});
|
|
58
|
+
const tokenCoins = spendableCoins.filter((coin) => coin.output?.token);
|
|
59
|
+
const bchCoins = spendableCoins.filter((coin) => !coin.output.token);
|
|
60
|
+
const isBuyingToken = tradeResult.entries[0].supply_token_id === NATIVE_BCH_TOKEN_ID;
|
|
61
|
+
const entriesSizes = getEntriesSize(tradeResult);
|
|
62
|
+
const totalPoolTxFee = BigInt(entriesSizes.inputFees + entriesSizes.outputFees);
|
|
63
|
+
let tokensToSupply = !isBuyingToken ? tradeResult.summary.supply : 0n;
|
|
64
|
+
let satoshisToSupply = isBuyingToken ? tradeResult.summary.supply : 0n;
|
|
65
|
+
satoshisToSupply += totalPoolTxFee;
|
|
66
|
+
if (platformFee) {
|
|
67
|
+
satoshisToSupply += platformFee.amount;
|
|
68
|
+
satoshisToSupply += BigInt(getOutputSize(platformFee));
|
|
69
|
+
}
|
|
70
|
+
const inputCoins = [];
|
|
71
|
+
const payouts = [];
|
|
72
|
+
let remainingTokens = 0n;
|
|
73
|
+
if (!isBuyingToken) {
|
|
74
|
+
// Selling tokens: consume token UTXOs until we've covered the supply
|
|
75
|
+
remainingTokens = tokensToSupply;
|
|
76
|
+
for (const spendableCoin of tokenCoins) {
|
|
77
|
+
if (remainingTokens <= 0n)
|
|
78
|
+
break;
|
|
79
|
+
inputCoins.push(spendableCoin);
|
|
80
|
+
remainingTokens -= spendableCoin.output.token.amount;
|
|
81
|
+
satoshisToSupply += P2PKH_INPUT_SIZE;
|
|
82
|
+
satoshisToSupply -= spendableCoin.output.amount;
|
|
83
|
+
}
|
|
84
|
+
if (remainingTokens > 0n) {
|
|
85
|
+
throw new Error('Insufficient tokens to fund the trade');
|
|
86
|
+
}
|
|
87
|
+
// Excess tokens supplied → a token change output (counted in size calc)
|
|
88
|
+
if (remainingTokens < 0n) {
|
|
89
|
+
const changeTokenOutput = {
|
|
90
|
+
to: lockingBytecode,
|
|
91
|
+
amount: tokenOutputSats,
|
|
92
|
+
token: {
|
|
93
|
+
category: PLACEHOLDER_TOKEN_ID_FOR_SIZE_CALC,
|
|
94
|
+
amount: remainingTokens * -1n,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
satoshisToSupply += changeTokenOutput.amount;
|
|
98
|
+
satoshisToSupply += BigInt(getOutputSize(changeTokenOutput));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
// Buying tokens: fixed payout for the received token amount
|
|
103
|
+
payouts.push({
|
|
104
|
+
type: PayoutAmountRuleType.FIXED,
|
|
105
|
+
locking_bytecode: lockingBytecode,
|
|
106
|
+
amount: tokenOutputSats,
|
|
107
|
+
token: {
|
|
108
|
+
token_id: tradeResult.entries[0].demand_token_id,
|
|
109
|
+
amount: tradeResult.summary.demand,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const outputSize = getOutputSize({
|
|
113
|
+
to: lockingBytecode,
|
|
114
|
+
amount: tokenOutputSats,
|
|
115
|
+
token: {
|
|
116
|
+
category: tradeResult.entries[0].demand_token_id,
|
|
117
|
+
amount: tradeResult.summary.demand,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
satoshisToSupply += tokenOutputSats + BigInt(outputSize);
|
|
121
|
+
}
|
|
122
|
+
if (platformFee) {
|
|
123
|
+
const decoded = cashAddressToLockingBytecode(platformFee.to);
|
|
124
|
+
if (!decoded || typeof decoded === 'string' || !decoded.bytecode) {
|
|
125
|
+
throw new Error(`Invalid platform fee address: ${platformFee.to}`);
|
|
126
|
+
}
|
|
127
|
+
payouts.push({
|
|
128
|
+
type: PayoutAmountRuleType.FIXED,
|
|
129
|
+
locking_bytecode: decoded.bytecode,
|
|
130
|
+
amount: platformFee.amount,
|
|
131
|
+
});
|
|
132
|
+
satoshisToSupply += platformFee.amount + BigInt(getOutputSize(platformFee));
|
|
133
|
+
}
|
|
134
|
+
// Base tx overhead (version + locktime) and varint prefixes for inputs/outputs
|
|
135
|
+
satoshisToSupply += 8n;
|
|
136
|
+
const inputSizePrefixLength = compactUintPrefixToLength(bigIntToCompactUint(BigInt(tradeResult.entries.length + inputCoins.length))[0]);
|
|
137
|
+
const outputSizePrefixLength = compactUintPrefixToLength(bigIntToCompactUint(BigInt(tradeResult.entries.length + payouts.length))[0]);
|
|
138
|
+
satoshisToSupply += BigInt(inputSizePrefixLength) + BigInt(outputSizePrefixLength);
|
|
139
|
+
// Cover the remainder with BCH inputs
|
|
140
|
+
let remainingSats = satoshisToSupply;
|
|
141
|
+
for (const spendableCoin of bchCoins) {
|
|
142
|
+
if (remainingSats <= 0n)
|
|
143
|
+
break;
|
|
144
|
+
inputCoins.push(spendableCoin);
|
|
145
|
+
remainingSats -= spendableCoin.output.amount;
|
|
146
|
+
remainingSats += P2PKH_INPUT_SIZE;
|
|
147
|
+
}
|
|
148
|
+
if (remainingSats > 0n) {
|
|
149
|
+
throw new Error('Insufficient BCH to fund the trade and transaction fees');
|
|
150
|
+
}
|
|
151
|
+
payouts.push({
|
|
152
|
+
type: PayoutAmountRuleType.CHANGE,
|
|
153
|
+
locking_bytecode: lockingBytecode,
|
|
154
|
+
allow_mixing_native_and_token: false,
|
|
155
|
+
allow_mixing_native_and_token_when_bch_change_is_dust: false,
|
|
156
|
+
add_change_to_txfee_when_bch_change_is_dust: true,
|
|
157
|
+
});
|
|
158
|
+
return { inputCoins, payouts };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Sum the on-chain byte sizes of the pool inputs and outputs for a trade.
|
|
162
|
+
*/
|
|
163
|
+
export function getEntriesSize(tradeResult) {
|
|
164
|
+
const inputFees = tradeResult.entries
|
|
165
|
+
.map((entry) => buildPoolV0UnlockingBytecode(entry.pool.parameters))
|
|
166
|
+
.map((unlockingBytecode) => getInputSize(unlockingBytecode))
|
|
167
|
+
.reduce((subtotal, size) => subtotal + size, 0);
|
|
168
|
+
const outputFees = tradeResult.entries
|
|
169
|
+
.map((entry) => {
|
|
170
|
+
const output = poolTradeToOutput(entry);
|
|
171
|
+
return getOutputSize(output);
|
|
172
|
+
})
|
|
173
|
+
.reduce((subtotal, size) => subtotal + size, 0);
|
|
174
|
+
return { inputFees, outputFees };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Build a signed transaction for a trade using test coins, then optionally
|
|
178
|
+
* verify it. Used to validate a trade before broadcasting.
|
|
179
|
+
*/
|
|
180
|
+
export function testTradeResult(opts) {
|
|
181
|
+
const exlab = opts.exlab ?? new ExchangeLab();
|
|
182
|
+
const { tradeResult } = opts;
|
|
183
|
+
const firstEntry = tradeResult.entries[0];
|
|
184
|
+
const isSupplyBch = firstEntry.supply_token_id === NATIVE_BCH_TOKEN_ID;
|
|
185
|
+
const tokenId = isSupplyBch ? firstEntry.demand_token_id : firstEntry.supply_token_id;
|
|
186
|
+
const key = new Uint8Array(32).fill(0x11);
|
|
187
|
+
const locking_bytecode = privateKeyToP2pkhLockingBytecode({
|
|
188
|
+
privateKey: key,
|
|
189
|
+
throwErrors: true,
|
|
190
|
+
});
|
|
191
|
+
const tokenAmount = isSupplyBch ? 0n : (tradeResult.summary.supply * 3n) / 2n;
|
|
192
|
+
const satsAmount = (isSupplyBch ? tradeResult.summary.supply : 0n) +
|
|
193
|
+
tradeResult.summary.trade_fee +
|
|
194
|
+
100000n;
|
|
195
|
+
const coins = [
|
|
196
|
+
{
|
|
197
|
+
type: SpendableCoinType.P2PKH,
|
|
198
|
+
key,
|
|
199
|
+
outpoint: { txhash: new Uint8Array(32).fill(0x22), index: 1 },
|
|
200
|
+
output: { locking_bytecode, amount: satsAmount },
|
|
201
|
+
},
|
|
202
|
+
];
|
|
203
|
+
if (tokenAmount) {
|
|
204
|
+
coins.push({
|
|
205
|
+
type: SpendableCoinType.P2PKH,
|
|
206
|
+
key,
|
|
207
|
+
outpoint: { txhash: new Uint8Array(32).fill(0x33), index: 1 },
|
|
208
|
+
output: {
|
|
209
|
+
locking_bytecode,
|
|
210
|
+
amount: 1000n,
|
|
211
|
+
token: { token_id: tokenId, amount: tokenAmount },
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
const payoutRules = [];
|
|
216
|
+
if (isSupplyBch) {
|
|
217
|
+
payoutRules.push({
|
|
218
|
+
type: PayoutAmountRuleType.FIXED,
|
|
219
|
+
locking_bytecode,
|
|
220
|
+
amount: 1000n,
|
|
221
|
+
token: { token_id: tokenId, amount: tradeResult.summary.demand },
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
payoutRules.push({
|
|
225
|
+
type: PayoutAmountRuleType.CHANGE,
|
|
226
|
+
locking_bytecode,
|
|
227
|
+
allow_mixing_native_and_token: false,
|
|
228
|
+
allow_mixing_native_and_token_when_bch_change_is_dust: false,
|
|
229
|
+
add_change_to_txfee_when_bch_change_is_dust: true,
|
|
230
|
+
});
|
|
231
|
+
const tradeTx = exlab.createTradeTx(tradeResult.entries, coins, payoutRules, null, 1n);
|
|
232
|
+
if (opts.verify)
|
|
233
|
+
exlab.verifyTradeTx(tradeTx);
|
|
234
|
+
return tradeTx;
|
|
235
|
+
}
|
|
236
|
+
export function watchtowerUtxosToSpendableCoins(opts) {
|
|
237
|
+
const { utxos, wallet } = opts;
|
|
238
|
+
const addressPathPrivkeyMap = new Map();
|
|
239
|
+
return utxos.map((utxo) => {
|
|
240
|
+
let privateKey = addressPathPrivkeyMap.get(utxo.address_path);
|
|
241
|
+
if (!privateKey) {
|
|
242
|
+
const wif = wallet.getPrivateKeyWifAt(utxo.address_path);
|
|
243
|
+
const decodedWif = decodePrivateKeyWif(wif);
|
|
244
|
+
if (typeof decodedWif === 'string')
|
|
245
|
+
throw new Error(decodedWif);
|
|
246
|
+
privateKey = decodedWif.privateKey;
|
|
247
|
+
addressPathPrivkeyMap.set(utxo.address_path, privateKey);
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
type: SpendableCoinType.P2PKH,
|
|
251
|
+
key: privateKey,
|
|
252
|
+
outpoint: { txhash: hexToBin(utxo.txid), index: utxo.vout },
|
|
253
|
+
output: {
|
|
254
|
+
locking_bytecode: privateKeyToP2pkhLockingBytecode({
|
|
255
|
+
privateKey,
|
|
256
|
+
throwErrors: true,
|
|
257
|
+
}),
|
|
258
|
+
amount: BigInt(utxo.value),
|
|
259
|
+
token: !utxo.is_cashtoken
|
|
260
|
+
? undefined
|
|
261
|
+
: {
|
|
262
|
+
token_id: utxo.tokenid,
|
|
263
|
+
amount: BigInt(utxo.amount ?? 0),
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* On-chain byte size of a transaction input for a given unlocking script.
|
|
271
|
+
* Mirrors cashscript getInputSize().
|
|
272
|
+
*/
|
|
273
|
+
export function getInputSize(inputScript) {
|
|
274
|
+
const scriptSize = inputScript.length;
|
|
275
|
+
const prefixSize = scriptSize > 252 ? 3 : 1;
|
|
276
|
+
return 32 + 4 + prefixSize + scriptSize + 4;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* On-chain byte size of a transaction output.
|
|
280
|
+
* Mirrors cashscript getOutputSize() (string `to` is treated as a CashAddress).
|
|
281
|
+
*/
|
|
282
|
+
export function getOutputSize(output) {
|
|
283
|
+
let lockingBytecode;
|
|
284
|
+
if (typeof output.to === 'string') {
|
|
285
|
+
const decoded = cashAddressToLockingBytecode(output.to);
|
|
286
|
+
if (typeof decoded === 'string') {
|
|
287
|
+
throw new Error(`Invalid CashAddress: ${decoded}`);
|
|
288
|
+
}
|
|
289
|
+
lockingBytecode = decoded?.bytecode;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
lockingBytecode = output.to;
|
|
293
|
+
}
|
|
294
|
+
if (!lockingBytecode) {
|
|
295
|
+
throw new Error('Invalid locking bytecode for output size calculation');
|
|
296
|
+
}
|
|
297
|
+
let size = 8 +
|
|
298
|
+
compactUintPrefixToLength(bigIntToCompactUint(BigInt(lockingBytecode.length))[0]) +
|
|
299
|
+
lockingBytecode.length;
|
|
300
|
+
if (output.token) {
|
|
301
|
+
size +=
|
|
302
|
+
34 +
|
|
303
|
+
compactUintPrefixToLength(bigIntToCompactUint(BigInt(output.token.amount))[0]);
|
|
304
|
+
}
|
|
305
|
+
return size;
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=transact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transact.js","sourceRoot":"","sources":["../../../src/wallet/cauldron/transact.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,WAAW,EACX,4BAA4B,GAG7B,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,GAKlB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,mBAAmB,EACnB,4BAA4B,EAC5B,yBAAyB,EACzB,mBAAmB,EACnB,QAAQ,EACR,gCAAgC,GACjC,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAG9C,MAAM,kCAAkC,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;KAClE,IAAI,CAAC,GAAG,CAAC;KACT,IAAI,CAAC,EAAE,CAAC,CAAA;AAEX,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,IAAI,CAAA;AAW7B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I,CAAA;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "paytaca-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Command-line interface for the Paytaca Bitcoin Cash wallet",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -41,12 +41,13 @@
|
|
|
41
41
|
"license": "SEE LICENSE IN LICENSE",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@bitauth/libauth": "2.0.0-alpha.8",
|
|
44
|
+
"@cashlab/cauldron": "^1.0.3",
|
|
44
45
|
"@napi-rs/keyring": "^1.2.0",
|
|
45
46
|
"bip39": "^3.1.0",
|
|
46
47
|
"chalk": "^5.4.1",
|
|
47
48
|
"commander": "^12.1.0",
|
|
48
|
-
"nostr-tools": "^2.23.3",
|
|
49
49
|
"js-sha256": "^0.9.0",
|
|
50
|
+
"nostr-tools": "^2.23.3",
|
|
50
51
|
"qrcode-terminal": "^0.12.0",
|
|
51
52
|
"watchtower-cash-js": "^0.2.4"
|
|
52
53
|
},
|