@ledgerhq/coin-ton 0.7.0-nightly.2 → 0.7.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +18 -15
- package/jest.config.js +0 -1
- package/lib/__tests__/fixtures/common.fixtures.d.ts +4 -3
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
- package/lib/__tests__/fixtures/common.fixtures.js +1 -9
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -1
- package/lib/__tests__/integration/bridge.integration.test.js +2 -2
- package/lib/__tests__/integration/bridge.integration.test.js.map +1 -1
- package/lib/__tests__/unit/api.unit.test.js +0 -1
- package/lib/__tests__/unit/api.unit.test.js.map +1 -1
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +3 -12
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +0 -38
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
- package/lib/__tests__/unit/utils.unit.test.js +1 -43
- package/lib/__tests__/unit/utils.unit.test.js.map +1 -1
- package/lib/bridge/js.d.ts +3 -3
- package/lib/bridge/js.d.ts.map +1 -1
- package/lib/config.d.ts +0 -2
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/constants.d.ts +0 -18
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +1 -20
- package/lib/constants.js.map +1 -1
- package/lib/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/deviceTransactionConfig.js +3 -14
- package/lib/deviceTransactionConfig.js.map +1 -1
- package/lib/estimateMaxSpendable.d.ts +3 -3
- package/lib/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/estimateMaxSpendable.js +5 -6
- package/lib/estimateMaxSpendable.js.map +1 -1
- package/lib/getTransactionStatus.d.ts +3 -3
- package/lib/getTransactionStatus.d.ts.map +1 -1
- package/lib/getTransactionStatus.js +2 -2
- package/lib/getTransactionStatus.js.map +1 -1
- package/lib/prepareTransaction.d.ts +3 -3
- package/lib/prepareTransaction.d.ts.map +1 -1
- package/lib/prepareTransaction.js +2 -1
- package/lib/prepareTransaction.js.map +1 -1
- package/lib/signOperation.d.ts +4 -4
- package/lib/signOperation.d.ts.map +1 -1
- package/lib/signOperation.js.map +1 -1
- package/lib/synchronisation.d.ts +3 -3
- package/lib/synchronisation.d.ts.map +1 -1
- package/lib/synchronisation.js +3 -4
- package/lib/synchronisation.js.map +1 -1
- package/lib/types.d.ts +2 -79
- package/lib/types.d.ts.map +1 -1
- package/lib/utils.d.ts +4 -8
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +5 -30
- package/lib/utils.js.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +4 -3
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
- package/lib-es/__tests__/fixtures/common.fixtures.js +1 -9
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -1
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -1
- package/lib-es/__tests__/integration/bridge.integration.test.js +1 -1
- package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -1
- package/lib-es/__tests__/unit/api.unit.test.js +0 -1
- package/lib-es/__tests__/unit/api.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +3 -12
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +0 -15
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
- package/lib-es/__tests__/unit/utils.unit.test.js +1 -20
- package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -1
- package/lib-es/bridge/js.d.ts +3 -3
- package/lib-es/bridge/js.d.ts.map +1 -1
- package/lib-es/bridge/js.js +1 -1
- package/lib-es/bridge/js.js.map +1 -1
- package/lib-es/config.d.ts +0 -2
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/constants.d.ts +0 -18
- package/lib-es/constants.d.ts.map +1 -1
- package/lib-es/constants.js +0 -19
- package/lib-es/constants.js.map +1 -1
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
- package/lib-es/deviceTransactionConfig.js +4 -15
- package/lib-es/deviceTransactionConfig.js.map +1 -1
- package/lib-es/estimateMaxSpendable.d.ts +3 -3
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/estimateMaxSpendable.js +6 -7
- package/lib-es/estimateMaxSpendable.js.map +1 -1
- package/lib-es/getTransactionStatus.d.ts +3 -3
- package/lib-es/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/getTransactionStatus.js +2 -2
- package/lib-es/getTransactionStatus.js.map +1 -1
- package/lib-es/prepareTransaction.d.ts +3 -3
- package/lib-es/prepareTransaction.d.ts.map +1 -1
- package/lib-es/prepareTransaction.js +2 -1
- package/lib-es/prepareTransaction.js.map +1 -1
- package/lib-es/signOperation.d.ts +4 -4
- package/lib-es/signOperation.d.ts.map +1 -1
- package/lib-es/signOperation.js.map +1 -1
- package/lib-es/synchronisation.d.ts +3 -3
- package/lib-es/synchronisation.d.ts.map +1 -1
- package/lib-es/synchronisation.js +3 -4
- package/lib-es/synchronisation.js.map +1 -1
- package/lib-es/types.d.ts +2 -79
- package/lib-es/types.d.ts.map +1 -1
- package/lib-es/utils.d.ts +4 -8
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +5 -29
- package/lib-es/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/__tests__/fixtures/common.fixtures.ts +5 -12
- package/src/__tests__/integration/bridge.integration.test.ts +3 -3
- package/src/__tests__/unit/api.unit.test.ts +0 -1
- package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +3 -20
- package/src/__tests__/unit/prepareTransaction.unit.test.ts +0 -17
- package/src/__tests__/unit/utils.unit.test.ts +1 -22
- package/src/bridge/js.ts +3 -3
- package/src/config.ts +0 -2
- package/src/constants.ts +0 -20
- package/src/deviceTransactionConfig.ts +4 -23
- package/src/estimateMaxSpendable.ts +17 -13
- package/src/getTransactionStatus.ts +9 -9
- package/src/prepareTransaction.ts +6 -5
- package/src/signOperation.ts +4 -6
- package/src/synchronisation.ts +12 -17
- package/src/types.ts +1 -103
- package/src/utils.ts +8 -39
package/src/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { decodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
1
|
+
import { decodeAccountId, findSubAccountById } from "@ledgerhq/coin-framework/account/index";
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
2
3
|
import {
|
|
3
4
|
Builder,
|
|
4
5
|
SendMode,
|
|
@@ -10,22 +11,17 @@ import {
|
|
|
10
11
|
} from "@ton/ton";
|
|
11
12
|
import BigNumber from "bignumber.js";
|
|
12
13
|
import { estimateFee } from "./bridge/bridgeHelpers/api";
|
|
13
|
-
import { getCoinConfig } from "./config";
|
|
14
14
|
import {
|
|
15
15
|
JettonOpCode,
|
|
16
16
|
MAX_COMMENT_BYTES,
|
|
17
17
|
TOKEN_TRANSFER_FORWARD_AMOUNT,
|
|
18
18
|
TOKEN_TRANSFER_MAX_FEE,
|
|
19
19
|
TOKEN_TRANSFER_QUERY_ID,
|
|
20
|
-
WORKCHAIN,
|
|
21
20
|
} from "./constants";
|
|
22
21
|
import {
|
|
23
|
-
KnownJetton,
|
|
24
|
-
TonAccount,
|
|
25
22
|
TonCell,
|
|
26
23
|
TonComment,
|
|
27
24
|
TonPayloadJettonTransfer,
|
|
28
|
-
TonSubAccount,
|
|
29
25
|
TonTransaction,
|
|
30
26
|
Transaction,
|
|
31
27
|
} from "./types";
|
|
@@ -59,31 +55,14 @@ export const addressesAreEqual = (addr1: string, addr2: string) => {
|
|
|
59
55
|
}
|
|
60
56
|
};
|
|
61
57
|
|
|
62
|
-
/**
|
|
63
|
-
* Returns the known jetton ID and workchain for a given token address.
|
|
64
|
-
* Returns null if the token is not found in the known jettons list.
|
|
65
|
-
*/
|
|
66
|
-
function getKnownJettonId(tokenAddress: string, knownJettons: KnownJetton[]) {
|
|
67
|
-
const index = knownJettons.findIndex(jetton => jetton.masterAddress.toString() === tokenAddress);
|
|
68
|
-
return index > -1 ? { jettonId: index, workchain: WORKCHAIN } : null;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Finds a sub-account by its ID in a TON account.
|
|
73
|
-
* Returns undefined if no matching sub-account is found.
|
|
74
|
-
*/
|
|
75
|
-
export function findSubAccountById(account: TonAccount, id: string): TonSubAccount | undefined {
|
|
76
|
-
return account.subAccounts?.find(a => a.id === id) as TonSubAccount | undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
58
|
/**
|
|
80
59
|
* Builds a TonTransaction object based on the given transaction details.
|
|
81
60
|
*/
|
|
82
|
-
export
|
|
61
|
+
export const buildTonTransaction = (
|
|
83
62
|
transaction: Transaction,
|
|
84
63
|
seqno: number,
|
|
85
|
-
account:
|
|
86
|
-
): TonTransaction {
|
|
64
|
+
account: Account,
|
|
65
|
+
): TonTransaction => {
|
|
87
66
|
const { subAccountId, useAllAmount, amount, comment: commentTx, recipient } = transaction;
|
|
88
67
|
let recipientParsed = recipient;
|
|
89
68
|
// if recipient is not valid calculate fees with empty address
|
|
@@ -97,16 +76,12 @@ export function buildTonTransaction(
|
|
|
97
76
|
// if there is a sub account, the transaction is a token transfer
|
|
98
77
|
const subAccount = findSubAccountById(account, subAccountId ?? "");
|
|
99
78
|
|
|
100
|
-
if (subAccount && !subAccount.jettonWallet) {
|
|
101
|
-
throw new Error("[ton] jetton wallet not found");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
79
|
const finalAmount = subAccount
|
|
105
80
|
? toNano(TOKEN_TRANSFER_MAX_FEE) // for commission fees, excess will be returned
|
|
106
81
|
: useAllAmount
|
|
107
82
|
? BigInt(0)
|
|
108
83
|
: BigInt(amount.toFixed());
|
|
109
|
-
const to = subAccount
|
|
84
|
+
const to = subAccount ? subAccount.token.contractAddress : recipientParsed;
|
|
110
85
|
|
|
111
86
|
const tonTransaction: TonTransaction = {
|
|
112
87
|
to: TonAddress.parse(to),
|
|
@@ -127,9 +102,6 @@ export function buildTonTransaction(
|
|
|
127
102
|
if (subAccount) {
|
|
128
103
|
const forwardPayload = commentTx.text.length ? comment(commentTx.text) : null;
|
|
129
104
|
|
|
130
|
-
const currencyConfig = getCoinConfig();
|
|
131
|
-
const knownJettons = currencyConfig.infra.KNOWN_JETTONS;
|
|
132
|
-
|
|
133
105
|
tonTransaction.payload = {
|
|
134
106
|
type: "jetton-transfer",
|
|
135
107
|
queryId: BigInt(TOKEN_TRANSFER_QUERY_ID),
|
|
@@ -139,14 +111,11 @@ export function buildTonTransaction(
|
|
|
139
111
|
customPayload: null,
|
|
140
112
|
forwardAmount: BigInt(TOKEN_TRANSFER_FORWARD_AMOUNT),
|
|
141
113
|
forwardPayload,
|
|
142
|
-
knownJetton: knownJettons
|
|
143
|
-
? getKnownJettonId(subAccount?.token.contractAddress, knownJettons)
|
|
144
|
-
: null,
|
|
145
114
|
};
|
|
146
115
|
}
|
|
147
116
|
|
|
148
117
|
return tonTransaction;
|
|
149
|
-
}
|
|
118
|
+
};
|
|
150
119
|
|
|
151
120
|
/**
|
|
152
121
|
* Validates if the given comment is valid.
|
|
@@ -163,7 +132,7 @@ export const getTransferExpirationTime = () => Math.floor(Date.now() / 1000 + 60
|
|
|
163
132
|
* Estimates the fees for a Ton transaction.
|
|
164
133
|
*/
|
|
165
134
|
export const getTonEstimatedFees = async (
|
|
166
|
-
account:
|
|
135
|
+
account: Account,
|
|
167
136
|
needsInit: boolean,
|
|
168
137
|
tx: TonTransaction,
|
|
169
138
|
) => {
|