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

Commit

Permalink
Update Polkadot bot spec to withdraw staking funds sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
hakim-adamik committed May 13, 2022
1 parent 9b53c31 commit 3e54f4d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/families/polkadot/cli-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const options = [
{
name: "mode",
type: String,
desc: "mode of transaction: send, nominate, bond, claimReward",
desc: "mode of transaction: send, nominate, bond, claimReward, withdrawUnbonded",
},
{
name: "fees",
Expand Down
57 changes: 40 additions & 17 deletions src/families/polkadot/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
import { DeviceModelId } from "@ledgerhq/devices";

const currency = getCryptoCurrencyById("polkadot");
const POLKADOT_MIN_SAFE = parseCurrencyUnit(currency.units[0], "0.05");
// FIXME Should be replaced with EXISTENTIAL_DEPOSIT_RECOMMENDED_MARGIN in logic.ts
const POLKADOT_MIN_SAFE = parseCurrencyUnit(currency.units[0], "0.1");
// FIXME SHould be replaced with EXISTENTIAL_DEPOSIT in logic.ts
const EXISTENTIAL_DEPOSIT = parseCurrencyUnit(currency.units[0], "1.0");
const MIN_LOCKED_BALANCE_REQ = parseCurrencyUnit(currency.units[0], "1.0");
const polkadot: AppSpec<Transaction> = {
Expand Down Expand Up @@ -49,8 +51,9 @@ const polkadot: AppSpec<Transaction> = {
mutations: [
{
name: "send 50%~",
maxRun: 1,
maxRun: 2,
transaction: ({ account, siblings, bridge }) => {
invariant(account.polkadotResources, "polkadot");
const sibling = pickSiblings(siblings, 2);
let amount = account.spendableBalance
.div(1.9 + 0.2 * Math.random())
Expand Down Expand Up @@ -81,18 +84,17 @@ const polkadot: AppSpec<Transaction> = {
},
{
name: "bond - bondExtra",
maxRun: 2,
maxRun: 1,
transaction: ({ account, bridge }) => {
invariant(account.polkadotResources, "polkadot");
invariant(canBond(account), "can't bond");
const { minimumBondBalance } = getCurrentPolkadotPreloadData();
invariant(
new BigNumber(100000).gt(
getMinimumAmountToBond(account, new BigNumber(minimumBondBalance))
),
"can't bond because too much unbond"
"not enough balance to bond"
);
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
const options: {
recipient?: string;
rewardDestination?: string;
Expand Down Expand Up @@ -134,14 +136,14 @@ const polkadot: AppSpec<Transaction> = {
},
{
name: "unbond",
maxRun: 1,
maxRun: 2,
transaction: ({ account, bridge }) => {
invariant(canUnbond(account), "can't unbond");
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
invariant(canUnbond(account), "can't unbond");
invariant(
account.spendableBalance.gt(POLKADOT_MIN_SAFE),
"cant cover fee"
"can't cover fee"
);
const amount = (polkadotResources as PolkadotResources).lockedBalance
.minus((polkadotResources as PolkadotResources).unlockingBalance)
Expand All @@ -163,17 +165,15 @@ const polkadot: AppSpec<Transaction> = {
name: "rebond",
maxRun: 1,
transaction: ({ account, bridge }) => {
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
invariant(
account.polkadotResources?.unlockingBalance.gt(
MIN_LOCKED_BALANCE_REQ
),
polkadotResources?.unlockingBalance.gt(MIN_LOCKED_BALANCE_REQ),
"can't rebond"
);
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
invariant(
account.spendableBalance.gt(POLKADOT_MIN_SAFE),
"cant cover fee"
"can't cover fee"
);
const amount = BigNumber.maximum(
(polkadotResources as PolkadotResources).unlockingBalance.times(0.2),
Expand All @@ -196,9 +196,8 @@ const polkadot: AppSpec<Transaction> = {
name: "nominate",
maxRun: 1,
transaction: ({ account, bridge }) => {
invariant(account.polkadotResources, "polkadot");
invariant(canNominate(account), "can't nominate");
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
invariant(
account.spendableBalance.gt(POLKADOT_MIN_SAFE),
"cant cover fee"
Expand All @@ -221,6 +220,30 @@ const polkadot: AppSpec<Transaction> = {
};
},
},
{
name: "withdraw",
maxRun: 2,
transaction: ({ account, bridge }) => {
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
invariant(
polkadotResources?.unlockedBalance.gt(0),
"nothing to withdraw"
);
invariant(
account.spendableBalance.gt(POLKADOT_MIN_SAFE),
"can't cover fee"
);
return {
transaction: bridge.createTransaction(account),
updates: [
{
mode: "withdrawUnbonded",
},
],
};
},
},
],
};
export default {
Expand Down

1 comment on commit 3e54f4d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

($22.88) for Bot 'Polkadot on Silicium'

⚠️ 6 mutations uncovered

Details of the 0 mutations

Spec Polkadot (3)

Spec Polkadot found 3 Polkadot accounts (preload: 12s). Will use Polkadot 12.9200.0 on nanoS 2.1.0
(19s) Polkadot 1 cross: 1.0619 DOT (164ops) (134PU8cEURfnfm9uH43zfLmSMzYv19qWmwb1vqndfyVbCVsX on 44'/354'/0'/0'/0') polkadotbip44#0 js:2:polkadot:134PU8cEURfnfm9uH43zfLmSMzYv19qWmwb1vqndfyVbCVsX:polkadotbip44
(11.5s) Polkadot 2: 1.0449 DOT (214ops) (1NxpxpMCxP8eV1ctrp8C3wXD7zN5f2WRNKENDa51w8e9hQC on 44'/354'/1'/0'/0') polkadotbip44#1 js:2:polkadot:1NxpxpMCxP8eV1ctrp8C3wXD7zN5f2WRNKENDa51w8e9hQC:polkadotbip44
(15.2s) Polkadot 3: 0 DOT (0ops) (11ysWistr6HA7ZQtAdyTWKTgwBfzTWKsACnxca4QQPGZHsG on 44'/354'/2'/0'/0') polkadotbip44#2 js:2:polkadot:11ysWistr6HA7ZQtAdyTWKTgwBfzTWKsACnxca4QQPGZHsG:polkadotbip44

Details of the 6 uncovered mutations

Spec Polkadot (6)

  • send 50%~: balance is too low (3)
  • bond - bondExtra: balance is too low (3)
  • unbond: balance is too low (3)
  • rebond: balance is too low (3)
  • nominate: balance is too low (3)
  • withdraw: balance is too low (3)

Portfolio ($22.88)

⚠️ 1 specs don't have enough funds! (Polkadot)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Polkadot (1) 378 0.10649 DOT ($22.88) ❌ 134PU8cEURfnfm9uH43zfLmSMzYv19qWmwb1vqndfyVbCVsX

Please sign in to comment.