From d09d428005134314730801219877b51fce7586b8 Mon Sep 17 00:00:00 2001 From: HFazelinia Date: Mon, 30 Sep 2024 18:38:14 +0330 Subject: [PATCH 1/2] change minimum satoshi in BitcoinChain --- .changeset/quiet-snakes-crash.md | 5 +++++ packages/chains/bitcoin/lib/BitcoinChain.ts | 10 ++++++---- packages/chains/bitcoin/tests/BitcoinChain.spec.ts | 5 ++--- 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/quiet-snakes-crash.md diff --git a/.changeset/quiet-snakes-crash.md b/.changeset/quiet-snakes-crash.md new file mode 100644 index 00000000..cb1d390c --- /dev/null +++ b/.changeset/quiet-snakes-crash.md @@ -0,0 +1,5 @@ +--- +'@rosen-chains/bitcoin': minor +--- + +set minimum satoshi to 546 diff --git a/packages/chains/bitcoin/lib/BitcoinChain.ts b/packages/chains/bitcoin/lib/BitcoinChain.ts index ed4fd31b..53373e76 100644 --- a/packages/chains/bitcoin/lib/BitcoinChain.ts +++ b/packages/chains/bitcoin/lib/BitcoinChain.ts @@ -492,8 +492,7 @@ class BitcoinChain extends AbstractUtxoChain { * @returns the minimum amount */ getMinimumNativeToken = (): bigint => { - // there is no token in bitcoin - return 0n; + return 546n; // smallest non-dust value }; /** @@ -646,8 +645,11 @@ class BitcoinChain extends AbstractUtxoChain { */ minimumMeaningfulSatoshi = (feeRatio: number): bigint => { return BigInt( - Math.ceil( - (feeRatio * SEGWIT_INPUT_WEIGHT_UNIT) / 4 // estimate fee per weight and convert to virtual size + Math.max( + Math.ceil( + (feeRatio * SEGWIT_INPUT_WEIGHT_UNIT) / 4 // estimate fee per weight and convert to virtual size + ), + Number(this.getMinimumNativeToken()) ) ); }; diff --git a/packages/chains/bitcoin/tests/BitcoinChain.spec.ts b/packages/chains/bitcoin/tests/BitcoinChain.spec.ts index 3a956fe3..4028c58b 100644 --- a/packages/chains/bitcoin/tests/BitcoinChain.spec.ts +++ b/packages/chains/bitcoin/tests/BitcoinChain.spec.ts @@ -87,9 +87,8 @@ describe('BitcoinChain', () => { const expectedRequiredAssets = structuredClone( testData.transaction2Order[0].assets ); - expectedRequiredAssets.nativeToken += BigInt( - Math.ceil(SEGWIT_INPUT_WEIGHT_UNIT / 4) - ); + expectedRequiredAssets.nativeToken += + bitcoinChain.getMinimumNativeToken(); expect(getCovBoxesSpy).toHaveBeenCalledWith( testUtils.configs.addresses.lock, expectedRequiredAssets, From e469affdfa2f9b8f9da8925c628e9e1c3e86c973 Mon Sep 17 00:00:00 2001 From: HFazelinia Date: Mon, 30 Sep 2024 18:42:25 +0330 Subject: [PATCH 2/2] remove legacy and script address payment restrictions in BitcoinChain --- .changeset/gold-fans-breathe.md | 5 +++++ packages/chains/bitcoin/lib/BitcoinChain.ts | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/gold-fans-breathe.md diff --git a/.changeset/gold-fans-breathe.md b/.changeset/gold-fans-breathe.md new file mode 100644 index 00000000..fb463e35 --- /dev/null +++ b/.changeset/gold-fans-breathe.md @@ -0,0 +1,5 @@ +--- +'@rosen-chains/bitcoin': minor +--- + +remove legacy and script address payment restrictions in BitcoinChain diff --git a/packages/chains/bitcoin/lib/BitcoinChain.ts b/packages/chains/bitcoin/lib/BitcoinChain.ts index 53373e76..0638b204 100644 --- a/packages/chains/bitcoin/lib/BitcoinChain.ts +++ b/packages/chains/bitcoin/lib/BitcoinChain.ts @@ -167,8 +167,14 @@ class BitcoinChain extends AbstractUtxoChain { if (order.assets.tokens.length) { throw Error('Bitcoin does not support tokens in payment order'); } - if (order.address.slice(0, 4) !== 'bc1q') { - throw Error('Bitcoin does not support payment to non-segwit addresses'); + if ( + order.address.slice(0, 4) !== 'bc1q' && + order.address[0] !== '1' && + order.address[0] !== '3' + ) { + throw Error( + 'Bitcoin supports payments only to native-segwit, legacy or script addresses' + ); } const orderBtc = this.unwrapBtc(order.assets.nativeToken).amount;