From 11559c03c0f9a2a97503e3dd3f5080314f271682 Mon Sep 17 00:00:00 2001 From: kvhnuke <10602065+kvhnuke@users.noreply.github.com> Date: Fri, 15 Sep 2023 14:10:50 -0700 Subject: [PATCH] devop: set dust values for btc networks --- .../providers/bitcoin/networks/bitcoin-testnet.ts | 1 + .../src/providers/bitcoin/networks/bitcoin.ts | 1 + .../src/providers/bitcoin/networks/dogecoin.ts | 1 + .../src/providers/bitcoin/networks/litecoin.ts | 1 + .../src/providers/bitcoin/types/bitcoin-network.ts | 3 +++ .../providers/bitcoin/ui/send-transaction/index.vue | 13 ++++++++++--- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/extension/src/providers/bitcoin/networks/bitcoin-testnet.ts b/packages/extension/src/providers/bitcoin/networks/bitcoin-testnet.ts index 0a1572a7e..7193f9c83 100644 --- a/packages/extension/src/providers/bitcoin/networks/bitcoin-testnet.ts +++ b/packages/extension/src/providers/bitcoin/networks/bitcoin-testnet.ts @@ -21,6 +21,7 @@ const bitcoinOptions: BitcoinNetworkOptions = { currencyNameLong: "Test Bitcoin", icon: require("./icons/tbtc.svg"), decimals: 8, + dust: 0.00000546, node: "https://api.blockchain.info/haskoin-store/btc-testnet/", activityHandler: wrapActivityHandler(haskoinHandler), basePath: "m/49'/1'/0'/0", diff --git a/packages/extension/src/providers/bitcoin/networks/bitcoin.ts b/packages/extension/src/providers/bitcoin/networks/bitcoin.ts index ae19fe97d..f08a76e91 100644 --- a/packages/extension/src/providers/bitcoin/networks/bitcoin.ts +++ b/packages/extension/src/providers/bitcoin/networks/bitcoin.ts @@ -26,6 +26,7 @@ const bitcoinOptions: BitcoinNetworkOptions = { basePath: "m/49'/0'/0'/0", feeHandler: BTCFeeHandler, apiType: HaskoinAPI, + dust: 0.00000546, networkInfo: { messagePrefix: "\x18Bitcoin Signed Message:\n", bech32: "bc", diff --git a/packages/extension/src/providers/bitcoin/networks/dogecoin.ts b/packages/extension/src/providers/bitcoin/networks/dogecoin.ts index e0552c517..63b06beea 100644 --- a/packages/extension/src/providers/bitcoin/networks/dogecoin.ts +++ b/packages/extension/src/providers/bitcoin/networks/dogecoin.ts @@ -23,6 +23,7 @@ const dogeOptions: BitcoinNetworkOptions = { node: "https://partners.mewapi.io/nodes/ss/doge", coingeckoID: "dogecoin", apiType: SSApi, + dust: 0.01, activityHandler: wrapActivityHandler(ssHandler), basePath: "m/44'/3'/0'/0", feeHandler: () => { diff --git a/packages/extension/src/providers/bitcoin/networks/litecoin.ts b/packages/extension/src/providers/bitcoin/networks/litecoin.ts index 856fe7d77..a565d52e9 100644 --- a/packages/extension/src/providers/bitcoin/networks/litecoin.ts +++ b/packages/extension/src/providers/bitcoin/networks/litecoin.ts @@ -22,6 +22,7 @@ const litecoinOptions: BitcoinNetworkOptions = { decimals: 8, node: "https://partners.mewapi.io/nodes/ss/ltc", coingeckoID: "litecoin", + dust: 0.0001, apiType: SSApi, activityHandler: wrapActivityHandler(ssHandler), basePath: "m/49'/2'/0'/0", diff --git a/packages/extension/src/providers/bitcoin/types/bitcoin-network.ts b/packages/extension/src/providers/bitcoin/types/bitcoin-network.ts index 19f3b78cd..3258c4866 100644 --- a/packages/extension/src/providers/bitcoin/types/bitcoin-network.ts +++ b/packages/extension/src/providers/bitcoin/types/bitcoin-network.ts @@ -41,6 +41,7 @@ export interface BitcoinNetworkOptions { coingeckoID?: string; basePath: string; networkInfo: BitcoinNetworkInfo; + dust: number; feeHandler: () => Promise>; activityHandler: ( network: BaseNetwork, @@ -60,6 +61,7 @@ export const getAddress = (pubkey: string, network: BitcoinNetworkInfo) => { export class BitcoinNetwork extends BaseNetwork { public assets: BaseToken[] = []; public networkInfo: BitcoinNetworkInfo; + public dust: number; private activityHandler: ( network: BaseNetwork, address: string @@ -85,6 +87,7 @@ export class BitcoinNetwork extends BaseNetwork { this.activityHandler = options.activityHandler; this.networkInfo = options.networkInfo; this.feeHandler = options.feeHandler; + this.dust = options.dust; } public async getAllTokens(pubkey: string): Promise { diff --git a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue index c5608d65c..80182b591 100644 --- a/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue +++ b/packages/extension/src/providers/bitcoin/ui/send-transaction/index.vue @@ -167,6 +167,9 @@ const hasEnoughBalance = computed(() => { if (!isValidDecimals(sendAmount.value, selectedAsset.value.decimals!)) { return false; } + if (Number(sendAmount.value) < (props.network as BitcoinNetwork).dust) { + return false; + } return toBN(selectedAsset.value.balance ?? "0").gte( toBN(toBase(sendAmount.value ?? "0", selectedAsset.value.decimals!)).add( toBN( @@ -211,8 +214,10 @@ onMounted(async () => { }); const nativeBalanceAfterTransaction = computed(() => { - if (nativeBalance.value && amount.value !== "") { - const rawAmount = toBN(toBase(amount.value, selectedAsset.value.decimals!)); + if (nativeBalance.value) { + const rawAmount = toBN( + toBase(sendAmount.value, selectedAsset.value.decimals!) + ); return toBN(nativeBalance.value).sub(rawAmount); } return toBN(0); @@ -276,6 +281,8 @@ const isInputsValid = computed(() => { if (!isValidDecimals(sendAmount.value, selectedAsset.value.decimals!)) { return false; } + if (Number(sendAmount.value) < (props.network as BitcoinNetwork).dust) + return false; if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false; return true; }); @@ -382,7 +389,7 @@ const sendAction = async () => { }); }); const balance = toBN(selectedAsset.value.balance!); - const toAmount = toBN(toBase(amount.value, selectedAsset.value.decimals)); + const toAmount = toBN(toBase(sendAmount.value, selectedAsset.value.decimals)); const currentFee = toBN( toBase( gasCostValues.value[selectedFee.value].nativeValue,