@ledgerhq/coin-hedera
Version:
Ledger Hedera Coin integration
106 lines • 5.05 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const currencies_1 = require("@ledgerhq/coin-module-framework/currencies");
const cryptoassets_1 = require("@ledgerhq/cryptoassets");
const devices_1 = require("@ledgerhq/devices");
const account_1 = require("@ledgerhq/ledger-wallet-framework/account");
const specs_1 = require("@ledgerhq/ledger-wallet-framework/bot/specs");
const expect_1 = __importDefault(require("expect"));
const invariant_1 = __importDefault(require("invariant"));
const speculos_deviceActions_1 = require("./speculos-deviceActions");
const currency = (0, cryptoassets_1.getCryptoCurrencyById)("hedera");
const memoTestMessage = "This is a test memo.";
// Ensure that, when the recipient corresponds to an empty account,
// the amount to send is greater or equal to the required minimum
// balance for such a recipient
const checkSendableToEmptyAccount = (amount, recipient) => {
const minBalanceNewAccount = (0, currencies_1.parseCurrencyUnit)(currency.units[0], "0.1");
if ((0, account_1.isAccountEmpty)(recipient) && amount.lte(minBalanceNewAccount)) {
(0, invariant_1.default)(amount.gt(minBalanceNewAccount), "not enough funds to send to new account");
}
};
// NOTE: because we can't create Hedera accounts in Ledger Live,
// the bot will only use the 3 existing accounts that have been setup
const hedera = {
name: "Hedera",
appQuery: {
model: devices_1.DeviceModelId.nanoS,
appName: "Hedera",
// FIXME app v1.1.0 has a known issue, this should be removed when a stable version is released
firmware: "2.1.0",
appVersion: "1.0.8",
},
genericDeviceAction: speculos_deviceActions_1.acceptTransaction,
currency,
transactionCheck: ({ maxSpendable }) => {
(0, invariant_1.default)(maxSpendable.gt(0), "Balance is too low");
},
allowEmptyAccounts: true,
mutations: [
{
name: "Send ~50%",
feature: "send",
maxRun: 1,
testDestination: specs_1.genericTestDestination,
transaction: ({ account, siblings, bridge, }) => {
const sibling = (0, specs_1.pickSiblings)(siblings, 4);
const recipient = sibling.freshAddress;
const transaction = bridge.createTransaction(account);
const amount = account.balance.div(1.9 + 0.2 * Math.random()).integerValue();
checkSendableToEmptyAccount(amount, sibling);
return {
transaction,
updates: [{ amount }, { recipient }],
};
},
test: ({ account, accountBeforeTransaction, operation, }) => {
(0, specs_1.botTest)("account balance moved with operation value", () => (0, expect_1.default)(account.balance.toString()).toBe(accountBeforeTransaction.balance.minus(operation.value).toString()));
},
},
{
name: "Send max",
feature: "sendMax",
maxRun: 1,
testDestination: specs_1.genericTestDestination,
transaction: ({ account, siblings, bridge, }) => {
const sibling = (0, specs_1.pickSiblings)(siblings, 4);
const recipient = sibling.freshAddress;
const transaction = bridge.createTransaction(account);
return {
transaction,
updates: [{ recipient }, { useAllAmount: true }],
};
},
test: ({ account, accountBeforeTransaction, operation }) => {
(0, specs_1.botTest)("Account balance should have decreased", () => {
(0, expect_1.default)(account.balance.toNumber()).toEqual(accountBeforeTransaction.balance.minus(operation.value).toNumber());
});
},
},
{
name: "Memo",
feature: "send",
maxRun: 1,
transaction: ({ account, siblings, bridge, }) => {
const sibling = (0, specs_1.pickSiblings)(siblings, 4);
const recipient = sibling.freshAddress;
const transaction = bridge.createTransaction(account);
const amount = account.balance.div(1.9 + 0.2 * Math.random()).integerValue();
checkSendableToEmptyAccount(amount, sibling);
return {
transaction,
updates: [{ recipient }, { amount }, { memo: memoTestMessage }],
};
},
test: ({ transaction }) => {
(0, specs_1.botTest)("transaction.memo is set", () => (0, expect_1.default)(transaction.memo).toBe(memoTestMessage));
},
testDestination: specs_1.genericTestDestination,
},
],
};
exports.default = { hedera };
//# sourceMappingURL=bot-specs.js.map