Skip to content

Commit cf709de

Browse files
committed
fix: use utxos that were imported
1 parent ea9f31e commit cf709de

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/vms/pvm/etna-builder/builder.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ describe('./src/vms/pvm/etna-builder/builder.test.ts', () => {
312312
// Ensure that the unsigned tx utxos are the filtered utxos,
313313
// and not the inputUtxos registered in the spend helper.
314314
// This is only relevant for the ImportTx.
315-
expect(unsignedTx.utxos).toHaveLength(2);
315+
expect(unsignedTx.utxos).toHaveLength(1);
316+
expect(unsignedTx.utxos).not.toContain(utxos[0]);
316317
expect(unsignedTx.utxos).not.toContain(utxos[1]);
317318
});
318319

src/vms/pvm/etna-builder/builder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,10 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
309309
utxo.assetId.toString() === context.avaxAssetID,
310310
);
311311

312-
const { importedInputs, importedAmounts } = filteredUtxos.reduce<{
312+
const { importedInputs, importedAmounts, inputUtxos } = filteredUtxos.reduce<{
313313
importedInputs: TransferableInput[];
314314
importedAmounts: Record<string, bigint>;
315+
inputUtxos: Utxo[];
315316
}>(
316317
(acc, utxo) => {
317318
const { sigIndicies: inputSigIndices } =
@@ -342,9 +343,10 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
342343
[assetId]:
343344
(acc.importedAmounts[assetId] ?? 0n) + utxo.output.amount(),
344345
},
346+
inputUtxos: [...acc.inputUtxos, utxo],
345347
};
346348
},
347-
{ importedInputs: [], importedAmounts: {} },
349+
{ importedInputs: [], importedAmounts: {}, inputUtxos: [] },
348350
);
349351

350352
if (importedInputs.length === 0) {
@@ -397,6 +399,9 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
397399
context,
398400
);
399401

402+
// Note: We don't use the `inputUTXOs` from `spendResults`
403+
// for the `UnsignedTx` because we want to use the original
404+
// UTXOs that were imported.
400405
const { changeOutputs, inputs } = spendResults;
401406

402407
return new UnsignedTx(
@@ -411,7 +416,7 @@ export const newImportTx: TxBuilderFn<NewImportTxProps> = (
411416
Id.fromString(sourceChainId),
412417
importedInputs.sort(TransferableInput.compare),
413418
),
414-
filteredUtxos,
419+
inputUtxos,
415420
addressMaps,
416421
);
417422
};

0 commit comments

Comments
 (0)