@ledgerhq/coin-solana 0.25.1 → 0.26.0-nightly.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/lib/__tests__/fixtures/helpers.fixture.d.ts +5 -1
- package/lib/__tests__/fixtures/helpers.fixture.d.ts.map +1 -1
- package/lib/__tests__/fixtures/helpers.fixture.js +6 -5
- package/lib/__tests__/fixtures/helpers.fixture.js.map +1 -1
- package/lib/buildTransaction.test.js +1 -1
- package/lib/buildTransaction.test.js.map +1 -1
- package/lib/prepareTransaction.d.ts.map +1 -1
- package/lib/prepareTransaction.js +11 -1
- package/lib/prepareTransaction.js.map +1 -1
- package/lib/prepareTransaction.test.js +31 -1
- package/lib/prepareTransaction.test.js.map +1 -1
- package/lib/signOperation.d.ts.map +1 -1
- package/lib/signOperation.js +2 -0
- package/lib/signOperation.js.map +1 -1
- package/lib/signer.d.ts +1 -0
- package/lib/signer.d.ts.map +1 -1
- package/lib/signer.js.map +1 -1
- package/lib/tx-fees.js +1 -0
- package/lib/tx-fees.js.map +1 -1
- package/lib/types.d.ts +1 -0
- package/lib/types.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.d.ts +5 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.js +6 -5
- package/lib-es/__tests__/fixtures/helpers.fixture.js.map +1 -1
- package/lib-es/buildTransaction.test.js +1 -1
- package/lib-es/buildTransaction.test.js.map +1 -1
- package/lib-es/prepareTransaction.d.ts.map +1 -1
- package/lib-es/prepareTransaction.js +13 -3
- package/lib-es/prepareTransaction.js.map +1 -1
- package/lib-es/prepareTransaction.test.js +31 -1
- package/lib-es/prepareTransaction.test.js.map +1 -1
- package/lib-es/signOperation.d.ts.map +1 -1
- package/lib-es/signOperation.js +2 -0
- package/lib-es/signOperation.js.map +1 -1
- package/lib-es/signer.d.ts +1 -0
- package/lib-es/signer.d.ts.map +1 -1
- package/lib-es/signer.js.map +1 -1
- package/lib-es/tx-fees.js +1 -0
- package/lib-es/tx-fees.js.map +1 -1
- package/lib-es/types.d.ts +1 -0
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/fixtures/helpers.fixture.ts +11 -6
- package/src/buildTransaction.test.ts +1 -1
- package/src/prepareTransaction.test.ts +39 -1
- package/src/prepareTransaction.ts +13 -2
- package/src/signOperation.ts +2 -0
- package/src/signer.ts +1 -0
- package/src/tx-fees.ts +1 -0
- package/src/types.ts +1 -0
|
@@ -15,6 +15,7 @@ import { prepareTransaction } from "./prepareTransaction";
|
|
|
15
15
|
import { SolanaAccount, Transaction, TransferCommand } from "./types";
|
|
16
16
|
import BigNumber from "bignumber.js";
|
|
17
17
|
import { transaction } from "./__tests__/fixtures/helpers.fixture";
|
|
18
|
+
import { NotEnoughGas } from "@ledgerhq/errors";
|
|
18
19
|
|
|
19
20
|
jest.mock("./estimateMaxSpendable", () => {
|
|
20
21
|
const originalModule = jest.requireActual("./estimateMaxSpendable");
|
|
@@ -30,6 +31,43 @@ jest.mock("./estimateMaxSpendable", () => {
|
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
describe("testing prepareTransaction", () => {
|
|
34
|
+
it("packs a 'NotEnoughGas' error if the sender can not afford the fees during a token transfer", async () => {
|
|
35
|
+
const preparedTransaction = await prepareTransaction(
|
|
36
|
+
{
|
|
37
|
+
currency: { units: [{ magnitude: 2 }] },
|
|
38
|
+
subAccounts: [
|
|
39
|
+
{
|
|
40
|
+
id: "subAccountId",
|
|
41
|
+
type: "TokenAccount",
|
|
42
|
+
token: { contractAddress: "mintAddress", units: [{ magnitude: 2 }] },
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
} as unknown as SolanaAccount,
|
|
46
|
+
transaction({ kind: "token.transfer", subAccountId: "subAccountId" }),
|
|
47
|
+
{
|
|
48
|
+
getAccountInfo: () => ({
|
|
49
|
+
data: {
|
|
50
|
+
parsed: {
|
|
51
|
+
type: "mint",
|
|
52
|
+
info: {
|
|
53
|
+
mintAuthority: null,
|
|
54
|
+
supply: "",
|
|
55
|
+
decimals: 2,
|
|
56
|
+
isInitialized: true,
|
|
57
|
+
freezeAuthority: null,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
program: "spl-token",
|
|
61
|
+
},
|
|
62
|
+
}),
|
|
63
|
+
} as unknown as ChainAPI,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(preparedTransaction.model.commandDescriptor?.errors.gasPrice).toBeInstanceOf(
|
|
67
|
+
NotEnoughGas,
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
33
71
|
it("should return a new transaction from the raw transaction when user provide it", async () => {
|
|
34
72
|
// Given
|
|
35
73
|
const solanaTransaction = {
|
|
@@ -64,7 +102,7 @@ describe("testing prepareTransaction", () => {
|
|
|
64
102
|
);
|
|
65
103
|
|
|
66
104
|
const estimatedFees = 0.00005;
|
|
67
|
-
const rawTransaction = transaction("any random value");
|
|
105
|
+
const rawTransaction = transaction({ raw: "any random value" });
|
|
68
106
|
const chainAPI = api(estimatedFees);
|
|
69
107
|
const getFeeForMessageSpy = jest.spyOn(chainAPI, "getFeeForMessage");
|
|
70
108
|
|
|
@@ -4,10 +4,11 @@ import {
|
|
|
4
4
|
InvalidAddress,
|
|
5
5
|
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
6
6
|
NotEnoughBalance,
|
|
7
|
+
NotEnoughGas,
|
|
7
8
|
RecipientRequired,
|
|
8
9
|
} from "@ledgerhq/errors";
|
|
9
10
|
import type { Account } from "@ledgerhq/types-live";
|
|
10
|
-
import { findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { findSubAccountById, getFeesUnit } from "@ledgerhq/coin-framework/account/index";
|
|
11
12
|
import { ChainAPI } from "./network";
|
|
12
13
|
import {
|
|
13
14
|
getMaybeMintAccount,
|
|
@@ -88,6 +89,7 @@ import {
|
|
|
88
89
|
VersionedTransaction,
|
|
89
90
|
} from "@solana/web3.js";
|
|
90
91
|
import BigNumber from "bignumber.js";
|
|
92
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
|
91
93
|
|
|
92
94
|
async function deriveCommandDescriptor(
|
|
93
95
|
mainAccount: SolanaAccount,
|
|
@@ -319,7 +321,15 @@ const deriveTokenTransferCommandDescriptor = async (
|
|
|
319
321
|
const { fee, spendable: spendableSol } = await estimateFeeAndSpendable(api, mainAccount, tx);
|
|
320
322
|
|
|
321
323
|
if (spendableSol.lt(assocAccRentExempt) || spendableSol.isZero()) {
|
|
322
|
-
|
|
324
|
+
const query = new URLSearchParams({
|
|
325
|
+
...(mainAccount?.id ? { account: mainAccount.id } : {}),
|
|
326
|
+
});
|
|
327
|
+
errors.gasPrice = new NotEnoughGas(undefined, {
|
|
328
|
+
fees: formatCurrencyUnit(getFeesUnit(mainAccount.currency), new BigNumber(fee)),
|
|
329
|
+
ticker: mainAccount.currency.ticker,
|
|
330
|
+
cryptoName: mainAccount.currency.name,
|
|
331
|
+
links: [`ledgerlive://buy?${query.toString()}`],
|
|
332
|
+
});
|
|
323
333
|
}
|
|
324
334
|
|
|
325
335
|
if (!tx.useAllAmount && tx.amount.lte(0)) {
|
|
@@ -347,6 +357,7 @@ const deriveTokenTransferCommandDescriptor = async (
|
|
|
347
357
|
amount: txAmount,
|
|
348
358
|
mintAddress,
|
|
349
359
|
mintDecimals,
|
|
360
|
+
tokenId: tokenAccount.token.id,
|
|
350
361
|
recipientDescriptor: recipientDescriptor,
|
|
351
362
|
memo: model.uiState.memo,
|
|
352
363
|
tokenProgram: tokenProgram,
|
package/src/signOperation.ts
CHANGED
|
@@ -64,6 +64,7 @@ function getResolution(
|
|
|
64
64
|
return {
|
|
65
65
|
deviceModelId,
|
|
66
66
|
certificateSignatureKind,
|
|
67
|
+
tokenInternalId: command.tokenId,
|
|
67
68
|
createATA: {
|
|
68
69
|
address: command.recipientDescriptor.walletAddress,
|
|
69
70
|
mintAddress: command.mintAddress,
|
|
@@ -73,6 +74,7 @@ function getResolution(
|
|
|
73
74
|
return {
|
|
74
75
|
deviceModelId,
|
|
75
76
|
certificateSignatureKind,
|
|
77
|
+
tokenInternalId: command.tokenId,
|
|
76
78
|
tokenAddress: command.recipientDescriptor.tokenAccAddress,
|
|
77
79
|
};
|
|
78
80
|
}
|
package/src/signer.ts
CHANGED
package/src/tx-fees.ts
CHANGED
|
@@ -176,6 +176,7 @@ const createDummyTokenTransferTx = (address: string): Transaction => {
|
|
|
176
176
|
amount: 0,
|
|
177
177
|
mintAddress: randomAddresses[0],
|
|
178
178
|
mintDecimals: 0,
|
|
179
|
+
tokenId: "",
|
|
179
180
|
ownerAddress: address,
|
|
180
181
|
ownerAssociatedTokenAccountAddress: randomAddresses[1],
|
|
181
182
|
recipientDescriptor: {
|