@ledgerhq/coin-solana 0.28.0 → 0.29.0-nightly.1
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +28 -0
- package/lib/__tests__/fixtures/helpers.fixture.d.ts +36 -1
- package/lib/__tests__/fixtures/helpers.fixture.d.ts.map +1 -1
- package/lib/__tests__/fixtures/helpers.fixture.js +2 -1
- package/lib/__tests__/fixtures/helpers.fixture.js.map +1 -1
- package/lib/__tests__/scan-accounts.test.js +5 -1
- package/lib/__tests__/scan-accounts.test.js.map +1 -1
- package/lib/bridge.integration.test.js +1 -0
- package/lib/bridge.integration.test.js.map +1 -1
- package/lib/buildTransaction.d.ts.map +1 -1
- package/lib/buildTransaction.js +5 -0
- package/lib/buildTransaction.js.map +1 -1
- package/lib/getTransactionStatus.d.ts.map +1 -1
- package/lib/getTransactionStatus.js +2 -0
- package/lib/getTransactionStatus.js.map +1 -1
- package/lib/network/chain/account/token.d.ts +9 -0
- package/lib/network/chain/account/token.d.ts.map +1 -1
- package/lib/network/chain/account/tokenExtensions.d.ts +6 -0
- package/lib/network/chain/account/tokenExtensions.d.ts.map +1 -1
- package/lib/network/chain/account/tokenExtensions.js +1 -0
- package/lib/network/chain/account/tokenExtensions.js.map +1 -1
- package/lib/prepareTransaction.d.ts.map +1 -1
- package/lib/prepareTransaction.js +4 -61
- package/lib/prepareTransaction.js.map +1 -1
- package/lib/prepareTransaction.test.js +37 -52
- package/lib/prepareTransaction.test.js.map +1 -1
- package/lib/rawTransaction.d.ts +5 -0
- package/lib/rawTransaction.d.ts.map +1 -0
- package/lib/rawTransaction.js +52 -0
- package/lib/rawTransaction.js.map +1 -0
- package/lib/signOperation.d.ts.map +1 -1
- package/lib/signOperation.js +16 -0
- package/lib/signOperation.js.map +1 -1
- package/lib/specs.d.ts.map +1 -1
- package/lib/specs.js +1 -0
- package/lib/specs.js.map +1 -1
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +14 -20
- package/lib/transaction.js.map +1 -1
- package/lib/tx-fees.js +1 -0
- package/lib/tx-fees.js.map +1 -1
- package/lib/types.d.ts +10 -2
- package/lib/types.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.d.ts +36 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.js +2 -1
- package/lib-es/__tests__/fixtures/helpers.fixture.js.map +1 -1
- package/lib-es/__tests__/scan-accounts.test.js +5 -1
- package/lib-es/__tests__/scan-accounts.test.js.map +1 -1
- package/lib-es/bridge.integration.test.js +1 -0
- package/lib-es/bridge.integration.test.js.map +1 -1
- package/lib-es/buildTransaction.d.ts.map +1 -1
- package/lib-es/buildTransaction.js +5 -0
- package/lib-es/buildTransaction.js.map +1 -1
- package/lib-es/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/getTransactionStatus.js +2 -0
- package/lib-es/getTransactionStatus.js.map +1 -1
- package/lib-es/network/chain/account/token.d.ts +9 -0
- package/lib-es/network/chain/account/token.d.ts.map +1 -1
- package/lib-es/network/chain/account/tokenExtensions.d.ts +6 -0
- package/lib-es/network/chain/account/tokenExtensions.d.ts.map +1 -1
- package/lib-es/network/chain/account/tokenExtensions.js +1 -0
- package/lib-es/network/chain/account/tokenExtensions.js.map +1 -1
- package/lib-es/prepareTransaction.d.ts.map +1 -1
- package/lib-es/prepareTransaction.js +3 -60
- package/lib-es/prepareTransaction.js.map +1 -1
- package/lib-es/prepareTransaction.test.js +37 -52
- package/lib-es/prepareTransaction.test.js.map +1 -1
- package/lib-es/rawTransaction.d.ts +5 -0
- package/lib-es/rawTransaction.d.ts.map +1 -0
- package/lib-es/rawTransaction.js +44 -0
- package/lib-es/rawTransaction.js.map +1 -0
- package/lib-es/signOperation.d.ts.map +1 -1
- package/lib-es/signOperation.js +16 -0
- package/lib-es/signOperation.js.map +1 -1
- package/lib-es/specs.d.ts.map +1 -1
- package/lib-es/specs.js +1 -0
- package/lib-es/specs.js.map +1 -1
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +14 -20
- package/lib-es/transaction.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 +10 -2
- package/lib-es/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/fixtures/helpers.fixture.ts +4 -0
- package/src/__tests__/scan-accounts.test.ts +5 -1
- package/src/bridge.integration.test.ts +1 -0
- package/src/buildTransaction.ts +5 -0
- package/src/getTransactionStatus.ts +2 -0
- package/src/network/chain/account/tokenExtensions.ts +1 -0
- package/src/prepareTransaction.test.ts +31 -71
- package/src/prepareTransaction.ts +3 -100
- package/src/rawTransaction.ts +59 -0
- package/src/signOperation.ts +24 -0
- package/src/specs.ts +1 -0
- package/src/transaction.ts +17 -20
- package/src/tx-fees.ts +1 -0
- package/src/types.ts +13 -1
package/lib-es/types.d.ts
CHANGED
|
@@ -98,7 +98,11 @@ export type TokenTransferCommand = {
|
|
|
98
98
|
transferFee?: TransferFeeCalculated | undefined;
|
|
99
99
|
};
|
|
100
100
|
};
|
|
101
|
-
export type
|
|
101
|
+
export type RawCommand = {
|
|
102
|
+
kind: "raw";
|
|
103
|
+
raw: string;
|
|
104
|
+
};
|
|
105
|
+
export type Command = TransferCommand | TokenTransferCommand | TokenCreateATACommand | TokenCreateApproveCommand | TokenCreateRevokeCommand | StakeCreateAccountCommand | StakeDelegateCommand | StakeUndelegateCommand | StakeWithdrawCommand | StakeSplitCommand | RawCommand;
|
|
102
106
|
export type CommandDescriptor = {
|
|
103
107
|
command: Command;
|
|
104
108
|
fee: number;
|
|
@@ -169,9 +173,13 @@ export type StakeSplitTransaction = {
|
|
|
169
173
|
stakeAccAddr: string;
|
|
170
174
|
};
|
|
171
175
|
};
|
|
176
|
+
export type RawTransaction = {
|
|
177
|
+
kind: "raw";
|
|
178
|
+
uiState: object;
|
|
179
|
+
};
|
|
172
180
|
export type TransactionModel = {
|
|
173
181
|
commandDescriptor?: CommandDescriptor;
|
|
174
|
-
} & (TransferTransaction | TokenTransferTransaction | TokenCreateATATransaction | TokenCreateApproveTransaction | TokenCreateRevokeTransaction | StakeCreateAccountTransaction | StakeDelegateTransaction | StakeUndelegateTransaction | StakeWithdrawTransaction | StakeSplitTransaction);
|
|
182
|
+
} & (TransferTransaction | TokenTransferTransaction | TokenCreateATATransaction | TokenCreateApproveTransaction | TokenCreateRevokeTransaction | StakeCreateAccountTransaction | StakeDelegateTransaction | StakeUndelegateTransaction | StakeWithdrawTransaction | StakeSplitTransaction | RawTransaction);
|
|
175
183
|
export type Transaction = TransactionCommon & {
|
|
176
184
|
family: "solana";
|
|
177
185
|
model: TransactionModel;
|
package/lib-es/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAC;AACrC,OAAO,EACL,OAAO,EACP,UAAU,EACV,SAAS,EACT,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAE3D,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAAC;AAEF,MAA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CACvD,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG;IACpD,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAExD,MAAM,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAE9D,MAAM,MAAM,eAAe,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAC9D,MAAM,MAAM,kBAAkB,GAAG,SAAS,CAAC,uBAAuB,CAAC,CAAC;AAEpE,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,cAAc,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,0BAA0B,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/coin-solana",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0-nightly.1",
|
|
4
4
|
"description": "Ledger Solana Coin integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ledger",
|
|
@@ -56,15 +56,15 @@
|
|
|
56
56
|
"rxjs": "^7.8.1",
|
|
57
57
|
"semver": "7.7.1",
|
|
58
58
|
"superstruct": "0.16.7",
|
|
59
|
-
"@ledgerhq/coin-framework": "^5.7.
|
|
60
|
-
"@ledgerhq/cryptoassets": "^13.22.0",
|
|
59
|
+
"@ledgerhq/coin-framework": "^5.7.1-nightly.1",
|
|
60
|
+
"@ledgerhq/cryptoassets": "^13.22.1-nightly.0",
|
|
61
61
|
"@ledgerhq/devices": "8.4.8",
|
|
62
62
|
"@ledgerhq/errors": "^6.23.0",
|
|
63
|
-
"@ledgerhq/live-env": "^2.
|
|
64
|
-
"@ledgerhq/live-network": "^2.0.
|
|
63
|
+
"@ledgerhq/live-env": "^2.13.0-nightly.0",
|
|
64
|
+
"@ledgerhq/live-network": "^2.0.14-nightly.0",
|
|
65
65
|
"@ledgerhq/logs": "^6.13.0",
|
|
66
|
-
"@ledgerhq/types-cryptoassets": "^7.
|
|
67
|
-
"@ledgerhq/types-live": "^6.78.0"
|
|
66
|
+
"@ledgerhq/types-cryptoassets": "^7.24.0-nightly.0",
|
|
67
|
+
"@ledgerhq/types-live": "^6.78.1-nightly.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@faker-js/faker": "^8.4.1",
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
import BigNumber from "bignumber.js";
|
|
9
9
|
import { v4, v5, parse } from "uuid";
|
|
10
10
|
import { Transaction } from "../../types";
|
|
11
|
+
import { TokenAccountExtensions } from "../../network/chain/account/tokenExtensions";
|
|
11
12
|
|
|
12
13
|
const seed = v4();
|
|
13
14
|
|
|
@@ -99,6 +100,7 @@ export function parsedTokenInfo({
|
|
|
99
100
|
isNative,
|
|
100
101
|
amount,
|
|
101
102
|
decimals,
|
|
103
|
+
extensions,
|
|
102
104
|
}: {
|
|
103
105
|
state?: "initialized" | "uninitialized" | "frozen";
|
|
104
106
|
owner?: PublicKey;
|
|
@@ -106,6 +108,7 @@ export function parsedTokenInfo({
|
|
|
106
108
|
isNative?: boolean;
|
|
107
109
|
amount?: number;
|
|
108
110
|
decimals?: number;
|
|
111
|
+
extensions?: TokenAccountExtensions;
|
|
109
112
|
}) {
|
|
110
113
|
const amountOrDefault = amount ?? 2000;
|
|
111
114
|
const decimalsOrDefault = decimals ?? 3;
|
|
@@ -115,6 +118,7 @@ export function parsedTokenInfo({
|
|
|
115
118
|
owner: owner ?? publicKeyOf("owner"),
|
|
116
119
|
mint: mint ?? publicKeyOf("mint"),
|
|
117
120
|
state: state ?? "initialized",
|
|
121
|
+
extensions: extensions ?? [],
|
|
118
122
|
tokenAmount: {
|
|
119
123
|
amount: amountOrDefault.toString(),
|
|
120
124
|
decimals: decimalsOrDefault,
|
|
@@ -236,7 +236,11 @@ describe("Scan account", () => {
|
|
|
236
236
|
lamports: 30000,
|
|
237
237
|
program: "spl-token-2022",
|
|
238
238
|
type: "account",
|
|
239
|
-
info: parsedTokenInfo({
|
|
239
|
+
info: parsedTokenInfo({
|
|
240
|
+
state: "frozen",
|
|
241
|
+
owner: publicKeyOf(address),
|
|
242
|
+
extensions: [{ extension: "immutableOwner" }, { extension: "pausableAccount" }],
|
|
243
|
+
}),
|
|
240
244
|
}),
|
|
241
245
|
},
|
|
242
246
|
],
|
package/src/buildTransaction.ts
CHANGED
|
@@ -39,6 +39,9 @@ export const buildTransactionWithAPI = async (
|
|
|
39
39
|
let web3SolanaTransaction: VersionedTransaction;
|
|
40
40
|
if (transaction.raw) {
|
|
41
41
|
web3SolanaTransaction = OnChainTransaction.deserialize(Buffer.from(transaction.raw, "base64"));
|
|
42
|
+
// If we want to retry correctly we might want to update the recent blockhash
|
|
43
|
+
// Needs more testing before enabling
|
|
44
|
+
// web3SolanaTransaction.message.recentBlockhash = recentBlockhash.blockhash;
|
|
42
45
|
} else {
|
|
43
46
|
const instructions = await buildInstructions(api, transaction);
|
|
44
47
|
const transactionMessage = new TransactionMessage({
|
|
@@ -106,6 +109,8 @@ async function buildInstructionsForCommand(
|
|
|
106
109
|
return buildStakeWithdrawInstructions(api, command);
|
|
107
110
|
case "stake.split":
|
|
108
111
|
return buildStakeSplitInstructions(api, command);
|
|
112
|
+
case "raw":
|
|
113
|
+
throw new Error("Raw transactions should not be built with this function");
|
|
109
114
|
default:
|
|
110
115
|
return assertUnreachable(command);
|
|
111
116
|
}
|
|
@@ -54,6 +54,7 @@ function getAmount(command: Command) {
|
|
|
54
54
|
case "stake.delegate":
|
|
55
55
|
case "stake.undelegate":
|
|
56
56
|
case "stake.split":
|
|
57
|
+
case "raw":
|
|
57
58
|
return 0;
|
|
58
59
|
default:
|
|
59
60
|
return assertUnreachable(command);
|
|
@@ -80,6 +81,7 @@ function getTotalSpent({ command, fee }: CommandDescriptor) {
|
|
|
80
81
|
case "stake.undelegate":
|
|
81
82
|
case "stake.withdraw":
|
|
82
83
|
case "stake.split":
|
|
84
|
+
case "raw":
|
|
83
85
|
return fee;
|
|
84
86
|
default:
|
|
85
87
|
return assertUnreachable(command);
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Account,
|
|
3
|
-
BlockhashWithExpiryBlockHeight,
|
|
4
|
-
DecodedTransferInstruction,
|
|
5
|
-
MessageCompiledInstruction,
|
|
6
|
-
PublicKey,
|
|
7
|
-
SystemInstruction,
|
|
8
|
-
SystemProgram,
|
|
9
|
-
TransactionInstruction,
|
|
10
|
-
VersionedMessage,
|
|
11
|
-
VersionedTransaction,
|
|
12
|
-
} from "@solana/web3.js";
|
|
1
|
+
import { Account, VersionedMessage } from "@solana/web3.js";
|
|
13
2
|
import { ChainAPI } from "./network";
|
|
14
3
|
import { prepareTransaction } from "./prepareTransaction";
|
|
15
|
-
import { SolanaAccount, Transaction
|
|
4
|
+
import { SolanaAccount, Transaction } from "./types";
|
|
16
5
|
import BigNumber from "bignumber.js";
|
|
17
6
|
import { transaction } from "./__tests__/fixtures/helpers.fixture";
|
|
18
7
|
import { NotEnoughGas } from "@ledgerhq/errors";
|
|
@@ -33,6 +22,7 @@ jest.mock("./estimateMaxSpendable", () => {
|
|
|
33
22
|
describe("testing prepareTransaction", () => {
|
|
34
23
|
it("packs a 'NotEnoughGas' error if the sender can not afford the fees during a token transfer", async () => {
|
|
35
24
|
const preparedTransaction = await prepareTransaction(
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
36
26
|
{
|
|
37
27
|
currency: { units: [{ magnitude: 2 }] },
|
|
38
28
|
subAccounts: [
|
|
@@ -44,6 +34,7 @@ describe("testing prepareTransaction", () => {
|
|
|
44
34
|
],
|
|
45
35
|
} as unknown as SolanaAccount,
|
|
46
36
|
transaction({ kind: "token.transfer", subAccountId: "subAccountId" }),
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
47
38
|
{
|
|
48
39
|
getAccountInfo: () => ({
|
|
49
40
|
data: {
|
|
@@ -70,44 +61,16 @@ describe("testing prepareTransaction", () => {
|
|
|
70
61
|
|
|
71
62
|
it("should return a new transaction from the raw transaction when user provide it", async () => {
|
|
72
63
|
// Given
|
|
73
|
-
const solanaTransaction = {
|
|
74
|
-
message: {
|
|
75
|
-
staticAccountKeys: [SystemProgram.programId],
|
|
76
|
-
compiledInstructions: [
|
|
77
|
-
{
|
|
78
|
-
programIdIndex: 0,
|
|
79
|
-
data: "some random data",
|
|
80
|
-
accountKeyIndexes: [0],
|
|
81
|
-
},
|
|
82
|
-
] as unknown as MessageCompiledInstruction[],
|
|
83
|
-
isAccountSigner: (_index: number) => true,
|
|
84
|
-
isAccountWritable: (_index: number) => true,
|
|
85
|
-
} as unknown as VersionedMessage,
|
|
86
|
-
} as VersionedTransaction;
|
|
87
|
-
const deserializeSpy = jest.spyOn(VersionedTransaction, "deserialize");
|
|
88
|
-
deserializeSpy.mockImplementationOnce(
|
|
89
|
-
(_serializedTransaction: Uint8Array) => solanaTransaction,
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const sender = PublicKey.unique();
|
|
93
|
-
const recipient = PublicKey.unique();
|
|
94
|
-
const decodeTransferSpy = jest.spyOn(SystemInstruction, "decodeTransfer");
|
|
95
|
-
decodeTransferSpy.mockImplementationOnce(
|
|
96
|
-
(_instruction: TransactionInstruction) =>
|
|
97
|
-
({
|
|
98
|
-
lamports: BigInt(1),
|
|
99
|
-
fromPubkey: sender,
|
|
100
|
-
toPubkey: recipient,
|
|
101
|
-
}) as DecodedTransferInstruction,
|
|
102
|
-
);
|
|
103
|
-
|
|
104
64
|
const estimatedFees = 0.00005;
|
|
105
|
-
const rawTransaction = transaction({
|
|
65
|
+
const rawTransaction = transaction({
|
|
66
|
+
raw: "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAEDNzWs4isgmR+LEHY8ZcgBBLMnC4ckD1iuhSa2/Y+69I91oyGFaAZ/9w4srgx9KoqiHtPM6Vur7h4D6XVoSgrEhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALt5JNk+MAN8BXYrlkxMEL1C/sM3+ZFYwZw4eofBOKp4BAgIAAQwCAAAAgJaYAAAAAAA=",
|
|
67
|
+
});
|
|
106
68
|
const chainAPI = api(estimatedFees);
|
|
107
69
|
const getFeeForMessageSpy = jest.spyOn(chainAPI, "getFeeForMessage");
|
|
108
70
|
|
|
109
71
|
// When
|
|
110
72
|
const preparedTransaction = await prepareTransaction(
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
111
74
|
{} as SolanaAccount,
|
|
112
75
|
rawTransaction,
|
|
113
76
|
chainAPI,
|
|
@@ -116,40 +79,36 @@ describe("testing prepareTransaction", () => {
|
|
|
116
79
|
// Then
|
|
117
80
|
expect(preparedTransaction).not.toBe(rawTransaction);
|
|
118
81
|
|
|
119
|
-
expect(deserializeSpy).toHaveBeenCalledTimes(1);
|
|
120
|
-
expect(deserializeSpy).toHaveBeenCalledWith(Buffer.from("any random value", "base64"));
|
|
121
|
-
|
|
122
|
-
expect(decodeTransferSpy).toHaveBeenCalledTimes(1);
|
|
123
|
-
expect(decodeTransferSpy).toHaveBeenCalledWith({
|
|
124
|
-
data: Buffer.from("some random data"),
|
|
125
|
-
programId: SystemProgram.programId,
|
|
126
|
-
keys: [{ pubkey: SystemProgram.programId, isSigner: true, isWritable: true }],
|
|
127
|
-
});
|
|
128
|
-
|
|
129
82
|
expect(getFeeForMessageSpy).toHaveBeenCalledTimes(1);
|
|
130
|
-
expect(getFeeForMessageSpy).toHaveBeenCalledWith(solanaTransaction.message);
|
|
131
83
|
|
|
132
|
-
expect(preparedTransaction
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
84
|
+
expect(preparedTransaction).toMatchObject({
|
|
85
|
+
raw: rawTransaction.raw,
|
|
86
|
+
family: "solana",
|
|
87
|
+
amount: BigNumber(0),
|
|
88
|
+
recipient: "",
|
|
89
|
+
model: {
|
|
90
|
+
kind: "raw",
|
|
91
|
+
uiState: {},
|
|
92
|
+
commandDescriptor: {
|
|
93
|
+
command: {
|
|
94
|
+
kind: "raw",
|
|
95
|
+
raw: rawTransaction.raw,
|
|
96
|
+
},
|
|
97
|
+
fee: estimatedFees,
|
|
98
|
+
warnings: {},
|
|
99
|
+
errors: {},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
146
103
|
});
|
|
147
104
|
|
|
148
105
|
it("should return a new transaction when user does not provide a raw one", async () => {
|
|
149
106
|
const nonRawTransaction = transaction();
|
|
150
107
|
const preparedTransaction = await prepareTransaction(
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
151
109
|
{} as SolanaAccount,
|
|
152
110
|
nonRawTransaction,
|
|
111
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
153
112
|
{} as ChainAPI,
|
|
154
113
|
);
|
|
155
114
|
|
|
@@ -158,12 +117,13 @@ describe("testing prepareTransaction", () => {
|
|
|
158
117
|
});
|
|
159
118
|
|
|
160
119
|
function api(estimatedFees?: number) {
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
161
121
|
return {
|
|
162
122
|
getLatestBlockhash: () => {
|
|
163
123
|
return Promise.resolve({
|
|
164
124
|
blockhash: "blockhash",
|
|
165
125
|
lastValidBlockHeight: 1,
|
|
166
|
-
}
|
|
126
|
+
});
|
|
167
127
|
},
|
|
168
128
|
|
|
169
129
|
getFeeForMessage: (_message: VersionedMessage) => Promise.resolve(estimatedFees),
|
|
@@ -79,15 +79,7 @@ import { estimateFeeAndSpendable, estimateTokenMaxSpendable } from "./estimateMa
|
|
|
79
79
|
import { MemoTransferExt, TransferFeeConfigExt } from "./network/chain/account/tokenExtensions";
|
|
80
80
|
import { calculateToken2022TransferFees } from "./helpers/token";
|
|
81
81
|
import { TokenAccountInfo } from "./network/chain/account/token";
|
|
82
|
-
import {
|
|
83
|
-
DecodedTransferInstruction,
|
|
84
|
-
MessageCompiledInstruction,
|
|
85
|
-
PublicKey,
|
|
86
|
-
SystemInstruction,
|
|
87
|
-
SystemProgram,
|
|
88
|
-
VersionedMessage,
|
|
89
|
-
VersionedTransaction,
|
|
90
|
-
} from "@solana/web3.js";
|
|
82
|
+
import { deriveRawCommandDescriptor, toLiveTransaction } from "./rawTransaction";
|
|
91
83
|
import BigNumber from "bignumber.js";
|
|
92
84
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/formatCurrencyUnit";
|
|
93
85
|
|
|
@@ -118,102 +110,13 @@ async function deriveCommandDescriptor(
|
|
|
118
110
|
return deriveStakeWithdrawCommandDescriptor(mainAccount, tx, model, api);
|
|
119
111
|
case "stake.split":
|
|
120
112
|
return deriveStakeSplitCommandDescriptor(mainAccount, tx, model, api);
|
|
113
|
+
case "raw":
|
|
114
|
+
return deriveRawCommandDescriptor(tx, api);
|
|
121
115
|
default:
|
|
122
116
|
return assertUnreachable(model);
|
|
123
117
|
}
|
|
124
118
|
}
|
|
125
119
|
|
|
126
|
-
function fromBigIntToBigNumber(bigInt: bigint): BigNumber {
|
|
127
|
-
return BigNumber(bigInt.toString());
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function toSolanaTransaction(serializedTransaction: string): VersionedTransaction {
|
|
131
|
-
return VersionedTransaction.deserialize(Buffer.from(serializedTransaction, "base64"));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function findInstruction(
|
|
135
|
-
compiledInstructions: MessageCompiledInstruction[],
|
|
136
|
-
staticAccountKeys: PublicKey[],
|
|
137
|
-
): MessageCompiledInstruction | undefined {
|
|
138
|
-
return compiledInstructions.find(instruction => {
|
|
139
|
-
return (
|
|
140
|
-
staticAccountKeys[instruction.programIdIndex].toString() ===
|
|
141
|
-
SystemProgram.programId.toString()
|
|
142
|
-
);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function decodeInstruction(
|
|
147
|
-
message: VersionedMessage,
|
|
148
|
-
instruction: MessageCompiledInstruction,
|
|
149
|
-
): DecodedTransferInstruction {
|
|
150
|
-
return SystemInstruction.decodeTransfer({
|
|
151
|
-
data: Buffer.from(instruction.data),
|
|
152
|
-
programId: SystemProgram.programId,
|
|
153
|
-
keys: instruction.accountKeyIndexes.map(index => {
|
|
154
|
-
return {
|
|
155
|
-
pubkey: message.staticAccountKeys[index],
|
|
156
|
-
isSigner: message.isAccountSigner(index),
|
|
157
|
-
isWritable: message.isAccountWritable(index),
|
|
158
|
-
};
|
|
159
|
-
}),
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function buildTransferTransaction(
|
|
164
|
-
raw: string,
|
|
165
|
-
lamports: bigint,
|
|
166
|
-
fromPubkey: PublicKey,
|
|
167
|
-
toPubkey: PublicKey,
|
|
168
|
-
estimatedFees: number | null,
|
|
169
|
-
): Transaction {
|
|
170
|
-
return {
|
|
171
|
-
raw,
|
|
172
|
-
family: "solana",
|
|
173
|
-
amount: fromBigIntToBigNumber(lamports),
|
|
174
|
-
recipient: String(toPubkey),
|
|
175
|
-
model: {
|
|
176
|
-
kind: "transfer",
|
|
177
|
-
uiState: {},
|
|
178
|
-
commandDescriptor: {
|
|
179
|
-
command: {
|
|
180
|
-
kind: "transfer",
|
|
181
|
-
amount: fromBigIntToBigNumber(lamports).toNumber(),
|
|
182
|
-
sender: String(fromPubkey),
|
|
183
|
-
recipient: String(toPubkey),
|
|
184
|
-
},
|
|
185
|
-
fee: estimatedFees ?? 0,
|
|
186
|
-
warnings: {},
|
|
187
|
-
errors: {},
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async function toLiveTransaction(
|
|
194
|
-
api: ChainAPI,
|
|
195
|
-
serializedTransaction: string,
|
|
196
|
-
): Promise<Transaction> {
|
|
197
|
-
const solanaTransaction = toSolanaTransaction(serializedTransaction);
|
|
198
|
-
const message = solanaTransaction.message;
|
|
199
|
-
const instruction = findInstruction(message.compiledInstructions, message.staticAccountKeys);
|
|
200
|
-
|
|
201
|
-
if (!instruction) {
|
|
202
|
-
throw new Error("No supported instructions found on Solana transaction");
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const decodedInstruction = decodeInstruction(message, instruction);
|
|
206
|
-
const estimatedFees = await api.getFeeForMessage(message);
|
|
207
|
-
|
|
208
|
-
return buildTransferTransaction(
|
|
209
|
-
serializedTransaction,
|
|
210
|
-
decodedInstruction.lamports,
|
|
211
|
-
decodedInstruction.fromPubkey,
|
|
212
|
-
decodedInstruction.toPubkey,
|
|
213
|
-
estimatedFees,
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
120
|
const prepareTransaction = async (
|
|
218
121
|
mainAccount: SolanaAccount,
|
|
219
122
|
tx: Transaction,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ChainAPI } from "./network";
|
|
2
|
+
import { Transaction } from "./types";
|
|
3
|
+
import { VersionedTransaction } from "@solana/web3.js";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
|
|
6
|
+
function buildRawTransaction(raw: string, estimatedFees: number | null): Transaction {
|
|
7
|
+
return {
|
|
8
|
+
raw,
|
|
9
|
+
family: "solana",
|
|
10
|
+
amount: BigNumber(0),
|
|
11
|
+
recipient: "",
|
|
12
|
+
model: {
|
|
13
|
+
kind: "raw",
|
|
14
|
+
uiState: {},
|
|
15
|
+
commandDescriptor: {
|
|
16
|
+
command: {
|
|
17
|
+
kind: "raw",
|
|
18
|
+
raw,
|
|
19
|
+
},
|
|
20
|
+
fee: estimatedFees ?? 0,
|
|
21
|
+
warnings: {},
|
|
22
|
+
errors: {},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export async function toLiveTransaction(
|
|
29
|
+
api: ChainAPI,
|
|
30
|
+
serializedTransaction: string,
|
|
31
|
+
): Promise<Transaction> {
|
|
32
|
+
const solanaTransaction = VersionedTransaction.deserialize(
|
|
33
|
+
Buffer.from(serializedTransaction, "base64"),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const estimatedFees = await api.getFeeForMessage(solanaTransaction.message);
|
|
37
|
+
|
|
38
|
+
return buildRawTransaction(serializedTransaction, estimatedFees);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function deriveRawCommandDescriptor(tx: Transaction, api: ChainAPI) {
|
|
42
|
+
if (!tx.raw) {
|
|
43
|
+
throw new Error("Raw transaction is required to derive command descriptor");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const liveTx = await toLiveTransaction(api, tx.raw);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
liveTx.model.commandDescriptor || {
|
|
50
|
+
command: {
|
|
51
|
+
kind: "raw",
|
|
52
|
+
raw: tx.raw,
|
|
53
|
+
},
|
|
54
|
+
fee: tx.model.commandDescriptor?.fee ?? 0,
|
|
55
|
+
warnings: {},
|
|
56
|
+
errors: {},
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
package/src/signOperation.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Account, AccountBridge, OperationType } from "@ledgerhq/types-live
|
|
|
3
3
|
import type {
|
|
4
4
|
Command,
|
|
5
5
|
CommandDescriptor,
|
|
6
|
+
RawCommand,
|
|
6
7
|
SolanaOperation,
|
|
7
8
|
SolanaOperationExtra,
|
|
8
9
|
StakeCreateAccountCommand,
|
|
@@ -168,10 +169,32 @@ function buildOptimisticOperationForCommand(
|
|
|
168
169
|
return optimisticOpForStakeWithdraw(account, command, commandDescriptor);
|
|
169
170
|
case "stake.split":
|
|
170
171
|
return optimisticOpForStakeSplit(account, command, commandDescriptor);
|
|
172
|
+
case "raw":
|
|
173
|
+
return optimisticOpForRaw(account, transaction, command, commandDescriptor);
|
|
171
174
|
default:
|
|
172
175
|
return assertUnreachable(command);
|
|
173
176
|
}
|
|
174
177
|
}
|
|
178
|
+
|
|
179
|
+
function optimisticOpForRaw(
|
|
180
|
+
account: Account,
|
|
181
|
+
transaction: Transaction,
|
|
182
|
+
command: RawCommand,
|
|
183
|
+
commandDescriptor: CommandDescriptor,
|
|
184
|
+
): SolanaOperation {
|
|
185
|
+
const commons = optimisticOpcommons(commandDescriptor);
|
|
186
|
+
return {
|
|
187
|
+
...commons,
|
|
188
|
+
id: encodeOperationId(account.id, "", "OUT"),
|
|
189
|
+
type: "OUT",
|
|
190
|
+
accountId: account.id,
|
|
191
|
+
senders: [account.freshAddress],
|
|
192
|
+
recipients: [transaction.recipient],
|
|
193
|
+
value: new BigNumber(commons.fee ?? 0),
|
|
194
|
+
extra: getOpExtras(command),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
175
198
|
function optimisticOpForTransfer(
|
|
176
199
|
account: Account,
|
|
177
200
|
transaction: Transaction,
|
|
@@ -307,6 +330,7 @@ function getOpExtras(command: Command): SolanaOperationExtra {
|
|
|
307
330
|
case "stake.undelegate":
|
|
308
331
|
case "stake.withdraw":
|
|
309
332
|
case "stake.split":
|
|
333
|
+
case "raw":
|
|
310
334
|
break;
|
|
311
335
|
default:
|
|
312
336
|
return assertUnreachable(command);
|
package/src/specs.ts
CHANGED