From b4d92877672cb54c15d7284a0d6a74b52bc5168b Mon Sep 17 00:00:00 2001 From: Alouit Alexandre Date: Thu, 12 May 2022 09:10:10 +0200 Subject: [PATCH 1/4] Fix transaction mode mapping Send max must be balances.transfer palletMethod instead of balances.transferKeepAlive --- src/families/polkadot/js-signOperation.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/families/polkadot/js-signOperation.ts b/src/families/polkadot/js-signOperation.ts index 565d321614..861bf77124 100644 --- a/src/families/polkadot/js-signOperation.ts +++ b/src/families/polkadot/js-signOperation.ts @@ -29,6 +29,7 @@ const MODE_TO_TYPE = { }; const MODE_TO_PALLET_METHOD = { send: "balances.transferKeepAlive", + sendMax: "balances.transfer", bond: "staking.bond", bondExtra: "staking.bondExtra", unbond: "staking.unbond", @@ -52,6 +53,10 @@ const getExtra = (type: string, account: Account, transaction: Transaction) => { } : {}; + if (transaction.mode == "send" && transaction.useAllAmount) { + extra.palletMethod = MODE_TO_PALLET_METHOD["sendMax"]; + } + switch (type) { case "OUT": return { ...extra, transferAmount: new BigNumber(transaction.amount) }; From 2685c6c55844d877bac5699cc5f309bbf2543490 Mon Sep 17 00:00:00 2001 From: Alouit Alexandre Date: Thu, 12 May 2022 09:13:24 +0200 Subject: [PATCH 2/4] Fix 1 DOT Polkadot limitation On the Polkadot network, an address is only active when it holds a minimum amount, currently set at 1 DOT. There's a limitation when you hold ~ 1 DOT. Use recommended 1.1 DOT value. --- src/families/polkadot/js-getTransactionStatus.ts | 4 +++- src/families/polkadot/logic.ts | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/families/polkadot/js-getTransactionStatus.ts b/src/families/polkadot/js-getTransactionStatus.ts index a2feed207d..f1147bed9d 100644 --- a/src/families/polkadot/js-getTransactionStatus.ts +++ b/src/families/polkadot/js-getTransactionStatus.ts @@ -77,7 +77,9 @@ const getSendTransactionStatus = async ( const minimumBalanceExistential = getMinimumBalance(a); const leftover = a.spendableBalance.minus(totalSpent); - if ( + if (a.spendableBalance.lte(EXISTENTIAL_DEPOSIT)) { + errors.amount = new NotEnoughBalance(); + } else if ( minimumBalanceExistential.gt(0) && leftover.lt(minimumBalanceExistential) && leftover.gt(0) diff --git a/src/families/polkadot/logic.ts b/src/families/polkadot/logic.ts index a701e685d6..4d225f8d91 100644 --- a/src/families/polkadot/logic.ts +++ b/src/families/polkadot/logic.ts @@ -3,7 +3,7 @@ import type { Account, OperationType } from "../../types"; import type { Transaction } from "./types"; import { getCurrentPolkadotPreloadData } from "./preload"; -export const EXISTENTIAL_DEPOSIT = new BigNumber(10000000000); +export const EXISTENTIAL_DEPOSIT = new BigNumber(11000000000); export const MAX_NOMINATIONS = 16; export const MAX_UNLOCKINGS = 32; export const PRELOAD_MAX_AGE = 60 * 1000; From e8aea66666c24a6d3814256dd2d3b81b384fb60b Mon Sep 17 00:00:00 2001 From: Alouit Alexandre Date: Thu, 12 May 2022 11:31:08 +0200 Subject: [PATCH 3/4] Improve code readability Don't use ternary operator --- src/families/polkadot/js-signOperation.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/families/polkadot/js-signOperation.ts b/src/families/polkadot/js-signOperation.ts index 861bf77124..c0f204aa08 100644 --- a/src/families/polkadot/js-signOperation.ts +++ b/src/families/polkadot/js-signOperation.ts @@ -42,19 +42,14 @@ const MODE_TO_PALLET_METHOD = { }; const getExtra = (type: string, account: Account, transaction: Transaction) => { - const extra = MODE_TO_PALLET_METHOD[transaction.mode] - ? { - palletMethod: - MODE_TO_PALLET_METHOD[ - transaction.mode === "bond" && !isFirstBond(account) - ? "bondExtra" - : transaction.mode - ], - } - : {}; + const extra = { + palletMethod: MODE_TO_PALLET_METHOD[transaction.mode], + }; if (transaction.mode == "send" && transaction.useAllAmount) { extra.palletMethod = MODE_TO_PALLET_METHOD["sendMax"]; + } else if (transaction.mode === "bond" && !isFirstBond(account)) { + extra.palletMethod = MODE_TO_PALLET_METHOD["bondExtra"]; } switch (type) { From 437622f3ba3c904ae26c42940414c5286f02d763 Mon Sep 17 00:00:00 2001 From: Alouit Alexandre Date: Thu, 12 May 2022 11:33:59 +0200 Subject: [PATCH 4/4] Split Existential Deposit and margin Restore EXISTENTIAL_DEPOSIT, use new constant EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN to handle recommended margin --- src/families/polkadot/js-getTransactionStatus.ts | 7 ++++++- src/families/polkadot/logic.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/families/polkadot/js-getTransactionStatus.ts b/src/families/polkadot/js-getTransactionStatus.ts index f1147bed9d..2ed1a9db4f 100644 --- a/src/families/polkadot/js-getTransactionStatus.ts +++ b/src/families/polkadot/js-getTransactionStatus.ts @@ -36,6 +36,7 @@ import { calculateAmount, getMinimumAmountToBond, getMinimumBalance, + EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN, } from "./logic"; import { isValidAddress } from "./address"; import { getCurrentPolkadotPreloadData } from "./preload"; @@ -77,7 +78,11 @@ const getSendTransactionStatus = async ( const minimumBalanceExistential = getMinimumBalance(a); const leftover = a.spendableBalance.minus(totalSpent); - if (a.spendableBalance.lte(EXISTENTIAL_DEPOSIT)) { + if ( + a.spendableBalance.lte( + EXISTENTIAL_DEPOSIT.plus(EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN) + ) + ) { errors.amount = new NotEnoughBalance(); } else if ( minimumBalanceExistential.gt(0) && diff --git a/src/families/polkadot/logic.ts b/src/families/polkadot/logic.ts index 4d225f8d91..daaa26383a 100644 --- a/src/families/polkadot/logic.ts +++ b/src/families/polkadot/logic.ts @@ -3,7 +3,8 @@ import type { Account, OperationType } from "../../types"; import type { Transaction } from "./types"; import { getCurrentPolkadotPreloadData } from "./preload"; -export const EXISTENTIAL_DEPOSIT = new BigNumber(11000000000); +export const EXISTENTIAL_DEPOSIT = new BigNumber(10000000000); +export const EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN = new BigNumber(1000000000); // Polkadot recommended Existential Deposit error margin export const MAX_NOMINATIONS = 16; export const MAX_UNLOCKINGS = 32; export const PRELOAD_MAX_AGE = 60 * 1000;