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

Commit

Permalink
Merge remote-tracking branch 'ledgerhq/develop' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
hakim-adamik committed May 17, 2022
2 parents 8f980ab + 2298702 commit 5dff783
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 61 deletions.
79 changes: 79 additions & 0 deletions .github/workflows/bot-polkadot-silicium.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Bot 'Polkadot on Silicium'
on:
push:
branches:
- family/polkadot

jobs:
start-runner:
name: "start ec2 instance (Linux)"
if: ${{ always() }}
uses: ledgerhq/actions/.github/workflows/start-linux-runner.yml@main
secrets:
CI_BOT_TOKEN: ${{ secrets.CI_BOT_TOKEN }}

stop-runner:
name: "stop ec2 instance (Linux)"
needs: [start-runner, run-bot]
uses: ledgerhq/actions/.github/workflows/stop-linux-runner.yml@main
if: ${{ always() }}
with:
label: ${{ needs.start-runner.outputs.label }}
ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }}
secrets:
CI_BOT_TOKEN: ${{ secrets.CI_BOT_TOKEN }}

run-bot:
needs: [start-runner]
runs-on: ${{ needs.start-runner.outputs.label }}
steps:
- name: prepare runner
run: |
sudo growpart /dev/nvme0n1 1
sudo resize2fs /dev/nvme0n1p1
- uses: actions/checkout@v2
- name: Retrieving coin apps
uses: actions/checkout@v2
with:
repository: LedgerHQ/coin-apps
token: ${{ secrets.PAT }}
path: coin-apps
- uses: actions/setup-node@master
with:
node-version: 14.x
- name: install yarn
run: npm i -g yarn
- name: pull docker image
run: docker pull ghcr.io/ledgerhq/speculos
- name: kill apt-get
run: sudo killall -w apt-get apt || echo OK
- name: Install linux deps
run: sudo apt-get install -y libusb-1.0-0-dev jq
- name: Install dependencies
run: |
yarn global add yalc
yarn --frozen-lockfile
yarn ci-setup-cli
- name: BOT
env:
SEED: ${{ secrets.SEED3 }}
BOT_REPORT_FOLDER: botreport
VERBOSE_FILE: botreport/logs.txt
GITHUB_SHA: ${GITHUB_SHA}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_RUN_ID: ${{ github.run_id }}
GITHUB_WORKFLOW: ${{ github.workflow }}
SLACK_API_TOKEN: ${{ secrets.SLACK_API_TOKEN }}
SLACK_CHANNEL: ci-dot-ll
BOT_FILTER_FAMILY: polkadot
run: mkdir botreport; COINAPPS=$PWD/coin-apps yarn ci-test-bot
timeout-minutes: 120
- name: Run coverage
if: failure() || success()
run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} npx codecov
- name: upload logs
if: failure() || success()
uses: actions/upload-artifact@v1
with:
name: botreport
path: botreport/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"secp256k1": "^4.0.3",
"semver": "^7.3.5",
"sha.js": "^2.4.11",
"stellar-sdk": "^10.0.1",
"stellar-sdk": "^10.1.0",
"superstruct": "^0.14.2",
"triple-beam": "^1.3.0",
"varuint-bitcoin": "1.1.2",
Expand Down
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
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
65 changes: 41 additions & 24 deletions src/families/polkadot/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ import {
canUnbond,
canNominate,
isFirstBond,
getMinimumAmountToBond,
hasMinimumBondBalance,
} from "../../families/polkadot/logic";
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,11 @@ 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"
);
const { polkadotResources } = account;
invariant(polkadotResources, "polkadot");
invariant(hasMinimumBondBalance(account), "not enough balance to bond");
const options: {
recipient?: string;
rewardDestination?: string;
Expand Down Expand Up @@ -134,14 +130,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 +159,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 +190,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 +214,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
43 changes: 18 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5944,11 +5944,6 @@ [email protected]:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=

ini@^1.3.5:
version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

internal-slot@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz"
Expand Down Expand Up @@ -7420,7 +7415,7 @@ multihashes@^0.4.15, multihashes@~0.4.15:
multibase "^0.7.0"
varint "^5.0.0"

nan@^2.13.2, nan@^2.14.0, nan@^2.2.1:
nan@^2.13.2, nan@^2.2.1:
version "2.15.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee"
integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==
Expand Down Expand Up @@ -7475,7 +7470,7 @@ [email protected]:
dependencies:
whatwg-url "^5.0.0"

node-gyp-build@^4.1.0, node-gyp-build@^4.2.0, node-gyp-build@^4.2.2, node-gyp-build@^4.3.0:
node-gyp-build@^4.2.0, node-gyp-build@^4.2.2, node-gyp-build@^4.3.0:
version "4.3.0"
resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.3.0.tgz"
integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q==
Expand Down Expand Up @@ -8719,14 +8714,12 @@ [email protected]:
map-obj "^4.1.0"
to-snake-case "^1.0.0"

sodium-native@^2.3.0:
version "2.4.9"
resolved "https://registry.yarnpkg.com/sodium-native/-/sodium-native-2.4.9.tgz#7a7beb997efdbd2c773a385fb959f0cead5f5162"
integrity sha512-mbkiyA2clyfwAyOFIzMvsV6ny2KrKEIhFVASJxWfsmgfUEymgLIS2MLHHcGIQMkrcKhPErRaMR5Dzv0EEn+BWg==
sodium-native@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/sodium-native/-/sodium-native-3.3.0.tgz#50ee52ac843315866cce3d0c08ab03eb78f22361"
integrity sha512-rg6lCDM/qa3p07YGqaVD+ciAbUqm6SoO4xmlcfkbU5r1zIGrguXztLiEtaLYTV5U6k8KSIUFmnU3yQUSKmf6DA==
dependencies:
ini "^1.3.5"
nan "^2.14.0"
node-gyp-build "^4.1.0"
node-gyp-build "^4.3.0"

source-map-support@^0.5.17, source-map-support@^0.5.6:
version "0.5.21"
Expand Down Expand Up @@ -8793,25 +8786,25 @@ stack-utils@^2.0.3:
resolved "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz"
integrity sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=

stellar-base@^7.0.0:
version "7.0.0"
resolved "https://registry.npmjs.org/stellar-base/-/stellar-base-7.0.0.tgz"
integrity sha512-Sfk/u/6HT+8xSQ4HvTI3XgthTS3fhv/ie6Jx4OzLvg81pt09bDDN5YvRbG6v3gZdiRA0pwg2RRz5YS3ph5ePEg==
stellar-base@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/stellar-base/-/stellar-base-8.0.0.tgz#619e5fb7951fa8abb26322e51e611169a5d1cf62"
integrity sha512-MH0V94Hn/Ekq/yZxd+EQijkvfU+21zuqJAyEP8X+fhRR0IQYwGNByY003oLqIkgwqXotyofEQ76W5MoNFZmlpw==
dependencies:
base32.js "^0.1.0"
bignumber.js "^4.0.0"
crc "^3.5.0"
js-xdr "^1.1.3"
lodash "^4.17.21"
sha.js "^2.3.6"
tweetnacl "^1.0.0"
tweetnacl "^1.0.3"
optionalDependencies:
sodium-native "^2.3.0"
sodium-native "^3.3.0"

stellar-sdk@^10.0.1:
version "10.0.1"
resolved "https://registry.npmjs.org/stellar-sdk/-/stellar-sdk-10.0.1.tgz"
integrity sha512-NWvDAldw4GVFqWo1wGoR9lCyJ6xIcO2ab4YX8BQYp1Z45/Rogv3Kj3RERsso/9m+MR+d2OfTmAhIy0vruRGv/Q==
stellar-sdk@^10.1.0:
version "10.1.0"
resolved "https://registry.yarnpkg.com/stellar-sdk/-/stellar-sdk-10.1.0.tgz#91cf9ed3c84c9a9d4c8aaa6cca29bd997b7c778a"
integrity sha512-8PTKuyrQ5bIbsyrLav+JE/c+rrLynBygiB4dpvG30ou7K8P6a5ainmGyVMbCzlz1OkKWoaAW5rJAkl3RhlTZkA==
dependencies:
"@types/eventsource" "^1.1.2"
"@types/node" ">= 8"
Expand All @@ -8824,7 +8817,7 @@ stellar-sdk@^10.0.1:
eventsource "^1.0.7"
lodash "^4.17.21"
randombytes "^2.1.0"
stellar-base "^7.0.0"
stellar-base "^8.0.0"
toml "^2.3.0"
tslib "^1.10.0"
urijs "^1.19.1"
Expand Down

1 comment on commit 5dff783

@github-actions
Copy link

Choose a reason for hiding this comment

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

✅ 2 txs ($3.20) for Bot 'Hedera'

Details of the 2 mutations

Spec Hedera (3)

Spec Hedera found 3 Hedera accounts. Will use Hedera 1.0.8 on nanoS 2.1.0
(2715ms) Hedera 1 cross: 0.0000676 HBAR (5ops) (0.0.751515 on 44/3030) hederaBip44#0 js:2:hedera:0.0.751515:hederaBip44
(815ms) Hedera 2: 15.129 HBAR (25ops) (0.0.751518 on 44/3030) hederaBip44#1 js:2:hedera:0.0.751518:hederaBip44
(949ms) Hedera 3: 14.841 HBAR (25ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44
all accounts sync in 3.1s
▬ Hedera 1.0.8 on nanoS 2.1.0
→ FROM Hedera 2: 15.129 HBAR (25ops) (0.0.751518 on 44/3030) hederaBip44#1 js:2:hedera:0.0.751518:hederaBip44 (! sum of ops 0.51660478 HBAR)
max spendable ~15.127
★ using mutation 'Send ~50%'
→ TO Hedera 3: 14.841 HBAR (25ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44
✔️ transaction SEND 7.50217531 HBAR
TO 0.0.751521
STATUS (16ms)
  amount: 7.50217531 HBAR
  estimated fees: 0.000833 HBAR
  total spent: 7.50300831 HBAR
✔️ has been signed! (3.2s) 
✔️ broadcasted! (294ms) optimistic operation: 
  -7.50217531 HBAR   OUT        zDwT81f01_oaVyJ_tpT442HsgHReaAarycn75axVwFA1e2ebu8GCXMtRRY8AnHz0 2022-05-17T09:23
✔️ operation confirmed (11.6s): 
  -7.50312326 HBAR   OUT        zDwT81f01_oaVyJ_tpT442HsgHReaAarycn75axVwFA1e2ebu8GCXMtRRY8AnHz0 2022-05-17T09:23
✔️ Hedera 2: 7.626 HBAR (26ops) (0.0.751518 on 44/3030) hederaBip44#1 js:2:hedera:0.0.751518:hederaBip44 (! sum of ops -6.98651848 HBAR)
(final state reached in 11.6s)

all accounts sync in 1087ms
▬ Hedera 1.0.8 on nanoS 2.1.0
→ FROM Hedera 3: 22.343 HBAR (26ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44 (! sum of ops 6.96499354 HBAR)
max spendable ~22.341
★ using mutation 'Send max'
→ TO Hedera 2: 7.626 HBAR (26ops) (0.0.751518 on 44/3030) hederaBip44#1 js:2:hedera:0.0.751518:hederaBip44
✔️ transaction SEND 22.34155571 HBAR
TO 0.0.751518
STATUS (1.80ms)
  amount: 22.34155571 HBAR
  estimated fees: 0.000833 HBAR
  total spent: 22.34238871 HBAR
✔️ has been signed! (2851ms) 
✔️ broadcasted! (286ms) optimistic operation: 
  -22.34155571 HBAR  OUT        0L610HwoUvwWIne6K5Oo4YJmjtkOnacf_Xgr14UmVTOw2yUU430LxPO4cr5L_1o0 2022-05-17T09:23
✔️ operation confirmed (12.6s): 
  -22.34250366 HBAR  OUT        0L610HwoUvwWIne6K5Oo4YJmjtkOnacf_Xgr14UmVTOw2yUU430LxPO4cr5L_1o0 2022-05-17T09:23
✔️ Hedera 3: 0.000718 HBAR (27ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44 (! sum of ops -15.37751012 HBAR)
(final state reached in 12.6s)


Portfolio ($3.20)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Hedera (2) 59 (+4) 29.97 HBAR (- 0.0018959) ($3.20) 💪 0.0.751515

Please sign in to comment.