UNPKG

@ledgerhq/coin-filecoin

Version:
155 lines 6.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const invariant_1 = __importDefault(require("invariant")); const devices_1 = require("@ledgerhq/devices"); const bignumber_js_1 = __importDefault(require("bignumber.js")); const currencies_1 = require("@ledgerhq/cryptoassets/currencies"); const specs_1 = require("@ledgerhq/coin-framework/bot/specs"); const speculos_deviceActions_1 = require("./speculos-deviceActions"); const utils_1 = require("../bridge/utils"); const F4_RECIPIENT = "f410fncojwmrseefktoco6rcnb3zv2eiqfli7muhvqma"; const ETH_RECIPIENT = "0x689c9b3232210aa9b84ef444d0ef35d11102ad1f"; const MIN_SAFE = new bignumber_js_1.default(100000); const maxAccount = 6; const filecoinSpecs = { name: "Filecoin", currency: (0, currencies_1.getCryptoCurrencyById)("filecoin"), appQuery: { model: devices_1.DeviceModelId.nanoSP, appName: "Filecoin", appVersion: "0.24.5", firmware: "1.3.1", }, genericDeviceAction: (0, speculos_deviceActions_1.generateDeviceActionFlow)(utils_1.BotScenario.DEFAULT), testTimeout: 16 * 60 * 1000, minViableAmount: MIN_SAFE, transactionCheck: ({ maxSpendable }) => { (0, invariant_1.default)(maxSpendable.gt(MIN_SAFE), "balance is too low"); }, mutations: [ { name: "Send small to f4 address", feature: "send", maxRun: 1, deviceAction: (0, speculos_deviceActions_1.generateDeviceActionFlow)(utils_1.BotScenario.F4_RECIPIENT), testDestination: specs_1.genericTestDestination, transaction: ({ account, bridge }) => { const amount = new bignumber_js_1.default("100"); return { transaction: bridge.createTransaction(account), updates: [ { recipient: F4_RECIPIENT, }, { amount, }, ], }; }, }, { name: "Send small to eth address", feature: "send", maxRun: 1, deviceAction: (0, speculos_deviceActions_1.generateDeviceActionFlow)(utils_1.BotScenario.ETH_RECIPIENT), testDestination: specs_1.genericTestDestination, transaction: ({ account, bridge }) => { const amount = new bignumber_js_1.default("100"); return { transaction: bridge.createTransaction(account), updates: [ { recipient: ETH_RECIPIENT, }, { amount, }, ], }; }, }, { name: "Send 50%~", feature: "send", maxRun: 1, testDestination: specs_1.genericTestDestination, transaction: ({ account, siblings, bridge }) => { const sibling = (0, specs_1.pickSiblings)(siblings, maxAccount); let amount = account.spendableBalance.div(1.9 + 0.2 * Math.random()).integerValue(); if (!sibling.used && amount.lt(MIN_SAFE)) { (0, invariant_1.default)(account.spendableBalance.gt(MIN_SAFE), "send is too low to activate account"); amount = MIN_SAFE; } return { transaction: bridge.createTransaction(account), updates: [ { recipient: sibling.freshAddress, }, { amount, }, ], }; }, }, { name: "Transfer Max", feature: "sendMax", maxRun: 1, transaction: ({ account, siblings, bridge }) => { return { transaction: bridge.createTransaction(account), updates: [ { recipient: (0, specs_1.pickSiblings)(siblings, maxAccount).freshAddress, }, { useAllAmount: true, }, ], }; }, }, { name: "Send ~50% WFIL", feature: "tokens", maxRun: 1, deviceAction: (0, speculos_deviceActions_1.generateDeviceActionFlow)(utils_1.BotScenario.TOKEN_TRANSFER), transaction: ({ account, bridge, maxSpendable }) => { (0, invariant_1.default)(maxSpendable.gt(0), "Spendable balance is too low"); const subAccount = account.subAccounts?.find(a => a.type === utils_1.AccountType.TokenAccount && a.spendableBalance.gt(0)); (0, invariant_1.default)(subAccount && subAccount.type === utils_1.AccountType.TokenAccount, "no subAccount with WFIL"); const amount = subAccount.balance.div(1.9 + 0.2 * Math.random()).integerValue(); return { transaction: bridge.createTransaction(account), updates: [ { subAccountId: subAccount.id, }, { recipient: F4_RECIPIENT, }, { amount, }, ], }; }, test: ({ account, accountBeforeTransaction, transaction, status }) => { const subAccountId = transaction.subAccountId; const subAccount = account.subAccounts?.find(sa => sa.id === subAccountId); const subAccountBeforeTransaction = accountBeforeTransaction.subAccounts?.find(sa => sa.id === subAccountId); (0, specs_1.botTest)("subAccount balance moved with the tx status amount", () => expect(subAccount?.balance.toString()).toBe(subAccountBeforeTransaction?.balance.minus(status.amount).toString())); }, }, ], }; exports.default = { filecoinSpecs, }; //# sourceMappingURL=bot-specs.js.map