Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit d66e05a

Browse files
feat: filter out utxos less or equal to 10k sats (#27)
2 parents c974e8a + 17ff815 commit d66e05a

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simple-staking",
3-
"version": "0.2.24",
3+
"version": "0.2.25",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/utils/utxo/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { postVerifyUtxoOrdinals, UtxoInfo } from "@/app/api/postFilterOrdinals";
22

33
import { InscriptionIdentifier, UTXO } from "../wallet/wallet_provider";
44

5+
const LOW_VALUE_UTXO_THRESHOLD = 10000;
6+
57
/**
68
* Filters out UTXOs that contain ordinals.
79
* This method first attempts to get inscriptions from the wallet.
@@ -22,6 +24,9 @@ export const filterOrdinals = async (
2224
if (!utxos.length) {
2325
return [];
2426
}
27+
// Filter UTXOs that has value less than 10k sats
28+
utxos = filterLowValueUtxos(utxos);
29+
2530
// fallback to Babylon API if the wallet does not support getting inscriptions
2631
if (!getInscriptionsFromWalletCb) {
2732
return filterFromApi(utxos, address);
@@ -70,3 +75,14 @@ const filterFromApi = async (
7075
// helper function to get the identifier of a UTXO
7176
const getUTXOIdentifier = (utxo: { txid: string; vout: number }) =>
7277
`${utxo.txid}:${utxo.vout}`;
78+
79+
/*
80+
Filter out UTXOs that have value less than 10k sats
81+
Reasons as below:
82+
1. Most of the original UTXOs are less than 10k sats
83+
2. 10k sats or less has less economic value which will add more cost to the
84+
transaction due to fees
85+
*/
86+
const filterLowValueUtxos = (utxos: UTXO[]): UTXO[] => {
87+
return utxos.filter((utxo) => utxo.value > LOW_VALUE_UTXO_THRESHOLD);
88+
};

tests/utils/utox/utxo.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jest.mock("@/app/api/postFilterOrdinals");
77

88
describe("filterOrdinals", () => {
99
const mockUtxos: UTXO[] = [
10-
{ txid: "txid1", vout: 0, value: 1000, scriptPubKey: "scriptPubKey1" },
11-
{ txid: "txid2", vout: 1, value: 2000, scriptPubKey: "scriptPubKey2" },
12-
{ txid: "txid3", vout: 2, value: 3000, scriptPubKey: "scriptPub" },
10+
{ txid: "txid1", vout: 0, value: 100000, scriptPubKey: "scriptPubKey1" },
11+
{ txid: "txid2", vout: 1, value: 200000, scriptPubKey: "scriptPubKey2" },
12+
{ txid: "txid3", vout: 2, value: 300000, scriptPubKey: "scriptPub" },
1313
];
1414
const address = "testAddress";
1515

@@ -22,6 +22,24 @@ describe("filterOrdinals", () => {
2222
expect(result).toEqual([]);
2323
});
2424

25+
it("should filter out UTXOs have less than 10k sats", async () => {
26+
const getInscriptionsFromWalletCb = jest.fn().mockResolvedValue([]);
27+
28+
const mockedUTXOsWithLowValue = [
29+
{ txid: "txid1", vout: 0, value: 10000, scriptPubKey: "scriptPubKey1" },
30+
{ txid: "txid2", vout: 1, value: 9999, scriptPubKey: "scriptPubKey2" },
31+
{ txid: "txid3", vout: 2, value: 10001, scriptPubKey: "scriptPub" },
32+
];
33+
34+
const result = await filterOrdinals(
35+
mockedUTXOsWithLowValue,
36+
address,
37+
getInscriptionsFromWalletCb,
38+
);
39+
40+
expect(result).toEqual([mockedUTXOsWithLowValue[2]]);
41+
});
42+
2543
it("should filter out UTXOs that contain ordinals from the wallet", async () => {
2644
const mockInscriptions: InscriptionIdentifier[] = [
2745
{

0 commit comments

Comments
 (0)