Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
LIVE-1292 Cover Polkadot existential deposit edge case (#1953)
Browse files Browse the repository at this point in the history
* Fix transaction mode mapping

Send max must be balances.transfer palletMethod instead of balances.transferKeepAlive

* 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.

* Improve code readability

Don't use ternary operator

* Split Existential Deposit and margin

Restore EXISTENTIAL_DEPOSIT, use new constant EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN to handle recommended margin
  • Loading branch information
alexalouit authored May 12, 2022
1 parent 800ee7e commit 01e160a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/families/polkadot/js-getTransactionStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
calculateAmount,
getMinimumAmountToBond,
getMinimumBalance,
EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN,
} from "./logic";
import { isValidAddress } from "./address";
import { getCurrentPolkadotPreloadData } from "./preload";
Expand Down Expand Up @@ -78,6 +79,12 @@ const getSendTransactionStatus = async (
const leftover = a.spendableBalance.minus(totalSpent);

if (
a.spendableBalance.lte(
EXISTENTIAL_DEPOSIT.plus(EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN)
)
) {
errors.amount = new NotEnoughBalance();
} else if (
minimumBalanceExistential.gt(0) &&
leftover.lt(minimumBalanceExistential) &&
leftover.gt(0)
Expand Down
20 changes: 10 additions & 10 deletions src/families/polkadot/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -41,16 +42,15 @@ 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) {
case "OUT":
Expand Down
1 change: 1 addition & 0 deletions src/families/polkadot/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Transaction } from "./types";
import { getCurrentPolkadotPreloadData } from "./preload";

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;
Expand Down

0 comments on commit 01e160a

Please sign in to comment.