@ledgerhq/coin-tezos 6.3.0 → 6.3.1-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 +7 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.integ.test.js +9 -2
- package/lib/api/index.integ.test.js.map +1 -1
- package/lib/api/index.js +6 -38
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +5 -5
- package/lib/api/index.test.js.map +1 -1
- package/lib/bridge/prepareTransaction.test.js +2 -2
- package/lib/bridge/prepareTransaction.test.js.map +1 -1
- package/lib/bridge/signOperation.test.js +1 -1
- package/lib/bridge/signOperation.test.js.map +1 -1
- package/lib/logic/craftTransaction.js +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +1 -1
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.integ.test.js +5 -5
- package/lib/logic/estimateFees.js +4 -4
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +2 -5
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +2 -2
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.integ.test.js +9 -2
- package/lib-es/api/index.integ.test.js.map +1 -1
- package/lib-es/api/index.js +6 -38
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +5 -5
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.test.js +3 -3
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -1
- package/lib-es/bridge/signOperation.test.js +2 -2
- package/lib-es/bridge/signOperation.test.js.map +1 -1
- package/lib-es/logic/craftTransaction.js +2 -2
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +2 -2
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.integ.test.js +5 -5
- package/lib-es/logic/estimateFees.js +6 -6
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +2 -5
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +2 -2
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/package.json +9 -9
- package/src/api/index.integ.test.ts +13 -2
- package/src/api/index.test.ts +5 -5
- package/src/api/index.ts +8 -56
- package/src/bridge/prepareTransaction.test.ts +7 -3
- package/src/bridge/signOperation.test.ts +2 -2
- package/src/logic/craftTransaction.test.ts +2 -2
- package/src/logic/craftTransaction.ts +2 -2
- package/src/logic/estimateFees.integ.test.ts +5 -5
- package/src/logic/estimateFees.ts +7 -7
- package/src/logic/listOperations.test.ts +2 -2
- package/src/logic/listOperations.ts +4 -5
|
@@ -57,7 +57,7 @@ describe("Tezos Api", () => {
|
|
|
57
57
|
describe("listOperations", () => {
|
|
58
58
|
it("returns a list regarding address parameter", async () => {
|
|
59
59
|
// When
|
|
60
|
-
const [tx, _] = await module.listOperations(address, { minHeight: 0 });
|
|
60
|
+
const [tx, _] = await module.listOperations(address, { minHeight: 0, order: "asc" });
|
|
61
61
|
|
|
62
62
|
// Then
|
|
63
63
|
expect(tx.length).toBeGreaterThanOrEqual(1);
|
|
@@ -71,13 +71,24 @@ describe("Tezos Api", () => {
|
|
|
71
71
|
|
|
72
72
|
it("returns all operations", async () => {
|
|
73
73
|
// When
|
|
74
|
-
const [tx, _] = await module.listOperations(address, { minHeight: 0 });
|
|
74
|
+
const [tx, _] = await module.listOperations(address, { minHeight: 0, order: "asc" });
|
|
75
75
|
|
|
76
76
|
// Then
|
|
77
77
|
// Find a way to create a unique id. In Tezos, the same hash may represent different operations in case of delegation.
|
|
78
78
|
const checkSet = new Set(tx.map(elt => `${elt.tx.hash}${elt.type}${elt.senders[0]}`));
|
|
79
79
|
expect(checkSet.size).toEqual(tx.length);
|
|
80
80
|
});
|
|
81
|
+
|
|
82
|
+
it("returns operations from latest, but in asc order", async () => {
|
|
83
|
+
// When
|
|
84
|
+
const [txDesc] = await module.listOperations(address, { minHeight: 0, order: "desc" });
|
|
85
|
+
|
|
86
|
+
// Then
|
|
87
|
+
// Check if the result is sorted in ascending order
|
|
88
|
+
expect(txDesc[0].tx.block.height).toBeGreaterThanOrEqual(
|
|
89
|
+
txDesc[txDesc.length - 1].tx.block.height,
|
|
90
|
+
);
|
|
91
|
+
});
|
|
81
92
|
});
|
|
82
93
|
|
|
83
94
|
describe("lastBlock", () => {
|
package/src/api/index.test.ts
CHANGED
|
@@ -57,7 +57,7 @@ describe("get operations", () => {
|
|
|
57
57
|
|
|
58
58
|
it("could return no operation", async () => {
|
|
59
59
|
logicGetTransactions.mockResolvedValue([[], ""]);
|
|
60
|
-
const [operations, token] = await api.listOperations("addr", { minHeight: 100 });
|
|
60
|
+
const [operations, token] = await api.listOperations("addr", { minHeight: 100, order: "asc" });
|
|
61
61
|
expect(operations).toEqual([]);
|
|
62
62
|
expect(token).toEqual("");
|
|
63
63
|
});
|
|
@@ -81,11 +81,11 @@ describe("get operations", () => {
|
|
|
81
81
|
recipients: ["tz1Recipient"],
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
it("
|
|
84
|
+
it("only does 1 iteration", async () => {
|
|
85
85
|
logicGetTransactions.mockResolvedValue([[op], "888"]);
|
|
86
|
-
const [operations, token] = await api.listOperations("addr", { minHeight: 100 });
|
|
87
|
-
expect(logicGetTransactions).toHaveBeenCalledTimes(
|
|
88
|
-
expect(operations.length).toBe(
|
|
86
|
+
const [operations, token] = await api.listOperations("addr", { minHeight: 100, order: "asc" });
|
|
87
|
+
expect(logicGetTransactions).toHaveBeenCalledTimes(1);
|
|
88
|
+
expect(operations.length).toBe(1);
|
|
89
89
|
expect(token).toEqual("888");
|
|
90
90
|
});
|
|
91
91
|
});
|
package/src/api/index.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
Reward,
|
|
11
11
|
Stake,
|
|
12
12
|
} from "@ledgerhq/coin-framework/api/index";
|
|
13
|
-
import { log } from "@ledgerhq/logs";
|
|
14
13
|
import coinConfig, { type TezosConfig } from "../config";
|
|
15
14
|
import {
|
|
16
15
|
broadcast,
|
|
@@ -131,62 +130,15 @@ async function estimate(transactionIntent: TransactionIntent): Promise<TezosFeeE
|
|
|
131
130
|
};
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
type PaginationState = {
|
|
135
|
-
readonly pageSize: number;
|
|
136
|
-
readonly maxIterations: number; // a security to avoid infinite loop
|
|
137
|
-
currentIteration: number;
|
|
138
|
-
readonly minHeight: number;
|
|
139
|
-
continueIterations: boolean;
|
|
140
|
-
nextCursor?: string;
|
|
141
|
-
accumulator: Operation[];
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
async function fetchNextPage(address: string, state: PaginationState): Promise<PaginationState> {
|
|
145
|
-
const [operations, newNextCursor] = await listOperations(address, {
|
|
146
|
-
limit: state.pageSize,
|
|
147
|
-
token: state.nextCursor,
|
|
148
|
-
sort: "Ascending",
|
|
149
|
-
minHeight: state.minHeight,
|
|
150
|
-
});
|
|
151
|
-
const newCurrentIteration = state.currentIteration + 1;
|
|
152
|
-
let continueIteration = newNextCursor !== "";
|
|
153
|
-
if (newCurrentIteration >= state.maxIterations) {
|
|
154
|
-
log("coin:tezos", "(api/operations): max iterations reached", state.maxIterations);
|
|
155
|
-
continueIteration = false;
|
|
156
|
-
}
|
|
157
|
-
const accumulated = operations.concat(state.accumulator);
|
|
158
|
-
return {
|
|
159
|
-
...state,
|
|
160
|
-
continueIterations: continueIteration,
|
|
161
|
-
currentIteration: newCurrentIteration,
|
|
162
|
-
nextCursor: newNextCursor,
|
|
163
|
-
accumulator: accumulated,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
async function operationsFromHeight(
|
|
168
|
-
address: string,
|
|
169
|
-
start: number,
|
|
170
|
-
): Promise<[Operation[], string]> {
|
|
171
|
-
const firstState: PaginationState = {
|
|
172
|
-
pageSize: 200,
|
|
173
|
-
maxIterations: 10,
|
|
174
|
-
currentIteration: 0,
|
|
175
|
-
minHeight: start,
|
|
176
|
-
continueIterations: true,
|
|
177
|
-
accumulator: [],
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
let state = await fetchNextPage(address, firstState);
|
|
181
|
-
while (state.continueIterations) {
|
|
182
|
-
state = await fetchNextPage(address, state);
|
|
183
|
-
}
|
|
184
|
-
return [state.accumulator, state.nextCursor || ""];
|
|
185
|
-
}
|
|
186
|
-
|
|
187
133
|
async function operations(
|
|
188
134
|
address: string,
|
|
189
|
-
pagination: Pagination = { minHeight: 0 },
|
|
135
|
+
pagination: Pagination = { minHeight: 0, order: "asc" },
|
|
190
136
|
): Promise<[Operation[], string]> {
|
|
191
|
-
|
|
137
|
+
const [operations, newNextCursor] = await listOperations(address, {
|
|
138
|
+
limit: 200,
|
|
139
|
+
token: pagination.lastPagingToken,
|
|
140
|
+
sort: pagination.order === "asc" ? "Ascending" : "Descending",
|
|
141
|
+
minHeight: pagination.minHeight,
|
|
142
|
+
});
|
|
143
|
+
return [operations, newNextCursor || ""];
|
|
192
144
|
}
|
|
@@ -4,7 +4,7 @@ import prepareTransaction from "./prepareTransaction";
|
|
|
4
4
|
import { faker } from "@faker-js/faker";
|
|
5
5
|
import coinConfig, { TezosCoinConfig } from "../config";
|
|
6
6
|
import { mockConfig } from "../test/config";
|
|
7
|
-
import { COST_PER_BYTE,
|
|
7
|
+
import { COST_PER_BYTE, getRevealFee } from "@taquito/taquito";
|
|
8
8
|
|
|
9
9
|
const mockTezosEstimate = jest.fn();
|
|
10
10
|
jest.mock("../logic/tezosToolkit", () => ({
|
|
@@ -172,14 +172,18 @@ describe("prepareTransaction", () => {
|
|
|
172
172
|
|
|
173
173
|
// Then
|
|
174
174
|
const gasLimit = 500; // hardcoded in the function
|
|
175
|
-
const computedFees = new BigNumber(
|
|
175
|
+
const computedFees = new BigNumber(
|
|
176
|
+
tezosEstimate.suggestedFeeMutez + getRevealFee(account.freshAddress),
|
|
177
|
+
);
|
|
176
178
|
|
|
177
179
|
const maxAmount = account.balance.minus(computedFees);
|
|
178
180
|
|
|
179
181
|
expect(newTx).toEqual({
|
|
180
182
|
...tx,
|
|
181
183
|
fees: new BigNumber(tezosEstimate.suggestedFeeMutez),
|
|
182
|
-
estimatedFees: new BigNumber(
|
|
184
|
+
estimatedFees: new BigNumber(
|
|
185
|
+
tezosEstimate.suggestedFeeMutez + getRevealFee(account.freshAddress),
|
|
186
|
+
),
|
|
183
187
|
gasLimit: new BigNumber(tezosEstimate.gasLimit),
|
|
184
188
|
storageLimit: new BigNumber(tezosEstimate.storageLimit),
|
|
185
189
|
amount: maxAmount.minus(gasLimit - (tezosEstimate.opSize + gasLimit * 0.1)),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BigNumber from "bignumber.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getRevealFee, OpKind } from "@taquito/taquito";
|
|
3
3
|
import { SignOperationEvent } from "@ledgerhq/types-live";
|
|
4
4
|
import buildSignOperation, { getOperationContents } from "./signOperation";
|
|
5
5
|
import config, { type TezosCoinConfig } from "../config";
|
|
@@ -260,7 +260,7 @@ describe("getOperationContents - revealed account", () => {
|
|
|
260
260
|
expect(contents).toStrictEqual([
|
|
261
261
|
{
|
|
262
262
|
kind: OpKind.REVEAL,
|
|
263
|
-
fee:
|
|
263
|
+
fee: getRevealFee(account.freshAddress).toString(),
|
|
264
264
|
gas_limit: "100",
|
|
265
265
|
storage_limit: "200",
|
|
266
266
|
source: "pkh",
|
|
@@ -2,7 +2,7 @@ import { craftTransaction, rawEncode } from "./craftTransaction";
|
|
|
2
2
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
3
3
|
import coinConfig from "../config";
|
|
4
4
|
import { OpKind } from "@taquito/rpc";
|
|
5
|
-
import {
|
|
5
|
+
import { getRevealFee } from "@taquito/taquito";
|
|
6
6
|
|
|
7
7
|
type TransactionType = "send" | "delegate" | "undelegate";
|
|
8
8
|
|
|
@@ -128,7 +128,7 @@ describe("craftTransaction", () => {
|
|
|
128
128
|
expect(result.contents).toEqual([
|
|
129
129
|
{
|
|
130
130
|
kind: OpKind.REVEAL,
|
|
131
|
-
fee:
|
|
131
|
+
fee: getRevealFee(account.address).toString(),
|
|
132
132
|
gas_limit: "100",
|
|
133
133
|
storage_limit: "0",
|
|
134
134
|
source: publicKey.publicKeyHash,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type OperationContents, OpKind } from "@taquito/rpc";
|
|
2
|
-
import {
|
|
2
|
+
import { getRevealFee } from "@taquito/taquito";
|
|
3
3
|
import coinConfig from "../config";
|
|
4
4
|
import { UnsupportedTransactionMode } from "../types/errors";
|
|
5
5
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
@@ -48,7 +48,7 @@ export async function craftTransaction(
|
|
|
48
48
|
const revealGasLimit = Math.max(revealFees?.gasLimit || 0, minRevealGasLimit);
|
|
49
49
|
contents.push({
|
|
50
50
|
kind: OpKind.REVEAL,
|
|
51
|
-
fee:
|
|
51
|
+
fee: getRevealFee(address).toString(),
|
|
52
52
|
//TODO: use instead of previous line when this PR will be validated, as the value change (don't forget to update the test too)
|
|
53
53
|
// fee: getRevealFee(address).toString(),
|
|
54
54
|
gas_limit: revealGasLimit.toString(),
|
|
@@ -34,8 +34,8 @@ describe("estimateFees", () => {
|
|
|
34
34
|
const result = await estimateFees({ account, transaction });
|
|
35
35
|
// Then
|
|
36
36
|
expect(result).toEqual({
|
|
37
|
-
estimatedFees: BigInt("
|
|
38
|
-
fees: BigInt("
|
|
37
|
+
estimatedFees: BigInt("825"),
|
|
38
|
+
fees: BigInt("491"),
|
|
39
39
|
gasLimit: BigInt("2169"),
|
|
40
40
|
storageLimit: BigInt("277"),
|
|
41
41
|
amount: BigInt("1000000"),
|
|
@@ -56,11 +56,11 @@ describe("estimateFees", () => {
|
|
|
56
56
|
|
|
57
57
|
// Then
|
|
58
58
|
expect(result).toEqual({
|
|
59
|
-
estimatedFees: BigInt("
|
|
60
|
-
fees: BigInt("
|
|
59
|
+
estimatedFees: BigInt("823"),
|
|
60
|
+
fees: BigInt("489"),
|
|
61
61
|
gasLimit: BigInt("2169"),
|
|
62
62
|
storageLimit: BigInt("277"),
|
|
63
|
-
amount: BigInt("
|
|
63
|
+
amount: BigInt("1934629"),
|
|
64
64
|
});
|
|
65
65
|
});
|
|
66
66
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DerivationType } from "@taquito/ledger-signer";
|
|
2
2
|
import { compressPublicKey } from "@taquito/ledger-signer/dist/lib/utils";
|
|
3
|
-
import { COST_PER_BYTE,
|
|
4
|
-
import {
|
|
3
|
+
import { COST_PER_BYTE, getRevealFee, ORIGINATION_SIZE, Estimate } from "@taquito/taquito";
|
|
4
|
+
import { b58Encode, PrefixV2 } from "@taquito/utils";
|
|
5
5
|
import { log } from "@ledgerhq/logs";
|
|
6
6
|
import { getTezosToolkit } from "./tezosToolkit";
|
|
7
7
|
import { TezosOperationMode } from "../types/model";
|
|
@@ -41,9 +41,9 @@ export async function estimateFees({
|
|
|
41
41
|
account: CoreAccountInfo;
|
|
42
42
|
transaction: CoreTransactionInfo;
|
|
43
43
|
}): Promise<EstimatedFees> {
|
|
44
|
-
const encodedPubKey =
|
|
44
|
+
const encodedPubKey = b58Encode(
|
|
45
45
|
compressPublicKey(Buffer.from(account.xpub || "", "hex"), DerivationType.ED25519),
|
|
46
|
-
|
|
46
|
+
PrefixV2.Ed25519PublicKey,
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
const tezosToolkit = getTezosToolkit();
|
|
@@ -81,7 +81,7 @@ export async function estimateFees({
|
|
|
81
81
|
mutez: true,
|
|
82
82
|
to: transaction.recipient,
|
|
83
83
|
amount: Number(amount),
|
|
84
|
-
storageLimit:
|
|
84
|
+
storageLimit: ORIGINATION_SIZE, // https://github.com/TezTech/eztz/blob/master/PROTO_003_FEES.md for originating an account
|
|
85
85
|
});
|
|
86
86
|
break;
|
|
87
87
|
case "delegate":
|
|
@@ -110,7 +110,7 @@ export async function estimateFees({
|
|
|
110
110
|
}
|
|
111
111
|
const maxAmount =
|
|
112
112
|
parseInt(account.balance.toString()) -
|
|
113
|
-
(totalFees + (account.revealed ? 0 :
|
|
113
|
+
(totalFees + (account.revealed ? 0 : getRevealFee(account.address)));
|
|
114
114
|
// NOTE: from https://github.com/ecadlabs/taquito/blob/a70c64c4b105381bb9f1d04c9c70e8ef26e9241c/integration-tests/contract-empty-implicit-account-into-new-implicit-account.spec.ts#L33
|
|
115
115
|
// Temporary fix, see https://gitlab.com/tezos/tezos/-/issues/1754
|
|
116
116
|
// we need to increase the gasLimit and fee returned by the estimation
|
|
@@ -134,7 +134,7 @@ export async function estimateFees({
|
|
|
134
134
|
estimation.storageLimit = BigInt(estimate.storageLimit);
|
|
135
135
|
estimation.estimatedFees = estimation.fees;
|
|
136
136
|
if (!account.revealed) {
|
|
137
|
-
estimation.estimatedFees = estimation.estimatedFees + BigInt(
|
|
137
|
+
estimation.estimatedFees = estimation.estimatedFees + BigInt(getRevealFee(account.address));
|
|
138
138
|
}
|
|
139
139
|
} catch (e) {
|
|
140
140
|
if (typeof e !== "object" || !e) throw e;
|
|
@@ -201,8 +201,8 @@ describe("listOperations", () => {
|
|
|
201
201
|
});
|
|
202
202
|
|
|
203
203
|
it("should order the results in descending order even if the sort option is set to ascending", async () => {
|
|
204
|
-
const op1 = { ...undelegate, level: "1" };
|
|
205
|
-
const op2 = { ...undelegate, level: "2" };
|
|
204
|
+
const op1 = { ...undelegate, level: "1", timestamp: "2022-09-12T01:00:00Z" };
|
|
205
|
+
const op2 = { ...undelegate, level: "2", timestamp: "2022-09-12T01:01:00Z" };
|
|
206
206
|
mockNetworkGetTransactions.mockResolvedValue([op1, op2]);
|
|
207
207
|
const [results, _] = await listOperations("any address", options);
|
|
208
208
|
expect(results.map(op => op.tx.block.height)).toEqual(["2", "1"]);
|
|
@@ -45,11 +45,10 @@ export async function listOperations(
|
|
|
45
45
|
const filteredOperations = operations
|
|
46
46
|
.filter(op => isAPITransactionType(op) || isAPIDelegationType(op) || isAPIRevealType(op))
|
|
47
47
|
.reduce((acc, op) => acc.concat(convertOperation(address, op)), [] as Operation[]);
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return [filteredOperations, nextToken];
|
|
48
|
+
const sortedOperations = filteredOperations.sort(
|
|
49
|
+
(a, b) => b.tx.date.getTime() - a.tx.date.getTime(),
|
|
50
|
+
);
|
|
51
|
+
return [sortedOperations, nextToken];
|
|
53
52
|
}
|
|
54
53
|
|
|
55
54
|
// note that "initiator" of APITransactionType is never used in the conversion
|