UNPKG

@ledgerhq/coin-tezos

Version:
160 lines • 7.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const sample_1 = __importDefault(require("lodash/sample")); const invariant_1 = __importDefault(require("invariant")); const index_1 = require("@ledgerhq/cryptoassets/index"); const index_2 = require("@ledgerhq/coin-framework/currencies/index"); const specs_1 = require("@ledgerhq/coin-framework/bot/specs"); const devices_1 = require("@ledgerhq/devices"); const types_1 = require("../types"); const bakers_1 = require("../network/bakers"); const bakers_whitelist_default_1 = __importDefault(require("../network/bakers.whitelist-default")); const bot_deviceActions_1 = require("./bot-deviceActions"); const maxAccount = 12; function expectUnrevealed(account) { if (!(0, types_1.isTezosAccount)(account)) throw Error("Not TezosAccount type"); (0, invariant_1.default)(account.tezosResources?.revealed === false, "account must be unreleaved"); } function expectRevealed(account) { if (!(0, types_1.isTezosAccount)(account)) throw Error("Not TezosAccount type"); (0, invariant_1.default)(account.tezosResources?.revealed === true, "account must be releaved"); } const tezosUnit = (0, index_1.getCryptoCurrencyById)("tezos").units[0]; const safeMinimumForDestinationNotCreated = (0, index_2.parseCurrencyUnit)(tezosUnit, "0.6"); const strictMin = (0, index_2.parseCurrencyUnit)(tezosUnit, "0.02"); const tezos = { name: "Tezos", currency: (0, index_1.getCryptoCurrencyById)("tezos"), appQuery: { model: devices_1.DeviceModelId.nanoS, appName: "TezosWallet", appVersion: "3.0.6", }, genericDeviceAction: bot_deviceActions_1.acceptTransaction, testTimeout: 2 * 60 * 1000, minViableAmount: strictMin, transactionCheck: ({ maxSpendable }) => { (0, invariant_1.default)(maxSpendable.gt(strictMin), "balance is too low"); }, mutations: [ { name: "send unrevealed", feature: "send", maxRun: 1, testDestination: specs_1.genericTestDestination, transaction: ({ maxSpendable, account, siblings, bridge }) => { expectUnrevealed(account); const sibling = (0, specs_1.pickSiblings)(siblings, maxAccount); const recipient = sibling.freshAddress; const amount = maxSpendable.div(2).integerValue(); if (sibling.balance.eq(0) && amount.lt(safeMinimumForDestinationNotCreated)) { throw new Error("need more funds to send to new address"); } return { transaction: bridge.createTransaction(account), updates: [{ recipient, amount }], }; }, }, { name: "send revealed", feature: "send", maxRun: 1, testDestination: specs_1.genericTestDestination, transaction: ({ maxSpendable, account, siblings, bridge }) => { expectRevealed(account); const sibling = (0, specs_1.pickSiblings)(siblings, maxAccount); const recipient = sibling.freshAddress; const amount = maxSpendable.div(2).integerValue(); if (sibling.balance.eq(0) && amount.lt(safeMinimumForDestinationNotCreated)) { throw new Error("need more funds to send to new address"); } return { transaction: bridge.createTransaction(account), updates: [{ recipient, amount }], }; }, }, { name: "send max (non delegating)", feature: "sendMax", maxRun: 1, testDestination: specs_1.genericTestDestination, transaction: ({ account, siblings, bridge, maxSpendable }) => { (0, invariant_1.default)(!(0, bakers_1.isAccountDelegating)(account), "account must not be delegating"); const sibling = (0, specs_1.pickSiblings)(siblings, maxAccount); const recipient = sibling.freshAddress; if (sibling.balance.eq(0) && maxSpendable.lt(safeMinimumForDestinationNotCreated)) { throw new Error("need more funds to send to new address"); } return { transaction: bridge.createTransaction(account), updates: [{ recipient, useAllAmount: true }], }; }, }, { name: "delegate unrevealed", feature: "staking", maxRun: 1, transaction: ({ account, bridge }) => { expectUnrevealed(account); const d = (0, bakers_1.getAccountDelegationSync)(account); const recipient = (0, sample_1.default)(d ? bakers_whitelist_default_1.default.filter(w => w !== d.address) : bakers_whitelist_default_1.default); return { transaction: bridge.createTransaction(account), updates: [{ recipient, mode: "delegate" }], }; }, }, { name: "delegate revealed", feature: "staking", maxRun: 1, transaction: ({ account, bridge }) => { expectRevealed(account); const d = (0, bakers_1.getAccountDelegationSync)(account); const recipient = (0, sample_1.default)(d ? bakers_whitelist_default_1.default.filter(w => w !== d.address) : bakers_whitelist_default_1.default); return { transaction: bridge.createTransaction(account), updates: [{ recipient, mode: "delegate" }], }; }, }, { name: "undelegate unrevealed", feature: "staking", maxRun: 1, transaction: ({ account, bridge }) => { (0, invariant_1.default)((0, bakers_1.getAccountDelegationSync)(account), "account must be delegating"); expectUnrevealed(account); return { transaction: bridge.createTransaction(account), updates: [{ mode: "undelegate" }], }; }, }, { name: "undelegate revealed", feature: "staking", maxRun: 1, transaction: ({ account, bridge }) => { (0, invariant_1.default)((0, bakers_1.getAccountDelegationSync)(account), "account must be delegating"); expectRevealed(account); return { transaction: bridge.createTransaction(account), updates: [{ mode: "undelegate" }], }; }, }, ], }; exports.default = { tezos, }; //# sourceMappingURL=bot-specs.js.map