@@ -60,6 +60,39 @@ export const encodeProtostone = ({
6060 } ) . encodedRunestone
6161}
6262
63+ export const addFrBtcWrapOutToPsbt = ( {
64+ frbtcWrapPsbt,
65+ account,
66+ psbt,
67+ } : {
68+ frbtcWrapPsbt : bitcoin . Psbt
69+ account : Account
70+ psbt : bitcoin . Psbt
71+ } ) => {
72+ const frbtcWrapTxId = getUnfinalizedPsbtTxId ( frbtcWrapPsbt )
73+ const output = frbtcWrapPsbt . txOutputs [ 0 ]
74+ if ( account . taproot ) {
75+ psbt . addInput ( {
76+ hash : frbtcWrapTxId ,
77+ index : 0 ,
78+ witnessUtxo : {
79+ script : output . script ,
80+ value : output . value ,
81+ } ,
82+ tapInternalKey : toXOnly ( Buffer . from ( account . taproot . pubkey , 'hex' ) ) ,
83+ } )
84+ } else if ( account . nativeSegwit ) {
85+ psbt . addInput ( {
86+ hash : frbtcWrapTxId ,
87+ index : 0 ,
88+ witnessUtxo : {
89+ script : output . script ,
90+ value : output . value ,
91+ } ,
92+ } )
93+ }
94+ }
95+
6396export const createExecutePsbt = async ( {
6497 alkanesUtxos,
6598 frontendFee,
@@ -138,28 +171,7 @@ export const createExecutePsbt = async ({
138171 const psbt = new bitcoin . Psbt ( { network : provider . network } )
139172
140173 if ( frbtcWrapPsbt ) {
141- const frbtcWrapTxId = getUnfinalizedPsbtTxId ( frbtcWrapPsbt )
142- const output = frbtcWrapPsbt . txOutputs [ 0 ]
143- if ( account . taproot ) {
144- psbt . addInput ( {
145- hash : frbtcWrapTxId ,
146- index : 0 ,
147- witnessUtxo : {
148- script : output . script ,
149- value : output . value ,
150- } ,
151- tapInternalKey : toXOnly ( Buffer . from ( account . taproot . pubkey , 'hex' ) ) ,
152- } )
153- } else if ( account . nativeSegwit ) {
154- psbt . addInput ( {
155- hash : frbtcWrapTxId ,
156- index : 0 ,
157- witnessUtxo : {
158- script : output . script ,
159- value : output . value ,
160- } ,
161- } )
162- }
174+ addFrBtcWrapOutToPsbt ( { frbtcWrapPsbt, account, psbt } ) ;
163175 }
164176 if ( alkanesUtxos ) {
165177 for ( const utxo of alkanesUtxos ) {
@@ -1003,6 +1015,7 @@ export const actualTransactRevealFee = async ({
10031015 provider,
10041016 feeRate,
10051017 account,
1018+ frbtcWrapPsbt,
10061019} : {
10071020 payload : AlkanesPayload
10081021 alkanesUtxos ?: FormattedUtxo [ ]
@@ -1016,6 +1029,7 @@ export const actualTransactRevealFee = async ({
10161029 provider : Provider
10171030 feeRate ?: number
10181031 account : Account
1032+ frbtcWrapPsbt ?: bitcoin . Psbt
10191033} ) => {
10201034 if ( ! feeRate ) {
10211035 feeRate = ( await provider . esplora . getFeeEstimates ( ) ) [ '1' ]
@@ -1034,6 +1048,7 @@ export const actualTransactRevealFee = async ({
10341048 provider,
10351049 feeRate,
10361050 account,
1051+ frbtcWrapPsbt,
10371052 } )
10381053
10391054 const { fee : estimatedFee } = await getEstimatedFee ( {
@@ -1056,6 +1071,7 @@ export const actualTransactRevealFee = async ({
10561071 feeRate,
10571072 fee : estimatedFee ,
10581073 account,
1074+ frbtcWrapPsbt,
10591075 } )
10601076
10611077 const { fee : finalFee , vsize } = await getEstimatedFee ( {
@@ -1228,6 +1244,18 @@ export const executeFallbackToWitnessProxy = async ({
12281244 remainingUtxos = utxos . filter (
12291245 utxo => ! spentUtxos . some ( spent => spent . txId === utxo . txId && spent . outputIndex === Number ( utxo . outputIndex ) )
12301246 ) ;
1247+ remainingUtxos . push ( {
1248+ txId : getUnfinalizedPsbtTxId ( frbtcWrapPsbt ) ,
1249+ outputIndex : frbtcWrapPsbt . txOutputs . length - 1 ,
1250+ satoshis : ( frbtcWrapPsbt . txOutputs [ frbtcWrapPsbt . txOutputs . length - 1 ] as bitcoin . PsbtTxOutput ) . value ,
1251+ scriptPk : ( frbtcWrapPsbt . txOutputs [ frbtcWrapPsbt . txOutputs . length - 1 ] as bitcoin . PsbtTxOutput ) . script . toString ( 'hex' ) ,
1252+ address : account . nativeSegwit . address ,
1253+ inscriptions : [ ] ,
1254+ runes : { } ,
1255+ alkanes : { } ,
1256+ confirmations : 0 ,
1257+ indexed : true , // technically not indexed but it can be used in future txs
1258+ } ) ;
12311259 if ( alkanesUtxos ) {
12321260 remainingAlkanesUtxos = alkanesUtxos . filter (
12331261 utxo => ! spentUtxos . some ( spent => spent . txId === utxo . txId && spent . outputIndex === Number ( utxo . outputIndex ) )
@@ -1536,6 +1564,7 @@ export const createTransactReveal = async ({
15361564 commitTxId,
15371565 commitPsbt,
15381566 account,
1567+ frbtcWrapPsbt,
15391568} : {
15401569 payload : AlkanesPayload
15411570 alkanesUtxos ?: FormattedUtxo [ ]
@@ -1550,15 +1579,17 @@ export const createTransactReveal = async ({
15501579 commitTxId : string
15511580 commitPsbt : bitcoin . Psbt
15521581 account : Account
1582+ frbtcWrapPsbt ?: bitcoin . Psbt
15531583} ) => {
15541584 try {
15551585 if ( ! feeRate ) {
15561586 feeRate = ( await provider . esplora . getFeeEstimates ( ) ) [ '1' ]
15571587 }
15581588
15591589 const psbt : bitcoin . Psbt = new bitcoin . Psbt ( { network : provider . network } )
1590+
15601591 const minFee = minimumFee ( {
1561- taprootInputCount : 1 ,
1592+ taprootInputCount : ( frbtcWrapPsbt ? 2 : 1 ) + ( alkanesUtxos ? alkanesUtxos . length : 0 ) ,
15621593 nonTaprootInputCount : 0 ,
15631594 outputCount : 2 ,
15641595 payload
@@ -1581,6 +1612,7 @@ export const createTransactReveal = async ({
15811612 network : provider . network ,
15821613 } )
15831614
1615+ // this needs to be the first input
15841616 psbt . addInput ( {
15851617 hash : commitTxId ,
15861618 index : 0 ,
@@ -1597,6 +1629,10 @@ export const createTransactReveal = async ({
15971629 ] ,
15981630 } )
15991631
1632+ if ( frbtcWrapPsbt ) {
1633+ addFrBtcWrapOutToPsbt ( { frbtcWrapPsbt, account, psbt } ) ;
1634+ }
1635+
16001636 let gatheredUtxos = {
16011637 utxos : [ ] ,
16021638 totalAmount : 0 ,
@@ -1760,6 +1796,7 @@ export const inscribePayloadBulk = async ({
17601796 provider,
17611797 feeRate,
17621798 account,
1799+ frbtcWrapPsbt,
17631800 } )
17641801
17651802 const { psbt : finalRevealPsbt } = await createTransactReveal ( {
@@ -1776,6 +1813,7 @@ export const inscribePayloadBulk = async ({
17761813 feeRate,
17771814 fee : revealFee ,
17781815 account,
1816+ frbtcWrapPsbt,
17791817 } )
17801818
17811819 let finalReveal = bitcoin . Psbt . fromBase64 ( finalRevealPsbt , {
0 commit comments